forked from DemonStarAlgol/CTF_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
碎片化图像拼合.py
29 lines (23 loc) · 788 Bytes
/
碎片化图像拼合.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
import os
import cv2
import numpy as np
channel = 2 # bgr三通道
imgs = [cv2.imread(os.path.join("./images", i)) for i in os.listdir("./images")]
def get_diff(A: np.array, B: np.array):
# return sum((A[:, -1, channel] - B[:, 0, channel]))
return sum((A[:, -1, channel] - B[:, 0, channel]) ** 0.25)
def combine(img1, img2):
return np.concatenate([img1, img2], axis=1)
while len(imgs) > 1:
index = None
min_diff = None
for j in range(1, len(imgs)):
if min_diff is None:
min_diff = get_diff(imgs[0], imgs[j])
index = j
elif (diff := get_diff(imgs[0], imgs[j])) < min_diff:
min_diff = diff
index = j
imgs[0] = combine(imgs[0], imgs[index])
imgs.pop(index)
cv2.imwrite("flag.png", imgs[0])