0

我是 OpenCV 和 Raspberry 的新手。我正在尝试cv.VideoWriter_fourcc在树莓派 4 上捕捉视频。我将图像转换为灰色,并用 模糊cv.bilateralFilter,并用 搜索圆圈cv.HoughCircles。生成的视频冻结并丢失帧。我首先将 FPS 设置为 24.0,但它看起来像是快进。我尝试了一些值,似乎 6.0 是匹配视频长度的最佳值。

我的代码包含更多不相关的步骤,我将在下面提供相关部分。

如何从中获得流畅的 30 或 60 FPS 视频?提前致谢。

#Open cam and initialize video codecs
cap = cv.VideoCapture(0)
fourcc = cv.VideoWriter_fourcc(*"MJPG")
out = cv.VideoWriter('myvideo.avi', fourcc, 22.0, (640,480))
.
.
#For 80 Sec while loop:
start_time = int(time.time())
duration = int(80)
.
.
while ((int(time.time())-start_time)<duration):
    istrue, frame = cap.read()
    #Gray and  blur
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    blur = cv.bilateralFilter(gray, 13,75,75) #Blur density is 13. 75 is irrelevant.
    #Find Circles
    circles = cv.HoughCircles(blur, cv.HOUGH_GRADIENT, 1, 1000, param1 = 50, param2=45, minRadius = 1, maxRadius = 0)
    #Put time as text
    cv.putText(frame, str(datetime.time(datetime.now())), (15,30), cv.FONT_HERSHEY_SIMPLEX, 0.5, (255,0,0), 1, cv.LINE_AA)
    
    #put  text at every 20 secs
    cv.putText(frame, every_20_sec(start_time), (15,50), cv.FONT_HERSHEY_SIMPLEX, 0.5, (255,0,0), 1, cv.LINE_AA)
    #cv.putText(frame, str(datetime.time(datetime.now())), (15,50), cv.FONT_HERSHEY_SIMPLEX, 0.5, (255,0,0), 1, cv.LINE_AA)
    if circles is not None:
        circles = np.uint16(np.around(circles))
        for i in circles[0,:]:
            cv.circle(frame, (i[0],i[1]), i[2], (0,255,0),2)
            cv.circle(frame, (i[0],i[1]), 1, (0,0,255), 2)
            #pixel coordinates as text
            pos_str = str(int(i[0])) + ' ' + str(int(i[1]))
            cv.putText(frame, pos_str, (i[0]+100,i[1]+100), cv.FONT_HERSHEY_SIMPLEX, 1, (255,0,0), 2, cv.LINE_AA)
            
            xlist.append(i[0])
            ylist.append(i[1])
    out.write(frame)

cap.release()
out.release()
4

0 回答 0