1、首先创建个简单的图片,大家都说会画圆形和矩形就可以画任意形状,因为我们可以对图片进行进行组合和按位操作
import cv2
import numpy as np
square = np.zeros((300,300),np.uint8)
cv2.rectangle(square,(50,50),(250,250),128,-2)
cv2.imshow("peng",square)
cv2.waitKey(0)
#画图
ellipse = np.zeros((300,300),np.uint8) cv2.ellipse(ellipse,(150,150),(150,150),30,0,180,255,-2)
cv2.imshow("ellipse",ellipse)
cv2.waitKey(0)
cv2.destroyAllWindows()
2、现在开始对图片进行按位操作,首先看And操作
And = cv2.bitwise_and(square,ellipse)
cv2.imshow("And",And)
cv2.waitKey(0)
cv2.destroyAllWindows()
3、or
bitwiseOR = cv2.bitwise_or(square,ellipse)
cv2.imshow("OR",bitwiseOR)
cv2.waitKey(0)
cv2.destroyAllWindows()
4、NOT,取反
bitwiseNOT = cv2.bitwise_not(square)
cv2.imshow("not",bitwiseNOT)
cv2.waitKey(0)
cv2.destroyAllWindows()
5、XOR两个图形的非交互处
bitwiseXOR = cv2.bitwise_xor(square,ellipse)
cv2.imshow("XOR",bitwiseXOR)
cv2.waitKey(0)
cv2.destroyAllWindows()