如何在图像中找到极限角?

时间:2019-10-16 03:05:38

标签: opencv tensorflow machine-learning deep-learning computer-vision

source image1 source image2

destination image1 destination image2

在上面的源图像(源图像1,图像2)中,我想找到最拐角点,并得到与目标图像1,图像2类似的点,就像我画出的红色圆圈点一样。

实际上,我研究了Harris,Shi Tomasi算法,但并不是那么极端。

实际上,我已经尝试使用Java代码 goodFeaturesTotrack ,例如:

az login

# upload certificate to Azure key vault
az keyvault certificate import --file "E:\Cert\P2SChildCert.pfx" --password "" --name "test1234" --vault-name "testkey08"

# download certificate as pfx file
az keyvault secret download --file "test2.pfx" --vault-name "testkey08" --name "test1234" --encoding base64

# upload the pfx file to Azue web app
az webapp config ssl upload --certificate-file "test2.pfx"  --name "andywebsite" --resource-group "andywebbot"  --certificate-password "" --query thumbprint --output tsv

结果图像如下:

magnify to find blue corner point

虽然它可以找到一些蓝色的特征点,但是却不如我显示的目标图像1,图像2那样极端。

那么,您是否有个好主意来找到具有特殊字符的角点?

2 个答案:

答案 0 :(得分:0)

您可以使用cv2.goodFeaturesToTrack()进行拐角检测。该函数有四个参数

corners = cv2.goodFeaturesToTrack(image, maxCorners, qualityLevel, minDistance)
  • image-输入8位或浮点32位灰度单通道图像
  • maxCorners-要返回的最大拐角数
  • qualityLevel-0-1之间的最小可接受角点质量等级。低于质量级别的所有角落
  • minDistance-拐角之间的最小欧几里得距离

enter image description here

import cv2

image = cv2.imread('1.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

corners = cv2.goodFeaturesToTrack(gray,10,0.2,20)

for corner in corners:
    x,y = corner.ravel()
    cv2.circle(image,(x,y),5,(36,255,12),-1)

cv2.imshow('image', image)
cv2.waitKey()

答案 1 :(得分:0)

如果您将二值图像像素视为要包含的点的集合,那么 alphashape 似乎可以为您提供所需的内容。

来自他们文档的示例:

points

enclosed