Skip to content

Commit 6b1b484

Browse files
committed
106~109 features and descriptor
1 parent 0b592fe commit 6b1b484

20 files changed

+288
-2
lines changed

Diff for: README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,8 @@ code_101 | [HOG Multiscale Detection](python/code_101/opencv_101.py) | ✏️
143143
code_102 | [HOG Extract Descriptor](python/code_102/opencv_102.py) | ✔️
144144
code_103 | [HOG Use Descriptors to Generate Sample Data](python/code_103/opencv_103.py) | ✔️
145145
code_104 | [(Detection Case)-HOG+SVM Train](python/code_104/opencv_104.py) | ✔️
146-
code_105 | [(Detection Case)-HOG+SVM Predict](python/code_105/opencv_105.py) | ✔️
146+
code_105 | [(Detection Case)-HOG+SVM Predict](python/code_105/opencv_105.py) | ✔️
147+
code_106 | [AKAZE Features and Descriptors](python/code_106) | ✔️
148+
code_107 | [Brisk Features and Descriptors](python/code_107) | ✔️
149+
code_108 | [GFTT Detector](python/code_108) | ✔️
150+
code_109 | [BLOB Feature Analysis](python/code_109) | ✔️

Diff for: README_CN.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,8 @@ code_101 | [HOG 多尺度检测](python/code_101/opencv_101.py) | ✏️
142142
code_102 | [HOG 提取描述子](python/code_102/opencv_102.py) | ✔️
143143
code_103 | [HOG 使用描述子生成样本数据](python/code_103/opencv_103.py) | ✔️
144144
code_104 | [(检测案例)-HOG+SVM 训练](python/code_104/opencv_104.py) | ✔️
145-
code_105 | [(检测案例)-HOG+SVM 预测](python/code_105/opencv_105.py) | ✔️
145+
code_105 | [(检测案例)-HOG+SVM 预测](python/code_105/opencv_105.py) | ✔️
146+
code_106 | [AKAZE 特征与描述子](python/code_106) | ✔️
147+
code_107 | [Brisk 特征与描述子](python/code_107) | ✔️
148+
code_108 | [GFTT关键点检测](python/code_108) | ✔️
149+
code_109 | [BLOB 特征分析](python/code_109) | ✔️

Diff for: python/code_106/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
### AKAZE特征与描述子
2+
3+
AKAZE特征提取算法是局部特征描述子算法,可以看成是SIFT算法的改进、采用非线性扩散滤波迭代来提取与构建尺度空间、采用与SIFT类似的方法寻找特征点、在描述子生成阶段采用ORB类似的方法生成描述子,但是描述子比ORB多了旋转不变性特征。
4+
5+
ORB采用LDB方法,AKAZE采用 M-LDB。
6+
7+
**代码:**
8+
9+
```python
10+
import cv2 as cv
11+
12+
box = cv.imread("box.png");
13+
box_in_sence = cv.imread("box_in_scene.png");
14+
cv.imshow("box", box)
15+
cv.imshow("box_in_sence", box_in_sence)
16+
17+
# 创建AKAZE特征检测器
18+
akaze = cv.AKAZE_create()
19+
kp1, des1 = akaze.detectAndCompute(box,None)
20+
kp2, des2 = akaze.detectAndCompute(box_in_sence,None)
21+
22+
# 暴力匹配
23+
bf = cv.BFMatcher(cv.NORM_HAMMING, crossCheck=True)
24+
matches = bf.match(des1,des2)
25+
26+
# 绘制匹配
27+
result = cv.drawMatches(box, kp1, box_in_sence, kp2, matches, None)
28+
cv.imshow("orb-match", result)
29+
cv.imwrite('orb-match.jpg', result)
30+
cv.waitKey(0)
31+
cv.destroyAllWindows()
32+
```
33+
34+
![](orb-match.jpg)

Diff for: python/code_106/box.png

49.5 KB
Loading

Diff for: python/code_106/box_in_scene.png

120 KB
Loading

Diff for: python/code_106/opencv_106.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import cv2 as cv
2+
3+
box = cv.imread("box.png");
4+
box_in_sence = cv.imread("box_in_scene.png");
5+
cv.imshow("box", box)
6+
cv.imshow("box_in_sence", box_in_sence)
7+
8+
# 创建AKAZE特征检测器
9+
akaze = cv.AKAZE_create()
10+
kp1, des1 = akaze.detectAndCompute(box,None)
11+
kp2, des2 = akaze.detectAndCompute(box_in_sence,None)
12+
13+
# 暴力匹配
14+
bf = cv.BFMatcher(cv.NORM_HAMMING, crossCheck=True)
15+
matches = bf.match(des1,des2)
16+
17+
# 绘制匹配
18+
result = cv.drawMatches(box, kp1, box_in_sence, kp2, matches, None)
19+
cv.imshow("orb-match", result)
20+
cv.imwrite('orb-match.jpg', result)
21+
cv.waitKey(0)
22+
cv.destroyAllWindows()
23+
24+

