I am trying to write a C++ program in my Jetson Nano which does the following:
- Receives video from camera and converts it to opencv Mat
- For each image obtained: Detects and/or tracks a specific object in it and draws a bounding box around the object.
- Outputs the images with the bounding boxes to a gstreamer pipeline which encodes those images to jpeg and then outputs those jpegs to some sink, for example, a tcpserversink.
So far, steps 1 and 2 work very well but in step 3 I seem to get a “JPEG parameter struct mismatch” error from gstreamer (more details will come later when I will have access to my computer).
For step 1 I wrote the following code which works fine:
VideoCapture input_video; input_video.open("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=800, height=450, framerate=60/1, format=NV12 ! nvvidconv ! videoconvert ! appsink emit-signals=true sync=false max-buffers=2 drop=true", CAP_GSTREAMER);
Step 3 was done by using OpenCv’s VideoWriter class.
Initializing the VideoWriter:
cv::VideoWriter video_writer; video_writer.open("appsrc ! nvjpegenc ! tcpserversink host=0.0.0.0 port=5000", CAP_GSTREAMER, 0, (double)60, cv::Size(800, 450), true);
For each image obtained (as a Mat object, with a bounding box drawn in it) I outputted it to the VideoWriter
video_writer << frame;
Where frame is the Mat object representing the frame.