mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 01:53:57 +08:00
Webcam: prepare to make camerad a PythonProcess (#31202)
* webcam * support /dev/* syntax * support strings
This commit is contained in:
@@ -3,6 +3,10 @@ import numpy as np
|
||||
|
||||
class Camera:
|
||||
def __init__(self, cam_type_state, stream_type, camera_id):
|
||||
try:
|
||||
camera_id = int(camera_id)
|
||||
except ValueError: # allow strings, ex: /dev/video0
|
||||
pass
|
||||
self.cam_type_state = cam_type_state
|
||||
self.stream_type = stream_type
|
||||
self.cur_frame_id = 0
|
||||
|
||||
@@ -25,7 +25,7 @@ class Camerad:
|
||||
|
||||
self.cameras = []
|
||||
for c in CAMERAS:
|
||||
cam = Camera(c.msg_name, c.stream_type, int(c.cam_id))
|
||||
cam = Camera(c.msg_name, c.stream_type, c.cam_id)
|
||||
assert cam.cap.isOpened(), f"Can't find camera {c}"
|
||||
self.cameras.append(cam)
|
||||
self.vipc_server.create_buffers(c.stream_type, 20, False, cam.W, cam.H)
|
||||
@@ -63,6 +63,11 @@ class Camerad:
|
||||
for t in threads:
|
||||
t.join()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
def main():
|
||||
camerad = Camerad()
|
||||
camerad.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user