mirror of
https://github.com/esimov/pigo.git
synced 2025-10-25 17:00:26 +08:00
fix: Windows exit code on python demos #58
This commit is contained in:
@@ -3,7 +3,6 @@ from ctypes import *
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
import cv2
|
import cv2
|
||||||
import time
|
|
||||||
|
|
||||||
os.system('go build -o pigo.so -buildmode=c-shared pigo.go')
|
os.system('go build -o pigo.so -buildmode=c-shared pigo.go')
|
||||||
pigo = cdll.LoadLibrary('./pigo.so')
|
pigo = cdll.LoadLibrary('./pigo.so')
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
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 pigo.so -buildmode=c-shared pigo.go')
|
os.system('go build -o pigo.so -buildmode=c-shared pigo.go')
|
||||||
pigo = cdll.LoadLibrary('./pigo.so')
|
pigo = cdll.LoadLibrary('./pigo.so')
|
||||||
|
|||||||
@@ -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,17 +1,15 @@
|
|||||||
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 flploc.so -buildmode=c-shared flploc.go')
|
os.system('go build -o flploc.so -buildmode=c-shared flploc.go')
|
||||||
pigo = cdll.LoadLibrary('./flploc.so')
|
pigo = cdll.LoadLibrary('./flploc.so')
|
||||||
os.system('rm flploc.so')
|
|
||||||
|
|
||||||
MAX_NDETS = 2024
|
MAX_NDETS = 2024
|
||||||
ARRAY_DIM = 5
|
ARRAY_DIM = 5
|
||||||
|
NUM_LP = 95
|
||||||
|
|
||||||
# define class GoPixelSlice to map to:
|
# define class GoPixelSlice to map to:
|
||||||
# C type struct { void *data; GoInt len; GoInt cap; }
|
# C type struct { void *data; GoInt len; GoInt cap; }
|
||||||
@@ -36,7 +34,7 @@ def process_frame(pixs):
|
|||||||
|
|
||||||
if data_pointer :
|
if data_pointer :
|
||||||
buffarr = ((c_longlong * ARRAY_DIM) * MAX_NDETS).from_address(addressof(data_pointer.contents))
|
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.
|
# The first value of the buffer aray represents the buffer length.
|
||||||
dets_len = res[0][0]
|
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_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)
|
|
||||||
|
|
||||||
showPupil = True
|
showPupil = True
|
||||||
showEyes = False
|
showEyes = False
|
||||||
showLandmarkPoints = True
|
showLandmarkPoints = True
|
||||||
|
|||||||
@@ -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,6 +1,5 @@
|
|||||||
from ctypes import *
|
from ctypes import *
|
||||||
|
|
||||||
import subprocess
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
import cv2
|
import cv2
|
||||||
@@ -8,7 +7,6 @@ import time
|
|||||||
|
|
||||||
os.system('go build -o puploc.so -buildmode=c-shared puploc.go')
|
os.system('go build -o puploc.so -buildmode=c-shared puploc.go')
|
||||||
pigo = cdll.LoadLibrary('./puploc.so')
|
pigo = cdll.LoadLibrary('./puploc.so')
|
||||||
os.system('rm puploc.so')
|
|
||||||
|
|
||||||
MAX_NDETS = 2024
|
MAX_NDETS = 2024
|
||||||
ARRAY_DIM = 5
|
ARRAY_DIM = 5
|
||||||
@@ -36,7 +34,7 @@ def process_frame(pixs):
|
|||||||
|
|
||||||
if data_pointer :
|
if data_pointer :
|
||||||
buffarr = ((c_longlong * ARRAY_DIM) * MAX_NDETS).from_address(addressof(data_pointer.contents))
|
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.
|
# The first value of the buffer aray represents the buffer length.
|
||||||
dets_len = res[0][0]
|
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_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)
|
|
||||||
|
|
||||||
showPupil = True
|
showPupil = True
|
||||||
showEyes = False
|
showEyes = False
|
||||||
|
|
||||||
@@ -84,7 +78,7 @@ while(True):
|
|||||||
(0, 255, 0), 2
|
(0, 255, 0), 2
|
||||||
)
|
)
|
||||||
|
|
||||||
cv2.imshow('', frame)
|
cv2.imshow('Pupil / eyes localization', frame)
|
||||||
|
|
||||||
key = cv2.waitKey(1)
|
key = cv2.waitKey(1)
|
||||||
if key & 0xFF == ord('q'):
|
if key & 0xFF == ord('q'):
|
||||||
|
|||||||
@@ -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,14 +1,11 @@
|
|||||||
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 puploc.so -buildmode=c-shared puploc.go')
|
os.system('go build -o puploc.so -buildmode=c-shared puploc.go')
|
||||||
pigo = cdll.LoadLibrary('./puploc.so')
|
pigo = cdll.LoadLibrary('./puploc.so')
|
||||||
os.system('rm puploc.so')
|
|
||||||
|
|
||||||
MAX_NDETS = 2024
|
MAX_NDETS = 2024
|
||||||
ARRAY_DIM = 5
|
ARRAY_DIM = 5
|
||||||
@@ -50,7 +47,7 @@ def process_frame(pixs):
|
|||||||
|
|
||||||
if data_pointer :
|
if data_pointer :
|
||||||
buffarr = ((c_longlong * ARRAY_DIM) * MAX_NDETS).from_address(addressof(data_pointer.contents))
|
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.
|
# The first value of the buffer aray represents the buffer length.
|
||||||
dets_len = res[0][0]
|
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_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)
|
|
||||||
|
|
||||||
while(True):
|
while(True):
|
||||||
ret, frame = cap.read()
|
ret, frame = cap.read()
|
||||||
pixs = np.ascontiguousarray(frame[:, :, 1].reshape((frame.shape[0], frame.shape[1])))
|
pixs = np.ascontiguousarray(frame[:, :, 1].reshape((frame.shape[0], frame.shape[1])))
|
||||||
@@ -87,7 +80,11 @@ while(True):
|
|||||||
px, py = col, row
|
px, py = col, row
|
||||||
elif angle > 0:
|
elif angle > 0:
|
||||||
if show_face:
|
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)
|
src_img = cv2.imread(base_dir + "/" + source_imgs[img_idx], cv2.IMREAD_UNCHANGED)
|
||||||
img_height, img_width, img_depth = src_img.shape
|
img_height, img_width, img_depth = src_img.shape
|
||||||
@@ -119,10 +116,10 @@ while(True):
|
|||||||
if px == None or py == None:
|
if px == None or py == None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
y1 = row-scale/2+(row-scale/2-(py-height))
|
y1 = int(row-scale/2+(row-scale/2-(py-height)))
|
||||||
y2 = row-scale/2+height+(row-scale/2-(py-height))
|
y2 = int(row-scale/2+height+(row-scale/2-(py-height)))
|
||||||
x1 = col-scale/2
|
x1 = int(col-scale/2)
|
||||||
x2 = col-scale/2+width
|
x2 = int(col-scale/2+width)
|
||||||
|
|
||||||
if y1 < 0 or y2 < 0:
|
if y1 < 0 or y2 < 0:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user