@@ -226,17 +226,13 @@ if __name__ == '__main__':
226226 * BlueRov video capture example
227227 * Based on:
228228 * https://stackoverflow.com/questions/10403588/adding-opencv-processing-to-gstreamer-application
229+ * Should be compiled with: g++ -g main.cpp `pkg-config --cflags --libs opencv4 gstreamer-1.0 gstreamer-app-1.0` -o example && ./example
229230 */
230-
231- // Include atomic std library
232231#include < atomic>
233-
234- // Include gstreamer library
232+ #include < cstdio>
235233#include < gst/gst.h>
236234#include < gst/app/app.h>
237-
238- // Include OpenCV library
239- #include < opencv.hpp>
235+ #include < opencv2/opencv.hpp>
240236
241237// Share frame between main loop and gstreamer callback
242238std::atomic<cv::Mat*> atomicFrame;
@@ -341,7 +337,7 @@ int main(int argc, char *argv[]) {
341337 gchar *descr = g_strdup(
342338 "udpsrc port=5600 "
343339 "! application/x-rtp, payload=96 ! rtph264depay ! h264parse ! avdec_h264 "
344- "! decodebin ! videoconvert ! video/x-raw,format=(string)BGR ! videoconvert "
340+ "! videoconvert ! video/x-raw,format=(string)BGR ! videoconvert "
345341 "! appsink name=sink emit-signals=true sync=false max-buffers=1 drop=true"
346342 );
347343
@@ -380,9 +376,9 @@ int main(int argc, char *argv[]) {
380376 while(1) {
381377 g_main_iteration(false);
382378
383- cv::Mat* frame = atomicFrame.load( );
379+ const cv::Mat* frame = atomicFrame.exchange(nullptr );
384380 if(frame) {
385- cv::imshow("Frame", atomicFrame.load()[0] );
381+ cv::imshow("Frame", *frame );
386382 cv::waitKey(30);
387383 }
388384 }
0 commit comments