-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.py
More file actions
88 lines (65 loc) · 2.36 KB
/
Copy pathreader.py
File metadata and controls
88 lines (65 loc) · 2.36 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
88
print('Gathering corners of template ballots...')
from funs import *
import pandas as pd
from multiprocessing.pool import ThreadPool as Pool
import subprocess
import os
import numpy as np
import time
#Commented sections are configuration for continual downloading from shared drive,
#this script has been altered to instead pull from the optical drive
start = time.time()
pool_size = 16
image_folder = './templates/' #PATH TO FOLDER CONTAINING BALLOT SCANS GOES HERE. Make sure it ends in a slash ('/') !
template_folder = './templates/'
#shared_drive_path = 'EVIC_Data2\\MultCo_Drive_Feb2021\\writein_images\\election20201103\\'
df = pd.read_csv('writeins.csv')
df['teressa'] = 'NA'
df['min_lev'] = 'NA'
df['best_guess'] = 'NA'
chunks = np.array_split(df, 4700)
counter = 0
"""
def download(ids):
for i in ids:
subprocess.call(['rclone', 'copy',
'evic:{0}{1}.jpg'.format(shared_drive_path, i),
'C:\\Users\\Malen\\Downloads\\Ballot CSVs\\scary zone\\'],
shell = True)
"""
def worker(chunk):
#download(chunk.iloc[0:,0])
for i, row in chunk.iterrows():
ballot_path = '{0}{1}.jpg'.format(image_folder, row[0])
try:
best_guess, min_lev = read_ballot(ballot_path, row[1])
if min_lev > 8:
tr_flag = 0
else:
tr_flag = 1
chunk.at[i, 'teressa'] = tr_flag
chunk.at[i, 'min_lev'] = min_lev
chunk.at[i, 'best_guess'] = best_guess
except:
pass
#try:
# os.remove(ballot_path)
#except:
# print(ballot_path + ' failed to delete.')
global counter
counter += 1
if counter % 100 == 0:
print('{0}/4700 chunks processed, {1}% done'.format(counter, int(counter/47)))
print('{0} minutes elapsed...'.format(str((time.time() - start)/60).split('.')[0]))
pool = Pool(pool_size)
#making sure image folder was configured before running
if image_folder != '':
for chunk in chunks:
pool.apply_async(worker, (chunk,))
else:
print('Specify image_folder!')
pool.close()
pool.join()
results = pd.concat(chunks)
results.to_csv('results.csv', index = False)
#Sample of 1000 had 2/660 false positive, 46/331 false negative