标签:ubuntu 摄像头 ros ar-drone opencv
Ubuntu 12.04
ROS Hydro
可参考这篇blog:http://blog.csdn.net/yake827/article/details/44564057
blog:http://blog.csdn.net/celesius/article/details/39188119
已安装adrone_autonomy package 并且可以运行
https://github.com/AutonomyLab/ardrone_autonomy
文档:http://ardrone-autonomy.readthedocs.org
已通过catkin创建一个package (方法见上一篇文章)这里我创建的名称为droneTest
获取ar drone的摄像头实时图像并且可以进行处理
http://answers.ros.org/question/79306/help-with-streaming-ardrone-camera-images-to-opencv/
http://wiki.ros.org/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages
http://wiki.ros.org/vision_opencv
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
static const char WINDOW[]="RGB Image";
static const char WINDOW2[]="Gray Image";
void process(const sensor_msgs::ImageConstPtr& cam_image){
cv_bridge::CvImagePtr cv_ptr;
try
{
cv_ptr = cv_bridge::toCvCopy(cam_image,sensor_msgs::image_encodings::BGR8);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception:%s",e.what());
return;
}
Mat img_rgb = cv_ptr->image;
Mat img_gray;
cvtColor(img_rgb,img_gray,CV_RGB2GRAY);
imshow(WINDOW,img_rgb);
imshow(WINDOW2,img_gray);
cvWaitKey(1);
}
int main(int argc, char **argv){
ros::init(argc,argv,"droneTest");
ros::NodeHandle n;
image_transport::ImageTransport it(n);
image_transport::Subscriber image_sub = it.subscribe("/ardrone/image_raw",1,process);
cv::namedWindow(WINDOW);
cv::namedWindow(WINDOW2);
ros::spin();
return 0;
}
这里使用cv_bridge的toCvCopy来实现格式转换,非常简单
主要目的是添加依赖和添加opencv库
cmake_minimum_required(VERSION 2.8.3)
project(droneTest)
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
sensor_msgs
cv_bridge
image_transport
)
catkin_package()
find_package(OpenCV)
include_directories(
${OpenCV_INCLUDE_DIRS}
)
include_directories(include ${catkin_INCLUDE_DIRS})
add_executable(droneTest src/droneTest.cpp)
target_link_libraries(droneTest ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
add_dependencies(droneTest droneTest_generate_messages_cpp)
编译catkin,在terminal中输入:
cd ~/catkin_ws
catkin_make
这里说明一下就是package.xml这个文件改不改不影响,我发现甚至把里面的dependency都删掉也可以make。
接下来是运行
这里我为了运行方便一般把package复制到~/workshop下
然后把~/catkin_ws/devel/lib/droneTest 复制到~/workshop/droneTest下,这里我的ROS_PACKAGE_PATH 包含~/workshop
我在bashrc中有添加如下代码:
source /opt/ros/hydro/setup.bash
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/workshop
Step 6:运行
1打开一个terminal运行roscore
2 连接ar drone
3 再打开一个terminal运行rosrun ardrone_autonomy ardrone_driver
4 再打开一个terminal运行rosrun droneTest droneTest
ok了
版权声明:本文为博主原创文章,未经博主允许不得转载。
AR Drone系列之:使用ROS catkin创建package并使用cv_bridge实现对ar drone摄像头数据的处理
标签:ubuntu 摄像头 ros ar-drone opencv
原文地址:http://blog.csdn.net/songrotek/article/details/47439617