-
Notifications
You must be signed in to change notification settings - Fork 0
/
cvtest.cpp
38 lines (33 loc) · 1.01 KB
/
cvtest.cpp
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
#include <ros/ros.h>
#include "std_msgs/String.h"
#include <sstream>
#include <stdio.h>
#include <sensor_msgs/image_encodings.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char **argv)
{
ros::init(argc, argv, "rsdk_xdisplay_image");
ros::NodeHandle n;
image_transport::ImageTransport it(n);
image_transport::Publisher pub;
pub = it.advertise("/robot/xdisplay", 1);
cv::Mat img = cv::imread("sample.jpg");//reading an image
if(!img.data){
printf("Cannot Open Imgfile!¥n");
return(-1);
}
cv::namedWindow("img",CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO);
cv::imshow("img",img);
cv_bridge::CvImage out_msg;
out_msg.encoding = sensor_msgs::image_encodings::BGR8;
out_msg.image = img;
pub.publish(out_msg.toImageMsg());
ros::Rate loop_rate(10);
ros::spinOnce(); //callbackyoudesu
loop_rate.sleep(); //sleep
cvWaitKey(100000);
return 0;
}