当前位置:网站首页>[300 opencv routines] 239. accurate positioning of Harris corner detection (cornersubpix)
[300 opencv routines] 239. accurate positioning of Harris corner detection (cornersubpix)
2022-07-25 12:55:00 【YouCans】
『youcans Of OpenCV routine 300 piece - General catalogue 』
【youcans Of OpenCV routine 300 piece 】239. Harris Accurate positioning of corner detection (cornerSubPix)
An angle is a rapid change in the direction of a straight line . A corner is usually defined as the intersection of two edges , In other words, the neighborhood of the corner should have the boundaries of two different regions in different directions .
Angle is a highly effective feature . Corner detection (Corner Detection) It is widely used in motion detection 、 Image matching 、 Video tracking 、 3D reconstruction and target recognition .
6.2 OpenCV Medium Harris Angle detector
OpenCV Provided in Harris Corner detection function cv.cornerHarris().
Function description :
cv.cornerHarris(src, blockSize, ksize, k[, dst=None, borderType=BORDER_DEFAULT] ) → dst
function cv.cornerHarris function Harris Angle detector .
For each pixel (x,y) Calculate the gradient covariance matrix M ( x , y ) M(x,y) M(x,y). Then calculate the characteristics :
d s t ( x , y ) = d e t M ( x , y ) − k ⋅ ( t r M ( x , y ) ) 2 dst(x,y) = det M^{(x,y)} - k \cdot (tr M^{(x,y)})^2 dst(x,y)=detM(x,y)−k⋅(trM(x,y))2
Then the corner is a local maximum in the feature response image . Define when in practice R Greater than the set threshold , And the point that is the local maximum is the corner .
Parameter description :
- src: The input image , Single channel 8 Bit image or floating point image
- dst: Output image ,Harris Detector response , Size and src identical , The format is CV_32FC1
- blockSize: neighborhood size
- ksize:Sobel Aperture parameter of the operator
- k:Harris Detector adjustment parameters , Usually take 0.04~0.06
- borderType: Boundary extension type
- cv.BORDER_CONSTANT
- cv.BORDER_REPLICATE
- cv.BORDER_REFLECT
- cv.BORDER_REFLECT_101
- cv.BORDER_TRANSPARENT
routine 14.20:Harris Accurate positioning of corner detection (cornerSubPix)
OpenCV Provides functions cv.cornerSubPix() Used to refine corner position , The corner position detected with sub-pixel accuracy is refined .
cv.cornerSubPix(image, corners, winSize, zeroZone, criteria[, ]) → corners
function cv.cornerSubPix Used to refine corner position . The algorithm sets the centroid of the angle as the new center , Iterative calculation to obtain the sub-pixel precise position of corner points or radial saddle points .
Parameter description :
- image: The input image , Single channel 8 Bit image or floating point image
- corners: The set of real Numbers , When entering, it is the initial coordinate of the corner , When output, it is the fine coordinate of the corner
- winSize: Half the side length of the search window , Such as winSize = Size(5,5) Indicates that the search window is 11*11
- zeroZone: Half the size of the dead zone in the middle of the search area ,(-1,-1) Indicates that there is no dead zone
- criteria: Criteria for the termination of iterative process , The number of iterations reaches the set value maxCount Or the corner displacement is less than the set threshold epsilon
matters needing attention :
- Input/output parameter corners The format of must be converted to real numbers , Is not an integer .
- function cv.cornerSubPix() Used to refine corner position , It can not only be used for Harris Refine the corner detection results , It can also be used to refine the detection results of other corners .
# 14.20 Harris Accurate positioning of corner detection (cornerSubPix)
img = cv2.imread("../images/sign01.png", flags=1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # (600, 540)
print(img.shape) # (600, 836, 3)
# Corner detection
gray = np.float32(gray) # uint8,float32 All support
dst = cv2.cornerHarris(gray, 2, 3, 0.04) # Harris Corner detection
_, dst = cv2.threshold(dst, 0.01 * dst.max(), 255, 0) # Extract corners
dst = np.uint8(dst) # (600, 836)
# Corner detection result image
imgCorner = np.copy(img)
imgCorner[:,:,2] = cv2.bitwise_or(imgCorner[:,:,2], dst) # Filter corners , The red mark
# Fine positioning of the detected corners
ret, labels, stats, centroids = cv2.connectedComponentsWithStats(dst) # Detect the connected area
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.001) # Stopping criterion
fineCorners = cv2.cornerSubPix(gray, np.float32(centroids), (5,5), (-1,-1), criteria) # (144, 2)
# Fine positioning detection image
imgFineCorners = np.copy(img)
centroids = centroids.astype(np.int) # The centroid of the connected region (x,y)
fineCorners = fineCorners.astype(np.int) # Finely positioned corners (x,y)
imgFineCorners[centroids[:, 1], centroids[:, 0]] = [0,255,0] # Harris Detection location , green
imgFineCorners[fineCorners[:, 1], fineCorners[:, 0]] = [0,0,255] # Fine detection position , Red
plt.figure(figsize=(9, 6))
plt.subplot(131), plt.axis('off'), plt.title("Origin")
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.subplot(132), plt.axis('off'), plt.title("Harris corners")
plt.imshow(cv2.cvtColor(imgCorner[115:195, 90:200], cv2.COLOR_BGR2RGB))
plt.subplot(133), plt.axis('off'), plt.title("cornerSubPix")
plt.imshow(cv2.cvtColor(imgFineCorners[115:195, 90:200], cv2.COLOR_BGR2RGB))
plt.tight_layout()
plt.show()

