Linux检测视频是否损坏,为什么python OpenCV GUI在linux上的简单视频循环检测程序中崩溃?...

下面是一个用Python 2.7.12和OpenCV3.2.0测试的可用代码。在import numpy as np

import cv2

capture = cv2.VideoCapture("001.mp4")

#capture = cv2.VideoCapture(0)

while capture.isOpened():

# grab the current frame and initialize the status text

grabbed, frame = capture.read()

if frame is not None:

# convert the frame to grayscale, blur it, and detect circles

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

blur = cv2.medianBlur(gray,5)

circles = cv2.HoughCircles(blur,cv2.HOUGH_GRADIENT,1,20, \

param1=50,param2=30,minRadius=0,maxRadius=0)

if circles is not None:

# convert the (x, y) coordinates and radius of the circles to integers

circles = np.round(circles[0, :]).astype("int")

#circles = np.uint16(np.around(circles[0,:]))

# loop over the (x, y) coordinates and radius of the circles

for (x, y, r) in circles:

# draw the circle in the output image, then draw a rectangle

# corresponding to the center of the circle

cv2.circle(frame, (x, y), r, (255, 0, 255), 2)

# show the frame and record if a key is pressed

cv2.imshow("Frame", frame)

# if the 'q' key is pressed, stop the loop

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

break

capture.release()

cv2.destroyAllWindows()

主要的变化是在for (x, y, r) in circles:循环中获取并绘制圆。添加cv2.medianBlur()后,视频播放有点慢。通过cv2.HoughCircles()检测,它甚至进一步减慢了速度。在

这是用圆圈播放的视频截图。假设您可能需要修改cv2.HoughCircles()函数参数和圆检索来满足您的需求。在

iVAuP.png

希望这能有所帮助。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值