Capture video size and frame rate with gstreamer/opencv

hi,
Are you currently working with an ROV or a Gstreamer based video sysyem?

yes, ROV video system used

you are able to see videos with your QGroundControl ,Right?

yes QGC reporting is Windows 10 based.
thank you

ok understood. Please go through this.
gstreamer-windows

in linux system , open a terminal and copy-paste the commands and you can see the frame rate and other details overlayed on video, provided your system is installed with gstreamer.

thank you

http://www.ardusub.com/developers/opencv.html
I even succeeded in viewing live video using the code in this link.

Thanks for the answer.

The video comes as encoded H264 frames via UDP, it’s a way to get video as fast as possible.

You can get the frame rate and image size directly from your ROV video stream configuration, the only value that may change is the frame rate, but it should not change if everything is working as expected.

But, if you want to get theses values directly with a program/script, you can get it with python with the line caps.get_structure(0).get_value('height') or caps.get_structure(0).get_value('width'), and with C++ using the variables width and height. The frame rate will be the rate that a new frame will be available, that can be done in the python script with the frequency of frame_available function and in the C++ with framecount frequency.

Thank you.
To check the frequency of the frame_available(self) function
How many times can I check the number of calls in 1 second?

Can I do this??
while True:
# Wait for the next frame
if not video.frame_available():
continue
# fps check
** curTime = time.time()**
** sec = curTime - prevTime**
** prevTime = curTime**

** fps = 1/(sec)**
** #end**
frame = video.frame()
cv2.imshow(‘frame’, frame)
if cv2.waitKey(1) & 0xFF == ord(‘q’):
break

Hello
Is my answer wrong??

Happy New Years

I look forward to your answer.
help me

The idea looks right. Have you tried it?

I tried it.
The fps came out higher than the setting value.
The sec comes out as 0.00x, so the fps value comes out in three digits.

Help me

Is this calculation correct??

Please stop spamming the bluerobotics engineers, particularly without providing any additional information about what you’ve tried/what specifically you’re struggling with - they’re busy people and will get to your question when they have time.

Your framerate measuring logic seems fine to me, although it’s better to use time.perf_counter() than time.time() for precise timing scenarios. The actual issue you’re having is that the Video class defined in the ardusub docs will always have frame_available after the first frame has been read. If you check how it’s defined it just checks that the internal _frame variable isn’t None, and the Video.frame function just returns what’s currently stored in the _frame variable. Accordingly, there’s no way (without modifying that class) to find out the actual rate that frames are coming in - what you’re timing with your current code is just how long it took to get to the next loop iteration, which should be a couple of milliseconds.

If it’s important for you to know the actual framerate you can modify the Video.callback() function to do your timing for you instead (since that’s when each new frame actually gets pulled in), or you can change to using gstreamer as an opencv backend instead of as a python library, and use something like the measure_framerate function in my library pythonic-cv, as I’ve outlined here.

Thank you.
I was so frustrated that I kept posting.