我试图在dnn模块中使用blobFromImages创建一个由多个帧组成的blob。在
def batch_process(self, frames):
blob = cv.dnn.blobFromImages(frames, 1./255, (368, 368), (0, 0, 0), swapRB=False, crop=False)
self.net.setInput(blob)
out = self.net.forward()
detected_points = np.zeros((frames.shape[0], 36))
for i in range(frames.shape[0]):
points = np.array([])
for j in range(18):
heatMap = out[i, j, :, :]
_, conf, _, point = cv.minMaxLoc(heatMap)
if conf > 0.1:
points = np.append(points, [point[0], point[1]])
else:
points = np.append(points, [0, 0])
detected_points[i] = points
return detected_points
但是当我调用这个函数时,我得到一个错误这:在
^{pr2}$blobFromImage()可以在类似的单个帧上正常工作。据我所知,blobFromImages()需要一个帧数组。因此,我传递一个numpy数组shape(32480640,3)作为参数。有人能帮我找出我遗漏了什么吗?我似乎找不到使用blobFromImages()的示例。我希望使用它,因为它可能比使用blobFromImage()缩短处理时间。在
首先,让我们分析错误消息并将其转换为易于理解的内容。在
因为这是来自OpenCV的C++实现,所以假定{{CD1>}是^{} 的实例是安全的(我们可以检查源代码来确定这个)。^{} 的文档说明如下:
好的,这是数组中每个元素的数据类型。要破译
^{pr2}$5
的值代表哪种数据类型(提示:上面的列表按升序排列,编号从0开始),我们可以参考Core HAL的文档,其中列出了这些值。在所以,错误信息是:
您没有向我们展示您是如何创建
frames
,但可以安全地假设它是一个由8位无符号整数组成的数组。要解决这个问题,只需将其转换为正确的数据类型,即使cv.dnn.blobFromImages
的第一个参数为np.float32(frames)
。在相关问题 更多 >
编程相关推荐