I'm trying to get the angle of the middle line in a domino. SimpleBlobDetector can find it, but it gives me an angle value of -1. Does anyone know why that can be? and how can i fix that still using SimpleBlobDetector? and if SimpleBlobDetector is not an option, what else can i do to find the center and angle of these lines?
import numpy as np
import cv2
import os
import time
#from matplotlib import pyplot as plt
def main():
capWebcam = cv2.VideoCapture(0) # declare a VideoCapture object and associate to webcam, 0 => use 1st webcam
params = cv2.SimpleBlobDetector_Params()
params.filterByCircularity = True
params.minCircularity = 0.73
params2 = cv2.SimpleBlobDetector_Params()
params2.filterByInertia = True
params2.maxInertiaRatio = 0.3
# show original resolution
print "default resolution = " + str(capWebcam.get(cv2.CAP_PROP_FRAME_WIDTH)) + "x" + str(capWebcam.get(cv2.CAP_PROP_FRAME_HEIGHT))
capWebcam.set(cv2.CAP_PROP_FRAME_WIDTH, 320.0) # change resolution to 320x240 for faster processing
capWebcam.set(cv2.CAP_PROP_FRAME_HEIGHT, 240.0)
capWebcam.set(cv2.CAP_PROP_FPS, 1)
# show updated resolution
print "updated resolution = " + str(capWebcam.get(cv2.CAP_PROP_FRAME_WIDTH)) + "x" + str(capWebcam.get(cv2.CAP_PROP_FRAME_HEIGHT))
if capWebcam.isOpened() == False: # check if VideoCapture object was associated to webcam successfully
print "error: capWebcam not accessed successfully\n\n" # if not, print error message to std out
os.system("pause") # pause until user presses a key so user can see error message
return # and exit function (which exits program)
# end if
while cv2.waitKey(1) != 27 and capWebcam.isOpened(): # until the Esc key is pressed or webcam connection is lost
blnFrameReadSuccessfully, img = capWebcam.read() # read next frame
if not blnFrameReadSuccessfully or img is None: # if frame was not read successfully
print "error: frame not read from webcam\n" # print error message to std out
os.system("pause") # pause until user presses a key so user can see error message
break # exit while loop (which exits program)
det = cv2.SimpleBlobDetector_create(params)
det2 = cv2.SimpleBlobDetector_create(params2)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
time.sleep(0.1)
keypts = det.detect(gray)
time.sleep(0.1)
keypts2 = det2.detect(gray)
print len(keypts)
print len(keypts2)
for l in keypts2:
print l.pt
print l.angle
time.sleep(0.3)
imgwk = cv2.drawKeypoints(gray, keypts, img,color= (200,0,139),flags=2)
time.sleep(0.1)
imgwk2 = cv2.drawKeypoints(img, keypts2, gray,color= (200,0,139),flags=2)
cv2.namedWindow("img", cv2.WINDOW_AUTOSIZE) # or use WINDOW_NORMAL to allow window resizing
cv2.imshow("img", img)
# hold windows open until user presses a key
cv2.destroyAllWindows()
return
###################################################################################################
if __name__ == "__main__":
main()