-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintensityFind.py
More file actions
68 lines (63 loc) · 1.9 KB
/
intensityFind.py
File metadata and controls
68 lines (63 loc) · 1.9 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
import cv2 as cv
import numpy as np
import math
BLACK_THRESH_S = 35
BLACK_THRESH_V = 70
#Takes a HSV image and returns a list of the most intense pixels in it
def findMaxIntensities(img):
imgS = img[:,:,1]
maxI = 0
maxSet = []
for i in range(imgS.shape[0]):
for j in range(imgS.shape[1]):
if imgS[i,j] > maxI:
maxI = imgS[i,j]
maxSet = [(i,j)]
elif imgS[i,j] == maxI:
maxSet.append((i,j))
#print(maxI)
return maxSet
#Takes a HSV image and returns a list of the most intense pixels in it,
# after applying filtering to minimize black bars on the edges
def findMaxIntensitiesFiltered(img):
imgS = img[:,:,1]
imgV = img[:,:,2]
maxI = 0
maxSet = []
centerX = imgS.shape[0]/2
centerY = imgS.shape[1]/2
#print("centers x/y", centerX, centerY)
for i in range(imgS.shape[0]):
dX = abs(centerX-i)
for j in range(imgS.shape[1]):
dY = abs(centerY-j)
sF = cosCorrectFactor(dX,dY,centerX,centerY)
cS = sF*imgS[i,j]
cV = sF*imgV[i,j]
if cS <= BLACK_THRESH_S and cV <= BLACK_THRESH_V:
pass
else:
maxSet.append((i,j))
# elif cS > maxI:
# maxI = imgS[i,j]
# maxSet = [(i,j)]
# elif cS == maxI:
# maxSet.append((i,j))
return maxSet
#Takes a distance from a center and returns a weight between 0 and 1
# determined by cosine such that a point at the cetner has weight 1,
# and a point at the extremes has weight ~0.
def cosCorrectFactor(dx, dy, centerX, centerY):
relevantD = max((dx/centerX), dy/centerY)
relevnatDRads = (math.pi/2) * relevantD
return math.cos(relevnatDRads)
if __name__ == '__main__':
print(cosCorrectFactor(0,0,50,100))
print(cosCorrectFactor(50,0,50,100))
print(cosCorrectFactor(20,50,50,100))
'''
img = cv.imread('../cards/42398')
imgHSV = cv.cvtColor(img, cv.COLOR_BGR2HSV)
findMaxIntensities(imgHSV)
cv.imshow("out", imgHSV[:,:,1])
cv.waitKey()'''