Ask Your Question
0

error += operator in iOS

asked 2012-10-26 22:46:23 -0600

kaojinz gravatar image

updated 2012-10-27 01:12:11 -0600

Hi, I try OpenCV Cookbook example in iOS. but, next Error occurs.

How to solve the problem?

error message in xcode:

OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in arithm_op, file /Users/kaojinz/opencv/modules/core/src/arithm.cpp, line 1273 libc++abi.dylib: terminate called throwing an exception


source code:

UIImage *boldtImage = [UIImage imageNamed:@"boldt.jpg"];
UIImage *rainImage = [UIImage imageNamed:@"rain.jpg"];

cv::Mat image1, image2, result;

image1 = [boldtImage CVMat];
image2 = [rainImage CVMat];

// create vector of 3 images
std::vector<cv::Mat> planes;
// split 1 3-channel image into 3 1-channel images
cv::split(image1, planes);
// add to blue channel
planes[0] += image2;      <<== error !
// merge the 3 1-channel images into 1 3-channel image
cv::merge(planes,result);

self.imageView.image = [UIImage imageWithCVMat:result];

in error part : opencv2.framework/Header/core/mat.hpp

static inline Mat& operator += (const Mat& a, const Mat& b)
{
    add(a, b, (Mat&)a);
    return (Mat&)a;
}

using convert UIImage to Mat code: https://github.com/aptogo/OpenCVForiPhone/blob/master/OpenCVClient/UIImage%2BOpenCV.mm

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-10-30 01:26:31 -0600

worst guy ever gravatar image

updated 2012-10-30 01:27:38 -0600

The clue is in the error message:

'array op array' (where arrays have the same size and the same number of channels)

Your addition fails because panels[0] is a single channel image and image2 has as many channels as are in rain.jpg (presumably three). What effect are you trying to achieve?

edit flag offensive delete link more

Comments

Um.. single channel image. OK! I Understand. Thank you.

kaojinz gravatar imagekaojinz ( 2012-10-31 19:55:05 -0600 )edit

Question Tools

Stats

Asked: 2012-10-26 22:46:23 -0600

Seen: 656 times

Last updated: Oct 30 '12