Python OpenCV2-使用SimpleBlobDetector发现的窄矩形,但可以';t提取角度

Python OpenCV2-使用SimpleBlobDetector发现的窄矩形,但可以';t提取角度,python,opencv,raspberry-pi,Python,Opencv,Raspberry Pi,我想得到多米诺骨牌中间线的角度。SimpleBlobDetector可以找到它,但它给了我一个-1的角度值。 有人知道为什么会这样吗?我如何使用SimpleBlobDetector解决这个问题?如果SimpleBlobDetector不是一个选项,我还能做什么来找到这些线的中心和角度 import numpy as np import cv2 import os import time #from matplotlib import pyplot as plt def main():

我想得到多米诺骨牌中间线的角度。SimpleBlobDetector可以找到它,但它给了我一个-1的角度值。 有人知道为什么会这样吗?我如何使用SimpleBlobDetector解决这个问题?如果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()

我不确定SimpleBlob检测器是否是最好的,但您看过了吗


它似乎与您的问题非常相似,并且似乎在识别矩形的角度方面做得非常好

我将尝试一下。谢谢:DDo你知道如何转换这个:'cv::RotatedRect RotatedRect=cv::Minarealect(轮廓[i]);//读取点和角度cv::Point2f rect_points[4];旋转反射点(矩形点);浮动角度=rotatedRect.angle;//角度//读取旋转矩形cv的中心::点2F中心=旋转矩形中心;//中心到python?