with tutorial raspberry instalar how for python opencv raspberry-pi

python - tutorial - opencv raspberry pi camera



OpenCV2-Rectángulos estrechos encontrados usando SimpleBlobDetector, pero no puede extraer el ángulo (1)

Estoy tratando de obtener el ángulo de la línea media en un dominó. SimpleBlobDetector puede encontrarlo, pero me da un valor de ángulo de -1. ¿Alguien sabe por qué eso puede ser? y ¿cómo puedo arreglar eso aún usando SimpleBlobDetector? y si SimpleBlobDetector no es una opción, ¿qué más puedo hacer para encontrar el centro y el ángulo de estas líneas?

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()