forked from freder/cinemetrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_2_sort_motion_spectrum.py
47 lines (33 loc) · 986 Bytes
/
04_2_sort_motion_spectrum.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
# -*- coding: utf-8 -*-
import cv
import os
import os.path
import sys
OUTPUT_DIR_NAME = "downsampled"
def main():
os.chdir(os.path.join(sys.argv[1], "motion"))
try:
os.mkdir(OUTPUT_DIR_NAME)
except OSError:
pass
#os.system("del klein\\*.png")
os.system("convert motion_*.png -adaptive-resize 500x500! " + OUTPUT_DIR_NAME + "\\motion_%02d.png")
os.chdir(OUTPUT_DIR_NAME)
os.system("convert motion_*.png -append result.png")
img = cv.LoadImageM("result.png")
values = []
for y in range(img.rows):
value = cv.Get1D( cv.GetRow(img, y), 0)[0]
values.append(value)
values.sort(reverse=True)
output_img = cv.CreateImage(cv.GetSize(img), cv.IPL_DEPTH_8U, 3)
for y in range(img.rows):
for x in range(img.cols):
cv.Set2D(output_img, y, x, cv.RGB(values[y], values[y], values[y]))
cv.SaveImage("result_sorted.png", output_img)
raw_input("- done -")
return
# #########################
if __name__ == "__main__":
main()
# #########################