-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
47 lines (42 loc) · 1.62 KB
/
main.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
# File Import
import cv2
import os
import sys
sys.path.insert(0, './assets')
import CubeOpt as co
import CubeTrac as ct
import argparse
# Setting Up Arg Parser
parser = argparse.ArgumentParser(description="Rubic Cube Color Detection With 2 Different method")
parser.add_argument("-co","--cubeopt",action="store_true", help="Detection using Cube Optimisation method (HSV Detection)")
parser.add_argument("-ct","--cubetrac",action="store_true", help="Detection using CubeTracking method (Cannry Detection)")
args = parser.parse_args()
dict_args = vars(args)
# Get List of file name from specific file
input_list = os.listdir(f"{os.getcwd()}\input\\")
# Main function to get output as per argument
def main(cubeopt=False, cubetrac=False):
if cubeopt:
for i in input_list:
name = i.split(".")[0]
img = cv2.imread(f"./input/{i}")
sample = co.CubeOpt(img)
sample.getFilteredCube()
cv2.imwrite(f"{os.getcwd()}\Output\\output_{name}.jpg", img)
# cv2.imwrite(f"{os.getcwd()}\output_opt\\output_{name}.jpg", img)
if cubetrac:
for i in input_list:
name = i.split(".")[0]
img=cv2.imread(f"./input/{i}")
sample = ct.CubeTrac(img)
text = sample.getTrackedCube()
with open(f"{os.getcwd()}\Output\\output_{name}", "w") as file:
# with open(f"{os.getcwd()}\output_trac\\output_{name}", "w") as file:
file.write(text)
return True
# Main Function Call
main(dict_args["cubeopt"],dict_args["cubetrac"])
cv2.destroyAllWindows()
if __name__ == "__main__":
main(False,True)
# pass