cv2.imread()
import numpy as np
import cv2
img=cv2.imread('messi5.jpg',0)
cv2.imshow()
cv2.imshow('image',img)
cv.waitKey(0)
plt.imshow(img[:,:,::-1])
cv2.imwrite()
cv2.imwrite('messigray.png',img)
cv2.line(img,start,end,color,thickness)
cv2.circle(img,centerpoint,r,color,thickness)
cv2.rectangle(img,leftupper,rightdown,color,thickness)
cv2.putText(img,text,station,font,fontsize,color,thickness,cv2.LINE_AA)
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
#1 创建图像
img=np.zeros((512,512,3),np.uint8)
#2 绘制图形
cv.line(img,(0,0),(511,511),(255,0,0),5)
cv.circle(img,(256,256),60,(0,0,255),-1)
cv.rectangle(img,(100,100),(400,400),(0,255,0),5)
cv.putText(img,'hello',(100,150),cv.FONT_HERSHEY_COMPLEX,5,(255,255,255),3)
#3 显示结果
plt.imshow(img[:,:,::-1])
plt.show()
注:opencv图像坐标系中,左上角是原点,y轴向下,x轴向右,单位像素点
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
img=np.zeros((256,256,3),np.uint8)
img[100:200,100:200]=(0,0,255)
plt.imshow(img[:,:,::-1])
img.shape
img.dtype
img.size
有时需要在B,G,R通道图像上单独工作。在这种情况下,需要将BGR图像分割成单个通道。或者在其他情况下,可能需要将这些单独的通道合并到BGR图像
b,g,r=cv.split(img)
img=cv.merge((b,g,r))
opencv中有150多种颜色空间转换方法。最广泛使用的转换方法有两种,BGR<->Gray和BGR<->HSV
cv.cvtColor(input_image,flag)