Ask Your Question

Revision history [back]

in your picture the background is gray tones which means values of b-g-r should be too close to each other.

so you can try to improve the code below.

import numpy
import cv2

image = cv2.imread("e:/test/15558562403795766.png")
bgr = cv2.split(image)

cv2.imshow("bgr[0]", bgr[0])
cv2.imshow("bgr[1]", bgr[1])
cv2.imshow("bgr[2]", bgr[2])

diff0 = cv2.absdiff(bgr[0], bgr[1])
diff1 = cv2.absdiff(bgr[0], bgr[2])

ret,result0 = cv2.threshold(diff0,20,255,cv2.THRESH_BINARY)
ret,result1 = cv2.threshold(diff1,20,255,cv2.THRESH_BINARY)
cv2.imshow("result0", result0)
cv2.imshow("result1", result1)
cv2.imshow("result", result0+result1)
cv2.waitKey(0)

image description