-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindDevices.py
More file actions
84 lines (64 loc) · 2.43 KB
/
findDevices.py
File metadata and controls
84 lines (64 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import cv2
import depthai as dai
from PySide6.QtCore import QThread, Signal
from PySide6.QtWidgets import QMessageBox
import contextlib
class Load_Device_Thread(QThread):
updateDevices = Signal(list)
loaded = Signal(int)
def __init__(self, parent=None):
QThread.__init__(self, parent)
def run(self):
self.webcam = Webcam_Devices()
self.oak = OAK_USB_Devices()
self.loaded.emit(1)
self.updateDevices.emit([self.webcam,self.oak])
def quit(self):
if self.webcam and self.oak is not None:
num_devs = '2 devices were found!'
elif not self.webcam and self.oak is not None:
num_devs = '1 device was found!'
elif self.webcam and self.oak is None:
num_devs = '1 device was found!'
else:
num_devs = 'No devices were found!'
dlg = QMessageBox()
dlg.setIcon(QMessageBox.Information)
# dlg.setTextFormat(Qt.AlignCenter)
dlg.setWindowTitle(" ")
dlg.setText(num_devs)
dlg.exec()
def Webcam_Devices():
cap = cv2.VideoCapture(0)
if cap is None or not cap.isOpened():
return(False)
else:
return(True)
def OAK_USB_Devices():
try:
devices = []
for device in dai.Device.getAllAvailableDevices():
mxId = device.getMxId()
info = dai.DeviceInfo(mxId) # MXID
#device_info = depthai.DeviceInfo("192.168.1.44") # IP Address
#device_info = depthai.DeviceInfo("3.3.3") # USB port name
pipeline = dai.Pipeline()
en_cam_list = []
with dai.Device(pipeline, info, usb2Mode=True) as dev:
cameras = dev.getConnectedCameras()
for cam in cameras:
if str(cam) == 'CameraBoardSocket.RGB':
en_cam_list.append('Color Camera')
elif str(cam) == 'CameraBoardSocket.LEFT':
en_cam_list.append('Mono Left Camera')
elif str(cam) == 'CameraBoardSocket.RIGHT':
en_cam_list.append('Mono Right Camera')
en_cam_list.append('Stereo')
info_dict = {mxId:en_cam_list}
devices.append(info_dict)
if len(devices) == 0:
return(None)
else:
return(devices)
except Exception:
return(None)