-
Notifications
You must be signed in to change notification settings - Fork 0
/
invariantTest.py
executable file
·71 lines (49 loc) · 1.62 KB
/
invariantTest.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 30 22:43:20 2019
@author: dougpalmer
"""
from __future__ import division
import cv2
import numpy as np
from vision3 import droidVision
import time
def BGR2invariant(frame,alpha):
#G - B - R BGR
invariant = 0.5 + np.log(frame[:,:,1]) - alpha * np.log(frame[:,:,2]) - (1-alpha) * np.log(frame[:,:,0]);
invariant = np.uint8(np.round(invariant * 255))
return invariant
if __name__=='__main__':
def nothing(*arg):
pass
L1 = 460e-9;
L2 = 520e-9;
L3 = 600e-9;
alpha = (L1*(L3-L2))/(L2*(L3-L1));
cap = cv2.VideoCapture('test_videos/output2.avi')
vis = droidVision()
cv2.namedWindow("BGR")
cv2.moveWindow('BGR',0,0)
cv2.namedWindow("INV")
cv2.moveWindow('INV',500,0)
cv2.createTrackbar("Alpha", "INV", 0, 100, nothing)
cv2.setTrackbarPos("Alpha", "INV", int(alpha*100))
while(cap.isOpened()):
ret, frame = cap.read()
if frame is not None:
alpha = cv2.getTrackbarPos("Alpha", "INV")
alphaNorm = alpha/100
invariant = BGR2invariant(frame,alphaNorm)
cv2.imshow("BGR",frame)
cv2.imshow("INV",invariant)
k = cv2.waitKey(1)
if k == 27: # wait for ESC key to exit
cap.release()
cv2.destroyAllWindows()
break
else:
print ('releasing resources')
cap.release()
cv2.destroyAllWindows()
break