python-2.7 - 使用OpenCV在实时Feed上进行霍夫变换

标签 python-2.7 opencv

我一直在尝试找出如何在网络摄像头feed上应用霍夫变换。但是我收到错误消息,它没有适当的格式,即使我对其进行了灰度缩放以检查它是否在uint8中也是如此。

cap = cv2.VideoCapture(1)

while(True):
    ret, frame = cap.read()
    frame = cv2.medianBlur(frame,5)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    ###
    #HughCircles Detection TEST  
    circles = cv2.HoughCircles(frame,cv2.HOUGH_GRADIENT,1,50,
                               param1=50,param2=30,minRadius=0,maxRadius=0) 
    circles = np.uint16(np.around(circles))
    if circles is None:
        for i in circles[0,:]:
            # draw the outer circle
            cv2.circle(frame,(i[0],i[1]),i[2],(0,255,0),2)
            # draw the center of the circle
            cv2.circle(frame,(i[0],i[1]),2,(0,0,255),3)
    #    
    ###

    # Display the resulting frame
    cv2.imshow('Board',frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

最佳答案

好吧,在另一篇文章中,我看到圈子在没有可见内容的情况下实际上返回了None,因此必须有一个if,以便它不表示None。

cap = cv2.VideoCapture(1)

while(True):
    ret, frame = cap.read()
    frame = cv2.medianBlur(frame,5)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

###
#HughCircles Detection TEST  
    circles = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT,1,50,
                          param1=50,param2=30,minRadius=0,maxRadius=0) 
    circles = np.uint16(np.around(circles))
    if circles != None:
        for i in circles[0,:]:
        # draw the outer circle
            cv2.circle(gray,(i[0],i[1]),i[2],(0,255,0),2)
        # draw the center of the circle
            cv2.circle(gray,(i[0],i[1]),2,(0,0,255),3)
#    
###

# Display the resulting frame
    cv2.imshow('Board',gray)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

关于python-2.7 - 使用OpenCV在实时Feed上进行霍夫变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33025729/

相关文章:

python - 格式化大字符串时出错 - 如何检测错误?

Bash:将变量作为单个参数/shell 引用参数传递

python-2.7 - 在 Python 中使用 XGBoost 根据多个输入变量预测输出

arrays - 为什么 Python 从数组中随机删除数字?

java - OpenCV java.lang.UnsatisfiedLinkError

c++ - C++ 中 channel 函数应用的通用机制?

opencv - 如何使用OpenCv设置BGR24格式?

OpenCV TBB IPP OpenMP 函数

Python 跳过数字

python - 如何使用 openCv python 将图像文件对象转换为 numpy 数组?