From 4ed29aa59219fdc2fa9ca9d657061bd1c757825d Mon Sep 17 00:00:00 2001 From: esimov Date: Wed, 9 Nov 2022 12:40:30 +0200 Subject: [PATCH] fix: Windows exit code on python demos #58 --- examples/facedet/demo.py | 1 - examples/facedet/faceblur.py | 2 -- examples/facial_landmark/flploc.h | 2 +- examples/facial_landmark/flploc.py | 10 ++-------- examples/puploc/puploc.h | 2 +- examples/puploc/puploc.py | 10 ++-------- examples/puploc_masquerade/puploc.h | 2 +- examples/puploc_masquerade/puploc.py | 23 ++++++++++------------- 8 files changed, 17 insertions(+), 35 deletions(-) diff --git a/examples/facedet/demo.py b/examples/facedet/demo.py index 1dd3f87..e7fe1ac 100644 --- a/examples/facedet/demo.py +++ b/examples/facedet/demo.py @@ -3,7 +3,6 @@ from ctypes import * import numpy as np import os import cv2 -import time os.system('go build -o pigo.so -buildmode=c-shared pigo.go') pigo = cdll.LoadLibrary('./pigo.so') diff --git a/examples/facedet/faceblur.py b/examples/facedet/faceblur.py index d1d9324..2f7fc07 100644 --- a/examples/facedet/faceblur.py +++ b/examples/facedet/faceblur.py @@ -1,10 +1,8 @@ from ctypes import * -import subprocess import numpy as np import os import cv2 -import time os.system('go build -o pigo.so -buildmode=c-shared pigo.go') pigo = cdll.LoadLibrary('./pigo.so') diff --git a/examples/facial_landmark/flploc.h b/examples/facial_landmark/flploc.h index 6444b73..4ffbc8a 100644 --- a/examples/facial_landmark/flploc.h +++ b/examples/facial_landmark/flploc.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/facial_landmark/flploc.py b/examples/facial_landmark/flploc.py index f3ca3b9..bd1fa5b 100644 --- a/examples/facial_landmark/flploc.py +++ b/examples/facial_landmark/flploc.py @@ -1,17 +1,15 @@ from ctypes import * -import subprocess import numpy as np import os import cv2 -import time os.system('go build -o flploc.so -buildmode=c-shared flploc.go') pigo = cdll.LoadLibrary('./flploc.so') -os.system('rm flploc.so') MAX_NDETS = 2024 ARRAY_DIM = 5 +NUM_LP = 95 # define class GoPixelSlice to map to: # C type struct { void *data; GoInt len; GoInt cap; } @@ -36,7 +34,7 @@ def process_frame(pixs): if data_pointer : 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,)) + res = np.ndarray(buffer=buffarr, dtype=c_longlong, shape=(NUM_LP, ARRAY_DIM,)) # The first value of the buffer aray represents the buffer length. dets_len = res[0][0] @@ -52,10 +50,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) - showPupil = True showEyes = False showLandmarkPoints = True diff --git a/examples/puploc/puploc.h b/examples/puploc/puploc.h index 6444b73..4ffbc8a 100644 --- a/examples/puploc/puploc.h +++ b/examples/puploc/puploc.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/puploc/puploc.py b/examples/puploc/puploc.py index 464507a..4196ead 100644 --- a/examples/puploc/puploc.py +++ b/examples/puploc/puploc.py @@ -1,6 +1,5 @@ from ctypes import * -import subprocess import numpy as np import os import cv2 @@ -8,7 +7,6 @@ import time os.system('go build -o puploc.so -buildmode=c-shared puploc.go') pigo = cdll.LoadLibrary('./puploc.so') -os.system('rm puploc.so') MAX_NDETS = 2024 ARRAY_DIM = 5 @@ -36,7 +34,7 @@ def process_frame(pixs): if data_pointer : 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,)) + res = np.ndarray(buffer=buffarr, dtype=c_longlong, shape=(ARRAY_DIM, ARRAY_DIM)) # The first value of the buffer aray represents the buffer length. dets_len = res[0][0] @@ -52,10 +50,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) - showPupil = True showEyes = False @@ -84,7 +78,7 @@ while(True): (0, 255, 0), 2 ) - cv2.imshow('', frame) + cv2.imshow('Pupil / eyes localization', frame) key = cv2.waitKey(1) if key & 0xFF == ord('q'): diff --git a/examples/puploc_masquerade/puploc.h b/examples/puploc_masquerade/puploc.h index 6444b73..4ffbc8a 100644 --- a/examples/puploc_masquerade/puploc.h +++ b/examples/puploc_masquerade/puploc.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/puploc_masquerade/puploc.py b/examples/puploc_masquerade/puploc.py index 50eaa3a..b4263c2 100644 --- a/examples/puploc_masquerade/puploc.py +++ b/examples/puploc_masquerade/puploc.py @@ -1,14 +1,11 @@ from ctypes import * -import subprocess import numpy as np import os import cv2 -import time os.system('go build -o puploc.so -buildmode=c-shared puploc.go') pigo = cdll.LoadLibrary('./puploc.so') -os.system('rm puploc.so') MAX_NDETS = 2024 ARRAY_DIM = 5 @@ -50,7 +47,7 @@ def process_frame(pixs): if data_pointer : 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,)) + res = np.ndarray(buffer=buffarr, dtype=c_longlong, shape=(ARRAY_DIM, ARRAY_DIM,)) # The first value of the buffer aray represents the buffer length. dets_len = res[0][0] @@ -66,10 +63,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) - while(True): ret, frame = cap.read() pixs = np.ascontiguousarray(frame[:, :, 1].reshape((frame.shape[0], frame.shape[1]))) @@ -87,7 +80,11 @@ while(True): px, py = col, row elif angle > 0: if show_face: - 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 + ) src_img = cv2.imread(base_dir + "/" + source_imgs[img_idx], cv2.IMREAD_UNCHANGED) img_height, img_width, img_depth = src_img.shape @@ -119,10 +116,10 @@ while(True): if px == None or py == None: continue - y1 = row-scale/2+(row-scale/2-(py-height)) - y2 = row-scale/2+height+(row-scale/2-(py-height)) - x1 = col-scale/2 - x2 = col-scale/2+width + y1 = int(row-scale/2+(row-scale/2-(py-height))) + y2 = int(row-scale/2+height+(row-scale/2-(py-height))) + x1 = int(col-scale/2) + x2 = int(col-scale/2+width) if y1 < 0 or y2 < 0: continue