ret和frame在这里是什么意思?

2024-05-17 04:35:04 发布

您现在位置:Python中文网/ 问答频道 /正文

何时使用ret和frame?这些变量包含哪些值? 我刚刚开始图像处理,所以如果有更多的变化,请让我知道。

谢谢你

import numpy as np
import cv2
cap = cv2.VideoCapture('Sample Lap HUL_OB_1.56.641_Graphic.mpg')

# Define the codec and create VideoWriter object
# fourcc = cv2.cv.CV_FOURCC(*'MJPG')
out = cv2.VideoWriter('output.mpg',0, 60.0, (640,480))
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
         # frame = cv2.flip(frame,0)
         # write the flipped frame
        out.write(frame)
        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
             break
     else:
        break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

Tags: theimportnumpyreleaseifoutcv2frame
3条回答

请看文档here

上面写着:

cap.read() returns a bool (True/False). If frame is read correctly, it will be True. So you can check end of the video by checking this return value.

这在cap.read文档中有解释。由于cap是一个VideoCapture对象,在“VideoCapture opencv Read”上使用Google将立即引导您找到opencv的文档。函数文档将指向read,它将详细解释retval

The methods/functions grab the next frame from video file or camera and return ...

“Frame”将获得相机中的下一帧(通过“cap”)。 “Ret”将从获取相机帧获得返回值,无论是真是假。我建议您阅读OpenCV教程(非常详细),比如下面的人脸识别: http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html

相关问题 更多 >