forked from cchighman/PriusWatchML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPriusDetector.py
109 lines (88 loc) · 3.38 KB
/
PriusDetector.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
import argparse
import datetime
import os
import time
import cv2
import numpy as np
from PriusImage import PriusImage
from PriusPalette import PriusPalette
ap = argparse.ArgumentParser()
ap.add_argument("-pp", "--predicted-path", required=False)
ap.add_argument("-sp", "--sample-path", required=False)
args = vars(ap.parse_args())
class PriusDetector:
def __init__(self, src):
self.src = src
self.image = cv2.imread(src)
def compare_images():
predictedPath = args["predicted_path"]
samplePath = args["sample_path"]
predictedImages = os.listdir(predictedPath)
sampleImages = os.listdir(samplePath)
shadePredictedCount = 0
avgPredictedCount = 0
pcaPredictedCount = 0
totalPredictedCount = 0
shadeSampleCount = 0
avgSampleCount = 0
pcaSampleCount = 0
totalSamleCount = 0
print("\nPrius Matches\n")
for img in predictedImages:
start = time.time()
try:
print("\nColor Profile for " + img)
path = args["predicted_path"] + img
priusImage = PriusImage(path)
palette = PriusPalette()
totalPredictedCount = totalPredictedCount + 1
if priusImage.has_required_shades():
shadePredictedCount = shadePredictedCount + 1
avg = priusImage.avg_color()
avgInPalette = palette.has_shade(avg)
print("Average Color: " + str(avg) + " Palette Match? " + str(avgInPalette))
if avgInPalette:
avgPredictedCount = avgPredictedCount + 1
requiredColors = []
for color in priusImage.pca_colors():
requiredColors.append(palette.has_shade(color))
print("PCA Analysis\n")
if any(requiredColors):
pcaPredictedCount = pcaPredictedCount + 1
# print("Successfully validated palette, average, and PCA for " + img)
except Exception as e:
print(e)
end = time.time()
print("\nRequired Palettes: " + str(shadePredictedCount) + " Average Color: " + str(
avgPredictedCount) + " PCA Colors: " + str(pcaPredictedCount) + " Total: " + str(
totalPredictedCount) + " Time: " + str(end - start) + "\n")
if args["sample_path"] is not None:
print("\nPrius Matches\n")
for img in SampleImages:
start = time.time()
try:
print("\nColor Profile for " + img)
path = args["sample-path"] + img
priusImage = prius_image.PriusImage(path)
palette = prius_palette.PriusPalette()
totalSampleCount = totalSampleCount + 1
if priusImage.has_required_shades():
shadeSampleCount = shadeSampleCount + 1
avg = priusImage.avg_color()
avgInPalette = palette.has_shade(avg)
print("Average Color: " + str(avg) + " Palette Match? " + str(avgInPalette))
if avgInPalette:
avgSampleCount = avgSampleCount + 1
requiredColors = []
for color in priusImage.pca_colors():
requiredColors.append(palette.has_shade(color))
print("PCA Analysis\n")
if any(requiredColors):
pcaSampleCount = pcaSampleCount + 1
# print("Successfully validated palette, average, and PCA for " + img)
except Exception as e: print(e)
end = time.time()
print("\nRequired Palettes: " + str(shadeSampleCount) + " Average Color: " + str(
avgSampleCount) + " PCA Colors: " + str(pcaSampleCount) + " Total: " + str(
totalSampleCount) + " Time: " + str(end - start) + "\n")
compare_images()