Skip to content
Advertisement

How to convert color with OpenCV?

I am struggling with converting red color to another color, blue, yellow, green and so on.

I’ve already achieved to convert red color to gray scale color as bellow.

JavaScript

But what I really want to achieve is turn a color into another one but not gray scale. How should I change the code or any good reference? Thank you.

Advertisement

Answer

You are using the value 125 to all points in your mask with:

JavaScript

If you want to change to a colored pixel, just assign a color array to that pixel such as:

JavaScript

afterbefore

Complete code:

JavaScript
Advertisement