Update app.py
Browse files
app.py
CHANGED
|
@@ -164,8 +164,8 @@ def removeSmallDashes(imgOriginal,green):
|
|
| 164 |
img1=cv2.dilate(smalldashes, kernel3, iterations=2)
|
| 165 |
img2=cv2.erode(img1, kernel3, iterations=2)
|
| 166 |
|
| 167 |
-
smalldashes=cv2.medianBlur(img2,
|
| 168 |
-
smalldashes=cv2.medianBlur(smalldashes,
|
| 169 |
# cv2_imshow(smalldashes)
|
| 170 |
smalldashesOut=green.copy()
|
| 171 |
smalldashesOut=cv2.cvtColor(smalldashesOut,cv2.COLOR_GRAY2BGR)
|
|
@@ -287,29 +287,35 @@ def hexRGB(color):
|
|
| 287 |
color= tuple(int(color[i:i+2], 16) for i in (0, 2, 4)) #hex to rgb
|
| 288 |
color=np.array(color) #rgb to bgr
|
| 289 |
return color
|
| 290 |
-
|
| 291 |
def DetectColor(img,color=0):
|
| 292 |
|
| 293 |
imgCopy=img.copy()
|
| 294 |
-
|
| 295 |
-
#
|
| 296 |
color=hexRGB(color)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
-
|
| 299 |
-
upper= np.array([min(color[2]+tol,255), min(color[1]+tol,255), min(color[0]+tol,255)], dtype = "uint8")
|
| 300 |
-
mask = cv2.inRange(imgCopy, lower, upper)
|
| 301 |
|
| 302 |
detectedColors = cv2.bitwise_and(imgCopy,imgCopy, mask= mask) # Bitwise-AND mask and original image
|
| 303 |
|
| 304 |
kernel=np.ones((3,3),np.uint8)
|
| 305 |
mask=cv2.dilate(mask,kernel, iterations=5)
|
| 306 |
mask=cv2.erode(mask,kernel, iterations=4)
|
| 307 |
-
# cv2_imshow(mask)
|
| 308 |
|
| 309 |
detectedColors=cv2.dilate(detectedColors,kernel, iterations=5)
|
| 310 |
detectedColors=cv2.erode(detectedColors,kernel, iterations=4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
return mask, detectedColors, color
|
| 312 |
|
|
|
|
| 313 |
def detectAllColors(img,finalColorArray):
|
| 314 |
for i in range(len(finalColorArray)):
|
| 315 |
detectedColors= DetectColor(img,finalColorArray[i])[1]
|
|
|
|
| 164 |
img1=cv2.dilate(smalldashes, kernel3, iterations=2)
|
| 165 |
img2=cv2.erode(img1, kernel3, iterations=2)
|
| 166 |
|
| 167 |
+
smalldashes=cv2.medianBlur(img2,5)
|
| 168 |
+
smalldashes=cv2.medianBlur(smalldashes,5)
|
| 169 |
# cv2_imshow(smalldashes)
|
| 170 |
smalldashesOut=green.copy()
|
| 171 |
smalldashesOut=cv2.cvtColor(smalldashesOut,cv2.COLOR_GRAY2BGR)
|
|
|
|
| 287 |
color= tuple(int(color[i:i+2], 16) for i in (0, 2, 4)) #hex to rgb
|
| 288 |
color=np.array(color) #rgb to bgr
|
| 289 |
return color
|
|
|
|
| 290 |
def DetectColor(img,color=0):
|
| 291 |
|
| 292 |
imgCopy=img.copy()
|
| 293 |
+
imgCopy=cv2.cvtColor(imgCopy,cv2.COLOR_BGR2HSV)
|
| 294 |
+
tol=5 #tolerance
|
| 295 |
color=hexRGB(color)
|
| 296 |
+
h,s,v = cv2.cvtColor(np.uint8([[[color[2],color[1],color[0]]]]),cv2.COLOR_BGR2HSV)[0][0]
|
| 297 |
+
|
| 298 |
+
lower =np.array( [h- tol, 100, 100 ], dtype='uint8')
|
| 299 |
+
upper = np.array( [h + tol, 255, 255],dtype='uint8')
|
| 300 |
|
| 301 |
+
mask = cv2.inRange(imgCopy, lower , upper)
|
|
|
|
|
|
|
| 302 |
|
| 303 |
detectedColors = cv2.bitwise_and(imgCopy,imgCopy, mask= mask) # Bitwise-AND mask and original image
|
| 304 |
|
| 305 |
kernel=np.ones((3,3),np.uint8)
|
| 306 |
mask=cv2.dilate(mask,kernel, iterations=5)
|
| 307 |
mask=cv2.erode(mask,kernel, iterations=4)
|
|
|
|
| 308 |
|
| 309 |
detectedColors=cv2.dilate(detectedColors,kernel, iterations=5)
|
| 310 |
detectedColors=cv2.erode(detectedColors,kernel, iterations=4)
|
| 311 |
+
|
| 312 |
+
detectedColors=cv2.cvtColor(detectedColors,cv2.COLOR_HSV2BGR)
|
| 313 |
+
detectedColors=cv2.medianBlur(detectedColors,7)
|
| 314 |
+
# cv2_imshow(detectedColors)
|
| 315 |
+
|
| 316 |
return mask, detectedColors, color
|
| 317 |
|
| 318 |
+
|
| 319 |
def detectAllColors(img,finalColorArray):
|
| 320 |
for i in range(len(finalColorArray)):
|
| 321 |
detectedColors= DetectColor(img,finalColorArray[i])[1]
|