Diff for: python/code_106/orb-match.jpg

174 KB
Loading

Diff for: python/code_107/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
### Brisk特征提取与描述子匹配
2+
3+
BRISK(Binary robust invariant scalable keypoints)是一种基于尺度空间不变性类似ORB特征描述子的特征提取算法。BRISK主要步骤可以分为如下两步:
4+
1. 构建尺度空间金字塔实现关键点定位
5+
2. 根据关键点生成描述子
6+
7+
**代码:**
8+
9+
```python
10+
import cv2 as cv
11+
12+
box = cv.imread("box.png");
13+
box_in_sence = cv.imread("box_in_scene.png");
14+
cv.imshow("box", box)
15+
cv.imshow("box_in_sence", box_in_sence)
16+
17+
# 创建BRISK特征检测器
18+
brisk = cv.BRISK_create()
19+
kp1, des1 = brisk.detectAndCompute(box,None)
20+
kp2, des2 = brisk.detectAndCompute(box_in_sence,None)
21+
22+
# 暴力匹配
23+
bf = cv.BFMatcher(cv.NORM_HAMMING, crossCheck=True)
24+
matches = bf.match(des1,des2)
25+
26+
# 绘制匹配
27+
result = cv.drawMatches(box, kp1, box_in_sence, kp2, matches, None)
28+
cv.imshow("orb-match", result)
29+
cv.imwrite('orb-match.jpg', result)
30+
cv.waitKey(0)
31+
cv.destroyAllWindows()
32+
```
33+
34+
![](orb-match.jpg)

Diff for: python/code_107/box.png

49.5 KB
Loading

Diff for: python/code_107/box_in_scene.png

120 KB
Loading

Diff for: python/code_107/opencv_107.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import cv2 as cv
2+
3+
box = cv.imread("box.png");
4+
box_in_sence = cv.imread("box_in_scene.png");
5+
cv.imshow("box", box)
6+
cv.imshow("box_in_sence", box_in_sence)
7+
8+
# 创建BRISK特征检测器
9+
brisk = cv.BRISK_create()
10+
kp1, des1 = brisk.detectAndCompute(box,None)
11+
kp2, des2 = brisk.detectAndCompute(box_in_sence,None)
12+
13+
# 暴力匹配
14+
bf = cv.BFMatcher(cv.NORM_HAMMING, crossCheck=True)
15+
matches = bf.match(des1,des2)
16+
17+
# 绘制匹配
18+
result = cv.drawMatches(box, kp1, box_in_sence, kp2, matches, None)
19+
cv.imshow("orb-match", result)
20+
cv.imwrite('orb-match.jpg', result)
21+
cv.waitKey(0)
22+
cv.destroyAllWindows()

Diff for: python/code_107/orb-match.jpg

184 KB
Loading

Diff for: python/code_108/GFTT-Keypoint-Detect.jpg

57.1 KB
Loading

Diff for: python/code_108/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### 特征提取之关键点检测 - GFTTDetector
2+
3+
该方法是基于shi-tomas角点检测变化而来的一种特征提取方法,OpenCV创建该检测器的API与goodfeaturetotrack的API参数极其类似:
4+
```
5+
Ptr<GFTTDetector> cv::GFTTDetector::create(
6+
int maxCorners = 1000,
7+
double qualityLevel = 0.01,
8+
double minDistance = 1,
9+
int blockSize = 3,
10+
bool useHarrisDetector = false,
11+
double k = 0.04
12+
)
13+
```
14+
唯一不同的,该方法返回一个指针。
15+
16+
PS:
17+
>需要注意的是该方法无法提取描述子,只支持提取关键点!
18+
19+
**代码:**
20+
21+
```python
22+
import cv2 as cv
23+
24+
25+
image = cv.imread("hist_02.jpg");
26+
cv.imshow("input", image)
27+
28+
# 创建GFTT特征检测器
29+
gftt = cv.GFTTDetector_create(100, 0.01,1, 3, False, 0.04)
30+
kp1 = gftt.detect(image,None)
31+
result = cv.drawKeypoints(image, kp1, None, (0, 255, 0), cv.DrawMatchesFlags_DEFAULT)
32+
33+
cv.imshow("GFTT-Keypoint-Detect", result)
34+
cv.imwrite("GFTT-Keypoint-Detect.jpg", result)
35+
cv.waitKey(0)
36+
cv.destroyAllWindows()
37+
```
38+
39+
![](GFTT-Keypoint-Detect.jpg)

Diff for: python/code_108/hist_02.jpg

