Ask Your Question

error += operator in iOS

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

kaojinz gravatar image

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

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

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:

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

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

worst guy ever gravatar image

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

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


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

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

Question Tools


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

Seen: 504 times

Last updated: Oct 30 '12