gpt4 book ai didi

python - Python OPenCV Hough Circle需要很长时间才能从网络摄像头加载图像

转载 作者:行者123 更新时间:2023-12-02 16:37:27 26 4
gpt4 key购买 nike

我正在尝试从网络摄像头获取视频流,并使用HoughCircles()检测其中的圈子。但是,无论何时我尝试运行代码,视频都会花费一些时间来加载图像,或者根本不会加载图像。我们将非常感谢您提供有关如何获取代码进行圆圈检测的任何帮助。

注意:我不是要实时执行任何操作。我只想获取一些基本的圆圈检测功能,以处理来自网络摄像头的视频流。

这是代码:

import cv2
import numpy as np
import sys

cap = cv2.VideoCapture(0)
width = 320
height = 240
dim = (width, height)
while(True):
gray = cv2.medianBlur(cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2GRAY),5)
resized = cv2.resize(gray,dim,interpolation = cv2.INTER_AREA)
edges = cv2.Canny(gray,100,200)
circ = cv2.HoughCircles(resized,cv2.HOUGH_GRADIENT,1,30,param1=50,param2=75,
minRadius=0,maxRadius=0)
cv2.imshow('video',resized)
if circ is not None:
circ = np.uint16(np.around(circ))[0,:]
print(circ)
for j in circ:
cv2.circle(resized, (j[0], j[1]), j[2], (0, 255, 0), 2)
cv2.imshow('video',resized)
if cv2.waitKey(1)==27:# esc Key
break
cap.release()
cv2.destroyAllWindows()

再次感谢您的帮助。

最佳答案

好,我想通了。我不得不减少HoughCircles中的参数的混乱。我已将circ = cv2.HoughCircles(resized,cv2.HOUGH_GRADIENT,1,30,param1=50,param2=75, minRadius=0,maxRadius=0)更改为cv2.HoughCircles(resized,cv2.HOUGH_GRADIENT,1,50,param1=50,param2=35, minRadius=0,maxRadius=0),这使该代码可以显示视频流,同时以合理的帧频检测圆圈。也感谢@ZdaR的帮助。

Here's the code that works


import cv2
import numpy as np
import serial

cap = cv2.VideoCapture(1)
width = 320
height = 240
dim = (width, height)
while(True):
gray = cv2.medianBlur(cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2GRAY),5)
resized = cv2.resize(gray,dim,interpolation = cv2.INTER_AREA)
circ = cv2.HoughCircles(resized,cv2.HOUGH_GRADIENT,1,50,param1=50,param2=35,
minRadius=0,maxRadius=0)
cv2.imshow('video',resized)
if circ is not None:
circ = np.uint16(np.around(circ))[0,:]
print(circ)
for j in circ:
cv2.circle(resized, (j[0], j[1]), j[2], (0, 255, 0), 2)
cv2.imshow('video',resized)
if cv2.waitKey(1)==27:# esc Key
break
cap.release()
cv2.destroyAllWindows()

关于python - Python OPenCV Hough Circle需要很长时间才能从网络摄像头加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53755187/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com