我是靠谱客的博主 精明黑裤,最近开发中收集的这篇文章主要介绍ROS&OpenCV进行摄像头数据的采集与订阅发布(转)编译出错 cannot find -lopencv_dep_cudart,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
一銤阳光原文链接 点击打开链接
依赖
opencv库
ros-indigo-image-transport
首先用openCV来捕获视频流,然后转换成ROS图像的传输格式
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/highgui/highgui.hpp>
int main( int argc, char **argv )
{
ros::init( argc, argv, "pub_cam_node" );
ros::NodeHandle n;
// Open camera with CAMERA_INDEX (webcam is typically #0).
const int CAMERA_INDEX = 0;
cv::VideoCapture capture( CAMERA_INDEX ); //摄像头视频的读操作
if( not capture.isOpened() )
{
ROS_ERROR_STREAM(
"Failed to open camera with index " << CAMERA_INDEX << "!"
);
ros::shutdown();
}
//1 捕获视频
//2 创建ROS中图像的发布者
image_transport::ImageTransport it( n );
image_transport::Publisher pub_image = it.advertise( "camera", 1 );
//cv_bridge功能包提供了ROS图像和OpenCV图像转换的接口,建立了一座桥梁
cv_bridge::CvImagePtr frame = boost::make_shared< cv_bridge::CvImage >();
frame->encoding = sensor_msgs::image_encodings::BGR8;
while( ros::ok() ) {
capture >> frame->image; //流的转换
if( frame->image.empty() )
{
ROS_ERROR_STREAM( "Failed to capture frame!" );
ros::shutdown();
}
//打成ROS数据包
frame->header.stamp = ros::Time::now();
pub_image.publish( frame->toImageMsg() );
cv::waitKey( 3 );//opencv刷新图像 3ms
ros::spinOnce();
}
capture.release(); //释放流
return EXIT_SUCCESS;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
OpenCV可以捕获摄像头数据,或者从文件中读取数据
cv::VideoCapture capture( const string& filename, // 输入文件名 );
cv::VideoCapture capture( int device // 视频捕捉设备 id ); 设备号从0开始往后排
再写一个节点来订阅这个ROS发布的图像话题
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
//sensor_msgs::Image ROS中image传递的消息形式
try
{
cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);
// cv::WaitKey(3);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
}
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "image_sub_node");
ros::NodeHandle nh;
cv::namedWindow("view");
cv::startWindowThread();
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub = it.subscribe("camera", 1, imageCallback);
ros::spin();
cv::destroyWindow("view"); //窗口
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
还可以通过 web_video_server 把image通过网络进行传输
编译出错 cannot find -lopencv_dep_cudart
catkin_make 本质上还是make文件
在Cmakelists.txt中做相应的修改,
在cmake编译时 加参数 -D CUDA_USE_STATIC_CUDA_RUNTIME=OFF
或者直接在Cmakelist.txt文件中修改,
CMakeLists.txt中find_package(OpenCV REQUIRED)之前加上:set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
最后
以上就是精明黑裤为你收集整理的ROS&OpenCV进行摄像头数据的采集与订阅发布(转)编译出错 cannot find -lopencv_dep_cudart的全部内容,希望文章能够帮你解决ROS&OpenCV进行摄像头数据的采集与订阅发布(转)编译出错 cannot find -lopencv_dep_cudart所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复