Skip to content

Commit 8810d99

Browse files
patrickelectricES-Alexander
authored andcommitted
developers: opencv: Update c++ example
Fix wrong delete logic and add compile information Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
1 parent a1b4844 commit 8810d99

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

developers/opencv.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
242238
std::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

Comments
 (0)