简体   繁体   English

OpenCV:阈值和反转图像

[英]OpenCV: Threshold and Invert an image

I'm trying to threshold and invert an image with Cinder OpenCV block. 我正在尝试使用Cinder OpenCV块对图像进行阈值处理和反转。 In openFrameworks I would use something like that: 在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? 有什么建议吗?

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). 我在问题中发布的代码问题似乎与我尝试使用的阈值(255上为230)有关。 If I use a lower value (like for example 70 on 255) the color inversion actually works. 如果我使用较低的值(例如255上的70),则颜色反转实际上有效。

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

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