-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfeatureSample.py
83 lines (55 loc) · 1.79 KB
/
featureSample.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
from mousePoints import MousePoints
import numpy as np
import math
from cv2 import cv2
import matplotlib.pyplot as plt
from utils import getHistogram
def getFeatureSampleAverageColour(image):
y = image.shape[0]
boxDim = round(y / 15)
if (boxDim % 2 == 1):
boxDim += 1
cv2.imshow("Select", image)
coordinateStore = MousePoints("Select", image, boxDim)
points, boxDim = coordinateStore.getpt(1)
(x, y) = points[0][0], points[0][1]
cv2.destroyWindow("Select")
if (x, y) == (-1, -1):
return [-1, -1, -1]
if (x < boxDim):
x = boxDim / 2
if (y < boxDim):
y = boxDim / 2
if (x > image.shape[1] - boxDim):
x = image.shape[1] - boxDim
if (y > image.shape[0] - boxDim):
y = image.shape[0] - boxDim
crop_img = image[round(y-boxDim/2):round(y+boxDim/2),
round(x-boxDim/2):round(x+boxDim/2)]
mask = np.ones([boxDim, boxDim], np.uint8)
mean = cv2.mean(crop_img, mask=mask)
return mean
def getFeatureSampleHistogram(image):
y = image.shape[0]
boxDim = round(y / 10)
if (boxDim % 2 == 1):
boxDim += 1
cv2.imshow("Select", image)
coordinateStore = MousePoints("Select", image, boxDim)
points, boxDim = coordinateStore.getpt(1)
(x, y) = points[0][0], points[0][1]
cv2.destroyWindow("Select")
if (x, y) == (-1, -1):
return None
if (x < boxDim):
x = boxDim / 2
if (y < boxDim):
y = boxDim / 2
if (x > image.shape[1] - boxDim):
x = image.shape[1] - boxDim
if (y > image.shape[0] - boxDim):
y = image.shape[0] - boxDim
crop_img = image[round(y-boxDim/2):round(y+boxDim/2),
round(x-boxDim/2):round(x+boxDim/2)]
hist = getHistogram(crop_img)
return hist