简体   繁体   English

OpenCV:如何绘制颜色相对于应绘制表面相反的线?

[英]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. XOR技巧完全不同。 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. 您可能需要将颜色转换为HSV并检查饱和度S。如果较低(灰度),请绘制红色像素。 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; 如果原始像素的V高,则使用黑色(V = 0);否则,请使用黑色(V = 0)。 use white if the original pixel had a low V (dark saturated color) 如果原始像素的V值较低(深色饱和色),请使用白色

You can use the LineIterator method as suggested earlier. 您可以使用前面建议的LineIterator方法。

(BTW, the XOR trick has quite bad cases too. 0x7F ^ 0xFF = 0x80. That's bloody hard to see) (顺便说一句,XOR技巧也有非常糟糕的情况。0x7F ^ 0xFF = 0x80。这真是令人难忘。

使用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. 这是从我的脑海中冒出来的,我不是c ++开发人员,但是应该可以将线条画成单独的图像,然后模仿反转混合模式...基本上,您需要获取'negative'/反转像素后的颜色,您可以通过从最大颜色值中减去线条下方的颜色来获得。

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. 不确定颜色是从0到255还是从0.0到1.0,但是希望这可以说明这个想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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