-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
90 lines (73 loc) · 2.45 KB
/
Copy pathtest_setup.py
File metadata and controls
90 lines (73 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
"""
测试脚本 - 验证所有依赖包是否正确安装
"""
def test_imports():
"""测试所有必要的包是否能正常导入"""
try:
import cv2
print(f"✓ OpenCV 版本: {cv2.__version__}")
except ImportError as e:
print(f"✗ OpenCV 导入失败: {e}")
return False
try:
import numpy as np
print(f"✓ NumPy 版本: {np.__version__}")
except ImportError as e:
print(f"✗ NumPy 导入失败: {e}")
return False
try:
import skimage
print(f"✓ scikit-image 版本: {skimage.__version__}")
except ImportError as e:
print(f"✗ scikit-image 导入失败: {e}")
return False
try:
from PIL import Image
print(f"✓ Pillow 已安装")
except ImportError as e:
print(f"✗ Pillow 导入失败: {e}")
return False
try:
import tqdm
print(f"✓ tqdm 版本: {tqdm.__version__}")
except ImportError as e:
print(f"✗ tqdm 导入失败: {e}")
return False
return True
def test_opencv_functionality():
"""测试 OpenCV 基本功能"""
try:
import cv2
import numpy as np
# 创建一个测试图像
test_img = np.zeros((100, 100, 3), dtype=np.uint8)
test_img[:, :] = [255, 0, 0] # 蓝色图像
# 转换为HSV
hsv = cv2.cvtColor(test_img, cv2.COLOR_BGR2HSV)
# 计算直方图
hist = cv2.calcHist([hsv], [0, 1, 2], None, [50, 60, 60], [0, 180, 0, 256, 0, 256])
print("✓ OpenCV 图像处理功能正常")
return True
except Exception as e:
print(f"✗ OpenCV 功能测试失败: {e}")
return False
if __name__ == "__main__":
print("=" * 50)
print("图片相似度检查工具 - 依赖测试")
print("=" * 50)
# 测试导入
print("\n1. 测试包导入...")
import_success = test_imports()
# 测试 OpenCV 功能
print("\n2. 测试 OpenCV 功能...")
opencv_success = test_opencv_functionality()
# 总结
print("\n" + "=" * 50)
if import_success and opencv_success:
print("✓ 所有测试通过!环境配置成功。")
print("\n你现在可以运行主程序了:")
print("python main.py <参考图片> <搜索文件夹>")
else:
print("✗ 部分测试失败,请检查安装。")
print("=" * 50)