how to publisher image and camera
I don't know publisher image and camera Can you help me ? I use ros fuerte . I want to publisher camera but i don't now !
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org |
I don't know publisher image and camera Can you help me ? I use ros fuerte . I want to publisher camera but i don't now !
an example of code that get image from camera then publish the image:
#include "camera.h"
CameraDriver::CameraDriver()
{
ros::NodeHandle n("~");
n.param( "camera_index", id_camera, -1);
n.param( "show", show , false );
n.param( "fps", fps , 30 );
cvi.header.frame_id = "image";
cvi.encoding = sensor_msgs::image_encodings::BGR8;
it = new image_transport::ImageTransport(n);
pub=it->advertise("/image_raw",1);
if(id_camera == -1)
{
ROS_WARN("camera's id has not recived");
ROS_WARN("I will open every camera that I find :P ");
}
input_video.open(id_camera);
input_video.set(CV_CAP_PROP_FPS,fps);
if(!input_video.isOpened())
{
ROS_ERROR("Couldn't Open The Camera !");
ROS_ERROR("Babay :(");
ros::shutdown();
}
ros::Rate loop_rate(fps);
while (ros::ok())
{
input_video.read(frame);
cvi.image=frame;
cvi.header.stamp = ros::Time::now();
pub.publish(cvi.toImageMsg());
if(show)
{
imshow("imgout.jpg", frame);
if(waitKey(1) > 0);
}
loop_rate.sleep();
}
}
and .h
#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "cv_bridge/cv_bridge.h"
#include <sensor_msgs/image_encodings.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>
using namespace std;
using namespace cv;
class CameraDriver
{
public:
int id_camera;
int fps;
bool show;
VideoCapture input_video;
Mat frame;
cv_bridge::CvImage cvi;
image_transport::ImageTransport *it;
image_transport::Publisher pub;
explicit CameraDriver();
};
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2014-09-17 11:19:31 -0500
Seen: 2,474 times
Last updated: Sep 18 '14
custom stereo camera publisher fails mysteriously
How to start creating a package/node in ROS?
Unable to publish PoseStamped message
listener and talker in rosjava [closed]
How can I use webcam on fuerte?
what is the distance unit of /camera/depth/image_raw
What to publish from a new camera driver
When to change the buffer size parameter of advertise function
Please write more about what your looking for.
There are many ROS camera driver packages. Use one that supports your device: http://wiki.ros.org/Sensors/Cameras .
If you tell us what kind of camera you have, someone can probably suggest a good driver.