0

I am writing an application in C++ using OpenCV library. I am trying to do simple operations with matrices and on some data types operations output errors.

For example:

reduce(img, img, 0, CV_REDUCE_SUM, CV_8U); //does not work if img contains CV_8U
reduce(img, img, 0, CV_REDUCE_SUM, CV_64F); //does work if img contains CV_8U

And if try simple per element division:

Mat A = B / C; //generates data type assertion error if B and C are CV_32F

But does work if B and C are CV_64F.

I would really appreciate your help. Don't want to use CV_64F as it slows down my program significantly.

1
  • I've posted an answer for reduction operations. Division works perfectly with CV_32F types. Please provide a minimal reproducible example to see where is the problem. Commented Apr 27, 2016 at 12:14

1 Answer 1

1

Reduction operations needs a suitable destination type, otherwise they will fail in case they might produce inconsistent result due to saturation.

If you are summing (CV_REDUCE_SUM) CV_8U values, you need a destination type big enough to contain the sum, which is either: CV_32S, CV_32F or CV_64F.

You can check this, as well as other combinations in the source code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.