Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ret and frame mean here?

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.

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()
like image 210
Suhail Ahmed Khan Avatar asked Feb 27 '15 19:02

Suhail Ahmed Khan


People also ask

What is RET and frame in Opencv?

Basically, ret is a boolean regarding whether or not there was a return at all, at the frame is each frame that is returned. If there is no frame, you wont get an error, you will get None. gray = cv2. cvtColor(frame, cv2. COLOR_BGR2GRAY)

What is a frame in Opencv?

A frame of a video is simply an image and we display each frame the same way we display images, i.e., we use the function imshow(). As in the case of an image, we use the waitKey() after imshow() function to pause each frame in the video.

What is cap get ()?

cap. get(0) means CAP_PROP_POS_MSEC, which in turn gives Current position of the video file in milliseconds or video capture timestamp.


2 Answers

"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

like image 69
René Chiquete Avatar answered Nov 16 '22 01:11

René Chiquete


ret, frame = cap.read()
  1. ret is a boolean variable that returns true if the frame is available.
  2. frame is an image array vector captured based on the default frames per second defined explicitly or implicitly
like image 22
Atin Maiti Avatar answered Nov 16 '22 02:11

Atin Maiti