To load an image, you only need an api, imread (path, flag)
Two parameters of imread:
- Path: Your image path
- Flag: There are two commonly used values, IMREAD_ COLOR normally displays the rgb color image. If it is not filled in, it is also the default attribute value. IMREAD_ GRAYSCALE displays gray and white pictures.
import cv2 from cv2 import IMREAD_COLOR from cv2 import IMREAD_GRAYSCALE cv2.namedWindow('img',cv2.WINDOW_NORMAL) # 创建窗口并命名窗口和窗口是否可以改变大小 img=cv2.imread('你的图片路径',IMREAD_COLOR) # 加载图片,导入图片地址和图片的显示方式 cv2.imshow('img',img) # 显示图片 cv2.waitKey(0) # 窗口一直显示 cv2.destroyAllWindows() # 关闭所有窗口