【问题标题】:Finding circles in a live video feed using python 2.7.11and opencv 3.0.0使用 python 2.7.11 和 opencv 3.0.0 在实时视频源中查找圆圈
【发布时间】:2016-09-20 17:55:26
【问题描述】:

我需要帮助在我的网络摄像头的实时视频源中查找圈子。我只需要来自 python 的反馈,说明是否检测到一个圆圈。还有什么是找到以像素为单位的圆圈大小以便更好地检测的最佳方法。到目前为止我的代码

import cv2
import numpy as np
import sys

cap = cv2.VideoCapture(0)

while(True):

    ret, frame = cap.read()


    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray = cv2.medianBlur(gray,5)
    cimg = frame.copy()
    circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 10, np.array([]), 200, 100, 100, 200)
    if circles == 1:
        print('Circle true')
    else:
        print('No circle')
    cv2.imshow('video',gray)

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


cap.release()
cv2.destroyAllWindows()

【问题讨论】:

  • 那你在问什么?什么不工作?另外,请提供示例图片。
  • 我希望能够在视频流中找到任何大小的圆圈(在合理范围内),然后收到已检测到或未检测到圆圈的确认。因此,如果我在网络摄像头下移动一个类似圆盘的物体,那么我会确认已检测到一个圆圈。我相信现在我的问题是我的圈子功能。

标签: python opencv hough-transform


【解决方案1】:

就是这样!

import cv2
import numpy as np
import sys
cap = cv2.VideoCapture(0)
while(True):
    gray = cv2.medianBlur(cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2GRAY),5)
    cirles=cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 10)# ret=[[Xpos,Ypos,Radius],...]
    if cirles!=None:print "Circle There !"
    cv2.imshow('video',gray)
    if cv2.waitKey(1)==27:# esc Key
        break
cap.release()
cv2.destroyAllWindows()

【讨论】:

  • 感谢您的回复!我是这个网站的新手,不知道如何将我的代码放在灰色框中。你知道为什么我的 houghcircles 可以使用 7 个参数吗?还说你有一个圆形物体,它的一部分被切掉了,无论如何都会使霍夫圆更敏感而不是检测到它吗?我只是在玩弄价值观。 circles = cv2.HoughCircles(灰色, cv2.HOUGH_GRADIENT, 2, 60, 1, 200, 70, 70, 80)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-24
  • 2017-03-10
  • 2023-04-03
  • 1970-01-01
相关资源
最近更新 更多