2017-03-29 5 views
0

私はドミノで中間線の角度を取得しようとしています。 SimpleBlobDetectorはそれを見つけることができますが、角度値-1を返します。 それは誰でも知ることができますか?どうすればSimpleBlobDetectorを使って修正できますか? SimpleBlobDetectorがオプションでない場合、これらの線の中心と角度を見つけるために他に何ができますか?OpenCV2 - SimpleBlobDetectorを使って狭い矩形を見つけましたが、角度を取り出すことはできません

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

enter image description here

答えて

0

それは質問あなたに非常に似ているようだ、と思える私はSimpleBlob検出器は、このために最善であるかどうかわからないんだけど、あなたは

Detect centre and angle of rectangles in an image using Opencv

を見てきました長方形の角度を確認するのが非常にうまくいく。

+0

これを試してみよう。ありがとう:D – Luli

+0

これをどのように変換するか考えてください: 'cv :: RotatedRect rotateRect = cv :: minAreaRect(contours [i]); //読み取り点と角度 cv :: Point2f rect_points [4];rotateRect.points(rect_points); float angle = rotateRect.angle; // angle //回転した矩形の中心を読み取る cv :: Point2f center = rotatedRect.center; // center 'をPythonに? – Luli

関連する問題