summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'test-cli/test/helpers')
-rw-r--r--test-cli/test/helpers/camara.py18
-rw-r--r--test-cli/test/helpers/detect.py61
-rw-r--r--test-cli/test/helpers/sdl.py22
3 files changed, 76 insertions, 25 deletions
diff --git a/test-cli/test/helpers/camara.py b/test-cli/test/helpers/camara.py
index 9b2829c..afe8112 100644
--- a/test-cli/test/helpers/camara.py
+++ b/test-cli/test/helpers/camara.py
@@ -1,8 +1,7 @@
import cv2
-from test.helpers.syscmd import SysCommand
+import sh
class Camara(object):
- __parent = None
__device_name = None
__device = None
__w = 1280
@@ -13,8 +12,7 @@ class Camara(object):
__hue = 0.0
__exposure = 166
- def __init__(self, parent, device="video0", width=1280, height=720):
- self.__parent = parent
+ def __init__(self, device="video0", width=1280, height=720):
self.__device_name = device
self.__w = width
self.__h = height
@@ -64,21 +62,13 @@ class Camara(object):
def __configure(self):
self.__w = self.__setCamVar(cv2.CAP_PROP_FRAME_WIDTH, self.__w)
self.__h = self.__setCamVar(cv2.CAP_PROP_FRAME_HEIGHT, self.__h)
- cam_setup = SysCommand('v4lsetup', '{}/scripts/v4l-cam.sh'.format(self.__parent.getAppPath()))
- cam_setup.execute()
-
- #self.__contrast = self.__setCamVar(cv2.CAP_PROP_CONTRAST, self.__contrast)
- #self.__brightness = self.__setCamVar(cv2.CAP_PROP_BRIGHTNESS, self.__brightness)
- #self.__saturation = self.__setCamVar(cv2.CAP_PROP_SATURATION, self.__saturation)
- #self.__hue = self.__setCamVar(cv2.CAP_PROP_HUE, self.__hue)
- #self.__exposure = self.__setCamVar(cv2.CAP_PROP_EXPOSURE, self.__exposure)
-
+ sh.bash("../scripts/v4l-cam.sh")
def __setCamVar(self, key, val):
valold = cv2.VideoCapture.get(self.__device, key)
if valold != val:
cv2.VideoCapture.set(self.__device, key, val)
- t = cv2.VideoCapture.get(self.__device, key)
+ t = cv2.VideoCapture.get(self.__device, key)
return t
return val
diff --git a/test-cli/test/helpers/detect.py b/test-cli/test/helpers/detect.py
new file mode 100644
index 0000000..193dabf
--- /dev/null
+++ b/test-cli/test/helpers/detect.py
@@ -0,0 +1,61 @@
+import cv2
+import numpy as np
+
+
+class Detect_Color(object):
+ oFrame = None
+ img_hsv = None
+ __red_lower1 = [0, 50, 20]
+ __red_upper1 = [5, 255, 255]
+ __red_lower2 = [175, 50, 20]
+ __red_upper2 = [180, 255, 255]
+ __blue_lower = [110, 50, 50]
+ __blue_upper = [130, 255, 255]
+ __green_lower = [36, 25, 25]
+ __green_upper = [86, 255, 255]
+
+ def __init__(self, frame):
+ self.oFrame = frame
+ self.__hist()
+
+ def __hist(self):
+ self.img_hsv = cv2.cvtColor(self.oFrame, cv2.COLOR_BGR2HSV)
+
+ def getRed(self):
+ return self.__detect_two_areas([0, 50, 20], [5, 255, 255], [175, 50, 20], [180, 255, 255])
+
+ def getBlue(self):
+ return self.__detect_one_area([110, 50, 50], [130, 255, 255])
+
+ def getGreen(self):
+ return self.__detect_one_area([36, 25, 25], [86, 255, 255])
+
+ def __detect_one_area(self, lower, upper):
+ a_lower = np.array(lower)
+ a_upper = np.array(upper)
+ c_mask = cv2.inRange(self.img_hsv, a_lower, a_upper)
+ croped = cv2.bitwise_and(self.oFrame, self.oFrame, mask=c_mask)
+ mean_v = cv2.mean(self.oFrame, mask=c_mask)
+ mean = {}
+ mean['R'] = mean_v[2]
+ mean['G'] = mean_v[1]
+ mean['B'] = mean_v[0]
+ count = cv2.countNonZero(c_mask)
+ return c_mask, croped, mean, count
+
+ def __detect_two_areas(self, lower1, upper1, lower2, upper2):
+ a1_lower = np.array(lower1)
+ a1_upper = np.array(upper1)
+ a2_lower = np.array(lower2)
+ a2_upper = np.array(upper2)
+ c_mask1 = cv2.inRange(self.img_hsv, a1_lower, a1_upper)
+ c_mask2 = cv2.inRange(self.img_hsv, a2_lower, a2_upper)
+ c_mask = cv2.bitwise_or(c_mask1, c_mask2)
+ croped = cv2.bitwise_and(self.oFrame, self.oFrame, mask=c_mask)
+ mean_v = cv2.mean(self.oFrame, mask=c_mask)
+ mean = {}
+ mean['R'] = mean_v[2]
+ mean['G'] = mean_v[1]
+ mean['B'] = mean_v[0]
+ count = cv2.countNonZero(c_mask)
+ return c_mask, croped, mean, count
diff --git a/test-cli/test/helpers/sdl.py b/test-cli/test/helpers/sdl.py
index 8f55d9f..2abb6ee 100644
--- a/test-cli/test/helpers/sdl.py
+++ b/test-cli/test/helpers/sdl.py
@@ -22,10 +22,10 @@ class SDL2(object):
__renderer = None
__srender = None
- def __init__(self, parent):
+ def __init__(self):
os.environ['SDL_VIDEODRIVER'] = "x11"
os.environ['DISPLAY'] = ":0"
- self.__resources = sdl2.ext.Resources(parent.getAppPath(), 'files')
+ # self.__resources = sdl2.ext.Resources(parent.getAppPath(), 'files')
sdl2.ext.init()
self.__createWindow()
@@ -39,8 +39,8 @@ class SDL2(object):
self.__window.show()
SDL_ShowCursor(SDL_DISABLE)
- def createFont(self, fontName, fontSize, fontColor):
- return sdl2.ext.FontManager(font_path=self.__resources.get_path(fontName), size=fontSize, color=fontColor)
+ # def createFont(self, fontName, fontSize, fontColor):
+ # return sdl2.ext.FontManager(font_path=self.__resources.get_path(fontName), size=fontSize, color=fontColor)
def WriteText(self, text, x, y, fontManager):
imText = self.__factory.from_text(text, fontmanager=fontManager)
@@ -69,16 +69,16 @@ class SDL2(object):
def update(self):
self.__renderer.present()
- def showImage(self, filename):
- im = self.__factory.from_image(self.__resources.get_path(filename))
- self.__srender.render(im)
+ # def showImage(self, filename):
+ # im = self.__factory.from_image(self.__resources.get_path(filename))
+ # self.__srender.render(im)
class SDL2_Test(object):
__sdl2 = None
- def __init__(self, parent):
- self.__sdl2 = SDL2(parent)
+ def __init__(self):
+ self.__sdl2 = SDL2()
def Clear(self):
self.__sdl2.fillbgColor('black', True)
@@ -93,8 +93,8 @@ class SDL2_Message(object):
__fontManager_w = None
__fontManager_b = None
- def __init__(self, parent):
- self.__sdl2 = SDL2(parent)
+ def __init__(self):
+ self.__sdl2 = SDL2()
self.__fontManager_w = self.__sdl2.createFont('OpenSans-Regular.ttf', 24, Colors['white'])
self.__fontManager_b = self.__sdl2.createFont('OpenSans-Regular.ttf', 24, Colors['black'])