赞
踩
目录
坑二:deprecated pixel format used, make sure you did set range correctly
直接使用如下命令安装usb_cam功能包:
sudo apt-get install ros-melodic-usb-cam
然后插上自己的UVC摄像头,运行如下指令:
roslaunch usb_cam usb_cam-test.launch
此时可以检测到摄像头,但出来的图像是花的,如下:
在查看了摄像头的数据手册之后,发现摄像头的默认像素格式是mjpeg格式的:
于是乎查看了usb_cam-test.launch,发现原始的launch文件中定义的像素格式是yuyv格式的(第六行):
- <launch>
- <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
- <param name="video_device" value="/dev/video0" />
- <param name="image_width" value="640" />
- <param name="image_height" value="480" />
- <param name="pixel_format" value="yuyv" />
- <param name="camera_frame_id" value="usb_cam" />
- <param name="io_method" value="mmap"/>
- </node>
- <node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">
- <remap from="image" to="/usb_cam/image_raw"/>
- <param name="autosize" value="true" />
- </node>
- </launch>
所以,将上述"yuyv"改成"mjpeg" ,在运行相应的launch文件,就可以的到正常的图片了:
但是此时终端中会出现如下图所示的提示 :
虽然看着并没有什么影响,但是对于我等强迫症患者来说简直等同于error(T_T) ,在网上找了下以下解决方法:
将usb_cam源码从GitHub上下载到工作空间中,然后在usb_cam源码src文件中找到usb_cam.cpp文件,大约在第430+行找到如下代码段:
- if (pic_size != avframe_camera_size_)
- {
- ROS_ERROR("outbuf size mismatch. pic_size: %d bufsize: %d", pic_size, avframe_camera_size_);
- return;
- }
- video_sws_ = sws_getContext(xsize, ysize, avcodec_context_->pix_fmt, xsize, ysize, AV_PIX_FMT_RGB24, SWS_BILINEAR, NULL,
- NULL, NULL);
- sws_scale(video_sws_, avframe_camera_->data, avframe_camera_->linesize, 0, ysize, avframe_rgb_->data,
- avframe_rgb_->linesize);
- sws_freeContext(video_sws_);
在代码段:video_sws_ = sws_get... 位置上面一行插入以下代码:
- {
- AVPixelFormat pixFormat;
- switch (avcodec_context_->pix_fmt) {
- case AV_PIX_FMT_YUVJ420P :
- pixFormat = AV_PIX_FMT_YUV420P;
- break;
- case AV_PIX_FMT_YUVJ422P :
- pixFormat = AV_PIX_FMT_YUV422P;
- break;
- case AV_PIX_FMT_YUVJ444P :
- pixFormat = AV_PIX_FMT_YUV444P;
- break;
- case AV_PIX_FMT_YUVJ440P :
- pixFormat = AV_PIX_FMT_YUV440P;
- break;
- default:
- pixFormat = avcodec_context_->pix_fmt;
- break;
- }
- avcodec_context_->pix_fmt = pixFormat;
- }
然后保存、重新编译、source devel/setup.bash、运行launch文件、完美解决问题。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。