B4J Code Snippet jOpenCV with IP-cameras

Hi, All

After long trying and googling i have found that OpenCV with IP-cameras must work by special way.
Regular way is to use "mVideoCapture.read(vcMat)", as recommended by the lib author (again ton of Thanks to him !), it's OK for stable stream of USB-camera:


But IP-camera frames may be with various delays due to the network latency, so the real way is always to get the very latest video frame at the current moment, after previous frame processing.
And this can be done (if without the Threading lib, that i could not make to work) by the loop that makes the buffer empty:
B4X:
    'instead of: Dim Captured As Boolean = mVideoCapture.read(vcMat)
    'use:
    For i = 0 To 30 'it's qty of the FPS of the IP-camera stream setting
        mVideoCapture.grab    'grab all frames from buffer first without the decoding
    Next
    Dim Captured As Boolean = mVideoCapture.retrieve1(vcMat)    'decode the latest frame only

And such code will help to make video processing almost realtime, depending on the time of each frame processing.
But all this is done in the main thread, so for several IP-cameras - only the threading lib should help to grab several stream frames ASAP (help for this is needed).
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…