在用plt.imshow和cv2.imshow显示同一幅图时可能会出现颜色差别很大的现象。这是因为:
opencv的接口使用BGR,而matplotlib.pyplot 则是RGB模式
import cv2 import numpy as np import matplotlib.pyplot as plt img = cv2.imread(‘lena_std.tif‘) b,g,r = cv2.split(img) img2 = cv2.merge([r,g,b]) plt.subplot(121);plt.imshow(img) plt.subplot(122);plt.imshow(img2) plt.show() cv2.imshow(‘bgr image‘,img) cv2.imshow(‘rgb image‘,img2) cv2.waitKey(0) cv2.destroyAllWindows()
程序运行结果如下:
Matplotlib显示结果
OpenCV显示结果
参考资料:http://stackoverflow.com/questions/15072736/extracting-a-region-from-an-image-using-slicing-in-python-opencv/15074748#15074748
原文地址:https://www.cnblogs.com/Ph-one/p/12093193.html
时间: 2024-10-12 04:26:30