简体   繁体   中英

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

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?

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)

使用LineIterator对每个像素的颜色值进行手动XOR。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM