Main Page
Namespaces
Classes
Files
File List
File Members
src
camera_image.cpp
Go to the documentation of this file.
1
#include <
ros/ros.h
>
2
#include <
image_transport/image_transport.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;
12
image_transport::ImageTransport
it(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
}
ros::NodeHandle
image_transport.h
camera_image.msg
msg
Definition:
camera_image.py:47
ros::init
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
image_transport::ImageTransport::advertise
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
ros::Rate
camera_image.frame
frame
Definition:
camera_image.py:45
cv_bridge.h
image_transport::Publisher::publish
void publish(const sensor_msgs::Image &message) const
cv_bridge::CvImage
ros::Rate::sleep
bool sleep()
ros.h
image_transport::ImageTransport
image_transport::Publisher
main
int main(int argc, char **argv)
Definition:
camera_image.cpp:7
camera_image.pub
pub
Definition:
camera_image.py:36
ros::NodeHandle::ok
bool ok() const
ros::spinOnce
ROSCPP_DECL void spinOnce()
cv_bridge::CvImage::toImageMsg
sensor_msgs::ImagePtr toImageMsg() const
xbot_face
Author(s):
autogenerated on Sat Oct 10 2020 03:27:46