I have the set of images with bolts. Two of them are shown below.
I need to count thread peaks.
I have tried Harris corner detector and HoughLines transform without any success.
Any ideas?
I have the set of images with bolts. Two of them are shown below.
I need to count thread peaks.
I have tried Harris corner detector and HoughLines transform without any success.
Any ideas?
Hello try below code its having accuracy of 90-90% see if help
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)
res,thresh_img=cv2.threshold(inv_img,202,255,cv2.THRESH_BINARY_INV)
cv2.imwrite('image2.jpg',thresh_img)
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
sorry, for hardcoding threshold value I assume the background and light condition won't change.