Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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列表中选择不带逗号分隔的元素_Python_Opencv_Numpy Ndarray - Fatal编程技术网

在python列表中选择不带逗号分隔的元素

在python列表中选择不带逗号分隔的元素,python,opencv,numpy-ndarray,Python,Opencv,Numpy Ndarray,我有这样一份清单: [[437 5 91 91] [331 303 155 155]] 如何选择此列表中的第一个或第二个元素? 我想要的输出: [437 5 91 91] 在人脸检测中,我的相机中有两张脸,然后我的输出中有以下列表: face_cascade = cv2.CascadeClassifier(PATH) .... faces = face_cascade.detectMultiScale( gray,

我有这样一份清单:

[[437   5  91  91]
 [331 303 155 155]]
如何选择此列表中的第一个或第二个元素? 我想要的输出:

[437   5  91  91]
在人脸检测中,我的相机中有两张脸,然后我的输出中有以下列表:

face_cascade = cv2.CascadeClassifier(PATH) 
.... 
faces = face_cascade.detectMultiScale( gray, 
                                       scaleFactor=1.2, 
                                       minNeighbors=10, 
                                       minSize=(self.face_size, self.face_size) 
                                      )
当我打印(面)时,我有这个输出,我想选择其中一个元素

type(faces) gives `<class 'numpy.ndarray'>` this is type of faces
type(faces)给出了``这是面的类型

假设您指的是strinh而不是list,您可以执行以下操作

import json

test="[[437   5  91  91] [331 303 155 155]]"

#convert the multiple whitespace to single white space
test=' '.join(test.split())

#replace whitespace with comma
test=test.replace(" ",",")

#make a list of it
lists = json.loads(test)

print(lists[0])
问题:我想选择其中一个元素

type(faces) gives `<class 'numpy.ndarray'>` this is type of faces
了解



Python:cv2.CascadeClassifier.detectMultiScale2(图像[,缩放因子[,minNeighbors[,标志[,minSize[,maxSize]]])→ 对象、numDetections

检测输入图像中不同大小的对象。
检测到的对象作为矩形列表返回

此调用返回两个对象,您可以将其拆分,例如:

objects, numDetections =  cv2.CascadeClassifier.detectMultiScale2(...


这不是有效的python列表。这是一个语法错误。你是说一个看起来像列表的字符串,对吗?你是说这是一个字符串,你想把它转换成一个列表吗?当我打印(面)时,我有这个输出,我想选择一个元素。这在python中不是一个有效的列表。您可能希望使用正在使用的其他库以及生成“列表”的代码来更新您的问题。它可能是不同的对象类型,具有不同的访问语法。您是否尝试过键入(列表)?
objects = faces[0]
numDetections =  faces[1]