Question

I am working on some robot vision project where I need to do some object recognition by color. I am currently using masks for this purpose. So far so good, but now I need to tweak certain settings and I would like to actually see how these changes affect the end result.

My first thought was, 'Fine, print the mask on screen', so I tried to treat the mask like a surface but it turns out PyGame masks can not be 'blit' to the screen surface:

TypeError: argument 1 must be pygame.Surface, not pygame.mask.Mask

I am currently using PyGame.mask operations and guessing what the mask looks like but I think it would be very useful to display the current mask on screen. I think it might be even better if I could apply the mask to a surface and see what is actually being recognised but a black/white representation of the mask is enough. I read the docs but could not figure out how to proceed.

Also, the mask I am trying to display is generated by pygame.mask.from_threshold

Any clues on how to do this?

Was it helpful?

Solution

I have also been researching this and there seems to me to be a gap. I cannot find anyway of having a pygame.mask object and blit that back to a surface.

What i have found is that 'people' tend to get the mask.outline() then draw the points.

draw the outline of the mask eg:

olist = myImage_mask.outline()
pygame.draw.lines(blankSurf,(200,150,150),1,olist)

or fill the outline of the mask eg:

olist = myImage_mask.outline()
pygame.draw.polygon(blankSurf,(200,150,150),olist,0)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top