[mousetrap/gnome3-wip: 13/240] Created new Camera class and test_camera unit test.
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 13/240] Created new Camera class and test_camera unit test.
- Date: Mon, 8 Sep 2014 15:13:37 +0000 (UTC)
commit 44360884377e48c4f18ca04e96c8c783a62cb0b3
Author: Logan Hotchkiss <lhotchkiss17 gmail com>
Date: Thu Apr 17 10:12:03 2014 -0400
Created new Camera class and test_camera unit test.
src/mousetrap/core/camera.py | 34 +++++++++++++++++++++++++++++++++-
src/mousetrap/core/test_camera.py | 33 +++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 1 deletions(-)
---
diff --git a/src/mousetrap/core/camera.py b/src/mousetrap/core/camera.py
index bc9ee89..595cdf2 100644
--- a/src/mousetrap/core/camera.py
+++ b/src/mousetrap/core/camera.py
@@ -24,6 +24,38 @@ __date__ = "$Date$"
__copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
__license__ = "GPLv2"
+import cv2
+
class Camera(object):
- pass
+
+ def __init__(self, dev=0):
+ self.dev_id = None
+ self.capture = None
+ self.img = None
+
+ self.set_dev_id(dev)
+ self.start_camera()
+
+ def start_camera(self):
+ """
+ Start a new Video capture feed with the Web Camera
+ """
+ self.capture = cv2.VideoCapture(self.dev_id)
+
+ def set_dev_id(self, dev=0):
+ """
+ Sets the camera id for the device to be used
+ Arguments:
+ - dev: The Camera's Id (Default is 0)
+ """
+ self.dev_id = dev
+
+ def get_image(self):
+ """
+ Reads a new image from the camera
+ Returns the new image
+ """
+ ret, self.img = self.capture.read()
+
+ return self.img
\ No newline at end of file
diff --git a/src/mousetrap/core/test_camera.py b/src/mousetrap/core/test_camera.py
new file mode 100644
index 0000000..6c9c925
--- /dev/null
+++ b/src/mousetrap/core/test_camera.py
@@ -0,0 +1,33 @@
+__author__ = 'foss2serve'
+
+import unittest
+import camera
+
+
+class test_camera(unittest.TestCase):
+
+ def test_get_image_correctInput(self):
+
+ #Setup
+ cam = camera.Camera()
+
+ #Capture Image
+ img = cam.get_image()
+
+ self.assertTrue(
+ img is not None,
+ msg="Error: Image not captured"
+ )
+
+ def test_start_camera_correctInput(self):
+
+ #Setup
+ cam = camera.Camera()
+
+ self.assertTrue(
+ cam.capture.isOpened(),
+ msg="Error: Camera feed not initialized"
+ )
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]