How to make depth stream video
I'm using the command
rosrun image_view video_recorder image:=/kinect2/sd/image_depth _encoding:=16UC1
to make depth stream video. However, it crashes with the following error:
Starting to record MJPG video at [512 x 424]@15fps. Press Ctrl+C to stop recording.
OpenCV Error: Assertion failed (image->depth == 8) in writeFrame, file /build/buildd/opencv-2.4.8+dfsg1/modules/highgui/src/cap_ffmpeg.cpp, line 238
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.4.8+dfsg1/modules/highgui/src/cap_ffmpeg.cpp:238: error: (-215) image->depth == 8 in function writeFrame
Aborted (core dumped)
It doesnt work either with _encoding:=32FC1
, 32SC1
.
If _encoding:=mono16
is used, it says unable to convert 16UC1 to mono16
Is it a problem with converting from ROS encodingto OpenCV encoding? Or is the video-writer only limited to color videos? This would be strange.
Thanks.
Asked by shakith on 2015-11-04 05:42:48 UTC
Answers
The problem here is caused because depth images by convention are 16 bit monochrome images (1 unit encodes 1 mm of depth in most cases) but the video codecs being used in this case are only compatible with 8 bit color or mono image streams.
If you are producing this depth video with a view to using the video as sensor data and processing it into 3D information then you probably don't want to loose this resolution, however if you are producing the video just to view and are not too concerned about the exact values then there is an easy solution.
You'll want to make a simple ROS node which subscribes to the depth image topic, and converts each frame into an 8 bit mono or color image and publishes it. Then you can use the code to convert the depth camera topic into a form compatible with the video codecs.
There are many ways of doing the conversion itself. You can scale a color bar to the known depth range of your sensor, so that the pixel colors will be consistent between frames. Or you could normalise each frame individually so that the color bar is stretched to the depth range of that frame, but as the depth range of the images changes so will the coloring.
Hope this gives you some ideas.
Asked by PeteBlackerThe3rd on 2019-06-03 11:53:40 UTC
Comments
Hi,
I know it was long time ago but did anyone found a solution? I am struggling trying to save the video stream from the depth camera.
Asked by pulver on 2019-06-03 09:26:18 UTC
I didn't spot this one the first time around, but I've just added an answer to it now.
Asked by PeteBlackerThe3rd on 2019-06-03 11:53:58 UTC