Reputation: 1
I have problem with my function. This is making Average images. All codes seem to be fine, but the last sentence (Core.add) got a runtime error. This is average image making code with OpenCV library.
static public Mat getAVG(List ar) {
int i;
int w = 0;
int h = 0;
int type = 0;
int len = ar.size();
for(i = 0;i<len;i++){
Mat img_tmp = ar.get(i);
if(w < img_tmp.width()){
w = img_tmp.width();
}
if(h < img_tmp.height()){
h = img_tmp.height();
}
type = img_tmp.type();
}
Mat img = Mat.zeros(w,h,type);
for(i = 0;i<len;i++){
Mat img_tmp = ar.get(i);
Mat img_tmp_resize = new Mat();
Imgproc.resize(img_tmp, img_tmp_resize, new Size(w,h));
Mat img_tmp2 = new Mat();
Core.convertScaleAbs(img_tmp_resize, img_tmp2, 1.0/len, 0);
Core.add(img, img_tmp2, img); //**Here I got runtime error!!
}
return img;
}
Here is logcat error message:
12-04 13:53:21.979: E/AndroidRuntime(25271): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.smartdogv2/com.example.smartdogv2.MainActivity2}: CvException [org.opencv.core.CvException: /home/andreyk/OpenCV2/trunk/opencv_2.3.1.b2/modules/core/src/arithm.cpp:1253: error: (-209) 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 function void cv::arithm_op(const cv::_InputArray&, const cv::_InputArray&, const cv::_OutputArray&, const cv::_InputArray&, int, void ()(const uchar, size_t, const uchar, size_t, uchar*, size_t, cv::Size, void*), bool, void*) 12-04 13:53:21.979: E/AndroidRuntime(25271): ]
Upvotes: 0
Views: 1350
Reputation: 382
I think that this error refers to the fact that the Matrices' dimensions don't match.
I'm not sure exactly what are you trying to do in that loop, buy maybe you could print out the img and img_tmp2 rows/cols. Of course, as you're adding them, they must have the same dimensions. If they don't, that's the problem.
Upvotes: 1