From d46bce422fd03cd57d1ba336361da17d6efb48db Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Fri, 31 Jul 2020 02:07:37 +0200 Subject: TEST restructure --- test-cli/test/helpers/camara.py | 124 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 test-cli/test/helpers/camara.py (limited to 'test-cli/test/helpers/camara.py') diff --git a/test-cli/test/helpers/camara.py b/test-cli/test/helpers/camara.py new file mode 100644 index 0000000..9b2829c --- /dev/null +++ b/test-cli/test/helpers/camara.py @@ -0,0 +1,124 @@ +import cv2 +from test.helpers.syscmd import SysCommand + +class Camara(object): + __parent = None + __device_name = None + __device = None + __w = 1280 + __h = 720 + __contrast = 0.0 + __brightness = 0.0 + __saturation = 55.0 + __hue = 0.0 + __exposure = 166 + + def __init__(self, parent, device="video0", width=1280, height=720): + self.__parent = parent + self.__device_name = device + self.__w = width + self.__h = height + + def Close(self): + if self.__device is not None: + del self.__device + self.__device = None + + def Open(self): + self.Close() + self.__device = cv2.VideoCapture("/dev/{}".format(self.__device_name)) + if self.__device.isOpened(): + self.__configure() + return True + return False + + def getSize(self): + return self.__w, self.__h + + def setSize(self, w, h): + if self.__device is not None and self.__device.isOpened(): + self.__w = self.__setCamVar(cv2.CAP_PROP_FRAME_WIDTH, w) + self.__h = self.__setCamVar(cv2.CAP_PROP_FRAME_HEIGHT, h) + else: + self.__w = w + self.__h = h + + def setContrast(self, newVal): + if self.__device.isOpened(): + self.__contrast = self.__setCamVar(cv2.CAP_PROP_CONTRAST, newVal) + else: + self.__contrast = newVal + + def getContrast(self): + return self.__contrast + + def setBrightness(self, newVal): + if self.__device.isOpened(): + self.__brightness = self.__setCamVar(cv2.CAP_PROP_BRIGHTNESS, newVal) + else: + self.__brightness = newVal + + def getBrightness(self): + return self.__brightness + + 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) + + + 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) + return t + return val + + def __getCamVar(self, key): + return cv2.VideoCapture.get(self.__device, key); + + def getFrameCount(self): + return cv2.VideoCapture.get(self.__device, cv2.CAP_PROP_BUFFERSIZE); + + def getFrame(self): + if self.__device.isOpened(): + retval, image = self.__device.read() + if retval: + return image + return None + else: + return None + + def getImageSize(self, image): + if hasattr(image, 'shape'): + return image.shape[1], image.shape[0] + else: + return (0, 0, 0) + + def showFrame(self, name, frame, w=False, maxTime=3000): + cv2.imshow(name, frame) + if w: + if maxTime == -1: + cv2.waitKey() + else: + cv2.waitKey(maxTime) + + def saveFrame(self, fileName, Frame): + cv2.imwrite(fileName, Frame) + + def readImage(self, filename): + return cv2.imread('{}'.format(filename), 0) + + def destroyWindow(self, name): + cv2.destroyWindow(name) + + def closeWindows(self): + cv2.destroyAllWindows() \ No newline at end of file -- cgit v1.1 From ca73fcc336edc23db5750e93b6e1014d32a54ea5 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Tue, 29 Sep 2020 13:27:32 +0200 Subject: Added new test to validate video output with a webcam. --- test-cli/test/helpers/camara.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'test-cli/test/helpers/camara.py') 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 -- cgit v1.1 From 5771dcc8acabd2f4f560768cf45615e929409f6e Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Fri, 2 Oct 2020 15:33:12 +0200 Subject: fix execution camera setup script path not correct --- test-cli/test/helpers/camara.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'test-cli/test/helpers/camara.py') diff --git a/test-cli/test/helpers/camara.py b/test-cli/test/helpers/camara.py index afe8112..bcb1df7 100644 --- a/test-cli/test/helpers/camara.py +++ b/test-cli/test/helpers/camara.py @@ -4,6 +4,7 @@ import sh class Camara(object): __device_name = None __device = None + __setupScriptPath = '' __w = 1280 __h = 720 __contrast = 0.0 @@ -12,10 +13,11 @@ class Camara(object): __hue = 0.0 __exposure = 166 - def __init__(self, device="video0", width=1280, height=720): + def __init__(self, setup_script_path, device="video0", width=1280, height=720): self.__device_name = device self.__w = width self.__h = height + self.__setupScriptPath = setup_script_path; def Close(self): if self.__device is not None: @@ -62,7 +64,8 @@ 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) - sh.bash("../scripts/v4l-cam.sh") + sh.bash(self.__setupScriptPath + '/test/scripts/v4l-cam.sh') + # sh.bash("../scripts/v4l-cam.sh") def __setCamVar(self, key, val): valold = cv2.VideoCapture.get(self.__device, key) -- cgit v1.1 From e7631181c08c38c196558fc79b648d78ccaadcc8 Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Mon, 5 Oct 2020 11:44:22 +0200 Subject: Add qvideo variables --- test-cli/test/helpers/camara.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test-cli/test/helpers/camara.py') diff --git a/test-cli/test/helpers/camara.py b/test-cli/test/helpers/camara.py index bcb1df7..b23df74 100644 --- a/test-cli/test/helpers/camara.py +++ b/test-cli/test/helpers/camara.py @@ -17,7 +17,7 @@ class Camara(object): self.__device_name = device self.__w = width self.__h = height - self.__setupScriptPath = setup_script_path; + self.__setupScriptPath = setup_script_path def Close(self): if self.__device is not None: @@ -64,8 +64,7 @@ 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) - sh.bash(self.__setupScriptPath + '/test/scripts/v4l-cam.sh') - # sh.bash("../scripts/v4l-cam.sh") + sh.bash(self.__setupScriptPath) def __setCamVar(self, key, val): valold = cv2.VideoCapture.get(self.__device, key) -- cgit v1.1