Get the mean color inside a masked region

Hello,

I have a project where I have to recognize the color of a dashboard light. For that, all different possibilities (not lit up, red, orange, blue, …) have been taken . Is also created the mask which is white on the interesting pixels and black on the background. All these images are saved on the SD card.

I need now to get the mean color in the mask so I have a reference value for each possibility and then calculate this on live to determine in wich state is the ligth.

How can I do that ?

Thanks to anyone who will take some time to help me.

Yes, just use the get_stats() method and pass it an ROI which is where the object you want to detect is. You’ll get a list of color values that you can use from that.

Thank you for your answer. I’m trying this today.