当前位置:网站首页>[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
边栏推荐
- Software testing interview question: Please list the testing methods of several items?
- [high concurrency] deeply analyze the execution process of worker threads in the thread pool through the source code
- Table partition of MySQL
- Make a general cascade dictionary selection control based on jeecg -dictcascadeuniversal
- 零基础学习CANoe Panel(14)——二极管( LED Control )和液晶屏(LCD Control)
- Word style and multi-level list setting skills (II)
- 请问一下,使用数据集成从postgreSQL导数据到Mysql数据库,有部分数据的字段中出现emoj
- 我在源头SQLServer里面登记绝对删除的数据,传到MaxComputer,在数据清洗的时候写绝对
- Plus SBOM: assembly line BOM pbom
- Keeping MySQL highly available
猜你喜欢

More accurate and efficient segmentation of organs-at-risk in radiotherapy with Convolutional Neural

如何用因果推断和实验驱动用户增长? | 7月28日TF67

Zero basic learning canoe panel (12) -- progress bar

7行代码让B站崩溃3小时,竟因“一个诡计多端的0”

LeetCode 1184. 公交站间的距离

【Flutter -- 布局】层叠布局(Stack和Positioned)
![[shutter -- layout] stacked layout (stack and positioned)](/img/01/c588f75313580063cf32cc01677600.jpg)
[shutter -- layout] stacked layout (stack and positioned)

Selenium use -- installation and testing
软件测试流程包括哪些内容?测试方法有哪些?

【AI4Code】《CodeBERT: A Pre-Trained Model for Programming and Natural Languages》 EMNLP 2020
随机推荐
零基础学习CANoe Panel(13)—— 滑条(TrackBar )
R language uses wilcox The test function performs Wilcox signed rank test to obtain the confidence interval of the population median (the default output result includes the confidence interval of 95%
Deployment of Apache website services and implementation of access control
Substance Designer 2021软件安装包下载及安装教程
ECCV2022 | TransGrasp类级别抓取姿态迁移
[fluent -- example] case 1: comprehensive example of basic components and layout components
The larger the convolution kernel, the stronger the performance? An interpretation of replknet model
Clickhouse notes 03-- grafana accesses Clickhouse
A turbulent life
Spirng @Conditional 条件注解的使用
程序员奶爸自制AI喂奶检测仪,预判宝宝饿点,不让哭声影响老婆睡眠
shell基础知识(退出控制、输入输出等)
零基础学习CANoe Panel(15)—— 文本输出(CAPL Output View )
力扣 83双周赛T4 6131.不可能得到的最短骰子序列、303 周赛T4 6127.优质数对的数目
【OpenCV 例程 300篇】239. Harris 角点检测之精确定位(cornerSubPix)
Zero basic learning canoe panel (14) -- led control and LCD control
“蔚来杯“2022牛客暑期多校训练营2 补题题解(G、J、K、L)
Leetcode 0133. clone diagram
Jenkins configuration pipeline
跌荡的人生