Python ret 和 frame 在这里是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28773186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does ret and frame mean here?
提问by Suhail Ahmed Khan
When to use ret and frame? What values do these variables hold? I have just started with image processing, so if there are more changes do let me know.
什么时候使用ret和frame?这些变量持有什么值?我刚刚开始图像处理,所以如果有更多变化,请告诉我。
Thank you
谢谢
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()
回答by Marcus Müller
That is explained in cap.readdocs. Since capis a VideoCaptureobject, using Google on "VideoCapture opencv Read" will instantly lead you to openCV's documentation. The readfunctions doc will point you to grabwhich will explain in detail retval:
这在cap.read文档中有解释。由于cap是一个VideoCapture对象,在“VideoCapture opencv Read”上使用谷歌将立即引导您找到openCV的文档。该read功能的文档将指向你grab将详细解释retval:
The methods/functions grab the next frame from video file or camera and return ...
方法/函数从视频文件或相机中抓取下一帧并返回...
回答by René Chiquete
"Frame" will get the next frame in the camera (via "cap"). "Ret" will obtain return value from getting the camera frame, either true of false. I recommend you to read the OpenCV tutorials(which are highly detailed) like this one for face recognition: http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html
“Frame”将获取相机中的下一帧(通过“cap”)。“Ret”将通过获取相机帧获得返回值,无论是真还是假。我建议您阅读 OpenCV 教程(非常详细),例如人脸识别:http: //docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html
回答by mhaghighat
回答by Atin Maiti
ret, frame = cap.read()
retis a boolean variable that returns true if the frame is available.frameis an image array vector captured based on the default frames per second defined explicitly or implicitly
ret是一个布尔变量,如果框架可用则返回 true。frame是基于显式或隐式定义的默认每秒帧数捕获的图像数组向量

