OpenCV:如何用相对于应绘制的表面反转的颜色绘制一条线?
这样我们就有了一个图像。我们想要画一条必须被看到的线。那么如何绘制一条颜色与每个点应绘制的表面相反的线呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 LineIterator 并手动对每个像素的颜色值进行异或。
Use a LineIterator and XOR the colour values of each pixel manually.
这是我的想法,我不是 c++ 开发人员,但这应该是可能的
将线条绘制成单独的图像,然后模仿反转混合模式...基本上,您需要获得像素后面的“负”/反转颜色,这是通过从最大颜色值中减去线条下方的颜色来获得的。
比如:
不确定颜色是从 0 到 255 还是从 0.0 到 1.0,但希望这能说明这个想法。
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:
Not sure how if colours are from 0 to 255 or from 0.0 to 1.0, but hopefully this illustrates the idea.
XOR 技巧略有不同。不过,它在视觉上并不是最明显的,因为它完全忽略了人眼的工作原理。例如,在浅灰色上,饱和的红色在视觉上非常明显。
您可能想要将颜色转换为 HSV 并检查饱和度 S。如果低(灰度),则绘制红色像素。如果饱和度高,色调就很明显,白色或黑色像素会很突出。如果原始像素具有高 V,则使用黑色 (V=0);如果原始像素具有低 V(深色饱和色),则使用白色
您可以使用前面建议的 LineIterator 方法。
(顺便说一句,异或技巧也有很糟糕的情况。0x7F ^ 0xFF = 0x80。这很难看出来)
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)