python-3.x - TypeError : Layout of the output array img is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels)

标签 python-3.x opencv error-handling compiler-errors jupyter-notebook

我收到此代码错误:

import matplotlib.pyplot as plt
import cv2
import numpy as np

black = np.zeros(shape = (512, 512, 3), dtype = np.int64)
cv2.circle(black, center = (100, 100), radius = 50, color = (0, 255, 0), thickness = 10)

plt.imshow(black)
结果,应该在黑色图像上打印一个绿色圆圈。但是我越来越

TypeError: Layout of the output array img is incompatible with

cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels)

最佳答案

创建dtype = np.int64 numpy矩阵时使用black似乎是个问题。使用RGB图像时,通常不需要64位整数值,可以安全地将8位char值用作:

black = np.zeros(shape = (512, 512, 3), dtype = np.uint8)

但是,OpenCV在给定的矩阵中支持32位整数值,但是对于创建RGB图像来说似乎是过大的,因为所有RGB域颜色仅需要8位即可表示像素颜色分量(0-255)。

关于python-3.x - TypeError : Layout of the output array img is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53915690/

相关文章:

ruby-on-rails - Omniauth Youtube登录-重定向以在401 nolinkedoutube帐户上创建YouTube channel

python-3.x - 如何捕获通过 REST API 执行的 Saltstack `cmd.run` 的返回码

android - 配置 OpenCV 时出错。当我运行该应用程序时,它显示我有 cpp 文件,但它们没有使用受支持的 native 构建系统

python-3.x - 在 FactoryBoy 中,如何使用空的多对多成员字段设置我的工厂?

opencv - 手部检测和跟踪方法

python - 如何在 Python 中将实时数据读入循环与更多处理密集型操作分开?

php - 如果发生多个错误,如何仅显示一个错误?

powershell - 如何处理PowerShell中的Azure存储TableOperation错误?

python-3.x - Selenium 3 Firefox .click() 不工作

python-3.x - pandas:从包含列表的另一个 df 列中的一个 df 搜索列值