錯誤:
OpenCV Error: Assertion failed (((((sizeof(size_t)<<28)|0x8442211) >> ((traits::Depth<_Tp>::value) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file d:\opencv3.4.0\build\include\opencv2\core\mat.inl.hpp, line 1096

運行生成中斷之后,跳轉到代碼
CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
不知道是哪里的問題啊求解!!!!
我的代碼如下:
Mat regionGrowFast(const Mat &src, const Point2i seed, int throld)
{
//convert src to gray for getting gray value of every pixel
Mat gray;
cvtColor(src, gray, COLOR_RGB2GRAY);
// set every pixel to black
Mat result = Mat::zeros(src.size(), CV_8UC1);
if ((seed.x < 0) || (seed.y < 0))
return result;
result.at<uchar>(seed.y, seed.x) = 255;
//gray value of seed
int seed_gray = gray.at<uchar>(seed.y, seed.x); //顯示在這一句中斷的!
//grow direction sequenc
int grow_direction[8][2] = { { -1,-1 },{ 0,-1 },{ 1,-1 },{ 1,0 },{ 1,1 },{ 0,1 },{ -1,1 },{ -1,0 } };
//seeds collection
vector<Point2i> seeds;
seeds.push_back(seed);
//start growing
while (!seeds.empty()) {
//get a seed
Point2i current_seed = seeds.back();
seeds.pop_back();
for (int i = 0; i < 8; ++i) {
Point2i neighbor_seed(current_seed.x + grow_direction[i][0], current_seed.y + grow_direction[i][1]);
//check wether in image
if (neighbor_seed.x < 0 || neighbor_seed.y < 0 || neighbor_seed.x >(gray.cols - 1) || (neighbor_seed.y > gray.rows - 1))
continue;
int value = gray.at<uchar>(neighbor_seed.y, neighbor_seed.x);
if ((result.at<uchar>(neighbor_seed.y, neighbor_seed.x) == 0) && (abs(value - seed_gray) <= throld)) {
result.at<uchar>(neighbor_seed.y, neighbor_seed.x) = 255;
seeds.push_back(neighbor_seed);
}
}
}
return result;
}
int main()
{
Mat src=https://bbs.csdn.net/topics/GDAL2Mat("wh02changedetect1.img");
Point2i pt = Point2i(300, 400);
Mat out = regionGrowFast(src, pt, 50);
imwrite("D:\\output.bmp", out);
delete[] data02;
system("pause");
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/122661.html
標籤:C語言
上一篇:PHP陣列(二)
