Omnibus commited on
Commit
f00a6e1
·
1 Parent(s): 29136da

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +21 -20
utils.py CHANGED
@@ -13,26 +13,27 @@ def to_bin(data):
13
  else:
14
  raise TypeError("Type not supported.")
15
  def decode(image_name,txt=None):
16
- msg=""
17
- BGRimage = cv2.imread(f"{image_name}")
18
- image = cv2.cvtColor(BGRimage, cv2.COLOR_BGR2RGB)
19
- binary_data = ""
20
- for row in image:
21
- for pixel in row:
22
- r, g, b = to_bin(pixel)
23
- binary_data += r[-1]
24
- binary_data += g[-1]
25
- binary_data += b[-1]
26
- all_bytes = [ binary_data[i: i+8] for i in range(0, len(binary_data), 8) ]
27
- decoded_data = ""
28
- for byte in all_bytes:
29
- decoded_data += chr(int(byte, 2))
30
- if decoded_data[-5:] == "=====":
31
- break
32
- this = decoded_data[:-5].split("#####",1)[0]
33
- this = eval(this)
34
- enc_in=this
35
- return this,msg
 
36
 
37
  def encode(image_name, secret_data,txt=None):
38
  msg=""
 
13
  else:
14
  raise TypeError("Type not supported.")
15
  def decode(image_name,txt=None):
16
+ try:
17
+ BGRimage = cv2.imread(f"{image_name}")
18
+ image = cv2.cvtColor(BGRimage, cv2.COLOR_BGR2RGB)
19
+ binary_data = ""
20
+ for row in image:
21
+ for pixel in row:
22
+ r, g, b = to_bin(pixel)
23
+ binary_data += r[-1]
24
+ binary_data += g[-1]
25
+ binary_data += b[-1]
26
+ all_bytes = [ binary_data[i: i+8] for i in range(0, len(binary_data), 8) ]
27
+ decoded_data = ""
28
+ for byte in all_bytes:
29
+ decoded_data += chr(int(byte, 2))
30
+ if decoded_data[-5:] == "=====":
31
+ break
32
+ this = decoded_data[:-5].split("#####",1)[0]
33
+ #this = eval(this)
34
+ except Exception as e:
35
+ this = e
36
+ return this
37
 
38
  def encode(image_name, secret_data,txt=None):
39
  msg=""