count colored dots in image

前端 未结 3 1219
囚心锁ツ
囚心锁ツ 2020-12-09 00:15

First of all, sorry if this topic already exists (I think this is a common task, but couldn\'t find anything).

The point, is that I have an image who shows different

3条回答
  •  情话喂你
    2020-12-09 00:38

    Since you already know the colors you are looking for, I would segment the image based on color. The steps I would follow are:

    red_dot_count = 0 
    yellow_dot_count = 0
    green_dot_count = 0
    For each pixel in the image:
       if pixel color is red:
           floodfill using this pixel as seed pixel and target_color as black
           red_dot_count++
       if pixel color is green:
           floodfill using this pixel as seed pixel and target_color as black
           green_dot_count++
       if pixel is yellow:
           floodfill using this pixel as seed pixel and target_color as black
           yellow_dot_count++
    

    Your image would have to be a PNG image though as @Mark pointed out.

    Also, this assumes that the colors in the red, green and yellow dots do not appear anywhere else in the image.

提交回复
热议问题