1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| import cv2 import numpy as np import matplotlib.pyplot as plt violet=cv2.imread('violet.jpg') h,w,c= violet.shape key=np.random.randint(0,256,(h,w,c),dtype=np.uint8) violetXorKey=cv2.bitwise_xor(violet,key) mask=np.zeros((h,w,c),dtype=np.uint8) mask[200:500,250:550]=1 encryptface=cv2.bitwise_and(violetXorKey,mask*255) noface=cv2.bitwise_and(violet,(1-mask)*255) encryptViolet=noface+encryptface
plt.subplot(3,3,1) plt.imshow(cv2.cvtColor(violet,cv2.COLOR_BGR2RGB)) plt.title('original') plt.axis('off') plt.subplot(3,3,2) plt.imshow(cv2.cvtColor(key,cv2.COLOR_BGR2RGB)) plt.title('key') plt.axis('off') plt.subplot(3,3,3) plt.imshow(cv2.cvtColor(mask,cv2.COLOR_BGR2RGB)) plt.title('mask') plt.axis('off') plt.subplot(3,3,4) plt.imshow(cv2.cvtColor(violetXorKey,cv2.COLOR_BGR2RGB)) plt.title('violetXorKey') plt.axis('off') plt.subplot(3,3,5) plt.imshow(cv2.cvtColor(encryptface,cv2.COLOR_BGR2RGB)) plt.title('encryptface') plt.axis('off') plt.subplot(3,3,7) plt.imshow(cv2.cvtColor(noface,cv2.COLOR_BGR2RGB)) plt.title('noface') plt.axis('off') plt.subplot(3,3,8) plt.imshow(cv2.cvtColor(encryptViolet,cv2.COLOR_BGR2RGB)) plt.title('encryptViolet') plt.axis('off') plt.show()
|