Python OpenCV ——Matplotlib显示图片
Color image loaded by OpenCV is in BGR mode.But Matplotlib displays in RGB mode.So color images will not be displayed correctly in Matplotlib if image is read with OpenCV.Please see the exercises for more details.(引自文档)
import numpy as np
import cv2
from matplotlib import pyplot as plt
'''
img = cv2.imread('cute.jpg',0)
plt.imshow(img,cmap='gray',interpolation='bicubic')
plt.xticks([],plt.yticks([])) # to hide tick values on X and Y axis
plt.show()
''' '''
Color image loaded by OpenCV is in BGR mode.
But Matplotlib displays in RGB mode.
So color images will not be displayed correctly in Matplotlib if image is read with OpenCV.
Please see the exercises for more details.
'''
img = cv2.imread('cute.jpg')
b, g, r = cv2.split(img)
img2 = cv2.merge([r,g,b])
# img2 = img[:,:,::-1] this can be faster
plt.subplot(121);plt.imshow(img) # expects distorted color
plt.subplot(122);plt.imshow(img2) # expects true color
plt.show() cv2.imshow('bgr image',img) # expects true color
cv2.imshow('rgb image',img2) # expects distrorted color
cv2.waitKey(0)
cv2.destroyAllWindows()
图像输出:
Matlpotlib输出:

OpenCV输出:

Python OpenCV ——Matplotlib显示图片的更多相关文章
- python 读取并显示图片的两种方法
在 python 中除了用 opencv,也可以用 matplotlib 和 PIL 这两个库操作图片.本人偏爱 matpoltlib,因为它的语法更像 matlab. 一.matplotlib 1. ...
- Python+Opencv实现把图片转为视频
1. 安装Opencv包 在Python命令行输入如下命令(如果你使用的Anaconda,直接进入Anaconda Prompt键入命令即可.如果你不知道Anaconda是什么,可以参考王树义老师的文 ...
- python tips;matplotlib 显示中文
import numpy as npimport matplotlib.pyplot as pltimport matplotlib as mpl mpl.rcParams['axes.unicode ...
- python使用cv2显示图片像素值
给定一张灰度图,显示这张图片的像素值 def show_image_pixel(img): ''' :param img: 需要输出像素值的图像,要求是灰度图 :return: 无返回值 ''' he ...
- Python opencv计算批量图片的BGR各自的均值
#coding:utf-8 #第一种方式 很慢很慢 自己写的如何计算均值 ''' import cv2 import os def access_pixels(frame): print(frame. ...
- python opencv show图片,debug技巧
debug的时候可以直接把图片画出来debug. imshow函数就是python opencv的展示图片的函数,第一个是你要起的图片名,第二个是图片本身.waitKey函数是用来展示图片多久的,默认 ...
- RPi 2B python opencv camera demo example
/************************************************************************************** * RPi 2B pyt ...
- Tensorflow显示图片
Tensorflow在处理数据时,经常加载图像数据,有的时候是直接读取文件,有的则是读取二进制文件,为了更好的理解Tensorflow数据处理模式,先简单讲解显示图片机制,就能更好掌握是否读取正确了. ...
- python中用opencv读取并显示图片
一.读取并显示图片: import matplotlib.pyplot as plt # plt 用于显示图片 import matplotlib.image as mpimg # mpimg 用于读 ...
随机推荐
- Core Data系列文章(一)Core Data基础
在iOS开发数据库SQLite的使用介绍了iOS中使用SQLite对数据进行持久化存储,实际上是对数据库直接进行操作,而苹果专门有一套API来间接的对数据进行持久化存储,而且主要针对用户创建的对象 - ...
- hdu----(4686)Arc of Dream(矩阵快速幂)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 开发完iOS应用,接下去你该做的事
iOS专项总结 关于 analyze Clang 静态分析器 Slender Faux Pas Warning Leaks Time Profiler 加载时间 iOS App启动过程 帧率等 如何优 ...
- 再谈HTML
关于WEB 采用B/S计算模式开发的应用程序我们一般称为Web应用程序. WEB三大层面: 网页的结构部分:结构的定义使用HTML语言(超文本标记语言Hyper Text Mark Up Langua ...
- ios基础篇(三)——UIButton的详细介绍
按钮UIButton是ios开发中最常见的控件之一,下面来介绍UIButton的详细内容: 一.UIButton的定义 UIButton *button=[[UIButton buttonWithTy ...
- Storm(2) - Log Stream Processing
Introduction This chapter will present an implementation recipe for an enterprise log storage and a ...
- Eclipse 汉化包
http://www.eclipse.org/babel/downloads.php 下载地址,具体操作请百度. http://subclipse.tigris.org/update_1.6.x SV ...
- TCP的三次握手
第一次握手 客户端调用connect,向服务端发送连接请求报文.该报文是一个特殊报文,报文首部同步位SYN=1,同时确认位ACK=0,seq=x表示确认字段的值为x,该字段值由客户端选择,表示客户端向 ...
- 在完成一个异步任务后取消剩余任务(C#)
完整实例 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System. ...
- Unity中的Path对应各平台中的Path
OS: Application.dataPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.a ...