OpenCV:阈值和反转图像

Sr.*_*hie 3 c++ opencv cinder

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

someImage.threshold(230, true);
Run Code Online (Sandbox Code Playgroud)

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

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

cv::threshold (input, threshNear, 230, 255, CV_THRESH_BINARY_INV);     
Run Code Online (Sandbox Code Playgroud)

...这不起作用,或者

cv::threshold (input, threshNear, 100, 255, CV_8U);
cv::invert ( threshNear,  threshNearInverted);
Run Code Online (Sandbox Code Playgroud)

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

有什么建议吗?

Sr.*_*hie 6

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

 cv::threshold (input, threshNear, 70, 255, CV_THRESH_BINARY_INV);
Run Code Online (Sandbox Code Playgroud)

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

  • 哦,[binary_not](http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#bitwise-not) 可能是你的“反转”应该做的。 (4认同)