-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyerPointRecognize.py
More file actions
76 lines (59 loc) · 1.96 KB
/
PyerPointRecognize.py
File metadata and controls
76 lines (59 loc) · 1.96 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
from sklearn import neighbors
import cv2
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import PyerClassifier as pcla
import joblib
import PyerImg as pimg
def get_point(img):
#加载识别模型
clf = joblib.load('PyerPredictModel.pkl')
#获取点位在图中的坐标
locationList=[]
circles = pimg.get_circles(img)
circles = np.uint16(np.round(circles))
for i in range(circles.shape[1]):
flagPosition=[circles[0][i][0],circles[0][i][1]]
locationList.append(flagPosition)
#获取点位的数字和点位总数
classList=[]
total, mats = pcla.get_circle_imgs(img)
for i in range(total):
b_img = pcla.binarize(mats[i])
af = pcla.incise(b_img)
aList=af[0]
classList.append(clf.predict([aList])[0])
#生成该图点位信息的字典
result={'length':total,'center':locationList,'class':classList}
#修正该图点位信息的字典
recognizeResult=result_correct(result)
return recognizeResult
def result_correct(result):
total=result['length']
classList=result['class']
#点位的数字应小于等于点位总数
for i in range(total):
if classList[i] >total:
classList[i]=total
#获取应该要有的所有点位数字
correct=[]
for i in range(1,total+1):
correct.append(i)
#获取缺少的点位数字
for i in classList:
if correct.count(i)>0:
correct.remove(i)
#重复的点位数字改为缺少的点位数字
for i in range(total):
for j in range(i+1,total):
if classList[i]==classList[j]:
temp=correct[0]
classList[i]=temp
correct.remove(temp)
correctResult={'length':total,'center':result['center'],'class':classList}
return correctResult
# if __name__ == "__main__":
# img = cv2.imread('img/test1.jpg',1)
# result = get_point(img)
# print(result)