camera_image.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
3 #include <opencv2/highgui/highgui.hpp>
4 #include <cv_bridge/cv_bridge.h>
5 #include <sstream> // for converting the command line parameter to integer
6 
7 int main(int argc, char** argv)
8 {
9 
10  ros::init(argc, argv, "camera_image_publisher");
11  ros::NodeHandle nh;
13  image_transport::Publisher pub = it.advertise("/xbot/camera/image", 1);
14 
15  // Convert the passed as command line parameter index for the video device to an integer
16 // std::istringstream video_sourceCmd(0);
17 // int video_source;
18 // // Check if it is indeed a number
19 // if(!(video_sourceCmd >> video_source)) return 1;
20 
21  cv::VideoCapture cap(3);
22  // Check if video device can be opened with the given index
23  if(!cap.isOpened()) return 1;
24  cv::Mat frame;
25  sensor_msgs::ImagePtr msg;
26 
27  ros::Rate loop_rate(30);
28  while (nh.ok()) {
29  cap >> frame;
30  // Check if grabbed frame is actually full with some content
31  if(!frame.empty()) {
32  msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", frame).toImageMsg();
33  pub.publish(msg);
34  cv::waitKey(1);
35  }
36 
37  ros::spinOnce();
38  loop_rate.sleep();
39  }
40 }
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
void publish(const sensor_msgs::Image &message) const
bool sleep()
int main(int argc, char **argv)
Definition: camera_image.cpp:7
bool ok() const
ROSCPP_DECL void spinOnce()
sensor_msgs::ImagePtr toImageMsg() const


xbot_face
Author(s):
autogenerated on Sat Oct 10 2020 03:27:46