Compilation Command for RTSP streaming with OpenCV and GStreamer

I’m a new of Ubuntu user.
I’m trying to make RTSP streaming program using OpenCV and GStreamer.
I finished writing my program. But I couldn’t compile.
I tried some command line using g++. But all command I tried did not work.
I had finished installation gstreamer library for RTSP.

My environmet is as follows.
・Jetson Nano
・Image : r32.2.1

my command line and error messages is as below.

$ g++ -o streaming `pkg-config --cflags --libs gstreamer-1.0 gstreamer-video-1.0 opencv gstreamer-rtsp-server-1.0` streaming.cpp 
/tmp/cc8LtEzF.o: In function `main':
streaming.cpp:(.text+0xc0): undefined reference to `cv::VideoCapture::VideoCapture(cv::String const&, int)'
streaming.cpp:(.text+0xd0): undefined reference to `cv::VideoCapture::isOpened() const'
streaming.cpp:(.text+0x10c): undefined reference to `cv::VideoCapture::get(int) const'
streaming.cpp:(.text+0x1a8): undefined reference to `cv::VideoWriter::fourcc(char, char, char, char)'
streaming.cpp:(.text+0x1dc): undefined reference to `cv::VideoWriter::VideoWriter(cv::String const&, int, double, cv::Size_<int>, bool)'
streaming.cpp:(.text+0x1ec): undefined reference to `cv::VideoWriter::isOpened() const'
streaming.cpp:(.text+0x260): undefined reference to `cv::namedWindow(cv::String const&, int)'
streaming.cpp:(.text+0x2e4): undefined reference to `g_print'
streaming.cpp:(.text+0x310): undefined reference to `g_print'
streaming.cpp:(.text+0x314): undefined reference to `gst_rtsp_server_new'
streaming.cpp:(.text+0x338): undefined reference to `g_object_set'
streaming.cpp:(.text+0x340): undefined reference to `gst_rtsp_server_get_mount_points'
streaming.cpp:(.text+0x348): undefined reference to `gst_rtsp_media_factory_new'
streaming.cpp:(.text+0x35c): undefined reference to `gst_rtsp_media_factory_set_launch'
streaming.cpp:(.text+0x368): undefined reference to `g_print'
streaming.cpp:(.text+0x380): undefined reference to `gst_rtsp_mount_points_add_factory'
streaming.cpp:(.text+0x388): undefined reference to `g_object_unref'
streaming.cpp:(.text+0x394): undefined reference to `gst_rtsp_server_attach'
streaming.cpp:(.text+0x3ac): undefined reference to `cv::VideoCapture::read(cv::_OutputArray const&)'
streaming.cpp:(.text+0x404): undefined reference to `cv::waitKey(int)'
streaming.cpp:(.text+0x464): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
streaming.cpp:(.text+0x4b8): undefined reference to `cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)'
streaming.cpp:(.text+0x4d4): undefined reference to `cv::VideoWriter::write(cv::Mat const&)'
streaming.cpp:(.text+0x4f0): undefined reference to `cv::VideoWriter::~VideoWriter()'
streaming.cpp:(.text+0x500): undefined reference to `cv::VideoCapture::~VideoCapture()'
streaming.cpp:(.text+0x604): undefined reference to `cv::VideoWriter::~VideoWriter()'
streaming.cpp:(.text+0x624): undefined reference to `cv::VideoCapture::~VideoCapture()'
/tmp/cc8LtEzF.o: In function `cv::String::String(char const*)':
streaming.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4c): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cc8LtEzF.o: In function `cv::String::~String()':
streaming.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x10): undefined reference to `cv::String::deallocate()'
/tmp/cc8LtEzF.o: In function `cv::Mat::~Mat()':
streaming.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x34): undefined reference to `cv::fastFree(void*)'
/tmp/cc8LtEzF.o: In function `cv::Mat::release()':
streaming.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x58): undefined reference to `cv::Mat::deallocate()'
/tmp/cc8LtEzF.o: In function `cv::String::String(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
streaming.cpp:(.text._ZN2cv6StringC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN2cv6StringC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x60): undefined reference to `cv::String::allocate(unsigned long)'
collect2: error: ld returned 1 exit status

We have OpenCV + gstreamer samples in

Please download the package and check if you can compile the samples successfully. There should be no issue if you install the system through SDKManager.

Thanks you, DaneLLL.

I was able to compile all these samples. And I was able to compile my program.
It seems that the library specification was insufficient.
But another problem is occurring.

My program is like rtsp over udp.
If the input is videotestsrc, I can stream without any problems.
However, a segmentation fault will occur if the input is a videofile(filesrc).
A program that only display with cv::imshow using the same input video will continue playing until it reaches EOS.

What should I check?
Currently, we are investigating the possibility that the frame rate setting is not enough.

Cant get this to make on Jetson Nano
Compiling: opencv_gst_camera.cpp
opencv_gst_camera.cpp:33:10: fatal error: opencv2/core/core.hpp: No such file or directory
#include <opencv2/core/core.hpp

Hi robby_nvida,

What JetPack version are you using?
It’s working to compiler opencv_camera samples with R32.4.2 public_sources.

  1. scp opencv_gst_samples_src.tbz2 to Nano
  2. Install GStreamer:
    $sudo apt-get install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-libav gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-tools gstreamer1.0-alsa
  3. Compiation:
    $cd opencv-sample-apps/opencv_camera