Opencv:我如何计算螺栓上的螺纹峰值?

问题描述 投票:2回答:1

我有一组带螺栓的图像。其中两个如下所示。 我需要计算线程峰值。

我试过Harris角点探测器和HoughLines变换没有任何成功。

有任何想法吗?

enter image description here

enter image description here

python opencv
1个回答
1
投票

你好尝试下面的代码,它的准确率为90-90%,看看是否有帮助

import cv2

img=cv2.imread('bolt.jpg')
img_gray=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
inv_img=cv2.bitwise_not(img_gray)
cv2.imwrite('image1.jpg',inv_img)

enter image description here

res,thresh_img=cv2.threshold(inv_img,202,255,cv2.THRESH_BINARY_INV) 
cv2.imwrite('image2.jpg',thresh_img)

enter image description here

  thresh_img=255- thresh_img
  im2, contours, hierarchy = cv2.findContours(thresh_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
  sum1=0
  for c in contours:
    area=cv2.contourArea(c)
    if area>4:
        print (area)
        sum1+=1
    print sum1

对不起,对于硬编码阈值,我假设背景和光线条件不会改变。

© www.soinside.com 2019 - 2024. All rights reserved.