gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:53:35 40 4
gpt4 key购买 nike

我收到此代码错误:

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/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com