【发布时间】:2020-01-27 16:04:31
【问题描述】:
我正在尝试根据另一个 Mat 更新 Mat 的一部分。例如,我想选择img 中mask 中不为零的部分,并为其添加一个常量值。当我尝试这个时:
Mat mask = imread("some grayscale image with a white area in a black background", IMREAD_GRAYSCALE);
Mat img = Mat::zeros(mask.rows, mask.cols, CV_8UC1);
Mat bnry, locations;
threshold(mask, bnry, 100, 255, THRESH_BINARY);
findNonZero(bnry, locations);
img(locations) += 5;
我收到此错误:
错误:断言失败 ((int)ranges.size() == d)
img 和 mask 大小相同。
如何根据另一个图像(蒙版)选择图像的区域?
【问题讨论】:
-
在
imread中,如果你想在openCV中使用灰度图像作为1通道,你必须使用标志cv.:IMREAD_GRAYSCALE或cv::IMREAD_UNCHANGED。 -
好的,我已将其添加到 imread 中。