-
Notifications
You must be signed in to change notification settings - Fork 0
/
See3Cam.py
60 lines (47 loc) · 1.53 KB
/
See3Cam.py
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
from threading import Thread
import cv2
import subprocess
from subprocess import PIPE
import os
import time
import timeit
from queue import Queue
class See3Cam:
def __init__(self, src, width, height, framerate, name):
self.src = src
self.name = name
self.width = width
self.height = height
self.framerate = framerate
self.grabbed = False
self.frame = None
self.stream = cv2.VideoCapture(src)
self.stream.set(3, width)
self.stream.set(4, height)
self.stream.set(cv2.CAP_PROP_FPS, framerate)
self.running = self.stream.isOpened()
self.connected = True
self.stopped = False
def start(self):
t = Thread(target=self.update, args=())
t.daemon = True
t.start()
return self
def update(self):
while True:
if self.stopped:
return
(self.grabbed, self.frame) = self.stream.read()
def read(self):
#return self.Q.get()
return self.grabbed ,self.frame
def stop(self):
self.stopped = True
def find_cam(self, cam):
cmd = ["/usr/bin/v4l2-ctl", "--list-devices"]
out, err = subprocess.Popen(cmd,stdout=PIPE, stderr=PIPE).communicate()
out, err = out.strip(), err.strip()
for l in [i.split(b'\n\t') for i in out.split(b'\n\n')]:
if cam in l[0].decode(encoding="UTF-8"):
return (True, l[1].decode(encoding="UTF-8")[-1])
return False, None