OpenCV: How to draw a line with colors that are inversed relatively to the surface it should be drawn on?

StackOverflow https://stackoverflow.com/questions/4266316

Question

So we have an image. We want to draw a line that must definitely be seen. So how to draw a lines with colors that are inverted relatively to the surface it should be drawn on in each point?

Was it helpful?

Solution

Use a LineIterator and XOR the colour values of each pixel manually.

OTHER TIPS

The XOR trick is trivially different. It's not visually the most distinct, though, if only because it entirely ignores how human eyes work. For instance, on light greys, a saturated red color is visually quite distinct.

You might want to convert the color to HSV and check the saturation S. If low (greyscale), draw a red pixel. If the saturation is high, the hue is quite obvious, and a white or black pixel will stand out. Use black (V=0) if the the original pixel had a high V; use white if the original pixel had a low V (dark saturated color)

You can use the LineIterator method as suggested earlier.

(BTW, the XOR trick has quite bad cases too. 0x7F ^ 0xFF = 0x80. That's bloody hard to see)

This is from the top of my head and I'm not a c++ dev, but it should be possible to draw the line into a separate image and then mimic an invert blend mode...basically you need to get the 'negative'/inverted colour behind a pixel, which you get by subtracting the color bellow your line from the maximum colour value.

Something like:

uint invert(uint topPixel, uint bottomPixel) {
            return (255 - bottomPixel);
}

Not sure how if colours are from 0 to 255 or from 0.0 to 1.0, but hopefully this illustrates the idea.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top