C++ OpenCV:阈值和反转图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26137051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:31:48  来源:igfitidea点击:

OpenCV: Threshold and Invert an image

c++opencvcinder

提问by Sr.Richie

I'm trying to threshold and invert an image with Cinder OpenCV block. In openFrameworks I would use something like that:

我正在尝试使用 Cinder OpenCV 块阈值和反转图像。在 openFrameworks 中,我会使用类似的东西:

someImage.threshold(230, true);

...where true is the parameter to specify to threshold and invert.

...其中 true 是指定阈值和反转的参数。

In Cinder I'm trying the following:

在 Cinder 中,我正在尝试以下操作:

cv::threshold (input, threshNear, 230, 255, CV_THRESH_BINARY_INV);     

... that doesn't work, or

...这不起作用,或者

cv::threshold (input, threshNear, 100, 255, CV_8U);
cv::invert ( threshNear,  threshNearInverted);

...that produces and error and let the program stuck.

...产生错误并让程序卡住。

Any suggestion?

有什么建议吗?

回答by Sr.Richie

Ok, after more testing I've realized that actually the way to go is

好的,经过更多测试后,我意识到实际上要走的路是

 cv::threshold (input, threshNear, 70, 255, CV_THRESH_BINARY_INV);

the problem with the code I posted in my question looks like to be related with the threshold value I was trying to use (230 on 255). If I use a lower value (like for example 70 on 255) the color inversion actually works.

我在问题中发布的代码问题似乎与我尝试使用的阈值(255 上的 230)有关。如果我使用较低的值(例如 255 上的 70),颜色反转实际上有效。