-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoeq_validation.py
More file actions
97 lines (71 loc) · 2.81 KB
/
Copy pathoeq_validation.py
File metadata and controls
97 lines (71 loc) · 2.81 KB
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
import numpy as np
import cv2 as cv
import logging
class Validate:
def __init__(self):
logging.basicConfig(filename='systemlog/error.log', level=logging.ERROR)
logging.basicConfig(filename='systemlog/info.log', level=logging.INFO)
logging.basicConfig(filename='systemlog/debug.log', level=logging.DEBUG)
logging.basicConfig(filename='systemlog/warning.log', level=logging.WARNING)
# self.data = []
def find_quality_image(self, path):
# logging.basicConfig(filename='systemlog/system.log', level=logging.DEBUG)
gray = self.calculate_edge(path)
img = cv.imread(path, cv.IMREAD_GRAYSCALE)
(thresh, im_bw) = cv.threshold(img, 128, 255, cv.THRESH_BINARY | cv.THRESH_OTSU)
fm = cv.Laplacian(gray, cv.CV_64F).var()
if thresh >= fm:
message = path
info = path + '-' + "The image successfully send to scan process"
logging.info(info)
return message, 'success'
else:
message = path
error = path + '-' + "The image can not be scan because of poor quality"
logging.error(error)
return message, 'not_success'
# sys.exit('The quality of the image not satisfy minimal requirement')
"""
calculate conner edges with coordinate of first conner in top of answer sheet
@:return : coordinate x , y
@:return : height , width
@:return : gray
"""
def calculate_edge(self, img):
img2 = cv.imread(img)
gray = cv.cvtColor(img2, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(gray, (15, 15), 0)
return gray
def range(self, n):
a = 1 + 40 * (n - 1)
b = a + 40 - 1
return a, b
def circles(self, img):
img = cv.imread(img, 0)
img = cv.medianBlur(img, 3)
data = []
circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=24, maxRadius=33)
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
if i[1] > 500:
data.append([i[0], i[1]])
detect = sorted(data, key=lambda t: t[1])
return detect
def array_length(self, img):
data = self.circles(img)
len_data = len(data)
if len_data == 280:
return True
else:
return False
def calculate_qr_edge(self, img):
img = cv.imread(img, 0)
img = cv.medianBlur(img, 3)
data = []
circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=20, maxRadius=30)
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
if i[1] < 300:
data.append([i[0], i[1]])
detect = sorted(data, key=lambda t: t[0])
return detect