Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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);
}

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());