This repository has been archived by the owner on Jan 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualPipeline.py
106 lines (76 loc) · 2.43 KB
/
visualPipeline.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from config import runConfig
import cv2
import numpy as np
import manipulateImageS as MI
import sys
"""
Standalone demo for vision processing
reads frame from mjpeg-streamer
displays:
original
mask
original with mask outline
original with line, telemetry
"""
class Configuration:
def __init__(self):
self.os = None
self.camera = None
self.calibration = None
self.freqFrameNT = None
self.vertx = None
self.verty = None
self.os, self.camera, self.calibration, self.freqFrameNT, self.vertx, self.verty = runConfig()
def get_configuration(self, config_item):
item = getattr(self, config_item, None) # should be noted that getattr() only works for obj.attr and no further
return item
class Display:
def __init__(self):
self.image_original = None
self.image_hsv = None
self.mask = None
self.mask_dil_ero = None
self.mask_threshold = None
def create_display(self):
cv2.namedWindow('original')
cv2.namedWindow('hsv')
cv2.namedWindow('mask')
cv2.namedWindow('mask_dil_ero')
cv2.namedWindow('mask_threshold')
cv2.waitKey(0)
def main():
config = Configuration()
capture = acquire_capture(config)
image, ret = acquire_image(capture)
image_operations(image, config)
def image_operations(img_orig,config):
img = np.copy(img_orig) # HERE
lower_bound = np.array(config.calibration["green"]["green_lower"])
upper_bound = np.array(config.calibration["green"]["green_upper"])
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # HERE
mask_orig = cv2.inRange(hsv, lower_bound, upper_bound)
mask = np.copy(mask_orig) # HERE
mask_eroded_dilated = MI.erodeAndDilate(mask)
mask = np.copy(mask_eroded_dilated) # HERE
ret, mask_threshold = cv2.threshold(mask, 127, 255, 0)
mask = np.copy(mask_threshold) # HERE
def acquire_capture(config):
try:
capture = cv2.videoCapture(config.camera)
except:
print("ERROR: Unable to open capture. Exiting.")
sys.exit()
return capture
def acquire_image(capture):
image = None
if capture.isOpened():
ret, image = capture.read()
if ret:
return image
else:
print("WARNING: Capture read failed.")
else:
print("ERROR: Capture not opened.")
return image, ret
if __name__ == '__main__':
main()