OpenCV中的cv2.VideoCapture.read()方法捕获什么数据类型?

时间:2018-09-20 07:42:23

标签: python opencv types cv2

我想知道使用cv2.VideoCapture.read()方法捕获哪种数据类型。我一直在阅读OpenCV文档,发现了以下解释:

enter image description here

我遵循了OpenCV的一些基本教程,其中网络摄像头可以捕获数据并输出帧。在下面的图片中显示了帧数据。

enter image description here

下面是输出这些帧的代码:

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

所以我想知道从'frame'变量打印哪种数据类型?

最后,我想使用此“框架”数据在C#应用程序中将图像重建为视频。

1 个答案:

答案 0 :(得分:1)

您可以通过添加print(type(frame))来自己检查框架的类型。
当我使用print(type(frame))执行脚本时,将打印numpy.ndarray