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 开发者_如何学Pythonto 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)
Use a LineIterator and XOR the colour values of each pixel manually.
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.
精彩评论