/
uvcdynctrl.py
81 lines (65 loc) · 1.85 KB
/
uvcdynctrl.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# ------ LIBRARIES ----------
import cv2
import time
import math
import numpy as np
import random
import LARC1 as rb
import gtk
import subprocess
# ---------------------------
def goLive():
cap = cv2.VideoCapture(0)
while (1):
_, imgOriginal = cap.read()
cv2.imshow('im',imgOriginal)
c = cv2.waitKey(50)
if c == 27:
break
cv2.destroyAllWindows()
def nothing(x):
pass
def goLiveT():
cap = cv2.VideoCapture(0)
cv2.namedWindow('image')
# create trackbars for color change
cv2.createTrackbar('Thres','image',0,255,nothing)
# create switch for ON/OFF functionality
switch = '0 : OFF \n1 : ON'
cv2.createTrackbar(switch, 'image',0,1,nothing)
while (1):
_, imgOriginal = cap.read()
cv2.imshow('imgOriginal',imgOriginal)
filteredImage = rb.clearImage(imgOriginal)
# get current positions of four trackbars
binValue = cv2.getTrackbarPos('Thres','image')
s = cv2.getTrackbarPos(switch,'image')
k = cv2.waitKey(1) & 0xFF
if k == 27:
break
if s == 0:
pass
else:
thresImage = rb.doThresHold(filteredImage,binValue)
cv2.imshow('img', thresImage)
cv2.destroyAllWindows()
UVCDYNCTRLEXEC = "/usr/bin/uvcdynctrl"
endProcess = 'n'
while endProcess != 'y':
print "----------------------------"
mainOperation = str(raw_input('What do you want to do? '))
if mainOperation == 's':
method = str(raw_input('Which method do you want to execute? '))
value = str(raw_input('Which value? '))
subprocess.Popen([UVCDYNCTRLEXEC,"-s",method,"--",value])
elif mainOperation == 'g':
method = str(raw_input('Which method do you want to execute? '))
result = subprocess.Popen([UVCDYNCTRLEXEC,"-g",method])
print result
elif mainOperation == 'a':
subprocess.Popen([UVCDYNCTRLEXEC,"-c"])
elif mainOperation == 'c':
goLive()
elif mainOperation == 't':
goLiveT()
endProcess = str(raw_input('Do you want to finish the process? '))