评估失败图像.深度()在blobFromImages中

2024-10-01 00:26:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在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()缩短处理时间。在


Tags: selffalseforframesnetnpoutblob
1条回答
网友
1楼 · 发布于 2024-10-01 00:26:11

首先,让我们分析错误消息并将其转换为易于理解的内容。在

Assertion failed (image.depth() == 5) in blobFromImages

因为这是来自OpenCV的C++实现,所以假定{{CD1>}是^{}的实例是安全的(我们可以检查源代码来确定这个)。^{}的文档说明如下:

Returns the depth of a matrix element.

The method returns the identifier of the matrix element depth (the type of each individual channel). For example, for a 16-bit signed element array, the method returns CV_16S. A complete list of matrix types contains the following values:

  • CV_8U - 8-bit unsigned integers ( 0..255 )
  • CV_8S - 8-bit signed integers ( -128..127 )
  • CV_16U - 16-bit unsigned integers ( 0..65535 )
  • CV_16S - 16-bit signed integers ( -32768..32767 )
  • CV_32S - 32-bit signed integers ( -2147483648..2147483647 )
  • CV_32F - 32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN )
  • CV_64F - 64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN )

好的,这是数组中每个元素的数据类型。要破译5的值代表哪种数据类型(提示:上面的列表按升序排列,编号从0开始),我们可以参考Core HAL的文档,其中列出了这些值。在

^{pr2}$

所以,错误信息是:

I expected to get array of 32bit floats, but I got something else.


您没有向我们展示您是如何创建frames,但可以安全地假设它是一个由8位无符号整数组成的数组。要解决这个问题,只需将其转换为正确的数据类型,即使cv.dnn.blobFromImages的第一个参数为np.float32(frames)。在

相关问题 更多 >