Ask Your Question
0

Error: Sizes of input arguments do not match, why?

asked 2016-11-17 13:01:56 -0600

Noo7 gravatar image

I have the following code and it produces the error "Sizes of input arguments do not match" at the line where I try to add two cv::Mat objs together. Why?

std::vector<cv::Mat> depths;
for (int i = 0; i<102; ++i)
    depths.push_back(cv::imread(img_path + std::to_string(i) + img_suffix));

cv::Mat mean_depth = cv::Mat::zeros(depths.at(0).size(), CV_64F);

for (std::vector<int>::size_type i = 0; i != depths.size(); i++) {
    mean_depth = mean_depth + depths[i];
}
edit retag flag offensive close merge delete

Comments

did you mean to accumulate a mean image there?

berak gravatar imageberak ( 2016-11-17 14:04:56 -0600 )edit

yes, first i want to sum them though

Noo7 gravatar imageNoo7 ( 2016-11-17 14:13:24 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-11-18 02:43:20 -0600

berak gravatar image

updated 2016-11-18 03:03:30 -0600

you can only add Mat's of same size and same type.

since you're loading bgr images, your accum buffer needs to have 3 channels, too, also you would need to convert your loaded images to double, too (using cv::accumulate would spare you the manual conversion).

std::vector<cv::Mat> depths;
for (int i = 0; i<102; ++i) {
    cv::Mat im = cv::imread(img_path + std::to_string(i) + img_suffix);
    CV_Assert(! im.empty()); // please *always* check resources
    depths.push_back(im);
}
cv::Mat mean_depth = cv::Mat::zeros(depths.at(0).size(), CV_64FC3); //!!

for (std::vector<int>::size_type i = 0; i != depths.size(); i++) {
    cv::accumulate(depths[i], mean_depth);
}

// i can only guess, but you probably want this in the end:
mean_depth.convertTo(mean_depth, CV_8U, 1.0/depths.size());
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-11-17 13:01:56 -0600

Seen: 3,181 times

Last updated: Nov 18 '16