当前位置:网站首页>[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
边栏推荐
- JS 将伪数组转换成数组
- 微软提出CodeT:代码生成新SOTA,20个点的性能提升
- More accurate and efficient segmentation of organs-at-risk in radiotherapy with Convolutional Neural
- The larger the convolution kernel, the stronger the performance? An interpretation of replknet model
- Detailed explanation of flex box
- [problem solving] org.apache.ibatis.exceptions PersistenceException: Error building SqlSession. 1-byte word of UTF-8 sequence
- JS convert pseudo array to array
- 深度学习MEMC插帧论文列表paper list
- 想要白嫖正则大全是吧?这一次给你个够!
- Use vsftpd service to transfer files (anonymous user authentication, local user authentication, virtual user authentication)
猜你喜欢

微软提出CodeT:代码生成新SOTA,20个点的性能提升

感动中国人物刘盛兰
![[shutter -- layout] stacked layout (stack and positioned)](/img/01/c588f75313580063cf32cc01677600.jpg)
[shutter -- layout] stacked layout (stack and positioned)

Azure Devops (XIV) use azure's private nuget warehouse
![[advanced C language] dynamic memory management](/img/b7/6586b35500eb8f39a3ea8c125fb572.png)
[advanced C language] dynamic memory management

485通讯( 详解 )

Moving Chinese figure liushenglan

Selenium use -- installation and testing

零基础学习CANoe Panel(14)——二极管( LED Control )和液晶屏(LCD Control)

【历史上的今天】7 月 25 日:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone
随机推荐
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 supplementary problem solution (g, J, K, l)
零基础学习CANoe Panel(14)——二极管( LED Control )和液晶屏(LCD Control)
Synergetic process
力扣 83双周赛T4 6131.不可能得到的最短骰子序列、303 周赛T4 6127.优质数对的数目
Requirements specification template
Microsoft azure and Analysys jointly released the report "Enterprise Cloud native platform driven digital transformation"
conda常用命令:安装,更新,创建,激活,关闭,查看,卸载,删除,清理,重命名,换源,问题
[机器学习] 实验笔记 – 表情识别(emotion recognition)
I register the absolutely deleted data in the source sqlserver, send it to maxcomputer, and write the absolute data when cleaning the data
Moving Chinese figure liushenglan
Mysql 远程连接权限错误1045问题
Ministry of Public Security: the international community generally believes that China is one of the safest countries in the world
Selenium uses -- XPath and analog input and analog click collaboration
什么是CI/CD?
零基础学习CANoe Panel(13)—— 滑条(TrackBar )
web安全入门-UDP测试与防御
吕蒙正《破窑赋》
I want to ask whether DMS has the function of regularly backing up a database?
我想问DMS有没有定时备份某一个数据库的功能?
go : gin 自定义日志输出格式