ret和frame在这里意味着什么?

Suh*_*han 8 python opencv numpy image-processing

何时使用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()
Run Code Online (Sandbox Code Playgroud)

小智 20

ret, frame = cap.read()
Run Code Online (Sandbox Code Playgroud)
  1. ret是一个布尔变量,如果框架可用则返回 true。
  2. frame是基于显式或隐式定义的默认每秒帧数捕获的图像数组向量


小智 7

"Frame"将获得相机中的下一帧(通过"cap")."Ret"将从获取相机帧获得返回值,或者为true.我建议你阅读OpenCV教程(非常详细),就像这个用于人脸识别的教程:http: //docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html


Mar*_*ler 2

这在cap.read文档中进行了解释。由于cap它是一个VideoCapture对象,因此使用 Google 搜索“VideoCapture opencv Read”将立即引导您找到 openCV 的文档。函数read文档将向您指出,grab其中将详细解释retval

这些方法/函数从视频文件或相机中抓取下一帧并返回...