-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathtable_choose.py
1681 lines (1574 loc) · 81 KB
/
table_choose.py
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# encoding: utf-8
import os
import cv2 as cv
import numpy as np
import math
import num_out
import mnist_recognize
import chinese_out
import chinese_out_jiguan
import time_out
import csv
##### 初始化CSV文件 #####
csvfile = open("try1010.csv", 'w')
csvwrite = csv.writer(csvfile)
fileHeader = ["登记表编号","性别","民族","体重","血型","籍贯","高中学校名称","高中专业","高中学位","高中起止时间","高中是否毕业","大专学校名称","大专专业","大专学位","大专起止时间","大专是否毕业","本科学校名称","本科专业","本科学位","本科起止时间","本科是否毕业","研究生学校名称","研究生专业","研究生学位","研究生起止时间","研究生是否毕业","学校名称(其它)","专业(其它)","学位(其它)","起止时间(其它)","是否毕业(其它)"]
csvwrite.writerow(fileHeader)
path = 'test_data'
for (path,dirs,files) in os.walk(path):
for filename in files:
#docu_num = '20110158' #测试单张登记表
##### 按文件名读取登记表 #####
(docu_num,extension) = os.path.splitext(filename)
print "filename:", filename
##### 根据文件名年份的不同区分不同类型的登记表 #####
print docu_num[3]
if docu_num[3] == '1':
if len(docu_num) == 9 or (docu_num[5] == '3' and docu_num[6] == '1'):
table_style = 2
else:
table_style = 1
if docu_num[3] == '3':
table_style = 3
if docu_num[3] == '4' or docu_num[3] == '5':
table_style = 4
jiaozheng = 0
image = cv.imread('test_data/' + docu_num + '.jpg')
rows, cols, channels = image.shape
print rows, cols
image_copy = image.copy()
##### 旋转校正Rotation #####
#统计图中长横线的斜率来判断整体需要旋转矫正的角度
gray = cv.cvtColor(image, cv.COLOR_RGB2GRAY)
if table_style == 1 or table_style == 3 or table_style == 2:
edges = cv.Canny(gray, 50, 150, apertureSize=3) # 50,150,3
cv.imwrite('edges_whole.jpg', edges)
lines = cv.HoughLinesP(edges, 1, np.pi / 180, 500, 0, minLineLength=50, maxLineGap=50)#650,50,20
if table_style == 4:
edges_gray = cv.Canny(gray, 50, 150, apertureSize=3) # 50,150,3
edges = edges_gray[400:1000, 0:1000]
cv.imwrite('edges_whole.jpg', edges)
lines = cv.HoughLinesP(edges, 1, np.pi / 180, 200, 0, minLineLength=50, maxLineGap=35)#650,50,20
pi = 3.1415
theta_total = 0
theta_count = 0
for line in lines:
x1, y1, x2, y2 = line[0]
if table_style == 4:
y1 = y1 + 400
y2 = y2 + 400
rho = np.sqrt((x1 - x2)**2 + (y1 - y2)**2)
theta = math.atan(float(y2 - y1)/float(x2 - x1 + 0.001))
print(rho, theta, x1, y1, x2, y2)
if theta < pi/4 and theta > -pi/4:
theta_total = theta_total + theta
theta_count+=1
cv.line(image_copy, (x1, y1), (x2, y2), (0, 0, 255), 2)
#cv.line(edges, (x1, y1), (x2, y2), (0, 0, 0), 2)
theta_average = theta_total/theta_count
print theta_average, theta_average*180/pi
cv.imwrite('line_detect4rotation.jpg', image_copy)
#cv.imwrite('line_detect4rotation.jpg', ~edges)
#affineShrinkTranslationRotation = cv.getRotationMatrix2D((cols/2, rows/2), theta_average*180/pi, 1)
affineShrinkTranslationRotation = cv.getRotationMatrix2D((0, rows), theta_average*180/pi, 1)
ShrinkTranslationRotation = cv.warpAffine(image, affineShrinkTranslationRotation, (cols, rows))
image_copy = cv.warpAffine(image_copy, affineShrinkTranslationRotation, (cols, rows))
cv.imwrite('image_Rotation.jpg',ShrinkTranslationRotation)
##### 平移校正Move #####
#通过对表格左下角直角进行识别,将其顶点统一平移矫正至(78,1581)
#print "rows: ",rows
roi = image_copy[1450:rows, 0:150]#180
gray = cv.cvtColor(roi, cv.COLOR_RGB2GRAY)
edges = cv.Canny(gray, 50, 150, apertureSize=3) # 50,150,3
roi_mean_set = cv.mean(~edges[0:int((rows-1450)/2), 85:150])#通过区域灰度值特征排除文字对直线识别的干扰
roi_mean = roi_mean_set[0]
#cv.imwrite('edges_sample.jpg', edges)
cv.imwrite('edges_sample.jpg', ~edges[0:int((rows-1450)/2), 75:150])
lines = cv.HoughLinesP(edges, 1.0, np.pi / 180, 35, 0, minLineLength=10,maxLineGap=20)#50,10,20
lines_message_set = []
for line in lines:
x1, y1, x2, y2 = line[0]
y1 = y1 + 1450
y2 = y2 + 1450
rho = np.sqrt((x1 - x2)**2 + (y1 - y2)**2)
xielv = (y2 - y1)/(x2 - x1 + 0.001)
theta = math.atan(float(y2 - y1)/float(x2 - x1 + 0.001))
print(rho, theta, x1, y1, x2, y2, xielv)
lines_message = (rho, theta, x1, y1, x2, y2, xielv)
#cv.line(image, (x1, y1), (x2, y2), (0, 0, 255), 2)
lines_message_set.append(lines_message)
#print len(lines_message_set)
#求点到直线的距离
def point2line_distance(x1,y1,x2,y2,pointPx,pointPy):
A = y1 - y2
B = x2 - x1
C = x1*y2 - y1*x2
distance = abs(A*pointPx + B*pointPy + C)/((A*A + B*B)**0.5)
return distance
lines_cluster_set = []
repeat_num_set = []
for j in range(0,len(lines_message_set)):
for i in range(0,len(lines_message_set)):
if not(j in repeat_num_set):
lines_cluster_set.append(lines_message_set[j])
repeat_num_set.append(j)
print point2line_distance(lines_message_set[i][2], lines_message_set[i][3], lines_message_set[i][4], lines_message_set[i][5], (lines_message_set[j][2]+lines_message_set[j][4])/2, (lines_message_set[j][3]+lines_message_set[j][5])/2)
if i!=j and abs(lines_message_set[j][6] - lines_message_set[i][6]) < 0.1 and point2line_distance(lines_message_set[i][2], lines_message_set[i][3], lines_message_set[i][4], lines_message_set[i][5], (lines_message_set[j][2]+lines_message_set[j][4])/2, (lines_message_set[j][3]+lines_message_set[j][5])/2) <= 10:
repeat_num_set.append(i)
print lines_cluster_set
#对直角的横线、竖线进行分析,缺省时根据表格类型进行矫正
Point_heng = []
Point_shu = []
MiddlePoint_heng = (112,1450+(rows-1450)/2)
MiddlePoint_shu = (75,1450+(rows-1450)/4)
distance2point = rows-1450
distance2point2 = rows-1450
for j in range(0,len(lines_cluster_set)):
if abs(lines_cluster_set[j][6]) < 1:
if ((MiddlePoint_heng[0]-(lines_cluster_set[j][2]+lines_cluster_set[j][4])/2)**2 + (MiddlePoint_heng[1]-(lines_cluster_set[j][3]+lines_cluster_set[j][5])/2)**2)**0.5 < distance2point:
distance2point = ((MiddlePoint_heng[0]-(lines_cluster_set[j][2]+lines_cluster_set[j][4])/2)**2 + (MiddlePoint_heng[1]-(lines_cluster_set[j][3]+lines_cluster_set[j][5])/2)**2)**0.5
Point_heng = lines_cluster_set[j]
else:
if ((MiddlePoint_shu[0]-(lines_cluster_set[j][2]+lines_cluster_set[j][4])/2)**2 + (MiddlePoint_shu[1]-(lines_cluster_set[j][3]+lines_cluster_set[j][5])/2)**2)**0.5 < distance2point2:
distance2point2 = ((MiddlePoint_shu[0]-(lines_cluster_set[j][2]+lines_cluster_set[j][4])/2)**2 + (MiddlePoint_shu[1]-(lines_cluster_set[j][3]+lines_cluster_set[j][5])/2)**2)**0.5
Point_shu = lines_cluster_set[j]
need_stronger = 0
something_missing = 0
#缺省矫正
if Point_shu != []:
if Point_heng == []:
cross_x = 78
cross_y = 1616
something_missing = 1
if len(docu_num) == 9:
something_missing = 0
cross_x = 93
cross_y = 1666
if docu_num[3] == '4':
something_missing = 0
cross_x = 78
cross_y = 1655
if docu_num[3] == '4' and docu_num[5] == '6':
cross_x = 78
cross_y = 1665
else:
cross_x = (Point_shu[3]-Point_shu[6]*Point_shu[2]-Point_heng[3]+Point_heng[6]*Point_heng[2])/(Point_heng[6]-Point_shu[6])
cross_y = Point_heng[6]*cross_x + Point_heng[3] - Point_heng[6]*Point_heng[2]
cv.line(image_copy, (Point_heng[2], Point_heng[3]), (Point_heng[4], Point_heng[5]), (0, 0, 255), 2)
cv.line(image_copy, (Point_shu[2], Point_shu[3]), (Point_shu[4], Point_shu[5]), (0, 0, 255), 2)
else:
cross_x = Point_heng[2]
cross_y = Point_heng[3]
need_stronger = 1
if Point_heng != [] and cross_x > Point_heng[2] and len(docu_num) == 9 and docu_num[6] == '0' and docu_num[7] == '9':
cross_x = 50
cross_y = 1586
if Point_heng != [] and cross_x > Point_heng[2] and len(docu_num) == 9 and docu_num[6] == '1' and docu_num[7] == '8':
cross_x = 50
cross_y = 1616
print 'roi_mean:',roi_mean
if len(docu_num) == 9 and docu_num[7] == '8' and roi_mean < 230:
cross_x = 78
cross_y = 1631
if cross_y - 1648 < 3:
if len(docu_num) == 8 and docu_num[5] == '2' and docu_num[6] == '4':
cross_x = 78
cross_y = 1601
if len(docu_num) == 9 and docu_num[6] == '1' and docu_num[7] == '4':
cross_x = 78
cross_y = 1621
if table_style == 3 and cross_y < 1485:
cross_x = 78
cross_y = 1641
print cross_x,cross_y#当下直角顶点位置,标准位置为78,1581
cv.circle(image_copy, (int(cross_x), int(cross_y)), 3,(255,0,0),3)
cv.rectangle(image_copy,(0,1450),(180,rows),(255,0,0),3)
cv.imwrite('line_detect_possible_demo.jpg', image_copy)
rows, cols, channels = ShrinkTranslationRotation.shape
print rows, cols
affineShrinkTranslation = np.array([[1, 0, int(78 - cross_x)], [0, 1, int(1581 - cross_y)]], np.float32)
#affineShrinkTranslation = np.array([[1, 0, int(78 - 78)], [0, 1, int(1581 - 1581)]], np.float32)
shrinkTwoTimesTranslation = cv.warpAffine(ShrinkTranslationRotation, affineShrinkTranslation, (cols, rows))
image_copy = cv.warpAffine(image_copy, affineShrinkTranslation, (cols, rows))
##### 对201100XXX中左下角表格内有额外竖线的表格进行检测Detect_not_shu_line_in_201100XXX #####
if table_style == 2:
shrinkTwoTimesTranslation_copy_copy = shrinkTwoTimesTranslation.copy()
roi = shrinkTwoTimesTranslation[1350:1548, 125:300]#180
cv.rectangle(image_copy,(125,1350),(300,1548),(255,0,0),3)
gray = cv.cvtColor(roi, cv.COLOR_RGB2GRAY)
edges = cv.Canny(gray, 50, 150, apertureSize=3) # 50,150,3
lines = []
lines = cv.HoughLinesP(edges, 1.0, np.pi / 180, 100, 0, minLineLength=60,maxLineGap=20)#50,10,20
print lines
go_through = 0
try:
if lines == None:
go_through = 0
except:
go_through = 1
if go_through == 1:
pi = 3.1415
theta_total = 0
theta_count = 0
for line in lines:
x1, y1, x2, y2 = line[0]
x1 = x1 + 125
x2 = x2 + 125
y1 = y1 + 1350
y2 = y2 + 1350
rho = np.sqrt((x1 - x2)**2 + (y1 - y2)**2)
theta = math.atan(float(y2 - y1)/float(x2 - x1 + 0.001))
print(rho, theta, x1, y1, x2, y2)
if theta > pi/3 or theta < -pi/3:
table_style = 1
if len(docu_num) == 9 and docu_num[6] == '1' and docu_num[7] == '1':
jiaozheng = 1
cv.line(shrinkTwoTimesTranslation_copy_copy, (x1, y1), (x2, y2), (255, 0, 0), 2)
cv.imwrite('shrinkTwoTimesTranslation_copy_copy.jpg', shrinkTwoTimesTranslation_copy_copy)
##### 提取表格Table_Out #####
#分别通过对二值化后的表格用长横条、长竖条内核进行开操作,将表格分别化为全横线与全竖线,叠加后提取交点,即可得到表格中每个矩形的四个顶点
shrinkTwoTimesTranslation_gray = cv.cvtColor(shrinkTwoTimesTranslation, cv.COLOR_RGB2GRAY)
th2 = cv.adaptiveThreshold(~shrinkTwoTimesTranslation_gray,255,cv.ADAPTIVE_THRESH_MEAN_C,cv.THRESH_BINARY,15,-2)
cv.imwrite('th2.jpg', th2)
#长横条内核处理
shrinkTwoTimesTranslation_copy = shrinkTwoTimesTranslation.copy()
th2_copy = th2.copy()
scale = 44;#20,50,45,40,44
rows,cols = shrinkTwoTimesTranslation_gray.shape
horizontalsize = cols / scale
horizontalStructure = cv.getStructuringElement(cv.MORPH_RECT, (horizontalsize, 1))
erosion = cv.erode(th2,horizontalStructure,iterations = 1)
dilation = cv.dilate(erosion,horizontalStructure,iterations = 1)
#长竖条内核处理
scale = 39;#20,50,45,40,39
horizontalsize2 = rows / scale
horizontalStructure2 = cv.getStructuringElement(cv.MORPH_RECT, (1,horizontalsize2))
erosion2 = cv.erode(th2_copy,horizontalStructure2,iterations = 1)
dilation2 = cv.dilate(erosion2,horizontalStructure2,iterations = 1)
#全横线图与全竖线图叠加,并提取交点
mask = dilation + dilation2
cv.imwrite('mask.jpg', mask)
joints = cv.bitwise_and(dilation, dilation2)
cv.imwrite('joints.jpg', joints)
#根据矩形大小筛选矩形框,并画在矫正后的表格上
#cv.RETR_LIST,cv.CHAIN_APPROX_SIMPLE
mask, contours, hierarchy = cv.findContours(mask,cv.RETR_LIST,cv.CHAIN_APPROX_SIMPLE)
length = len(contours)
print length
small_rects = []
big_rects = []
for i in range(length):
cnt = contours[i]
area = cv.contourArea(cnt)
if area < 10:
continue
approx = cv.approxPolyDP(cnt, 3, True)#3
x, y, w, h = cv.boundingRect(approx)
rect = (x, y, w, h)
#cv.rectangle(img, (x, y), (x+w, y+h), (0, 0, 255), 3)
roi = joints[y:y+h, x:x+w]
roi, joints_contours, joints_hierarchy = cv.findContours(roi,cv.RETR_LIST,cv.CHAIN_APPROX_SIMPLE)
#print len(joints_contours)
#if h < 80 and h > 20 and w > 10 and len(joints_contours)<=4:
if h < 80 and h > 20 and w > 10 and len(joints_contours)<=6:#important
cv.rectangle(image_copy, (x, y), (x+w, y+h), (255-h*3, h*3, 0), 3)
small_rects.append(rect)
cv.imwrite('table_out.jpg', image_copy)
##### 在不同类型的表格中根据信息所在的大致位置获取相应矩形框的坐标 #####
#矫正后的表格中信息的大致位置各在一定范围内,根据大致位置的坐标点筛选出该表中该信息对应的矩形框具体坐标
request_info_set = []#存储筛选出的所需矩形框坐标
#pure_for_message = shrinkTwoTimesTranslation.copy()
print "table_style:", table_style
if table_style == 1:
request_info = (770, 150, 1150-770, 300-150)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(770,150),(1150,300),(255,0,0),1)#登记表编号0
for j in range(0,len(small_rects)):
(x, y, w, h) = small_rects[j]
if x < 1060 and y < 1130 and x+w > 1060 and y+h > 1130 and something_missing == 1:#特殊情况下表格矩形的提取
x_rem = x
y_rem = y
w_rem = w
h_rem = h
for j in range(0,len(small_rects)):
(x, y, w, h) = small_rects[j]
if x < 700 and y < 370 and x+w > 700 and y+h > 370 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#性别1
if x < 880 and y < 370 and x+w > 880 and y+h > 370 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#民族2
if x < 685 and y < 412 and x+w > 685 and y+h > 412 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#体重3
if x < 880 and y < 412 and x+w > 880 and y+h > 412 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(0,0,255),1)#血型4
if x < 890 and y < 452 and x+w > 890 and y+h > 452 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#籍贯5
if x < 486 and y < 1090 and x+w > 486 and y+h > 1090 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中学校名称6
if x < 696 and y < 1090 and x+w > 696 and y+h > 1090 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中专业7
if x < 808 and y < 1090 and x+w > 808 and y+h > 1090 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中学位8
if x < 931 and y < 1090 and x+w > 931 and y+h > 1090 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中起止时间9
if x < 1060 and y < 1087 and x+w > 1060 and y+h > 1087 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中是否毕业10
#提取是、否选项旁的正方形框
if jiaozheng == 1 or (len(docu_num) == 9 and (docu_num[6] == '2' or docu_num[6] == '3')) or (len(docu_num) == 8 and ((docu_num[5] == '3' and (docu_num[6] == '3' or (docu_num[6] == '3' and (docu_num[7] == '5' or docu_num[7] == '6' or docu_num[7] == '7' or docu_num[7] == '8' or docu_num[7] == '9')) or docu_num[6] == '4' or docu_num[6] == '5' or docu_num[6] == '7' or docu_num[6] == '8' or docu_num[6] == '9')) or docu_num[5] == '4')):
gaozhong_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.18*w+x):int(0.28*w+x)]
gaozhong_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.59*w+x):int(0.69*w+x)]
cv.imwrite('gaozhong_roi_left.jpg', gaozhong_roi_left)
cv.imwrite('gaozhong_roi_right.jpg', gaozhong_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.18*w+x),int(y+h/3.5)),(int(0.28*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.59*w+x),int(y+h/3.5)),(int(0.69*w+x),int(y+2.2*h/3)),(255,0,0),1)
else:
gaozhong_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
gaozhong_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('gaozhong_roi_left.jpg', gaozhong_roi_left)
cv.imwrite('gaozhong_roi_right.jpg', gaozhong_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
if x < 486 and y < 1130 and x+w > 486 and y+h > 1130 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专学校名称11
if x < 696 and y < 1130 and x+w > 696 and y+h > 1130 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专专业12
if x < 808 and y < 1130 and x+w > 808 and y+h > 1130 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专学位13
if x < 931 and y < 1130 and x+w > 931 and y+h > 1130 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专起止时间14
if x < 1060 and y < 1127 and x+w > 1060 and y+h > 1127 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专是否毕业15
#提取是、否选项旁的正方形框
if jiaozheng == 1 or (len(docu_num) == 9 and (docu_num[6] == '2' or docu_num[6] == '3')) or (len(docu_num) == 8 and ((docu_num[5] == '3' and (docu_num[6] == '3' or (docu_num[6] == '3' and (docu_num[7] == '5' or docu_num[7] == '6' or docu_num[7] == '7' or docu_num[7] == '8' or docu_num[7] == '9')) or docu_num[6] == '4' or docu_num[6] == '5' or docu_num[6] == '7' or docu_num[6] == '8' or docu_num[6] == '9')) or docu_num[5] == '4')):
dazhuan_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.18*w+x):int(0.28*w+x)]
dazhuan_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.59*w+x):int(0.69*w+x)]
cv.imwrite('dazhuan_roi_left.jpg', dazhuan_roi_left)
cv.imwrite('dazhuan_roi_right.jpg', dazhuan_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.18*w+x),int(y+h/3.5)),(int(0.28*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.59*w+x),int(y+h/3.5)),(int(0.69*w+x),int(y+2.2*h/3)),(255,0,0),1)
else:
dazhuan_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
dazhuan_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('dazhuan_roi_left.jpg', dazhuan_roi_left)
cv.imwrite('dazhuan_roi_right.jpg', dazhuan_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
if x < 486 and y < 1170 and x+w > 486 and y+h > 1170 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科学校名称16
if x < 696 and y < 1170 and x+w > 696 and y+h > 1170 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科专业17
if x < 808 and y < 1170 and x+w > 808 and y+h > 1170 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科学位18
if x < 931 and y < 1170 and x+w > 931 and y+h > 1170 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科起止时间19
if x < 1060 and y < 1167 and x+w > 1060 and y+h > 1167 or something_missing == 1:
if something_missing == 1:#特殊情况下表格矩形的提取
x = x_rem
y = y_rem + 40
w = w_rem
h = h_rem
else:
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科是否毕业20
#提取是、否选项旁的正方形框
if jiaozheng == 1 or (len(docu_num) == 9 and (docu_num[6] == '2' or docu_num[6] == '3')) or (len(docu_num) == 8 and ((docu_num[5] == '3' and (docu_num[6] == '3' or (docu_num[6] == '3' and (docu_num[7] == '5' or docu_num[7] == '6' or docu_num[7] == '7' or docu_num[7] == '8' or docu_num[7] == '9')) or docu_num[6] == '4' or docu_num[6] == '5' or docu_num[6] == '7' or docu_num[6] == '8' or docu_num[6] == '9')) or docu_num[5] == '4')):
benke_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.18*w+x):int(0.28*w+x)]
benke_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.59*w+x):int(0.69*w+x)]
cv.imwrite('benke_roi_left.jpg', benke_roi_left)
cv.imwrite('benke_roi_right.jpg', benke_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.18*w+x),int(y+h/3.5)),(int(0.28*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.59*w+x),int(y+h/3.5)),(int(0.69*w+x),int(y+2.2*h/3)),(255,0,0),1)
else:
benke_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
benke_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('benke_roi_left.jpg', benke_roi_left)
cv.imwrite('benke_roi_right.jpg', benke_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
if x < 486 and y < 1210 and x+w > 486 and y+h > 1210 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生学校名称21
if x < 696 and y < 1210 and x+w > 696 and y+h > 1210 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生专业22
if x < 808 and y < 1210 and x+w > 808 and y+h > 1210 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生学位23
if x < 931 and y < 1210 and x+w > 931 and y+h > 1210 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生起止时间24
if x < 1060 and y < 1207 and x+w > 1060 and y+h > 1207 or something_missing == 1:
if something_missing == 1:#特殊情况下表格矩形的提取
x = x_rem
y = y_rem + 80
w = w_rem
h = h_rem
else:
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生是否毕业25
#提取是、否选项旁的正方形框
if jiaozheng == 1 or (len(docu_num) == 9 and (docu_num[6] == '2' or docu_num[6] == '3')) or (len(docu_num) == 8 and ((docu_num[5] == '3' and (docu_num[6] == '3' or (docu_num[6] == '3' and (docu_num[7] == '5' or docu_num[7] == '6' or docu_num[7] == '7' or docu_num[7] == '8' or docu_num[7] == '9')) or docu_num[6] == '4' or docu_num[6] == '5' or docu_num[6] == '7' or docu_num[6] == '8' or docu_num[6] == '9')) or docu_num[5] == '4')):
yanjiu_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.18*w+x):int(0.28*w+x)]
yanjiu_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.59*w+x):int(0.69*w+x)]
cv.imwrite('yanjiu_roi_left.jpg', yanjiu_roi_left)
cv.imwrite('yanjiu_roi_right.jpg', yanjiu_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.18*w+x),int(y+h/3.5)),(int(0.28*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.59*w+x),int(y+h/3.5)),(int(0.69*w+x),int(y+2.2*h/3)),(255,0,0),1)
else:
yanjiu_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
yanjiu_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('yanjiu_roi_left.jpg', yanjiu_roi_left)
cv.imwrite('yanjiu_roi_right.jpg', yanjiu_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
#特殊情况下表格矩形的提取
if need_stronger == 1:
cv.rectangle(shrinkTwoTimesTranslation,(673,385),(740,420),(0,0,255),1)#性别
cv.rectangle(shrinkTwoTimesTranslation,(845,385),(938,420),(0,0,255),1)#民族
cv.rectangle(shrinkTwoTimesTranslation,(673,425),(720,460),(0,0,255),1)#体重
cv.rectangle(shrinkTwoTimesTranslation,(845,425),(938,465),(0,0,255),1)#血型
cv.rectangle(shrinkTwoTimesTranslation,(845,470),(938,510),(0,0,255),1)#籍贯
cv.rectangle(shrinkTwoTimesTranslation,(973,1095),(1153,1135),(0,0,255),1)#高中是否毕业
x = 973
y = 1095
w = 1153 - 973
h = 1135 - 1095
gaozhong_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
gaozhong_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('gaozhong_roi_left.jpg', gaozhong_roi_left)
cv.imwrite('gaozhong_roi_right.jpg', gaozhong_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(973,1135),(1153,1175),(0,0,255),1)
x = 973
y = 1135
w = 1153 - 973
h = 1175 - 1135
dazhuan_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
dazhuan_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('dazhuan_roi_left.jpg', dazhuan_roi_left)
cv.imwrite('dazhuan_roi_right.jpg', dazhuan_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(973,1175),(1153,1215),(0,0,255),1)
x = 973
y = 1175
w = 1153 - 973
h = 1215 - 1175
benke_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
benke_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('benke_roi_left.jpg', benke_roi_left)
cv.imwrite('benke_roi_right.jpg', benke_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(973,1220),(1153,1260),(0,0,255),1)
x = 973
y = 1220
w = 1153 - 973
h = 1260 - 1220
yanjiu_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
yanjiu_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('yanjiu_roi_left.jpg', yanjiu_roi_left)
cv.imwrite('yanjiu_roi_right.jpg', yanjiu_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
#测试各信息的大致位置
#cv.circle(shrinkTwoTimesTranslation, (700, 335), 3,(255,0,0),3)
#cv.circle(shrinkTwoTimesTranslation, (75, 1581), 3,(255,0,0),3)
#cv.rectangle(shrinkTwoTimesTranslation,(663,360),(740,400),(255,0,0),1)#性别
#cv.rectangle(shrinkTwoTimesTranslation,(835,360),(928,400),(255,0,0),1)#民族
#cv.rectangle(shrinkTwoTimesTranslation,(663,402),(710,442),(255,0,0),1)#体重
#cv.rectangle(shrinkTwoTimesTranslation,(835,402),(928,442),(255,0,0),1)#血型
#cv.rectangle(shrinkTwoTimesTranslation,(835,443),(948,482),(255,0,0),1)#籍贯
#cv.rectangle(shrinkTwoTimesTranslation,(345,1075),(627,1115),(255,0,0),1)#高中学校名称
#cv.rectangle(shrinkTwoTimesTranslation,(628,1075),(765,1115),(255,0,0),1)#高中专业
#cv.rectangle(shrinkTwoTimesTranslation,(766,1075),(850,1115),(255,0,0),1)#高中学位
#cv.rectangle(shrinkTwoTimesTranslation,(851,1075),(1011,1115),(255,0,0),1)#高中起止时间
#cv.rectangle(shrinkTwoTimesTranslation,(971,1070),(1150,1110),(255,0,0),1)#高中是否毕业
if table_style == 2:
request_info = (770, 150, 1150-770, 300-150)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(770,150),(1150,300),(255,0,0),1)#登记表编号0
for j in range(0,len(small_rects)):
(x, y, w, h) = small_rects[j]
if x < 700 and y < 335 and x+w > 700 and y+h > 335 :#350-20
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#性别1
if x < 885 and y < 335 and x+w > 885 and y+h > 335 :#x+5
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#民族2
if x < 685 and y < 377 and x+w > 685 and y+h > 377 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#体重3
if x < 885 and y < 377 and x+w > 885 and y+h > 377 :#x+5
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(0,0,255),1)#血型4
if x < 890 and y < 417 and x+w > 890 and y+h > 417 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#籍贯5
if x < 486 and y < 1045 and x+w > 486 and y+h > 1045 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中学校名称6
if x < 696 and y < 1045 and x+w > 696 and y+h > 1045 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中专业7
if x < 808 and y < 1045 and x+w > 808 and y+h > 1045 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中学位8
if len(docu_num) == 9 and (docu_num[6] == '2' and (docu_num[7] == '6' or docu_num[7] == '8' or docu_num[7] == '9')):
y_xiuzheng = 1090
else:
y_xiuzheng = 1055
if x < 931 and y < y_xiuzheng and x+w > 931 and y+h > y_xiuzheng :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中起止时间9
if x < 1060 and y < y_xiuzheng and x+w > 1060 and y+h > y_xiuzheng :#y+10
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中是否毕业10
if len(docu_num) == 9 and (docu_num[6] == '2' and (docu_num[7] == '6' or docu_num[7] == '8' or docu_num[7] == '9')) or (docu_num[6] == '3' and docu_num[8] == '9'):
gaozhong_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.22*w+x):int(0.32*w+x)]
gaozhong_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.55*w+x):int(0.65*w+x)]
cv.imwrite('gaozhong_roi_left.jpg', gaozhong_roi_left)
cv.imwrite('gaozhong_roi_right.jpg', gaozhong_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.22*w+x),int(y+h/3.5)),(int(0.32*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.55*w+x),int(y+h/3.5)),(int(0.65*w+x),int(y+2.2*h/3)),(255,0,0),1)
else:
gaozhong_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
gaozhong_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('gaozhong_roi_left.jpg', gaozhong_roi_left)
cv.imwrite('gaozhong_roi_right.jpg', gaozhong_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
if x < 486 and y < 1085 and x+w > 486 and y+h > 1085 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专学校名称11
if x < 696 and y < 1085 and x+w > 696 and y+h > 1085 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专专业12
if x < 808 and y < 1085 and x+w > 808 and y+h > 1085 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专学位13
if len(docu_num) == 9 and (docu_num[6] == '2' and (docu_num[7] == '6' or docu_num[7] == '8' or docu_num[7] == '9')):
y_xiuzheng = 1140
else:
y_xiuzheng = 1095
if x < 931 and y < y_xiuzheng and x+w > 931 and y+h > y_xiuzheng :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专起止时间14
if x < 1060 and y < y_xiuzheng and x+w > 1060 and y+h > y_xiuzheng :#y+10
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专是否毕业15
if len(docu_num) == 9 and (docu_num[6] == '2' and (docu_num[7] == '6' or docu_num[7] == '8' or docu_num[7] == '9')) or (docu_num[6] == '3' and docu_num[8] == '9'):
dazhuan_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.22*w+x):int(0.32*w+x)]
dazhuan_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.55*w+x):int(0.65*w+x)]
cv.imwrite('dazhuan_roi_left.jpg', dazhuan_roi_left)
cv.imwrite('dazhuan_roi_right.jpg', dazhuan_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.22*w+x),int(y+h/3.5)),(int(0.32*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.55*w+x),int(y+h/3.5)),(int(0.65*w+x),int(y+2.2*h/3)),(255,0,0),1)
else:
dazhuan_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
dazhuan_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('dazhuan_roi_left.jpg', dazhuan_roi_left)
cv.imwrite('dazhuan_roi_right.jpg', dazhuan_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
if x < 486 and y < 1125 and x+w > 486 and y+h > 1125 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科学校名称16
if x < 696 and y < 1125 and x+w > 696 and y+h > 1125 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科专业17
if x < 808 and y < 1125 and x+w > 808 and y+h > 1125 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科学位18
if len(docu_num) == 9 and (docu_num[6] == '2' and (docu_num[7] == '6' or docu_num[7] == '8' or docu_num[7] == '9')):
y_xiuzheng = 1190
else:
y_xiuzheng = 1135
if x < 931 and y < y_xiuzheng and x+w > 931 and y+h > y_xiuzheng :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科起止时间19
if x < 1060 and y < y_xiuzheng and x+w > 1060 and y+h > y_xiuzheng :#y+10
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科是否毕业20
if len(docu_num) == 9 and (docu_num[6] == '2' and (docu_num[7] == '6' or docu_num[7] == '8' or docu_num[7] == '9')) or (docu_num[6] == '3' and docu_num[8] == '9'):
benke_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.22*w+x):int(0.32*w+x)]
benke_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.55*w+x):int(0.65*w+x)]
cv.imwrite('benke_roi_left.jpg', benke_roi_left)
cv.imwrite('benke_roi_right.jpg', benke_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.22*w+x),int(y+h/3.5)),(int(0.32*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.55*w+x),int(y+h/3.5)),(int(0.65*w+x),int(y+2.2*h/3)),(255,0,0),1)
else:
benke_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
benke_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('benke_roi_left.jpg', benke_roi_left)
cv.imwrite('benke_roi_right.jpg', benke_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
if x < 486 and y < 1165 and x+w > 486 and y+h > 1165 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生学校名称21
if x < 696 and y < 1165 and x+w > 696 and y+h > 1165 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生专业22
if x < 808 and y < 1165 and x+w > 808 and y+h > 1165 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生学位23
if len(docu_num) == 9 and (docu_num[6] == '2' and (docu_num[7] == '6' or docu_num[7] == '8' or docu_num[7] == '9')):
y_xiuzheng = 1230
else:
y_xiuzheng = 1175
if x < 931 and y < y_xiuzheng and x+w > 931 and y+h > y_xiuzheng :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生起止时间24
if x < 1060 and y < y_xiuzheng and x+w > 1060 and y+h > y_xiuzheng :#y+10
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生是否毕业25
if len(docu_num) == 9 and (docu_num[6] == '2' and (docu_num[7] == '6' or docu_num[7] == '8' or docu_num[7] == '9')) or (docu_num[6] == '3' and docu_num[8] == '9'):
yanjiu_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.22*w+x):int(0.32*w+x)]
yanjiu_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.55*w+x):int(0.65*w+x)]
cv.imwrite('yanjiu_roi_left.jpg', yanjiu_roi_left)
cv.imwrite('yanjiu_roi_right.jpg', yanjiu_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.22*w+x),int(y+h/3.5)),(int(0.32*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.55*w+x),int(y+h/3.5)),(int(0.65*w+x),int(y+2.2*h/3)),(255,0,0),1)
else:
yanjiu_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.28*w+x):int(0.38*w+x)]
yanjiu_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.2*h/3), int(0.51*w+x):int(0.61*w+x)]
cv.imwrite('yanjiu_roi_left.jpg', yanjiu_roi_left)
cv.imwrite('yanjiu_roi_right.jpg', yanjiu_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.28*w+x),int(y+h/3.5)),(int(0.38*w+x),int(y+2.2*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.51*w+x),int(y+h/3.5)),(int(0.61*w+x),int(y+2.2*h/3)),(255,0,0),1)
if table_style == 3:
request_info = (970, 50, 1200-970, 200-50)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(970,50),(1200,200),(255,0,0),1)#登记表编号0
for j in range(0,len(small_rects)):
(x, y, w, h) = small_rects[j]
if x < 724 and y < 316 and x+w > 724 and y+h > 316 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#性别1
if x < 960 and y < 316 and x+w > 960 and y+h > 316 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#民族2
if x < 724 and y < 363 and x+w > 724 and y+h > 363 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#体重3
if x < 960 and y < 363 and x+w > 960 and y+h > 363 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#血型4
if x < 960 and y < 410 and x+w > 960 and y+h > 410 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#籍贯5
if x < 981 and y < 1089 and x+w > 981 and y+h > 1089 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中起止时间9
if x < 1105 and y < 1089 and x+w > 1105 and y+h > 1089 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中是否毕业10
if docu_num[5] == '3' and docu_num[6] == '8':
gaozhong_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.19*w+x):int(0.29*w+x)]
gaozhong_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.59*w+x):int(0.69*w+x)]
cv.imwrite('gaozhong_roi_left.jpg', gaozhong_roi_left)
cv.imwrite('gaozhong_roi_right.jpg', gaozhong_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.19*w+x),int(y+h/3.5)),(int(0.29*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.59*w+x),int(y+h/3.5)),(int(0.69*w+x),int(y+2.1*h/3)),(255,0,0),1)
else:
gaozhong_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.23*w+x):int(0.33*w+x)]
gaozhong_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.56*w+x):int(0.66*w+x)]
cv.imwrite('gaozhong_roi_left.jpg', gaozhong_roi_left)
cv.imwrite('gaozhong_roi_right.jpg', gaozhong_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.23*w+x),int(y+h/3.5)),(int(0.33*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.56*w+x),int(y+h/3.5)),(int(0.66*w+x),int(y+2.1*h/3)),(255,0,0),1)
if x < 981 and y < 1137 and x+w > 981 and y+h > 1137 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专起止时间14
if x < 1105 and y < 1137 and x+w > 1105 and y+h > 1137 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专是否毕业15
if docu_num[5] == '3' and docu_num[6] == '8':
dazhuan_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.19*w+x):int(0.29*w+x)]
dazhuan_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.59*w+x):int(0.69*w+x)]
cv.imwrite('dazhuan_roi_left.jpg', dazhuan_roi_left)
cv.imwrite('dazhuan_roi_right.jpg', dazhuan_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.19*w+x),int(y+h/3.5)),(int(0.29*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.59*w+x),int(y+h/3.5)),(int(0.69*w+x),int(y+2.1*h/3)),(255,0,0),1)
else:
dazhuan_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.23*w+x):int(0.33*w+x)]
dazhuan_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.56*w+x):int(0.66*w+x)]
cv.imwrite('dazhuan_roi_left.jpg', dazhuan_roi_left)
cv.imwrite('dazhuan_roi_right.jpg', dazhuan_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.23*w+x),int(y+h/3.5)),(int(0.33*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.56*w+x),int(y+h/3.5)),(int(0.66*w+x),int(y+2.1*h/3)),(255,0,0),1)
if x < 981 and y < 1185 and x+w > 981 and y+h > 1185 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科起止时间19
if x < 1105 and y < 1185 and x+w > 1105 and y+h > 1185 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科是否毕业20
if docu_num[5] == '3' and docu_num[6] == '8':
benke_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.19*w+x):int(0.29*w+x)]
benke_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.59*w+x):int(0.69*w+x)]
cv.imwrite('benke_roi_left.jpg', benke_roi_left)
cv.imwrite('benke_roi_right.jpg', benke_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.19*w+x),int(y+h/3.5)),(int(0.29*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.59*w+x),int(y+h/3.5)),(int(0.69*w+x),int(y+2.1*h/3)),(255,0,0),1)
else:
benke_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.23*w+x):int(0.33*w+x)]
benke_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.56*w+x):int(0.66*w+x)]
cv.imwrite('benke_roi_left.jpg', benke_roi_left)
cv.imwrite('benke_roi_right.jpg', benke_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.23*w+x),int(y+h/3.5)),(int(0.33*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.56*w+x),int(y+h/3.5)),(int(0.66*w+x),int(y+2.1*h/3)),(255,0,0),1)
if x < 981 and y < 1233 and x+w > 981 and y+h > 1233 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生起止时间24
if x < 1105 and y < 1233 and x+w > 1105 and y+h > 1233 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生是否毕业25
if docu_num[5] == '3' and docu_num[6] == '8':
yanjiu_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.19*w+x):int(0.29*w+x)]
yanjiu_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.59*w+x):int(0.69*w+x)]
cv.imwrite('yanjiu_roi_left.jpg', yanjiu_roi_left)
cv.imwrite('yanjiu_roi_right.jpg', yanjiu_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.19*w+x),int(y+h/3.5)),(int(0.29*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.59*w+x),int(y+h/3.5)),(int(0.69*w+x),int(y+2.1*h/3)),(255,0,0),1)
else:
yanjiu_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.23*w+x):int(0.33*w+x)]
yanjiu_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.56*w+x):int(0.66*w+x)]
cv.imwrite('yanjiu_roi_left.jpg', yanjiu_roi_left)
cv.imwrite('yanjiu_roi_right.jpg', yanjiu_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.23*w+x),int(y+h/3.5)),(int(0.33*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.56*w+x),int(y+h/3.5)),(int(0.66*w+x),int(y+2.1*h/3)),(255,0,0),1)
if table_style == 4:
request_info = (970, 50, 1200-970, 200-50)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(970,50),(1200,200),(255,0,0),1)#登记表编号0
for j in range(0,len(small_rects)):
(x, y, w, h) = small_rects[j]
if x < 724 and y < 292 and x+w > 724 and y+h > 292 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#性别1
if x < 960 and y < 292 and x+w > 960 and y+h > 292 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#民族2
if x < 724 and y < 339 and x+w > 724 and y+h > 339 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#体重3
if x < 960 and y < 339 and x+w > 960 and y+h > 339 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#血型4
if x < 960 and y < 386 and x+w > 960 and y+h > 386 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#籍贯5
if x < 981 and y < 1094 and x+w > 981 and y+h > 1094 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中起止时间9
if x < 1105 and y < 1094 and x+w > 1105 and y+h > 1094 :#y-15
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#高中是否毕业10
gaozhong_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.23*w+x):int(0.33*w+x)]
gaozhong_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.56*w+x):int(0.66*w+x)]
cv.imwrite('gaozhong_roi_left.jpg', gaozhong_roi_left)
cv.imwrite('gaozhong_roi_right.jpg', gaozhong_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.23*w+x),int(y+h/3.5)),(int(0.33*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.56*w+x),int(y+h/3.5)),(int(0.66*w+x),int(y+2.1*h/3)),(255,0,0),1)
if x < 981 and y < 1142 and x+w > 981 and y+h > 1142 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专起止时间14
if x < 1105 and y < 1142 and x+w > 1105 and y+h > 1142 :#y-15
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#大专是否毕业15
dazhuan_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.23*w+x):int(0.33*w+x)]
dazhuan_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.56*w+x):int(0.66*w+x)]
cv.imwrite('dazhuan_roi_left.jpg', dazhuan_roi_left)
cv.imwrite('dazhuan_roi_right.jpg', dazhuan_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.23*w+x),int(y+h/3.5)),(int(0.33*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.56*w+x),int(y+h/3.5)),(int(0.66*w+x),int(y+2.1*h/3)),(255,0,0),1)
if x < 981 and y < 1190 and x+w > 981 and y+h > 1190 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科起止时间19
if x < 1105 and y < 1190 and x+w > 1105 and y+h > 1190 :#y-15
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#本科是否毕业20
benke_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.23*w+x):int(0.33*w+x)]
benke_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.56*w+x):int(0.66*w+x)]
cv.imwrite('benke_roi_left.jpg', benke_roi_left)
cv.imwrite('benke_roi_right.jpg', benke_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.23*w+x),int(y+h/3.5)),(int(0.33*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.56*w+x),int(y+h/3.5)),(int(0.66*w+x),int(y+2.1*h/3)),(255,0,0),1)
if x < 981 and y < 1238 and x+w > 981 and y+h > 1238 :
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生起止时间24
if x < 1105 and y < 1238 and x+w > 1105 and y+h > 1238 :#y-15
request_info = (x, y, w, h)
request_info_set.append(request_info)
cv.rectangle(shrinkTwoTimesTranslation,(x,y),(x+w,y+h),(255,0,0),1)#研究生是否毕业25
yanjiu_roi_left = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.23*w+x):int(0.33*w+x)]
yanjiu_roi_right = shrinkTwoTimesTranslation[int(y+h/3.5):int(y+2.1*h/3), int(0.56*w+x):int(0.66*w+x)]
cv.imwrite('yanjiu_roi_left.jpg', yanjiu_roi_left)
cv.imwrite('yanjiu_roi_right.jpg', yanjiu_roi_right)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.23*w+x),int(y+h/3.5)),(int(0.33*w+x),int(y+2.1*h/3)),(255,0,0),1)
cv.rectangle(shrinkTwoTimesTranslation,(int(0.56*w+x),int(y+h/3.5)),(int(0.66*w+x),int(y+2.1*h/3)),(255,0,0),1)
#cv.rectangle(shrinkTwoTimesTranslation,(663,269),(786,315),(255,0,0),1)#性别
#cv.rectangle(shrinkTwoTimesTranslation,(900,269),(1020,315),(255,0,0),1)#民族
#cv.rectangle(shrinkTwoTimesTranslation,(663,316),(786,362),(255,0,0),1)#体重
#cv.rectangle(shrinkTwoTimesTranslation,(900,316),(1020,362),(255,0,0),1)#血型
#cv.rectangle(shrinkTwoTimesTranslation,(900,363),(1020,409),(255,0,0),1)#籍贯
#cv.rectangle(shrinkTwoTimesTranslation,(1016,1065),(1195,1113),(255,0,0),1)#高中是否毕业
#登记表编号,性别,民族,体重,血型,籍贯,高中学校名称,高中专业,高中学位,高中起止时间,高中是否毕业,大专学校名称,大专专业,大专学位,大专起止时间,大专是否毕业,本科学校名称,本科专业,本科学位,本科起止时间,本科是否毕业,研究生学校名称,研究生专业,研究生学位,研究生起止时间,研究生是否毕业,学校名称(其它),专业(其它),学位(其它),起止时间(其它),是否毕业(其它)
cv.imwrite('image_correct.jpg', shrinkTwoTimesTranslation)#关键信息框重点标注的矫正图像
########### 去除噪点Filter ###########
th2 = cv.medianBlur(th2,5)#5
horizontalStructure = cv.getStructuringElement(cv.MORPH_RECT, (2, 2))#2,2
th2 = cv.erode(th2,horizontalStructure,iterations = 1)
#horizontalStructure = cv.getStructuringElement(cv.MORPH_RECT, (1, 3))#2,2
#th2 = cv.dilate(th2,horizontalStructure,iterations = 1)