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()
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)
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.
cap. get(0) means CAP_PROP_POS_MSEC, which in turn gives Current position of the video file in milliseconds or video capture timestamp.
"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
ret, frame = cap.read()
ret
is a boolean variable that returns true if the frame is available.frame
is an image array vector captured based on the default frames per second defined explicitly or implicitly If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With