3

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

someImage.threshold(230, true);

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

In Cinder I'm trying the following:

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?

Saranjith
  • 11,242
  • 5
  • 69
  • 122
Sr.Richie
  • 5,680
  • 5
  • 38
  • 62
  • 2
    cv::invert is a *Matrix* inversion, not the color-inversion you probably wanted. – berak Oct 01 '14 at 08:31
  • also, please supply the *exact* error for any of your cases. – berak Oct 01 '14 at 08:32
  • @berak thanks for your comments about the cv::invert - and the vote down :) I've actually found out that the CV_THRESH_BINARY_INV param is the way to go, but the result was misleading due to the value I was using (see my own answer). I will investigate more about this value issue, unfortunately the lack of docs in cinder sometime is a bit overwhelming for me... – Sr.Richie Oct 01 '14 at 09:38

1 Answers1

7

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.

Sr.Richie
  • 5,680
  • 5
  • 38
  • 62
  • since you are basically using opencv: http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#threshold – berak Oct 01 '14 at 11:04
  • 4
    oh, and [binary_not](http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#bitwise-not) is probably what your 'invert' was supposed to do. – berak Oct 01 '14 at 11:06