how to display video we get from cv_bridge?
i am getting some errror in doing processing of that mutiple images . so i want to know whether i am doing right or not.
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
You may want to give this code a try to have a live stream from either your IP camera (Android phone) or a low cost USB camera.
cameraPub.cpp
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <camera_info_manager/camera_info_manager.h>
#include <sstream>
using namespace std;
using namespace cv;
using namespace ros;
int main(int argc, char** argv)
{
// Check if video source has been passed as a parameter
init(argc, argv, "cameraPub");
NodeHandle nh;
if(argc != 2)
{
cerr << endl << "Usage: rosrun ORB_SLAM2 cameraPub camera_name(webcam or phone?)" << endl;
ros::shutdown();
return 1;
}
stringstream ss;
string camera_name;
ss << argv[1];
ss >> camera_name;
//string camera_name = "logitech_B525";
//string camera_name = "Android";
image_transport::ImageTransport it(nh);
image_transport::Publisher pub_cam_msg = it.advertise(camera_name+"/image_raw", 1);
Publisher pub_cam_info = nh.advertise<sensor_msgs::CameraInfo>(camera_name+"/camera_info", 1);
// default camera
VideoCapture cap(0);
// camera_info -> setting file (.yaml)
const string camurl = "file:///path/to/settingFile/logitech_B525.yaml";
if (camera_name == "phone")
{
// IP webcam
cout<<"IP camera selected!"<<endl;
const string vsa = "http://192.168.43.26:8080/video?x.mjpeg";
VideoCapture cap(vsa);
// camera_info -> setting file (.yaml)
const string camurl = "file:///path/to/settingFile/Huawei_P10.yaml";
}
else
{
cout<<"Default Camera!"<<endl;
}
// Check video is open
if (!cap.isOpened())
{
cerr<<"Could not open video!!"<<endl;
nh.shutdown();
return 1;
}
cout << "\nCamera from " << camera_name << " ON ------------>>>>>>>>>>>>" << endl;
Mat frame;
sensor_msgs::ImagePtr cam_msg;
camera_info_manager::CameraInfoManager caminfo(nh, camera_name, camurl);
sensor_msgs::CameraInfo ci;
Rate loop_rate(5);
while (nh.ok()) {
cap >> frame;
if(!frame.empty())
{
cam_msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", frame).toImageMsg();
ci.header.stamp = ros::Time::now(); //
ci=caminfo.getCameraInfo();
pub_cam_msg.publish(cam_msg);
pub_cam_info.publish(ci);
imshow("video stream",frame);
waitKey(1); // 30 ms */
}
else
{
cout << "EMPTY FRAME!" << endl;
}
spinOnce();
}
return 0;
}
Asked: 2018-12-02 10:22:51 -0600
Seen: 501 times
Last updated: Dec 03 '18
Are there somebodies use OpenCV2.2 with ROS ?
services with sensor_msgs::Image response in diamondback ubuntu10.10
Any good examples of using dynamic_reconfigure for a python node?
Converting Kinect RGB image to OpenCV gives wrong colours
How to recieve an array over Publisher and Subscriber? (Python)
can you share more detail like your code? we can't say anything without more detail.