-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencryptImage.py
62 lines (42 loc) · 1.36 KB
/
encryptImage.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import sys
import cv2
import qrcode
from PIL import Image
from generateQR import generateQR,readQR
qrfilename = os.path.join(sys.path[0],"QR.png")
inputfilename = os.path.join(sys.path[0],"input.png")
outputfilename = os.path.join(sys.path[0],"output.png")
def encryptImage():
data = input('Enter data to be encoded: ')
generateQR(data,qrfilename)
print("Hiding a QR code within input.png")
im = Image.open(inputfilename)
qr = Image.open(qrfilename)
qr_pixel_map = qr.load()
im_pixel_map = im.load()
if qr.size > im.size:
print("input image smaller than qr code, try with a larger image")
return
for x in range(qr.size[0]):
for y in range(qr.size[1]):
pixel = im_pixel_map[x,y]
change = False
if qr_pixel_map[x,y]:
if sum(pixel)%2:
continue
else:
change = True
else:
if sum(pixel)%2:
change = True
else:
continue
if change:
im_pixel_map[x,y] = (pixel[0]-1,pixel[1],pixel[2])
im.save(outputfilename)
encryptImage()
outputfile = cv2.imread(outputfilename)
cv2.imshow("encrypted-img",outputfile)
cv2.waitKey(0)
cv2.destroyAllWindows()