1
1
import argparse
2
2
import cv2
3
- import math
4
3
import numpy as np
5
4
6
5
# When the four corners are identified, we will do a four-point
24
23
ALTERNATIVE_WIDTH = 50
25
24
ALTERNATIVE_WIDTH_WITH_MARGIN = 100
26
25
26
+
27
27
def calculate_contour_features (contour ):
28
28
"""Calculates interesting properties (features) of a contour.
29
29
@@ -73,8 +73,9 @@ def calculate_corner_features():
73
73
# contour (that is, it is _not_ the outer contour) to be the corner contour.
74
74
# If in trouble, verify that this contour is the corner contour with
75
75
# cv2.drawContours(corner_img, [corner_contour], -1, (255, 0, 0))
76
- corner_contour = next (ct for i , ct in enumerate (contours )
77
- if hierarchy [0 ][i ][3 ] != - 1 )
76
+ corner_contour = next (ct
77
+ for i , ct in enumerate (contours )
78
+ if hierarchy [0 ][i ][3 ] != - 1 )
78
79
79
80
return calculate_contour_features (corner_contour )
80
81
@@ -185,7 +186,6 @@ def perspective_transform(img, points):
185
186
[TRANSF_SIZE , 0 ]],
186
187
dtype = "float32" )
187
188
188
- img_dest = img .copy ()
189
189
transf = cv2 .getPerspectiveTransform (source , dest )
190
190
warped = cv2 .warpPerspective (img , transf , (TRANSF_SIZE , TRANSF_SIZE ))
191
191
return warped
@@ -210,8 +210,8 @@ def get_question_patch(transf, question_index):
210
210
br = sheet_coord_to_transf_coord (
211
211
ANSWER_SHEET_WIDTH - ANSWER_PATCH_RIGHT_MARGIN ,
212
212
FIRST_ANSWER_PATCH_TOP_Y +
213
- ANSWER_PATCH_HEIGHT +
214
- ANSWER_PATCH_HEIGHT_WITH_MARGIN * question_index
213
+ ANSWER_PATCH_HEIGHT +
214
+ ANSWER_PATCH_HEIGHT_WITH_MARGIN * question_index
215
215
)
216
216
return transf [tl [1 ]:br [1 ], tl [0 ]:br [0 ]]
217
217
@@ -224,7 +224,8 @@ def get_question_patches(transf):
224
224
def get_alternative_patches (question_patch ):
225
225
for i in range (5 ):
226
226
x0 , _ = sheet_coord_to_transf_coord (ALTERNATIVE_WIDTH_WITH_MARGIN * i , 0 )
227
- x1 , _ = sheet_coord_to_transf_coord (ALTERNATIVE_WIDTH + ALTERNATIVE_WIDTH_WITH_MARGIN * i , 0 )
227
+ x1 , _ = sheet_coord_to_transf_coord (ALTERNATIVE_WIDTH +
228
+ ALTERNATIVE_WIDTH_WITH_MARGIN * i , 0 )
228
229
yield question_patch [:, x0 :x1 ]
229
230
230
231
@@ -270,9 +271,6 @@ def get_answers(source_file):
270
271
- Apply perpsective transform to get a bird's eye view
271
272
- Scan each line for the marked alternative
272
273
"""
273
-
274
- corner_features = calculate_corner_features ()
275
-
276
274
im_orig = cv2 .imread (source_file )
277
275
278
276
im_normalized = normalize (im_orig )
@@ -338,4 +336,3 @@ def main():
338
336
339
337
if __name__ == '__main__' :
340
338
main ()
341
-
0 commit comments