1
0
mirror of https://github.com/undera/pylgbst.git synced 2020-11-18 19:37:26 -08:00

One more video

This commit is contained in:
Andrey Pohilko 2018-08-03 13:43:26 +03:00
parent 881ba1d619
commit 544e7ed523
3 changed files with 13 additions and 8 deletions

View File

@ -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

View File

@ -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()

View File

@ -1,4 +1,4 @@
[
[130, 64, 0],
[140, 255, 250]
[125, 64, 64],
[145, 255, 250]
]