前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >OpenCV 角点检测

OpenCV 角点检测

作者头像
用户6021899
发布2020-05-20 23:38:14
6090
发布2020-05-20 23:38:14
举报

给棋盘的角点标上红色:

“我是横行无忌的红螃蟹"

给螃蟹的角点标上绿色

源码如下:

代码语言:python
复制
# -*- coding: utf-8 -*-
"""
Created on Dec 15 22:19:18 2019
@author: Administrator
"""
import numpy as np
import cv2
#img = cv2.imread("chessboard.jpg")
img = cv2.imread("crab.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray, blockSize=5, ksize=7, k=0.1)
#第三个参数ksize决定了角点检测的灵敏度,越小越灵敏,其取值必须是3到31之间的奇数
#第二个参数决定了mark点的大小。
print(np.where(dst >0.01* dst.max())) #角点的x坐标和y坐标
img [dst >0.01* dst.max()] = (125,255,0)#给角点标上颜色
#img [dst >0.01* dst.max()] = (0,0,255)
cv2.imshow('corners', img)
'''
cornerHarris(...)
    cornerHarris(src, blockSize, ksize, k[, dst[, borderType]]) -> dst
    .   @brief Harris corner detector.
    .   
    .   The function runs the Harris corner detector on the image. Similarly to cornerMinEigenVal and
    .   cornerEigenValsAndVecs , for each pixel \f$(x, y)\f$ it calculates a \f$2\times2\f$ gradient covariance
    .   matrix \f$M^{(x,y)}\f$ over a \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood. Then, it
    .   computes the following characteristic:
    .   
    .   \f[\texttt{dst} (x,y) =  \mathrm{det} M^{(x,y)} - k  \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2\f]
    .   
    .   Corners in the image can be found as the local maxima of this response map.
    .   
    .   @param src Input single-channel 8-bit or floating-point image.
    .   @param dst Image to store the Harris detector responses. It has the type CV_32FC1 and the same
    .   size as src .
    .   @param blockSize Neighborhood size (see the details on #cornerEigenValsAndVecs ).
    .   @param ksize Aperture parameter for the Sobel operator.
    .   @param k Harris detector free parameter. See the formula above.
    .   @param borderType Pixel extrapolation method. See #BorderTypes.
'''
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-05-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Python可视化编程机器学习OpenCV 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档