使用matplotlib显示灰度OpenCV图像 [英] Show grayscale OpenCV image with matplotlib

查看:84
本文介绍了使用matplotlib显示灰度OpenCV图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用anaconda使用以下命令安装了python的opencv3:
conda install -c menpo opencv3=3.2.0

I use opencv3 of python installed it by anaconda using:
conda install -c menpo opencv3=3.2.0

但是当我使用它将图片转换为灰度时,例如:

But when i use it to convert a picture to grayscale, like:

import cv2
import matplotlib.pyplot as plt

%matplotlib inline

image = cv2.imread('opencv_logo.png')

image1 = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

print (image.shape)
print (image1.shape)

plt.imshow(image1)

我不知道为什么:

我使用Windows + Miniconda. 谁能知道为什么并帮助我?谢谢.

I use windows + miniconda. Can anyone know why and help me ? Thanks.

推荐答案

您应该在plt.imshow()中添加另一个参数,以提及您想要灰度图像.

You are supposed to add another parameter in plt.imshow() so as to mention that you want a gray scale image.

像这样修改最后一行:plt.imshow(img, cmap='gray')

Modify the last line like this: plt.imshow(img, cmap='gray')

这样做后,我得到了以下信息:

Upon doing so I got the following:

这篇关于使用matplotlib显示灰度OpenCV图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