Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What datatype is captured with cv2.VideoCapture.read() method in OpenCV?

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:

enter image description here

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.

enter image description here

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.

like image 426
Maxime de Lange Avatar asked Sep 20 '18 07:09

Maxime de Lange


People also ask

What does cv2 VideoCapture read () return?

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 .

What is VideoCapture in OpenCV?

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.

What is cv2 VideoCapture in Python?

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.

How does cv2 VideoCapture work?

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.


1 Answers

You can check type of frame yourself by adding print(type(frame)).
When I execute script with print(type(frame)), numpy.ndarray is printed.

like image 136
goodahn Avatar answered Oct 10 '22 11:10

goodahn