Skip to content
This repository was archived by the owner on Feb 9, 2023. It is now read-only.

Commit 5eb0f5e

Browse files
committed
Formats code to flake8
1 parent 14dc7e9 commit 5eb0f5e

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
venv/

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length=100

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python:3.7
2+
3+
WORKDIR /opt/omr
4+
5+
COPY . .
6+
7+
RUN pip3 install -r requirements.txt
8+
9+
CMD ["python", "omr.py", "--help"]

omr.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import argparse
22
import cv2
3-
import math
43
import numpy as np
54

65
# When the four corners are identified, we will do a four-point
@@ -24,6 +23,7 @@
2423
ALTERNATIVE_WIDTH = 50
2524
ALTERNATIVE_WIDTH_WITH_MARGIN = 100
2625

26+
2727
def calculate_contour_features(contour):
2828
"""Calculates interesting properties (features) of a contour.
2929
@@ -73,8 +73,9 @@ def calculate_corner_features():
7373
# contour (that is, it is _not_ the outer contour) to be the corner contour.
7474
# If in trouble, verify that this contour is the corner contour with
7575
# 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)
7879

7980
return calculate_contour_features(corner_contour)
8081

@@ -185,7 +186,6 @@ def perspective_transform(img, points):
185186
[TRANSF_SIZE, 0]],
186187
dtype="float32")
187188

188-
img_dest = img.copy()
189189
transf = cv2.getPerspectiveTransform(source, dest)
190190
warped = cv2.warpPerspective(img, transf, (TRANSF_SIZE, TRANSF_SIZE))
191191
return warped
@@ -210,8 +210,8 @@ def get_question_patch(transf, question_index):
210210
br = sheet_coord_to_transf_coord(
211211
ANSWER_SHEET_WIDTH - ANSWER_PATCH_RIGHT_MARGIN,
212212
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
215215
)
216216
return transf[tl[1]:br[1], tl[0]:br[0]]
217217

@@ -224,7 +224,8 @@ def get_question_patches(transf):
224224
def get_alternative_patches(question_patch):
225225
for i in range(5):
226226
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)
228229
yield question_patch[:, x0:x1]
229230

230231

@@ -270,9 +271,6 @@ def get_answers(source_file):
270271
- Apply perpsective transform to get a bird's eye view
271272
- Scan each line for the marked alternative
272273
"""
273-
274-
corner_features = calculate_corner_features()
275-
276274
im_orig = cv2.imread(source_file)
277275

278276
im_normalized = normalize(im_orig)
@@ -338,4 +336,3 @@ def main():
338336

339337
if __name__ == '__main__':
340338
main()
341-

test_omr.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ def test_recognizes_digitally_marked_answer_sheet():
1010
def test_recognizes_photo_of_digitally_marked_answer_sheet():
1111
answers = get_answers(os.path.join("img", "answered-sheet-photo.jpg"))
1212
assert answers[0] == ['A', 'C', 'C', 'E', 'N/A', 'N/A', 'A', 'N/A', 'N/A', 'N/A']
13-

0 commit comments

Comments
 (0)