mirror of
https://github.com/esimov/pigo.git
synced 2025-10-26 17:30:32 +08:00
Fixed Windows error on talk detector demo
This commit is contained in:
@@ -35,6 +35,7 @@ func main() {}
|
|||||||
|
|
||||||
//export FindFaces
|
//export FindFaces
|
||||||
func FindFaces(pixels []uint8) uintptr {
|
func FindFaces(pixels []uint8) uintptr {
|
||||||
|
var talking int
|
||||||
pointCh := make(chan uintptr)
|
pointCh := make(chan uintptr)
|
||||||
|
|
||||||
results := clusterDetection(pixels, 480, 640)
|
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))
|
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))
|
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))
|
mar := (dist1 / dist2) * 0.19
|
||||||
dets[i] = append(dets[i], flp.Row, flp.Col, int(flp.Scale), int(results[i].Q), 3, mar)
|
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))
|
coords := make([]int, 0, len(dets))
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern GoUintptr FindFaces(GoSlice pixels);
|
extern __declspec(dllexport) GoUintptr FindFaces(GoSlice pixels);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
from ctypes import *
|
from ctypes import *
|
||||||
|
|
||||||
import subprocess
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
import cv2
|
import cv2
|
||||||
import time
|
|
||||||
|
|
||||||
os.system('go build -o talkdet.so -buildmode=c-shared talkdet.go')
|
os.system('go build -o talkdet.so -buildmode=c-shared talkdet.go')
|
||||||
pigo = cdll.LoadLibrary('./talkdet.so')
|
pigo = cdll.LoadLibrary('./talkdet.so')
|
||||||
os.system('rm talkdet.so')
|
|
||||||
|
|
||||||
MAX_NDETS = 2024
|
MAX_NDETS = 2024
|
||||||
ARRAY_DIM = 6
|
ARRAY_DIM = 6
|
||||||
|
NUM_LP = 95
|
||||||
|
|
||||||
MOUTH_AR_THRESH = 0.2
|
|
||||||
MOUTH_AR_CONSEC_FRAMES = 5
|
MOUTH_AR_CONSEC_FRAMES = 5
|
||||||
|
|
||||||
def verify_alpha_channel(frame):
|
def verify_alpha_channel(frame):
|
||||||
@@ -65,7 +62,7 @@ def process_frame(pixs):
|
|||||||
buffarr = ((c_longlong * ARRAY_DIM) *
|
buffarr = ((c_longlong * ARRAY_DIM) *
|
||||||
MAX_NDETS).from_address(addressof(data_pointer.contents))
|
MAX_NDETS).from_address(addressof(data_pointer.contents))
|
||||||
res = np.ndarray(buffer=buffarr, dtype=c_longlong,
|
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.
|
# The first value of the buffer aray represents the buffer length.
|
||||||
dets_len = res[0][0]
|
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_WIDTH, 640)
|
||||||
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
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
|
showFaceDet = False
|
||||||
showPupil = True
|
showPupil = True
|
||||||
showLandmarkPoints = True
|
showLandmarkPoints = True
|
||||||
@@ -110,7 +103,11 @@ while(True):
|
|||||||
if det_type == 0: # 0 == face;
|
if det_type == 0: # 0 == face;
|
||||||
face_col, face_row, face_dim = col, row, scale
|
face_col, face_row, face_dim = col, row, scale
|
||||||
if showFaceDet:
|
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;
|
elif det_type == 1: # 1 == pupil;
|
||||||
if showPupil:
|
if showPupil:
|
||||||
cv2.circle(frame, (int(col), int(row)), 4, (0, 0, 255), -1, 8, 0)
|
cv2.circle(frame, (int(col), int(row)), 4, (0, 0, 255), -1, 8, 0)
|
||||||
@@ -118,7 +115,7 @@ while(True):
|
|||||||
if showLandmarkPoints:
|
if showLandmarkPoints:
|
||||||
cv2.circle(frame, (int(col), int(row)), 4, (0, 255, 0), -1, 8, 0)
|
cv2.circle(frame, (int(col), int(row)), 4, (0, 255, 0), -1, 8, 0)
|
||||||
elif det_type == 3:
|
elif det_type == 3:
|
||||||
if mouth_ar < MOUTH_AR_THRESH: # mouth is open
|
if mouth_ar == 1: # mouth is open
|
||||||
talking = True
|
talking = True
|
||||||
counter = 0
|
counter = 0
|
||||||
else: # mouth is closed
|
else: # mouth is closed
|
||||||
@@ -130,10 +127,10 @@ while(True):
|
|||||||
|
|
||||||
if talking and counter < MOUTH_AR_CONSEC_FRAMES:
|
if talking and counter < MOUTH_AR_CONSEC_FRAMES:
|
||||||
frame = apply_circle_focus_blur(frame, face_col, face_row, face_dim, 25)
|
frame = apply_circle_focus_blur(frame, face_col, face_row, face_dim, 25)
|
||||||
cv2.putText(frame, "Bla bla bla...", (10, 30),
|
cv2.putText(frame, "Person talking...", (10, 30),
|
||||||
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
|
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 1)
|
||||||
|
|
||||||
cv2.imshow('', frame)
|
cv2.imshow('Talk detection demo', frame)
|
||||||
|
|
||||||
key = cv2.waitKey(1)
|
key = cv2.waitKey(1)
|
||||||
if key & 0xFF == ord('q'):
|
if key & 0xFF == ord('q'):
|
||||||
|
|||||||
Reference in New Issue
Block a user