Skip to content

Commit 3c3c9e2

Browse files
committed
OMR Reader using Python
1 parent bc668bd commit 3c3c9e2

27 files changed

+1121
-0
lines changed

Category.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import cv2
2+
import numpy as np
3+
4+
def category(cat):
5+
cate=""
6+
orginal=np.uint8(cat)
7+
orginal=cv2.resize(orginal,(202,626))
8+
c = ["GEN","OBC1","OBC2","SC","ST","PH"]
9+
10+
h,w = orginal.shape
11+
crop= orginal[140:h-5,140:w-5]
12+
# cv2.imshow('l',crop)
13+
14+
h1,w1 = crop.shape
15+
th, im_th = cv2.threshold(crop,127,255,0)
16+
17+
im_th=~im_th
18+
kernel = np.ones((5,5), np.uint8)
19+
binary = cv2.erode(im_th, kernel, iterations=2)
20+
21+
count = 0
22+
for x in range(0, h1,np.uint(np.floor(h1/6))):
23+
24+
if (x+int(h1/6) > h1):
25+
break
26+
row = binary[x:x+int(h1/6),:]
27+
visr=crop[x:x+int(h1/6),:]
28+
count+=1
29+
# cv2.imshow("Foreground", visr)
30+
# cv2.waitKey(0)
31+
_,cnts, _ = cv2.findContours(row, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
32+
33+
if len(cnts) == 1:
34+
cate=c[count-1]
35+
36+
37+
return cate

Center_code.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import cv2
2+
import numpy as np
3+
4+
def code(center):
5+
6+
orginal=np.uint8(center)
7+
orginal=cv2.resize(orginal,(267,583))
8+
9+
h,w = orginal.shape
10+
crop= orginal[158:h-5,18:w-18]
11+
12+
13+
th, im_th = cv2.threshold(crop,127,255,0)
14+
im_th=~im_th
15+
kernel = np.ones((5,5), np.uint8)
16+
binary = cv2.erode(im_th, kernel, iterations=2)
17+
18+
h1,w1 = crop.shape
19+
code = []
20+
for y in range(0, w1,np.uint(np.floor(w1/4))):
21+
if (y +int(w1/4) > w1):
22+
break
23+
column = binary[0:h1, y: y +int(w1/4)]
24+
visc=crop[0:h1, y: y +int(w1/4)]
25+
count=0
26+
for x in range(0, h1,np.uint(np.floor(h1/10))):
27+
28+
if (x+int(h1/10) > h1):
29+
break
30+
row = column[x:x+int(h1/10),:]
31+
visr=visc[x:x+int(h1/10),:]
32+
count+=1
33+
34+
# cv2.imshow("Foreground", visr)
35+
# cv2.waitKey(0)
36+
37+
_,cnts, _ = cv2.findContours(row, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
38+
if len(cnts) == 1:
39+
code.append(str(count))
40+
if len(code)>0:
41+
code=['0' if x == '10' else x for x in code]
42+
code=''.join(code)
43+
code=int(code)
44+
else:
45+
code=""
46+
return code
47+
48+

Input/10.jpg

978 KB
Loading

Input/11.jpg

973 KB
Loading

Input/12.jpg

1000 KB
Loading

Input/2.jpg

738 KB
Loading

Input/3.jpg

984 KB
Loading

Input/4.jpg

2.3 MB
Loading

Input/5.jpg

2.29 MB
Loading

Input/6.jpg

2.32 MB
Loading

0 commit comments

Comments
 (0)