Go to the documentation of this file.00001
00002
00003
00004
00005 #include <ctime>
00006 #include <iostream>
00007 #include <ros/ros.h>
00008 #include <raspicam/raspicam_cv.h>
00009 #include <image_transport/image_transport.h>
00010 #include <cv_bridge/cv_bridge.h>
00011 #include <sensor_msgs/image_encodings.h>
00012 #include <opencv2/highgui/highgui.hpp>
00013
00014 int main(int argc, char **argv) {
00015
00016 raspicam::RaspiCam_Cv Camera;
00017 cv::Mat cv_image;
00018 char c;
00019 int delay = 30;
00020 const char *WIN_NAME = "Test Window";
00021
00022
00023 ros::init(argc, argv, "raspicam_publisher");
00024 ros::NodeHandle node_obj;
00025 image_transpor::ImageTransport it(node_obj);
00026 image_transport::Publisher pub = it.advertise("camera/image", 1);
00027 ros::Rate loop_rate(30);
00028
00029
00030 sensor_msgs::ImagePtr msg;
00031
00032
00033 Camera.set(CV_CAP_PROP_FRAME_WIDTH, 640);
00034 Camera.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
00035
00036
00037
00038
00039
00040
00041
00042 ROS_INFO("Opening Camera...");
00043
00044 if (!Camera.open()) {
00045 ROS_ERROR("Error opening the camera!");
00046 }
00047
00048 while (node_obj.ok()) {
00049
00050 Camera.grab();
00051 Camera.retrieve(cv_image);
00052
00053
00054 msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", cv_image).toImageMsg();
00055 pub.publish(msg);
00056
00057
00058 c = (char) cvWaitKey(delay);
00059 if (c == 27)
00060 break;
00061
00062
00063 ros::spinOnce();
00064 loop_rate.sleep();
00065 }
00066
00067
00068 Camera.release();
00069
00070 return 0;
00071
00072
00073 }