Fixed pub_cam_thread to select pub_cam_loop_pyv4l2 only if the library was loaded.

This commit is contained in:
Josh Miklos
2020-04-13 20:59:47 -07:00
parent ce77f1ba33
commit 3f5823cd49
+10 -2
View File
@@ -7,10 +7,13 @@ import cv2
import warnings
import sys
using_pyv4l2cam = False
try:
if sys.platform == "linux":
from PyV4L2Cam.camera import Camera as pyv4lcamera
from PyV4L2Cam.controls import ControlIDs as pyv4lcontrolids
using_pyv4l2cam = True
except ImportError:
warnings.warn("Could not import PyV4L2Cam on linux. Camera capture will be slow.")
warnings.warn(
@@ -170,8 +173,13 @@ def pub_cam_thread(
) -> threading.Thread:
"""Run pub_cam_loop in a new thread. Starts on creation."""
if sys.platform == "linux" and (
isinstance(cam_id, int) or (isinstance(cam_id, str) and "/dev/video" in cam_id)
if (
sys.platform == "linux"
and using_pyv4l2cam
and (
isinstance(cam_id, int)
or (isinstance(cam_id, str) and "/dev/video" in cam_id)
)
):
pub_cam_loop = pub_cam_loop_pyv4l2
else: