0

I set my webcam in pygame to use HSV color space. But pygame.Surface.get_at only returns the RGB-color values. Is there a method for reading the HSV values of pixels in pygame?

If not, what is the recommended way of converting all pixels colors to HSV in pygame?

zelyev
  • 13
  • 2

1 Answers1

0

You can use python's colorsys module.

It contains a function rgb_to_hsv which you can use to convert the RGB values into HSV values.

sloth
  • 99,095
  • 21
  • 171
  • 219
  • Thank you. But i already used colorsys and also pygames pygame.Color.hsva to convert RGB to HSV values. It works, but the conversion is slow even though i work with small resolutions like 160x120. – zelyev Feb 05 '15 at 16:23
  • OK. Maybe you want to try mathplotlib? It provides a [rgb_to_hsv](http://matplotlib.org/api/colors_api.html#matplotlib.colors.rgb_to_hsv) function working on a numpy array. You could create such an array using pygame's `surfarray` module. Sorry but I can't test this myself at the moment. – sloth Feb 06 '15 at 08:06
  • Thanks @sloth. The rgb_to_hsv function of mathplotlib did the job: rgb = pygame.surfarray.pixels3d(image) hsv = matplotlib.colors.rgb_to_hsv(rgb / 255.0) – zelyev Nov 24 '17 at 14:59