绘制文本及中文文本
import cv2
import numpy as np
from PIL import ImageFont, Image,ImageDraw
img = np.full((1000,1000,3),fill_value=255,dtype=np.uint8)
# 第三个参数可选,字体样式,没有中文
cv2.putText(img,"Hello Open-cv",(400,400),cv2.FONT_HERSHEY_COMPLEX,2,(0,0,255))
font = ImageFont.truetype("./msyh.ttc",15)
img = Image.fromarray(img)
draw = ImageDraw.Draw(img)
draw.text((250,400),"你好",font=font,fill=(0,255,0,0))
img = np.array(img)
cv2.imshow("img",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
异或非位运算
import cv2
import numpy as np
img0_path = "./R-C.jpg"
img1_path = "./108.jpg"
img0 = cv2.imread(img0_path)
img1 = cv2.imread(img1_path)
cv_not = cv2.bitwise_not(img0)
img = np.hstack((img0,cv_not))
new_img1 = img1[:890,:600]
cv_and = cv2.bitwise_and(new_img1,img0)
print(new_img1[:3, :3], img0[:3, :3],cv_and[:3,:3])
print(134&105)
cv_or = cv2.bitwise_or(new_img1,img0)
print(new_img1[:3, :3], img0[:3, :3],cv_or[:3,:3])
print(134|105)
cv_xor = cv2.bitwise_xor(new_img1,img0)
print(new_img1[:3, :3], img0[:3, :3],cv_xor[:3,:3])
print(134|105)
cv2.imshow("img",cv_xor)
cv2.waitKey(0)
cv2.destroyAllWindows()