Hello everyone!
I’ve been trying to solve a problem for two week.The problem is that I want to use gstreamer to speed the opencv function named “VideoCapture” but the function named “cap.isOpened()” is return false,so I can’t get video frame to do processing.
Firstly,I used
VideoCapture cap("rtsp://admin:admin12345@192.168.1.64:554/h264/ch33/main/av_stream")
,video display effect is very poor with delayed,caton and mosaic.Someone here told me that I can use gstreamer to speed but he didn’t give detailed information.
Secondly,I tested the link https://devtalk.nvidia.com/default/topic/1001696/jetson-tx1/failed-to-open-tx1-on-board-camera/post/5117370/#5117370 to check if there was gstreamer in opencv and the result was fine that I can see the on-board camera video.
Thirdly,I tested
gst-launch-1.0 rtspsrc location="rtsp://admin:admin12345@192.168.1.64:554/h264/ch33/main/av_stream" latency=0 ! decodebin ! autovideosink
in shell and the result was fine that I can see my IP camera video.
Then I tested many kinds of gstreamer pipelines in the “VideoCapture” function,and have not see my IP camera video successfully.My code is as follows.
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui.hpp>
int main()
{
const char* gst = "rtspsrc location=\"rtsp://admin:admin12345@192.168.1.64:554/h264/ch33/main/av_stream\" ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)25/1 ! \
nvvidconv flip-method=2 ! video/x-raw, format=(string)I420 ! \
videoconvert ! video/x-raw, format=(string)BGR ! \
appsink";
cv::VideoCapture cap(gst);
if(!cap.isOpened())
{
std::cout<<"Failed to open camera."<<std::endl;
return -1;
}
unsigned int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
unsigned int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
unsigned int pixels = width*height;
std::cout <<"Frame size : "<<width<<" x "<<height<<", "<<pixels<<" Pixels "<<std::endl;
cv::namedWindow("MyCameraPreview", CV_WINDOW_AUTOSIZE);
cv::Mat frame_in(width, height, CV_8UC3);
while(1)
{
if (!cap.read(frame_in)) {
std::cout<<"Capture read error"<<std::endl;
break;
}
else {
cv::imshow("MyCameraPreview",frame_in);
cv::waitKey(1000/25); // let imshow draw and wait for next frame 40 ms for 25 fps
}
}
return 0;
}
I think it is the gstreamer pipeline I used is wrong.
BTW,my platform is jetson TX1,qt5.5,opencv2.4.13 which has been rebuild with gstreamer1.0.
Thank you for seeing here,I would appreciate it if you could give me some advice.