qgyd2021 commited on
Commit
9f02e35
·
1 Parent(s): cd535a8

[update]edit readme

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. README.md +70 -0
.gitignore CHANGED
@@ -1,3 +1,4 @@
 
1
  .idea/
2
  .git/
3
 
 
1
+
2
  .idea/
3
  .git/
4
 
README.md CHANGED
@@ -9,4 +9,74 @@ size_categories:
9
  ## WeChat 或 QQ 图标检测.
10
 
11
  任务: 从图像中检测出 WeChat 或 QQ 图标的位置.
 
12
  方法: 基于 OpenCV 库, 通过 SIFT 或 SURF 图像特征作检测.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  ## WeChat 或 QQ 图标检测.
10
 
11
  任务: 从图像中检测出 WeChat 或 QQ 图标的位置.
12
+
13
  方法: 基于 OpenCV 库, 通过 SIFT 或 SURF 图像特征作检测.
14
+
15
+ ```text
16
+ 由于 SURF 和 SIFT 算法有专利限制,
17
+ 其安装环境是:
18
+ python==3.6.5
19
+ opencv-contrib-python==3.4.2.16
20
+
21
+ 由于 huggingface 的 space 中的 python 为 3.10 版本, 已无法安装此 opencv 库.
22
+
23
+ 你也可以在这里找到相关代码, 但这个库已经不再维护了.
24
+
25
+ https://github.com/tianxing1994/OpenCV/
26
+ dir: 练习实例 -> SIFT_SURF 图像特征作目标检测(在图片中检测出 QQ 图标的位置)
27
+
28
+ 因此将实现方法记录如下:
29
+
30
+ ```
31
+
32
+ 实现步骤:
33
+
34
+ (1)采用 opencv 库的 SIFT 或 SURF 图像特征 `cv.xfeatures2d.SIFT_create()` 对目标区域生成特征点向量.
35
+
36
+ (2)为减少特征点数量, 对所有的特征点向量做聚类, 将聚类中心作为特征点, 得到 `template_descriptors`.
37
+
38
+ (3)计算目标图像中的所有 SIFT 或 SURF 图像特征点. 得到 `scene_descriptors`.
39
+
40
+ (4) 采用 `flann.knnMatch` 方法进行特征点匹配, (如果最近匹配距离比第二匹配距离的 0.7 倍还要小, 则认为这个点是 `good_match`, 即认为好的特征点具有独特征, 不会有其它更相似的点).
41
+
42
+ (5)最小要有3个 `good_match` 才认为图标匹配成功.
43
+
44
+ (6)最后根据 `good_match` 点的分布计算图标的中心, 我的做法是计算点集中心和平均距离, 将大于平均距离的点丢弃, 重复此过程, 直到半径小于阈值.
45
+
46
+
47
+ 涉及到的方法有:
48
+ ```python
49
+ import cv2 as cv
50
+
51
+ sift = cv.xfeatures2d.SIFT_create()
52
+
53
+ index_params = dict(algorithm=0, trees=5)
54
+ search_params = dict(checks=50)
55
+ flann = cv.FlannBasedMatcher(index_params, search_params)
56
+
57
+ keypoints, descriptors = sift.detectAndCompute(image, None)
58
+
59
+ matches = flann.knnMatch(
60
+ queryDescriptors=template_descriptors,
61
+ trainDescriptors=scene_descriptors,
62
+ k=2
63
+ )
64
+
65
+ good_matches = []
66
+ for m, n in matches:
67
+ if m.distance < 0.7 * n.distance:
68
+ good_matches.append(m)
69
+
70
+ k = 3
71
+ if len(good_matches) > k:
72
+ print(good_matches)
73
+ else:
74
+ print("Not enough matches are found - %d/%d" % (len(good_matches), k))
75
+
76
+
77
+ ```
78
+
79
+ 参考链接:
80
+ ```text
81
+ https://docs.opencv.org/3.0-beta/index.html
82
+ ```