import os
import numpy as np
import argparse
import cv2
import matplotlib.pyplot as plt
原始图片如下所示:
![34bb745187414ddca9463ace08cd445c.png](https://i-blog.csdnimg.cn/blog_migrate/9ad51785d40fc513973c12933f8f92c5.png)
OpenCV 假设图像是 BGR 通道顺序。OpenCV 的 imread、imwrite 和 imshow 都使用 BGR 顺序,所以如果我们使用 cv2.imshow 显示图像,图像不会改变。但它不适用于 matplotlib。
大多数图像处理库都使用 RGB 排序,例如 matplotlib,因此如果使用plt.imshow
,logo的颜色会发生变化。
img = cv2.imread("logo.png")
# show the image by cv2
# The cv2.imshow() and cv.imshow() functions from the opencv-
python package are incompatible with Jupyter notebook;
# see https://github.com/jupyter/notebook/issues/3935.
# As a replacement, you can use the following function:
from google.colab.patches import cv2_imshow
cv2_imshow(img)