From 544e7ed5232e007cf5161832c283e539ff499805 Mon Sep 17 00:00:00 2001 From: Andrey Pohilko Date: Fri, 3 Aug 2018 13:43:26 +0300 Subject: [PATCH] One more video --- README.md | 1 + examples/tracker/__init__.py | 16 ++++++++++------ examples/tracker/color.json | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4f536e9..0ceb206 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Demonstrational videos: [![Vernie Programmed](http://img.youtube.com/vi/oqsmgZlVE8I/0.jpg)](http://www.youtube.com/watch?v=oqsmgZlVE8I) [![Laser Engraver](http://img.youtube.com/vi/ZbKmqVBBMhM/0.jpg)](https://youtu.be/ZbKmqVBBMhM) [![Color Sorter](http://img.youtube.com/vi/829RKT8v8M0/0.jpg)](https://youtu.be/829RKT8v8M0) +[![Face Tracker](http://img.youtube.com/vi/WUOa3j-6XfI/0.jpg)](https://youtu.be/WUOa3j-6XfI) ## Features diff --git a/examples/tracker/__init__.py b/examples/tracker/__init__.py index 3c09f50..0e01e33 100644 --- a/examples/tracker/__init__.py +++ b/examples/tracker/__init__.py @@ -18,6 +18,8 @@ cascades_dir = '/usr/share/opencv/haarcascades' face_cascade = cv2.CascadeClassifier(cascades_dir + '/haarcascade_frontalface_default.xml') smile_cascade = cv2.CascadeClassifier(cascades_dir + '/haarcascade_smile.xml') +LINE_THICKNESS = 2 + class FaceTracker(MoveHub): def __init__(self, connection=None): @@ -41,14 +43,15 @@ class FaceTracker(MoveHub): fourcc = cv2.VideoWriter_fourcc(*'XVID') fps = cap.get(cv2.CAP_PROP_FPS) - video = cv2.VideoWriter('output.avi', fourcc, fps, size) + video = cv2.VideoWriter('output_%d.avi' % int(time.time()), fourcc, fps, size) try: while True: flag, img = cap.read() if self.cur_face is not None: (x, y, w, h) = self.cur_face - cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255,), 1) + if LINE_THICKNESS: + cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255,), LINE_THICKNESS) video.write(img) self.cur_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) logging.debug("Got frame") @@ -85,7 +88,7 @@ class FaceTracker(MoveHub): if cur_face is not None: (x, y, w, h) = cur_face roi_color = self.cur_img[y:y + h, x:x + w] - smile = self._reduce(smile_cascade.detectMultiScale(roi_color, 1.5, 15)) + smile = self._reduce(smile_cascade.detectMultiScale(roi_color, 1.5, 20)) else: smile = None @@ -95,7 +98,8 @@ class FaceTracker(MoveHub): else: (ex, ey, ew, eh) = smile self.cur_smile = (ex, ey, ew, eh) - cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 1) + if LINE_THICKNESS: + cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), LINE_THICKNESS) self.smile_counter += 1 logging.info("Smile counter: %s", self.smile_counter) @@ -186,8 +190,8 @@ class FaceTracker(MoveHub): self._smile(False) def _process_picture(self, plt): - #self.cur_face = self._find_face() - self.cur_face = self._find_color() + self.cur_face = self._find_face() + #self.cur_face = self._find_color() if self.cur_face is None: self.motor_external.stop() diff --git a/examples/tracker/color.json b/examples/tracker/color.json index 8a8121c..969728f 100644 --- a/examples/tracker/color.json +++ b/examples/tracker/color.json @@ -1,4 +1,4 @@ [ - [130, 64, 0], - [140, 255, 250] + [125, 64, 64], + [145, 255, 250] ] \ No newline at end of file