I am trying to store video file from multiple sources(RGB, Depth, and infrared) from kinect sensors.
This is the image that I visualized using cv2.imshow command: enter image description here using the following code:
cv2.imshow("ir", ir / 65535.)
cv2.imshow("depth", depth / 4500.)
cv2.imshow("color", color)
ir, depth both are array with size of (height, width), float32. color is a array with size of (height, width, 3), where 3 is the RGB channel and uint8 type from 0-255. Since ir and depth's value is large, we need to normalize them using the code above. And this code gave the above figures.
Now I want to store a series of image array as a video file. I use the following code:
ir_video= cv2.VideoWriter('ir.mp4', cv2.VideoWriter_fourcc(*'MP42'), fps, (height, width), False)
depth_video= cv2.VideoWriter('depth.mp4', cv2.VideoWriter_fourcc(*'MP42'), fps, (height, width), False)
color_video= cv2.VideoWriter('color.mp4', cv2.VideoWriter_fourcc(*'MP42'), fps, (height, width), True)
for loop: (pseudo for loop for this part, basically write every frame into the video)
ir_video.write(ir / 65535.)
depth_video.write(depth / 4500.)
color_video.write(color)
ir_video.release()
depth_video.release()
color_video.release()
Color video works very well, looks very similar to the cv2.imshow command. However, ir
and depth video are corrupted. All 0kb. I tried to change the fourcc code to cv2.VideoWriter_fourcc(*'mp4v')
. This time the ir
one saved a video that I can play. But it is very different from the cv2.imshow result. It is shown below: enter image description here
I'm wondering how I can correct save the result as I viewed in cv2.imshow command. What fourcc code should be used? Thanks a lot!
1条答案
按热度按时间dwbf0jvd1#
我在一个类似的项目中使用了其他深度相机(Orbbec,Asus Xtion),OpenCV的afaik视频作者类不支持16位深度图像,这就是为什么在评论中建议你应该转换为8位。你可以在这里看看我是用什么来保存这样一个视频的(这是关于使用OpenNI2,但主要概念是那里)。