OpenCV 4.5 - Ubuntu - Jetson Nano 2GB - C++
Hello I have a problem with getting video from my webcam (connected by USB to JetsonNano) by OpenCV
Here’s my code:
// cv::VideoCapture cap( ... );
cv::Mat frame;
if (!cap.isOpened()) // if not success, exit program
{
cout << "Cannot open the video cam" << endl;
return -1;
}
cv::namedWindow("test", cv::WINDOW_AUTOSIZE);
while(true)
{
try
{
cap >> frame;
cv::imshow("test", frame);
}
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
}
}
1 | cv::VideoCapture cap(0)
gives me:
[ WARN:0] global /home/legion/opencv/modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
2 | cv::VideoCapture cap("/dev/video0")
gives me:
[ WARN:0] global /home/legion/opencv/modules/videoio/src/cap_gstreamer.cpp (1761) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module source reported: Could not read from resource.
[ WARN:0] global /home/legion/opencv/modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /home/legion/opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Cannot open the video cam
3 | When I try to open camera by command, this one works:
$ gst-launch-1.0 v4l2src device=\"/dev/video0\" ! xvimagesink
so I gave it a try:
cv::VideoCapture cap("v4l2src device=\"/dev/video0\" ! xvimagesink")
it gives me:
[ WARN:0] global /home/legion/opencv/modules/videoio/src/cap_gstreamer.cpp (803) open OpenCV | GStreamer warning: cannot find appsink in manual pipeline
[ WARN:0] global /home/legion/opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Cannot open the video cam
If I gave other sinks : autosink or appsink, it’s also doesn’t work.
4 | I tried the solution from that link
cv::VideoCapture cap("v4l2src device=/dev/video0 ! video/x-raw,width=1920,height=1080,format=UYVY,framerate=30/1 ! videoconvert ! video/x-raw,format=BGR ! appsink")
and it’s gives me :
[ WARN:0] global /home/legion/opencv/modules/videoio/src/cap_gstreamer.cpp (1761) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data stream error.
[ WARN:0] global /home/legion/opencv/modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /home/legion/opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ERROR:0] global /home/legion/opencv/modules/videoio/src/cap.cpp (142) open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.5.0) /home/legion/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): v4l2src device=/dev/video0 ! video/x-raw,width=1920,height=1080,format=UYVY,framerate=30/1 ! videoconvert ! video/x-raw,format=BGR ! appsink in function 'icvExtractPattern'
Someone knows what’s going on and how to fix it?
Thanks ~~