【问题标题】:cv2.cvtcolor bgr2gray seems get an error imagecv2.cvtcolor bgr2gray 似乎得到一个错误图像
【发布时间】:2019-02-03 05:58:44
【问题描述】:

#代码如下,实现了,但结果可能是错误的,不是我想要的灰度,有人帮帮我,看起来很简单,但我不知道哪里错了

p>

导入 cv2 将 matplotlib.pyplot 导入为 plt 将 numpy 导入为 np 将 matplotlib.image 导入为 mpimg img = cv2.imread('calibration_test.png')

# i want simply convert the rgb image to grayscale and then print it out
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
plt.imshow(gray)
print(gray.shape)
# but the outcome is a colorful image

【问题讨论】:

    标签: python cv2 bgr


    【解决方案1】:

    灰度转换已正确完成。问题在于您如何显示图像。试试这个:

    plt.imshow(gray, cmap='gray')
    

    默认情况下imshow 会为单通道图像添加自己的颜色键,以便于查看。一个典型的例子是热图像,通常显示蓝色和红色,但所有颜色仅取决于一个通道。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 2021-09-09
      • 2014-12-05
      • 1970-01-01
      相关资源
      最近更新 更多