【发布时间】:2019-02-24 11:10:02
【问题描述】:
我想知道使用 cv2.VideoCapture.read() 方法正在捕获哪种数据类型。我一直在阅读 OpenCV 文档,发现了这样的解释:
我已经学习了一些关于 OpenCV 的基本教程,其中网络摄像头可以捕获数据并输出帧。下图中显示的是帧数据。
下面是输出这些帧的代码:
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
所以我想知道从“框架”变量中打印出什么样的数据类型?
最后我想使用这个“帧”数据在 C# 应用程序中将图像重新构造为视频。
【问题讨论】:
-
在 Python 中,OpenCV 的图像存储为 numpy 数组。在 OpenCV for C++ 中,它们被存储为自己的自定义类型,
Mat。 -
在 IPython 中开发代码非常快速和容易,您只需键入每一行代码,就像在编辑器或 IDE 中编写脚本一样,但是当你想知道一个变量是什么样子时,你只需输入它的名字并点击
Enter,它的格式很适合你,或者如果你想知道它的类型,你只需输入type(frame)它会告诉你,然后你继续创建您的代码。当一切看起来正确时,您只需键入%history并复制工作、调试过的代码并将其粘贴到文件中以供下次保存。