goodrobots / vision_landing

Precision landing using visual targets
GNU General Public License v3.0
202 stars 71 forks source link

Break out videocapture into separate thread #97

Closed fnoop closed 6 years ago

fnoop commented 6 years ago

When detection and processing is slower than it takes to retrieve frames, they will build up in the VideoCapture buffer. Break out into a separate thread retrieving the frames from VideoCapture as fast as possible and timestamp them.

fnoop commented 6 years ago

https://docs.opencv.org/3.4/d8/dfe/classcv_1_1VideoCapture.html

fnoop commented 6 years ago

Also need to break out VideoWriter: https://docs.opencv.org/3.4/dd/d9e/classcv_1_1VideoWriter.html

2018-07-19 09:48:11,492 DEBUG track_targets: Debug['Time(detectloop|GrabImage      )', '6.43434ms 6.43434ms']
2018-07-19 09:48:11,494 DEBUG track_targets: Debug['Time(detectloop|DecodeImage    )', '11.602ms 18.0363ms']
2018-07-19 09:48:11,497 DEBUG track_targets: Debug['Time(detectloop|MarkerDetect   )', '22.6277ms 40.6641ms']
2018-07-19 09:48:11,501 DEBUG track_targets: Debug['Time(detectloop|MarkerLock     )', '0.135572ms 40.7996ms']
2018-07-19 09:48:11,502 DEBUG track_targets: Debug['Time(detectloop|PoseEstimation )', '2.31488ms 43.1145ms']
2018-07-19 09:48:11,504 DEBUG track_targets: Debug['Time(detectloop|SendMessage    )', '1.14562ms 44.2601ms']
2018-07-19 09:48:11,506 DEBUG track_targets: Debug['Time(detectloop|DrawGreenAR    )', '2.0965ms 46.3566ms']
2018-07-19 09:48:11,508 DEBUG track_targets: Debug['Time(detectloop|OutputImage    )', '35.5989ms 81.9555ms']
2018-07-19 09:48:11,510 DEBUG track_targets: Debug['Time(detectloop|EndofLoop      )', '0.097708ms 82.0533ms']
2018-07-19 09:48:11,527 DEBUG track_targets: Debug['Time(detectloop|total          )', '0.040104ms 82.0934ms']
fnoop commented 6 years ago

Out of a total 82.0934ms time to process the above frame, only 22.6277ms are actually needed to extract the pose and send back the message. The rest should be broken out to separate threads.

fnoop commented 6 years ago

Note trying to set VideoCapture buffer to 0 results in: ERROR track_targets: VIDEOIO ERROR: V4L2: setting property #38 is not supported

fnoop commented 6 years ago

Completed in https://github.com/goodrobots/vision_landing/commit/cef02bd42b1ecf05706bbbecaf20bf4aec8ce12e