29 KB
Loading

Diff for: python/code_108/opencv_108.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import cv2 as cv
2+
3+
4+
image = cv.imread("hist_02.jpg");
5+
cv.imshow("input", image)
6+
7+
# 创建GFTT特征检测器
8+
gftt = cv.GFTTDetector_create(100, 0.01,1, 3, False, 0.04)
9+
kp1 = gftt.detect(image,None)
10+
result = cv.drawKeypoints(image, kp1, None, (0, 255, 0), cv.DrawMatchesFlags_DEFAULT)
11+
12+
cv.imshow("GFTT-Keypoint-Detect", result)
13+
cv.imwrite("GFTT-Keypoint-Detect.jpg", result)
14+
cv.waitKey(0)
15+
cv.destroyAllWindows()

Diff for: python/code_109/README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
### BLOB特征分析 – simpleblobdetector使用
2+
3+
BLOB是图像中灰度块的一种专业称呼,更加变通一点的可以说它跟我们前面二值图像分析的联通组件类似,通过特征提取中的SimpleBlobDetector可以实现常见的各种灰度BLOB对象组件检测与分离。使用该检测器的时候,可以根据需要输入不同参数,得到的结果跟输入的参数息息相关。常见的BLOB分析支持如下:
4+
- 根据BLOB面积过滤
5+
- 根据灰度/颜色值过滤
6+
- 根据圆度过滤
7+
- 根据长轴与短轴过滤
8+
- 根据凹凸进行过滤
9+
10+
**参数列表:**
11+
```
12+
SimpleBlobDetector::Params::Params()
13+
bool filterByArea
14+
bool filterByCircularity
15+
bool filterByColor
16+
bool filterByConvexity
17+
bool filterByInertia
18+
float maxArea
19+
float maxCircularity
20+
float maxConvexity
21+
float maxInertiaRatio
22+
float maxThreshold
23+
float minArea
24+
float minCircularity
25+
float minConvexity
26+
float minDistBetweenBlobs
27+
float minInertiaRatio
28+
```
29+
30+
代码:
31+
```python
32+
import cv2 as cv
33+
import numpy as np
34+
35+
# load image
36+
frame = cv.imread("zhifang_ball.png")
37+
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
38+
params = cv.SimpleBlobDetector_Params()
39+
40+
# Change thresholds
41+
params.minThreshold = 0;
42+
params.maxThreshold = 256;
43+
44+
# Filter by Area.
45+
params.filterByArea = True
46+
params.minArea = 100
47+
48+
# Filter by Circularity
49+
params.filterByCircularity = True
50+
params.minCircularity = 0.1
51+
52+
# Filter by Convexity
53+
params.filterByConvexity = True
54+
params.minConvexity = 0.5
55+
56+
# Filter by Inertia
57+
params.filterByInertia = True
58+
params.minInertiaRatio = 0.5
59+
60+
detector = cv.SimpleBlobDetector_create(params)
61+
62+
# Detect blobs.
63+
cv.imshow("input", frame)
64+
keypoints = detector.detect(gray)
65+
result = cv.drawKeypoints(frame, keypoints, None, (0, 0, 255), cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
66+
cv.imshow("result", result)
67+
cv.imwrite("result.png", result)
68+
cv.waitKey(0)
69+
cv.destroyAllWindows()
70+
```
71+
72+
![](result.png)

Diff for: python/code_109/opencv_109.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import cv2 as cv
2+
import numpy as np
3+
4+
# load image
5+
frame = cv.imread("zhifang_ball.png")
6+
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
7+
params = cv.SimpleBlobDetector_Params()
8+
9+
# Change thresholds
10+
params.minThreshold = 0;
11+
params.maxThreshold = 256;
12+
13+
# Filter by Area.
14+
params.filterByArea = True
15+
params.minArea = 100
16+
17+
# Filter by Circularity
18+
params.filterByCircularity = True
19+
params.minCircularity = 0.1
20+
21+
# Filter by Convexity
22+
params.filterByConvexity = True
23+
params.minConvexity = 0.5
24+
25+
# Filter by Inertia
26+
params.filterByInertia = True
27+
params.minInertiaRatio = 0.5
28+
29+
detector = cv.SimpleBlobDetector_create(params)
30+
31+
# Detect blobs.
32+
cv.imshow("input", frame)
33+
keypoints = detector.detect(gray)
34+
result = cv.drawKeypoints(frame, keypoints, None, (0, 0, 255), cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
35+
cv.imshow("result", result)
36+
cv.imwrite("result.png", result)
37+
cv.waitKey(0)
38+
cv.destroyAllWindows()

Diff for: python/code_109/result.png

434 KB
Loading

Diff for: python/code_109/zhifang_ball.png

452 KB
Loading

0 commit comments

Comments
 (0)