-
Notifications
You must be signed in to change notification settings - Fork 0
/
crush_compare.py
107 lines (75 loc) · 2.93 KB
/
crush_compare.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import time
import math
import json
import cart_repair
import cv2
import numpy as np
def append_horizontal(images):
max_height = 0
total_width = 0
padding = 1
for image in images:
image_height = image.shape[0]
image_width = image.shape[1]
if image_height > max_height:
max_height = image_height
total_width = total_width + image_width
final_image = np.zeros((max_height, (len(images)-1)*padding + total_width, 3), dtype=np.uint8)
current_x = 0
for image in images:
image_height = image.shape[0]
image_width = image.shape[1]
final_image[:image_height,current_x :image_width+current_x, :] = image
current_x += image_width+padding
return final_image
def create_row_cart(image, scale_count=10):
height = image.shape[0]
width = image.shape[1]
base = cv2.resize(image, (math.floor(width / 10), math.floor(height / 10)), interpolation = cv2.INTER_LANCZOS4)
r = base.copy()
height = base.shape[0]
width = base.shape[1]
for scale in range(2, scale_count):
x = cart_repair.process_frame(base.copy(), scale)
r = append_horizontal([r, x])
zeros = np.zeros((height, width * 2, 3), dtype=np.uint8)
r = append_horizontal([zeros, r])
cv2.putText(r, "cart_repair", (10, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255, 255), 1)
return r
def create_row(image, interp=cv2.INTER_CUBIC, text="Cubic", scale_count=10):
height = image.shape[0]
width = image.shape[1]
base = cv2.resize(image, (math.floor(width / 10), math.floor(height / 10)), interpolation = cv2.INTER_LANCZOS4)
r = base.copy()
height = base.shape[0]
width = base.shape[1]
for scale in range(2, scale_count):
x = cv2.resize(base.copy(), (math.floor(width * scale), math.floor(height * scale)), interpolation = interp)
r = append_horizontal([r, x])
zeros = np.zeros((height, width * 2, 3), dtype=np.uint8)
r = append_horizontal([zeros, r])
cv2.putText(r, text, (10, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255, 255), 1)
return r
def process_frame(image):
cubic_row = create_row(image, cv2.INTER_CUBIC, text="Bicubic")
nearest_row = create_row(image, cv2.INTER_NEAREST, text="Nearest")
linear_row = create_row(image, cv2.INTER_LINEAR, text="Linear")
area_row = create_row(image, cv2.INTER_AREA, text="Area")
lanczos_row = create_row(image, cv2.INTER_LANCZOS4, text="Lanczos v4")
cart_row = create_row_cart(image)
final = cv2.vconcat([cubic_row, nearest_row, linear_row, area_row, lanczos_row, cart_row])
#cv2.imshow("Base", base)
#cv2.waitKey()
#cv2.destroyAllWindows()
return final
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", help="Input file (image or video)")
parser.add_argument("-o", "--output-prefix", help="Output file prefix. (File extension is automatically chosen.)")
args = parser.parse_args()
if not args.input:
raise RuntimeError("Arguments not given.")
image = cv2.imread(args.input)
d = process_frame(image)
cv2.imwrite("{}.png".format(args.output_prefix), d)