I want to change the NumPy array from [x0 y0 x1 y1] to be [(y0, x0) (x1, y1)].
I already tried many things but still not found the right way.
This was my code:
import glob
import os
import cv2
import time
import dlib
import face_detection
import numpy as np
import inspect
print(inspect.getsource(dlib.get_frontal_face_detector()))
print(dlib.__file__)
def draw_faces(im, bboxes):
for bbox in bboxes:
x0, y0, x1, y1 = [int(_) for _ in bbox]
#cv2.rectangle(im, (x0, y0), (x1, y1), (0, 0, 255), 2)
image = cv2.rectangle(im, pt1=(x0, y0), pt2=(x1, y1), color=(0, 0, 255), thickness=4)
conv = np.array(((x0, y0), (x1, y1)))
if __name__ == "__main__":
impaths = "images"
impaths = glob.glob(os.path.join(impaths, "*.jpg"))
detector = face_detection.build_detector(
"DSFDDetector",
max_resolution=1080
)
for impath in impaths:
if impath.endswith("out.jpg"): continue
im = cv2.imread(impath)
print("Processing:", impath)
t = time.time()
dets = detector.detect(
im[:, :, ::-1]
)[:, :4]
conv = np.array(dets, dtype=int)
conv1= np.split(conv, [1,2])
draw_faces(im, dets)
print(conv1)
print(f"Detection time: {time.time()- t:.3f}")
imname = os.path.basename(impath).split(".")[0]
output_path = os.path.join(
os.path.dirname(impath),
f"{imname}_out.jpg"
)
cv2.imwrite(output_path, im)
The item I want to change comes from face_detection.build_detector ()
xandy, but only for the first tuple?