diff --git a/examples/talk_detector/talkdet.go b/examples/talk_detector/talkdet.go index 6429b96..f4f2bb0 100644 --- a/examples/talk_detector/talkdet.go +++ b/examples/talk_detector/talkdet.go @@ -35,6 +35,7 @@ func main() {} //export FindFaces func FindFaces(pixels []uint8) uintptr { + var talking int pointCh := make(chan uintptr) results := clusterDetection(pixels, 480, 640) @@ -112,8 +113,13 @@ func FindFaces(pixels []uint8) uintptr { dist1 := math.Sqrt(math.Pow(float64(p2.y-p1.y), 2) + math.Pow(float64(p2.x-p1.x), 2)) dist2 := math.Sqrt(math.Pow(float64(p4.y-p3.y), 2) + math.Pow(float64(p4.x-p3.x), 2)) - mar := int(round((dist1 / dist2) * 0.19)) - dets[i] = append(dets[i], flp.Row, flp.Col, int(flp.Scale), int(results[i].Q), 3, mar) + mar := (dist1 / dist2) * 0.19 + if mar < 0.4 { + talking = 1 + } else { + talking = 0 + } + dets[i] = append(dets[i], flp.Row, flp.Col, int(flp.Scale), int(results[i].Q), 3, talking) } coords := make([]int, 0, len(dets)) diff --git a/examples/talk_detector/talkdet.h b/examples/talk_detector/talkdet.h index 6444b73..4ffbc8a 100644 --- a/examples/talk_detector/talkdet.h +++ b/examples/talk_detector/talkdet.h @@ -68,7 +68,7 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; extern "C" { #endif -extern GoUintptr FindFaces(GoSlice pixels); +extern __declspec(dllexport) GoUintptr FindFaces(GoSlice pixels); #ifdef __cplusplus } diff --git a/examples/talk_detector/talkdet.py b/examples/talk_detector/talkdet.py index d552dac..7349b42 100644 --- a/examples/talk_detector/talkdet.py +++ b/examples/talk_detector/talkdet.py @@ -1,19 +1,16 @@ from ctypes import * -import subprocess import numpy as np import os import cv2 -import time os.system('go build -o talkdet.so -buildmode=c-shared talkdet.go') pigo = cdll.LoadLibrary('./talkdet.so') -os.system('rm talkdet.so') MAX_NDETS = 2024 ARRAY_DIM = 6 +NUM_LP = 95 -MOUTH_AR_THRESH = 0.2 MOUTH_AR_CONSEC_FRAMES = 5 def verify_alpha_channel(frame): @@ -65,7 +62,7 @@ def process_frame(pixs): buffarr = ((c_longlong * ARRAY_DIM) * MAX_NDETS).from_address(addressof(data_pointer.contents)) res = np.ndarray(buffer=buffarr, dtype=c_longlong, - shape=(MAX_NDETS, ARRAY_DIM,)) + shape=(NUM_LP, ARRAY_DIM,)) # The first value of the buffer aray represents the buffer length. dets_len = res[0][0] @@ -81,10 +78,6 @@ cap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) -# Changing the camera resolution introduce a short delay in the camera initialization. -# For this reason we should delay the object detection process with a few milliseconds. -time.sleep(0.4) - showFaceDet = False showPupil = True showLandmarkPoints = True @@ -110,7 +103,11 @@ while(True): if det_type == 0: # 0 == face; face_col, face_row, face_dim = col, row, scale if showFaceDet: - cv2.rectangle(frame, (col-scale/2, row-scale/2), (col+scale/2, row+scale/2), (0, 0, 255), 2) + cv2.rectangle(frame, + (int(col)-int(scale/2), int(row)-int(scale/2)), + (int(col)+int(scale/2), int(row)+int(scale/2)), + (0, 0, 255), 2 + ) elif det_type == 1: # 1 == pupil; if showPupil: cv2.circle(frame, (int(col), int(row)), 4, (0, 0, 255), -1, 8, 0) @@ -118,7 +115,7 @@ while(True): if showLandmarkPoints: cv2.circle(frame, (int(col), int(row)), 4, (0, 255, 0), -1, 8, 0) elif det_type == 3: - if mouth_ar < MOUTH_AR_THRESH: # mouth is open + if mouth_ar == 1: # mouth is open talking = True counter = 0 else: # mouth is closed @@ -130,10 +127,10 @@ while(True): if talking and counter < MOUTH_AR_CONSEC_FRAMES: frame = apply_circle_focus_blur(frame, face_col, face_row, face_dim, 25) - cv2.putText(frame, "Bla bla bla...", (10, 30), - cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2) + cv2.putText(frame, "Person talking...", (10, 30), + cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 1) - cv2.imshow('', frame) + cv2.imshow('Talk detection demo', frame) key = cv2.waitKey(1) if key & 0xFF == ord('q'):