1 | initial version |
Can you post an example image? Maybe you can use some contraints if you know the position of the camera/cube.
Anyway, I see a few problems with your approach:
cv2.merge(...)
and mask=cv2.cvtcolor(...)
.I suggest to apply edge detection (laplacian, canny or sobel) on the color_mask for each color, then merge these "color edges" too. Something like:
...
edges = np.zeros(hsv.shape, dtype=np.float64)
for color, (lower, upper) in colors.items():
...
color_edge = cv2.Laplacian(color_mask,cv2.CV_64F)
edges = edges + color_edge
mask = mask + color_mask