[英]Unable to crop an image in a for loop using OpenCV on Android
我正在嘗試在for循環中在Android上裁剪圖像,以便計算此區域中所有像素的總和:
int patch = 25;
for (int count1=0; count1<outputMat.cols(); count1 = count1+patch )
{
for (int count2=0; count2<outputMat.rows(); count2 = count2+patch )
{
int widthROI = count1+patch-1;
int heightROI = count2+patch-1;
Mat ROI = outputMat.submat(count1, count2, widthROI, heightROI);
}
}
我收到此錯誤:
32007-32007/org.opencv.samples.tutorial1 E/cv::error()﹕ OpenCV Error: Assertion failed (0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows) in cv::Mat::Mat(const cv::Mat&, const cv::Range&, const cv::Range&), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/core/src/matrix.cpp
有人可以幫忙嗎?
Mat.submat
參數的順序應為:
submat(row_start,row_end,column_start,column_end)
因此,參數的順序錯誤。
您正在使用.cols()
計算寬度,並使用.rows()
計算高度。 更改為count1 < outputMat.rows
和count2 < outputMat.cols
然后使用
.submat(count1,widthROI,count2,heightROI)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.