-
Notifications
You must be signed in to change notification settings - Fork 35
/
GrabberThread.py
49 lines (30 loc) · 1.34 KB
/
GrabberThread.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
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 2 15:44:40 2016
@author: agedemo
"""
import threading
import cv2
import GrabUnit
class GrabberThread(threading.Thread):
def __init__(self, parent, params):
threading.Thread.__init__(self)
camId = params.getint("camera", "Id")
camResolution = params.get("camera", "resolution")
camResolution = camResolution.upper().split("X")
camResolution = [int(x) for x in camResolution]
print(("Using camera %d at resolution %s" % (camId, camResolution)))
self.flipHor = params.getint("camera", "flip_horizontal")
self.video = cv2.VideoCapture(camId) # 0: Laptop camera, 1: USB-camera
#self.video.set(3, camResolution[0]) # 1280 #1920 Default: 640
#self.video.set(4, camResolution[1]) # 720 #1080 Default: 480
self.parent = parent
print("Grabber Thread initialized...")
def run(self):
while not self.parent.isTerminated():
stat, frame = self.video.read()
if frame is not None and not self.parent.isTerminated():
if self.flipHor:
frame = frame[:, ::-1, ...]
unit = GrabUnit.GrabUnit(frame)
self.parent.putUnit(unit)