-
Notifications
You must be signed in to change notification settings - Fork 0
/
___deprecated.py
178 lines (126 loc) · 5.44 KB
/
___deprecated.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# lastClipStable = False
# lastClipRect = None
# lastClipped = None
# lastMean = 128
# lastEntropy = 100
# minEntropy = 100000
# minEntropyMean = 128
# minEntropyClip = None
# minEntropyFrame = 0
# frameCount = 0
# minorCount = 0
# # 이전 프레임과의 차이를 계산
# diffGray = None
# clipEntropy = 0
# clipMean = 0
# if clipped is not None:
# cv2.imshow('Clipped', clipped)
# newKeyframe = False
# newSubFrame = False
# score = 0
# newClip = True
# if lastClipped is not None:
# (lh, lw) = lastClipped.shape[:2]
# (nh, nw) = clipped.shape[:2]
# if lh == nh and lw == nw:
# newClip = False
# lg = cv2.cvtColor(cv2.resize(lastClipped, None, fx=0.5, fy= 0.5), cv2.COLOR_BGR2GRAY)
# ng = cv2.cvtColor(cv2.resize(clipped, None, fx=0.5, fy=0.5), cv2.COLOR_BGR2GRAY)
# # 구조적 유사도
# (score, diff) = compare_ssim(lg, ng, full=True)
# diff = (diff * 255).astype("uint8")
# # 밝기
# clipMean = ng.mean()
# # 엔트로피
# clipEntropy = shannon_entropy(ng)
# #print('ssim:{s}, entropy:{e}, mean:{m}'.format(s=score, e=clipEntropy, m=clipMean))
# if score < 0.9:
# # 구조적 유사도가 90% 이하로 떨어지면 새 이미지로 간주한다
# newKeyframe = True
# elif abs(clipMean / lastMean - 1) > 0.05:
# # 밝기가 5% 이상 변하면 새 서브 프레임 구간으로 간주한다
# newSubFrame = True
# if newClip:
# # 새 이미지
# newKeyframe = True
# ng = cv2.cvtColor(cv2.resize(clipped, None, fx=0.5, fy=0.5), cv2.COLOR_BGR2GRAY)
# clipMean = ng.mean()
# clipEntropy = shannon_entropy(ng)
# if newKeyframe:
# if minEntropyClip is not None:
# fileName = 'frame{no:04d}-{sub:03d}-{total:d}.png'.format(no=frameCount, sub=minorCount, total=minEntropyFrame)
# (ch, cw) = minEntropyClip.shape[:2]
# print('Writing {} ({}x{})...'.format(fileName, cw, ch))
# cv2.imwrite(outputPath + '\\' + fileName, minEntropyClip)
# lastClipped = minEntropyClip.copy()
# lastEntropy = minEntropy
# else:
# lastClipped = clipped.copy()
# lastEntropy = clipEntropy
# lastMean = clipMean
# # 새로운 키 프레임
# frameCount += 1
# minorCount = 1
# # 엔트로피 키 프레임
# minEntropy = clipEntropy
# minEntropyClip = clipped.copy()
# minEntropyFrame = totalFrameCount
# else:
# if newSubFrame:
# # 새 서브 프레임 구간이 시작
# # 기존 프레임을 덤프
# if minEntropyClip is not None:
# fileName = 'frame{no:04d}-{sub:03d}-{total:d}.png'.format(no=frameCount, sub=minorCount, total=minEntropyFrame)
# (ch, cw) = minEntropyClip.shape[:2]
# print('Writing {} ({}x{})...'.format(fileName, cw, ch))
# cv2.imwrite(outputPath + '\\' + fileName, minEntropyClip)
# minorCount += 1
# lastClipped = minEntropyClip.copy()
# lastMean = clipMean
# lastEntropy = minEntropy
# minEntropy = clipEntropy
# minEntropyClip = clipped.copy()
# minEntropyFrame = totalFrameCount
# else:
# # 이전과 비슷한 프레임이 유지되는 중이다
# if clipEntropy < minEntropy:
# minEntropy = clipEntropy
# minEntropyClip = clipped.copy()
# minEntropyFrame = totalFrameCount
# lastClipped = clipped.copy()
# lastMean = clipMean
# lastEntropy = clipEntropy
# morphSize = 50
# erodedH = cv2.erode(first, np.ones((1,morphSize), np.uint8))
# dilatedH = cv2.dilate(erodedH, np.ones((1,morphSize), np.uint8))
# erodedV = cv2.erode(first, np.ones((morphSize,1), np.uint8))
# dilatedV = cv2.dilate(erodedV, np.ones((morphSize,1), np.uint8))
# dilated = cv2.add(dilatedH, dilatedV)
# Canny 결과를 Hough를 거쳐 가로세로 직선 성분을 구한다
# thres = cv2.getTrackbarPos('HoughThreshold', 'UI')
# #lines = cv2.HoughLines(dilated,1,np.pi/180,thres)
# lines = None
# vLines, hLines = detect.seperateLines(lines, w, h)
# hSegments = detect.getHorizontalSegments(first, hLines, vLines, houghThres, lineThreshold)
# vSegments = detect.getVerticalSegments(first, hLines, vLines, houghThres, lineThreshold)
# time_5 = time.time()
# #debugRender(hLines, vLines, hSegments, vSegments)
# # 가로 선과 세로 선 조합을 바탕으로 가능한 사각형을 찾아낸다
# maxRect, rects = detect.detectRectangle(hSegments, vSegments)
# # 클립 영역 디버그 렌더
# for i in range(len(rects)):
# (x1, y1, x2, y2) = rects[i]
# cv2.rectangle(frame, (x1,y1), (x2, y2), rectColor, 1)
# diff = cv2.absdiff(lastClipped, clipped)
# diffGray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
# error = diffGray.sum()
# errorPerPixel = error / (lw * lh)
# if errorPerPixel > 33:
# #print('{} - new frame'.format(errorPerPixel))
# newKeyframe = True
# elif errorPerPixel > 0.3:
# #print('{} - new subframe'.format(errorPerPixel))
# newSubFrame = True
# else:
# pass
# print(errorPerPixel)