LISHUZUOXUN_yangjiang/MCamera/camera_test.py

27 lines
575 B
Python
Raw Normal View History

2024-09-23 14:54:15 +08:00
import time
import cv2
from AcrossPlatform.get_platform import *
def camera_is_available(source=0):
# <20><><EFBFBD><EFBFBD>ƽ̨<C6BD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>İ<EFBFBD>
if SYS_PLATFORM == WINDOWS:
2024-09-23 16:09:59 +08:00
cap = cv2.VideoCapture(source, cv2.CAP_DSHOW)
2024-09-23 14:54:15 +08:00
elif SYS_PLATFORM == LINUX:
cap = cv2.VideoCapture(source, cv2.CAP_V4L2)
else:
cap = None
if cap is not None and cap.isOpened():
time.sleep(0.1)
ret, frame = cap.read()
if ret:
cap.release()
return True
return False
if __name__ == "__main__":
print(camera_is_available())