I’m using gstreamer pipelines for multiple cameras in a sensor suite, all of which are able to be visualized using gstreamer on my computer. The issue occurs when trying to use OpenCV functionality VideoCapture, which I’m using like this: cv::VideoCapture cap(hdr_gst_str, cv::CAP_GSTREAMER);
, where hdr_gst_str is the pipeline for my hdr camera.
I get the following error when running my script: [ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=178, duration=-1
I’ve tried looking into it and it seems many others are having this issue, but I’m unable to find a solid solve. I will post my simple ~50 line ROS node below for posterity. Any help is greatly appreciated.
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <sensor_msgs/Image.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core/mat.hpp>
int main(int argc, char** argv)
{
ros::init(argc, argv, "Vision_Node");
ros::NodeHandle n;
// Gstreamer strings to be used as arguments with cv::VideoCapture
std::string hdr_gst_str ("udpsrc port=5601 ! application/x-rtp, encoding-name=H264, payload=96 ! rtph264depay ! h264parse ! queue ! avdec_h264 ! videoconvert ! video/x-raw ! appsink");
//publisher declarations
ros::Publisher hdr_im_pub = n.advertise<sensor_msgs::Image>("hdr_image",100);
//image capture and image mat
cv::VideoCapture cap(hdr_gst_str, cv::CAP_GSTREAMER);
cv::Mat Img;
int counter;
while(n.ok())
{
//pull in and read images
counter++;
if (!cap.isOpened())
{
ROS_INFO("Failed to capture images");
}
cv_bridge::CvImage im_bridge;
sensor_msgs::Image im_msg;
std_msgs::Header header;
header.seq = counter; //image sequence
header.stamp = ros::Time::now(); //image timestamp
//image encoding might be wrong, HDR currently display as BGR instead of RGB
im_bridge = cv_bridge::CvImage(header, sensor_msgs::image_encodings::RGB16, Img);
//cv_bridge used to convert from cv image to ros message topic
im_bridge.toImageMsg(im_msg);
//ros image message topic publish
hdr_im_pub.publish(im_msg);
ros::spinOnce();
}
}