-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_access.py
60 lines (49 loc) · 2 KB
/
file_access.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
import cv2
from os import path
import os
def get_base_path():
this_file_path = path.realpath(__file__)
base_path = path.abspath(
path.join(this_file_path, '..')
)
return base_path
class FileAccess:
base_path = get_base_path()
@staticmethod
def get_file(file_name: str):
pic = \
FileAccess.get_genuine_file(file_name) if file_name[4:7] == file_name[-7: -4] \
else FileAccess.get_forged_file(file_name)
return pic
@staticmethod
def get_forged_file(file_name: str):
path_of_forged_signatures = \
os.path.join(FileAccess.base_path, "sample_Signature", "forged")
file_path = os.path.join(path_of_forged_signatures, file_name)
pic = cv2.imread(file_path)
return pic
@staticmethod
def get_genuine_file(file_name: str):
path_of_genuine_signatures = \
os.path.join(FileAccess.base_path, "sample_Signature", "genuine")
file_path = os.path.join(path_of_genuine_signatures, file_name)
pic = cv2.imread(file_path)
return pic
@staticmethod
def get_files_of_person(name: str):
if len(name) != 3:
raise Exception(f"`{str}` is not a valid person ID ")
path_of_original_signatures = os.path.join(FileAccess.base_path, "sample_Signature", "genuine")
os.chdir(path_of_original_signatures)
pic_names = os.listdir()
filtered_pics = [pic for pic in pic_names if pic[-7:-4] == name]
return [cv2.imread(pic_path) for pic_path in filtered_pics]
@staticmethod
def get_forged_of_person(name: str):
if len(name) != 3:
raise Exception(f"`{str}` is not a valid person ID ")
path_of_forged_signatures = os.path.join(FileAccess.base_path, "sample_Signature", "forged")
os.chdir(path_of_forged_signatures)
pic_names = os.listdir()
filtered_pics = [pic for pic in pic_names if pic[-7:-4] == name]
return [cv2.imread(pic_path) for pic_path in filtered_pics]