PTAM图像接口需要灰度图像
·
源码见github : https://github.com/ethz-asl/ethzasl_ptam
今天安装ptam想试一下效果,结果发现相机打开会出现幻影的情况.如下图所示. 通过浏览 github 其中的issue ,发现是ptam
ros上接口是只支持灰度图片.(猜测图片幻影也许就是因为三通道图片造成的). 所以需要改变其中关于图像的的ros接口. 所以我在
中间做了一个图像格式转换节点.. 其中利用到了opencv 的 cvtColor . 接口程序如后面说明:(ROS图像格式与opencv图像格式的相互转换.))
mark: 当时该usb_cam_node的驱动程序,直接取灰度图像格式,出错了,mark 之.
==> 记得之前跑单目视觉slam: Monoslam scenelib2 by Davison 的mono-slam 相机也有这样问题出现..后面再试试看.
注意:ptam 的launch 接口支持的相机模型参数是非针孔相机模型,需要按照它的校正程序运行....
// img_tran 节点程序
#include <ros/ros.h>
#include <opencv2/opencv.hpp>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
//#include "../image_convert/image_converter.h"
#include "ros/ros.h"
#include "std_msgs/String.h"
ros::Publisher image_pub ;
void chatterCallback(const sensor_msgs::ImageConstPtr& msg)
{
cv_bridge::CvImagePtr cv_ptr;
cv_ptr = cv_bridge::toCvCopy(msg,sensor_msgs::image_encodings::BGR8);
// cv_ptr->image.copyTo(cv_camera_);
cv::Mat image_gray;
cv::cvtColor(cv_ptr->image, image_gray,CV_BGR2GRAY);//灰度化
cv_bridge::CvImage cvi;
sensor_msgs::Image ros_img;
ros::Time time=ros::Time::now();
cvi.header.stamp = time;
cvi.header.frame_id = "image";
cvi.encoding = "mono8";
cvi.image = image_gray;
cvi.toImageMsg(ros_img);
image_pub.publish(cvi.toImageMsg());
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "img_tran");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/usb_cam/image_raw", 1000, chatterCallback);
image_pub = n.advertise<sensor_msgs::Image>("/mono_image", 1000);
ros::spin();
return 0;
}
相机启动文件.
<launch>
<!--node pkg="rviz" type="rviz" name="rviz"
args="-d $(find usb_cam)/launch/camera.rviz"/-->
<node name="usb_cam" pkg="usb_cam" type="usb_cam_node" respawn="false" output="log">
<param name="video_device" type="string" value="/dev/video1"/>
<param name="camera_frame_id" type="string" value="usb_cam"/>
<param name="framerate" type="int" value="50"/>
<param name="io_method" type="string" value="mmap"/>
<param name="image_width" type="int" value="640"/>
<param name="image_height" type="int" value="480"/>
<param name="pixel_format" type="string" value="yuyv"/>
</node>
<node name="img_tran" pkg="ar_localization" type="img_tran" respawn="false" output="log">
</node>
</launch>
ptam 启动文件.. 图像接口.
<launch>
<node name="ptam" pkg="ptam" type="ptam" clear_params="true" output="screen">
<remap from="image" to="$(optenv IMAGE /mono_image)" />
<remap from="pose" to="pose"/>
<rosparam file="$(find ptam)/PtamFixParams.yaml"/>
</node>
</launch>
相机参数文件
gui: True
ImageSizeX: 640
ImageSizeY: 480
ARBuffer_width: 1200
ARBuffer_height: 900
WiggleScale: 0.1
BundleMEstimator: Tukey
TrackerMEstimator: Tukey
MinTukeySigma: 0.4
CandidateMinSTScore: 70
Calibrator_BlurSigma: 1.0
Calibrator_MeanGate: 10
Calibrator_MinCornersForGrabbedImage: 20
Calibrator_Optimize: 0
Calibrator_Show: 0
Calibrator_NoDistortion: 0
CameraCalibrator_MaxStepDistFraction: 0.3
CameraCalibrator_CornerPatchSize: 20
GLWindowMenu_Enable: True
GLWindowMenu_mgvnMenuItemWidth: 90
GLWindowMenu_mgvnMenuTextOffset: 20
InitLevel: 1
MaxKFDistWiggleMult: 1
MaxPatchesPerFrame: 300
MaxKF: 15
parent_frame: world
TrackingQualityFoundPixels: 50
UseKFPixelDist: True
NoLevelZeroMapPoints: True
FASTMethod: OAST16
MaxStereoInitLoops: 4
AutoInitPixel: 20
# --- bluefox - low distort lens ---
Cam_fx: 0.795574
Cam_fy: 1.25149
Cam_cx: 0.50417
Cam_cy: 0.51687
Cam_s: 0.482014
# -----------------------------------
更多推荐
已为社区贡献3条内容
所有评论(0)