bro
This commit is contained in:
1 parent
de41a02749
commit
9af09cebd3
764 files changed
+54218
-78859
No files matched your search
@@ -56,9 +56,7 @@ def _pre_init_placeholder_varargs(*_, **__):
|
||||
|
||||
|
||||
class _PreInitPlaceholderCamera(AbstractCamera):
|
||||
def __init__(self, *args, **kwargs):
|
||||
_pre_init_placeholder()
|
||||
|
||||
__init__ = _pre_init_placeholder_varargs
|
||||
start = _pre_init_placeholder_varargs
|
||||
stop = _pre_init_placeholder_varargs
|
||||
get_controls = _pre_init_placeholder_varargs
|
||||
@@ -106,6 +104,20 @@ def _setup_backend(backend):
|
||||
list_cameras = _camera.list_cameras
|
||||
Camera = _camera.Camera
|
||||
|
||||
elif backend == "videocapture":
|
||||
from pygame import _camera_vidcapture
|
||||
|
||||
warnings.warn(
|
||||
"The VideoCapture backend is not recommended and may be removed."
|
||||
"For Python3 and Windows 8+, there is now a native Windows "
|
||||
"backend built into pygame.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
_camera_vidcapture.init()
|
||||
list_cameras = _camera_vidcapture.list_cameras
|
||||
Camera = _camera_vidcapture.Camera
|
||||
else:
|
||||
raise ValueError("unrecognized backend name")
|
||||
|
||||
@@ -113,16 +125,34 @@ def _setup_backend(backend):
|
||||
def get_backends():
|
||||
possible_backends = []
|
||||
|
||||
if sys.platform == "win32" and int(platform.win32_ver()[0].split(".")[0]) >= 8:
|
||||
possible_backends.append("_camera (MSMF)")
|
||||
if sys.platform == "win32":
|
||||
version_code = platform.win32_ver()[0].split(".")[0]
|
||||
if "Server" in version_code:
|
||||
version_code = ''.join(filter(str.isdigit, version_code))[:4]
|
||||
minimum_satisfied = int(version_code) >= 2012
|
||||
else:
|
||||
minimum_satisfied = int(version_code) >= 8
|
||||
|
||||
if sys.platform == "linux":
|
||||
if minimum_satisfied:
|
||||
try:
|
||||
# If cv2 is installed, prefer that on windows.
|
||||
import cv2
|
||||
|
||||
possible_backends.append("OpenCV")
|
||||
except ImportError:
|
||||
possible_backends.append("_camera (MSMF)")
|
||||
|
||||
if "linux" in sys.platform:
|
||||
possible_backends.append("_camera (V4L2)")
|
||||
|
||||
if "darwin" in sys.platform:
|
||||
possible_backends.append("OpenCV-Mac")
|
||||
|
||||
possible_backends.append("OpenCV")
|
||||
if "OpenCV" not in possible_backends:
|
||||
possible_backends.append("OpenCV")
|
||||
|
||||
if sys.platform == "win32":
|
||||
possible_backends.append("VideoCapture")
|
||||
|
||||
# see if we have any user specified defaults in environments.
|
||||
camera_env = os.environ.get("PYGAME_CAMERA", "").lower()
|
||||
@@ -131,6 +161,11 @@ def get_backends():
|
||||
possible_backends.remove("OpenCV")
|
||||
possible_backends = ["OpenCV"] + possible_backends
|
||||
|
||||
if camera_env in ("vidcapture", "videocapture"): # prioritize vidcapture
|
||||
if "VideoCapture" in possible_backends:
|
||||
possible_backends.remove("VideoCapture")
|
||||
possible_backends = ["VideoCapture"] + possible_backends
|
||||
|
||||
return possible_backends
|
||||
|
||||
|
||||
@@ -155,8 +190,8 @@ def init(backend=None):
|
||||
_setup_backend(backend)
|
||||
except ImportError:
|
||||
emsg = f"Backend '{backend}' is not supported on your platform!"
|
||||
if backend in ("opencv", "opencv-mac"):
|
||||
dep = "OpenCV"
|
||||
if backend in ("opencv", "opencv-mac", "videocapture"):
|
||||
dep = "vidcap" if backend == "videocapture" else "OpenCV"
|
||||
emsg += (
|
||||
f" Make sure you have '{dep}' installed to be able to use this backend"
|
||||
)
|
||||
@@ -176,7 +211,7 @@ def quit():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# try to use this camera stuff with the pygame camera example.
|
||||
# try and use this camera stuff with the pygame camera example.
|
||||
import pygame.examples.camera
|
||||
|
||||
# pygame.camera.Camera = Camera
|
||||
|
||||
Reference in new issue
Block a user