Ask Your Question
1

Failed to get characters/triangles

asked 2019-04-21 09:20:19 -0600

Nuser gravatar image

updated 2020-10-09 05:10:13 -0600

Hello, I wanted to read characters/triangles from a bar. I applied Otsu with different values to this bar but couldn't get the all characters exactly. The characters' colours are varying. Could someone give another way/algorithm to extract them? Also, is there any way to color sweeping, I mean try all colours then if exist, extract (extract all colored from black&white backgrounded image) ? Thanks for help

ret,im1 = cv2.threshold(crop_img,0,255,cv2.THRESH_OTSU)

The challenges, the last one is the hardest :(

image description

The best one I got which is unsuccesful:

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-04-21 11:48:16 -0600

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-04-21 09:20:19 -0600

Seen: 245 times

Last updated: Apr 21 '19