alex-ong / NESTrisOCR

OCR for statistics in NESTris
24 stars 7 forks source link

OpenCV: support video streams #21

Closed timotheeg closed 4 years ago

timotheeg commented 4 years ago

The current OpenCV capture class has 2 minor issues

  1. it casts the device id to int immediately, which is then tested for truthiness in main.py (because for window capture, it represents the window ID), but openCV device ID can be 0, which is falsy
  2. Casting to int implies the user only uses openCV for local device capture. However OpenCV supports many string-based identifier, like stream URLs.

This PR:

  1. delays the casting to int: the opencv id is kept as string initially, so it is truthy even if it's '0'
  2. handles casting failure and passes the opencv ID as-is.

2) above means that a casting failure is treated as the user passing a stream on purpose rather than being a mistake.

On real mistakes, openCV itself will complain.

alex-ong commented 4 years ago

Nice