利用OpenCV读取并显示一张图片
# This is a sample OpenCV script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import cv2
from matplotlib import pyplot as plt
def show_img(img_path):
plt.rcParams['figure.figsize'] = (15.0, 8.0)
img = cv2.imread(img_path)
# 将BGR图像转变为RGB图像以打印
img_rgb = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
plt.imshow(img_rgb)
# 去除x,y轴刻度
plt.xticks([])
plt.yticks([])
plt.show()
if __name__ == '__main__':
img="C:/Users/unicom/ML/DIP/opencv_notebooks/images/robot.jpg"
show_img(img)
遇到的小坑:
1、报错:
ImportError: No module named cv2
第一想法:
使用命令:
pip install cv2
会报错找不到请求的版本
解决方法:
使用命令
pip install opencv-python