Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -63,9 +63,9 @@ class WatermarkProcessor:
|
|
63 |
return im_name, f"Error adding watermark: {str(e)}"
|
64 |
|
65 |
def encode(self, image_path, watermark_text, metadata=None):
|
66 |
-
"""Encode watermark using simple LSB steganography with header
|
67 |
|
68 |
-
ํค๋(32๋นํธ)๋ watermark ๋ฐ์ดํฐ(
|
69 |
"""
|
70 |
try:
|
71 |
image = cv2.imread(image_path)
|
@@ -121,9 +121,9 @@ class WatermarkProcessor:
|
|
121 |
return image_path, f"Error in encoding: {str(e)}"
|
122 |
|
123 |
def decode(self, image_path):
|
124 |
-
"""Decode watermark using simple LSB steganography with header
|
125 |
|
126 |
-
๋จผ์ 32
|
127 |
"""
|
128 |
try:
|
129 |
# PNG ๋ฉํ๋ฐ์ดํฐ ๋จผ์ ํ์ธ
|
@@ -138,18 +138,33 @@ class WatermarkProcessor:
|
|
138 |
if image is None:
|
139 |
raise ValueError("Could not read image file")
|
140 |
|
141 |
-
|
142 |
-
|
|
|
|
|
143 |
for i in range(image.shape[0]):
|
144 |
for j in range(image.shape[1]):
|
145 |
for k in range(3):
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
-
|
|
|
|
|
149 |
header = binary_data[:32]
|
150 |
data_length = int(header, 2)
|
151 |
total_bits = data_length * 8
|
152 |
-
# ๋ณธ๋ฌธ ๋ฐ์ดํฐ ์ฝ๊ธฐ
|
153 |
message_bits = binary_data[32:32 + total_bits]
|
154 |
text = ''
|
155 |
for i in range(0, len(message_bits), 8):
|
|
|
63 |
return im_name, f"Error adding watermark: {str(e)}"
|
64 |
|
65 |
def encode(self, image_path, watermark_text, metadata=None):
|
66 |
+
"""Encode watermark using simple LSB steganography with header.
|
67 |
|
68 |
+
ํค๋(32๋นํธ)๋ watermark ๋ฐ์ดํฐ(JSON ๋ฌธ์์ด)์ ๊ธธ์ด(๋ฌธ์์)๋ฅผ ์ด์ง ๋ฌธ์์ด๋ก ์ ์ฅํฉ๋๋ค.
|
69 |
"""
|
70 |
try:
|
71 |
image = cv2.imread(image_path)
|
|
|
121 |
return image_path, f"Error in encoding: {str(e)}"
|
122 |
|
123 |
def decode(self, image_path):
|
124 |
+
"""Decode watermark using simple LSB steganography with header.
|
125 |
|
126 |
+
๋จผ์ 32๋นํธ(ํค๋)๋งํผ ์ฝ์ด ๋ฐ์ดํฐ ๊ธธ์ด(๋ฌธ์์)๋ฅผ ๊ตฌํ ํ, ๊ทธ ๊ธธ์ด์ ํด๋นํ๋ ๋ณธ๋ฌธ ๋นํธ๋ง ์ฝ์ด ๋ฌธ์์ด๋ก ๋ณต์ํฉ๋๋ค.
|
127 |
"""
|
128 |
try:
|
129 |
# PNG ๋ฉํ๋ฐ์ดํฐ ๋จผ์ ํ์ธ
|
|
|
138 |
if image is None:
|
139 |
raise ValueError("Could not read image file")
|
140 |
|
141 |
+
bits = []
|
142 |
+
total_needed = None
|
143 |
+
count = 0
|
144 |
+
# ํฝ์
์ํ: ํ์ํ ๋นํธ ์๋งํผ ์ฝ์ด์ค๊ธฐ
|
145 |
for i in range(image.shape[0]):
|
146 |
for j in range(image.shape[1]):
|
147 |
for k in range(3):
|
148 |
+
bits.append(str(image[i, j, k] & 1))
|
149 |
+
count += 1
|
150 |
+
# ํค๋ 32๋นํธ๋ฅผ ๋ชจ๋ ์ฝ์ ๊ฒฝ์ฐ
|
151 |
+
if count == 32 and total_needed is None:
|
152 |
+
header = ''.join(bits[:32])
|
153 |
+
data_length = int(header, 2)
|
154 |
+
total_needed = 32 + data_length * 8
|
155 |
+
if total_needed is not None and count >= total_needed:
|
156 |
+
break
|
157 |
+
if total_needed is not None and count >= total_needed:
|
158 |
+
break
|
159 |
+
if total_needed is not None and count >= total_needed:
|
160 |
+
break
|
161 |
|
162 |
+
if total_needed is None:
|
163 |
+
return "Error: Not enough data to read header"
|
164 |
+
binary_data = ''.join(bits[:total_needed])
|
165 |
header = binary_data[:32]
|
166 |
data_length = int(header, 2)
|
167 |
total_bits = data_length * 8
|
|
|
168 |
message_bits = binary_data[32:32 + total_bits]
|
169 |
text = ''
|
170 |
for i in range(0, len(message_bits), 8):
|