Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将特定NumPy数组更改为坐标_Python_Arrays_Numpy_Split - Fatal编程技术网

Python 将特定NumPy数组更改为坐标

Python 将特定NumPy数组更改为坐标,python,arrays,numpy,split,Python,Arrays,Numpy,Split,我想将NumPy数组从[x0y0x1y1]更改为[(y0,x0)(x1,y1)] 我已经尝试了很多东西,但仍然没有找到正确的方法 这是我的密码: 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())) pri

我想将NumPy数组从
[x0y0x1y1]
更改为
[(y0,x0)(x1,y1)]

我已经尝试了很多东西,但仍然没有找到正确的方法

这是我的密码:

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)

    

我要更改的项来自
face\u detection.build\u detector()

将NumPy数组转换为两个元组列表的示例:

a = np.array((1, 2, 3, 4))
b = [tuple(a[0:2]), tuple(a[2:4])]

我希望我能理解你的问题(你在非最小可复制样本中发布的代码)。

确保它不是打字错误——你想翻转
x
y
,但只翻转第一个元组?谢谢你的及时回复,是的。这是下一步计划所必需的。