I am wondering what kind of data type is being captured using the cv2.VideoCapture.read() method. I have been reading the OpenCV documents and I found this explanation:
I have followed a couple of basic tutorials with OpenCV where a webcam can capture data and outputs the frames. In the picture below the frame data is being shown.
And here follows the code that outputs these frames:
import cv2, time, base64
framesCaptured = 0;
video=cv2.VideoCapture(0) <====== Video capture for the webcam
# Save camera frames as movie
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('recording.avi', fourcc, 20.0, (640, 480))
while True:
framesCaptured += 1
check, frame = video.read() <====== Grabs and retrieves frames and decode
# Write video frames
out.write(frame)
# Print out statements
#print(check)
print(frame) <====== Print out frame data (as shown in the cmd picture below)
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow("frame", gray)
key=cv2.waitKey(1)
if key == ord('q'):
break
#print('Frames captured: ' + str(framesCaptured))
video.release()
out.release()
cv2.destroyAllWindows
So I am wondering what kind of data type is being printed from the 'frame' variable?
In the end I want to use this 'frame' data to re-construct the images to a video in a C# application.
read() ) from a VideoCapture returns a tuple (return value, image) . With the first item you check wether the reading was successful, and if it was then you proceed to use the returned image .
OpenCV VideoCapture OpenCV provides the VideoCature() function which is used to work with the Camera. We can do the following task: Read video, display video, and save video. Capture from the camera and display it.
cv2.VideoCapture(1): Means second camera or webcam. cv2.VideoCapture("file name.mp4"): Means video file. After this, we can start reading a Video from the camera frame by frame. We do this by calling the read method on the VideoCapture object. This method takes no arguments and returns a tuple.
cv2. VideoCapture is a function of openCV library(used for computer vision, machine learning, and image processing) which allows working with video either by capturing via live webcam or by a video file.
You can check type of frame yourself by adding print(type(frame))
.
When I execute script with print(type(frame))
, numpy.ndarray
is printed.
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