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

发布于 2024-10-04 03:32:22 字数 60 浏览 0 评论 0原文

这样我们就有了一个图像。我们想要画一条必须被看到的线。那么如何绘制一条颜色与每个点应绘制的表面相反的线呢?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠檬 2024-10-11 03:32:23

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

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

廻憶裏菂餘溫 2024-10-11 03:32:23

这是我的想法,我不是 c++ 开发人员,但这应该是可能的
将线条绘制成单独的图像,然后模仿反转混合模式...基本上,您需要获得像素后面的“负”/反转颜色,这是通过从最大颜色值中减去线条下方的颜色来获得的。

比如:

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

不确定颜色是从 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:

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.

毁虫ゝ 2024-10-11 03:32:22

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文