Ask Your Question

kaojinz's profile - activity

2012-10-31 19:55:05 -0600 commented answer error += operator in iOS

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

2012-10-26 22:48:20 -0600 received badge  Editor (source)
2012-10-26 22:46:23 -0600 asked a question error += operator in iOS

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