Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

developers: opencv: Update c++ example #256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions developers/opencv.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,13 @@ if __name__ == '__main__':
* BlueRov video capture example
* Based on:
* https://stackoverflow.com/questions/10403588/adding-opencv-processing-to-gstreamer-application
* Should be compiled with: g++ -g main.cpp `pkg-config --cflags --libs opencv4 gstreamer-1.0 gstreamer-app-1.0` -o example && ./example
*/

// Include atomic std library
#include <atomic>

// Include gstreamer library
#include <cstdio>
#include <gst/gst.h>
#include <gst/app/app.h>

// Include OpenCV library
#include <opencv.hpp>
#include <opencv2/opencv.hpp>

// Share frame between main loop and gstreamer callback
std::atomic<cv::Mat*> atomicFrame;
Expand Down Expand Up @@ -339,7 +335,7 @@ int main(int argc, char *argv[]) {
gchar *descr = g_strdup(
"udpsrc port=5600 "
"! application/x-rtp, payload=96 ! rtph264depay ! h264parse ! avdec_h264 "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is pretty standard to have a h264parse after depay. do you know why it had to be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, take a look now

"! decodebin ! videoconvert ! video/x-raw,format=(string)BGR ! videoconvert "
"! videoconvert ! video/x-raw,format=(string)BGR ! videoconvert "
"! appsink name=sink emit-signals=true sync=false max-buffers=1 drop=true"
);

Expand Down Expand Up @@ -378,9 +374,9 @@ int main(int argc, char *argv[]) {
while(1) {
g_main_iteration(false);

cv::Mat* frame = atomicFrame.load();
const cv::Mat* frame = atomicFrame.exchange(nullptr);
if(frame) {
cv::imshow("Frame", atomicFrame.load()[0]);
cv::imshow("Frame", *frame);
cv::waitKey(30);
}
}
Expand Down
Loading