【 At the end of this section 】
Copyright notice :
[email protected] Original works , Reprint must be marked with the original link :(https://blog.csdn.net/youcans/article/details/125821029)
Copyright 2022 youcans, XUPT
Crated:2022-7-15238. OpenCV Medium Harris Corner detection
239. Harris Accurate positioning of corner detection (cornerSubPix)
240. OpenCV Medium Shi-Tomas Corner detection
边栏推荐
- Detailed explanation of switch link aggregation [Huawei ENSP]
- Chapter5 : Deep Learning and Computational Chemistry
- If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
- 2022河南萌新联赛第(三)场:河南大学 I - 旅行
- 零基础学习CANoe Panel(12)—— 进度条(Progress Bar)
- 7行代码让B站崩溃3小时,竟因“一个诡计多端的0”
- 状态(State)模式
- Plus SBOM: assembly line BOM pbom
- Zero basic learning canoe panel (13) -- trackbar
- 需求规格说明书模板
猜你喜欢
软件测试面试题目:请你列举几个物品的测试方法怎么说?
![[shutter -- layout] stacked layout (stack and positioned)](/img/01/c588f75313580063cf32cc01677600.jpg)
[shutter -- layout] stacked layout (stack and positioned)

感动中国人物刘盛兰

想要做好软件测试,可以先了解AST、SCA和渗透测试

clickhouse笔记03-- Grafana 接入ClickHouse

Zero basic learning canoe panel (15) -- CAPL output view

【AI4Code】《GraphCodeBERT: Pre-Training Code Representations With DataFlow》 ICLR 2021

【AI4Code】《CodeBERT: A Pre-Trained Model for Programming and Natural Languages》 EMNLP 2020

【问题解决】org.apache.ibatis.exceptions.PersistenceException: Error building SqlSession.1 字节的 UTF-8 序列的字

Microsoft azure and Analysys jointly released the report "Enterprise Cloud native platform driven digital transformation"
随机推荐
需求规格说明书模板
shell基础知识(退出控制、输入输出等)
MySQL implements inserting data from one table into another table
What is ci/cd?
485 communication (detailed explanation)
想要做好软件测试,可以先了解AST、SCA和渗透测试
State mode
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
使用vsftpd服务传输文件(匿名用户认证、本地用户认证、虚拟用户认证)
【C语言进阶】动态内存管理
【AI4Code】《CoSQA: 20,000+ Web Queries for Code Search and Question Answering》 ACL 2021
论文解读(MaskGAE)《MaskGAE: Masked Graph Modeling Meets Graph Autoencoders》
Plus SBOM: assembly line BOM pbom
软件测试流程包括哪些内容?测试方法有哪些?
公安部:国际社会普遍认为中国是世界上最安全的国家之一
Kyligence 入选 Gartner 2022 数据管理技术成熟度曲线报告
软件测试面试题目:请你列举几个物品的测试方法怎么说?
Use of hystrix
Leetcode 0133. clone diagram
Zero basic learning canoe panel (14) -- led control and LCD control