【发布时间】:2014-03-07 11:48:18
【问题描述】:
我正在尝试使用 Visual Studio Express 2012 for Windows Desktop 重写 Mat 类型灰度图像中的像素值。我试过了:
imgGrayComp.at<uchar>(5, 4) = 0;
.
imgGrayComp.ptr(4)[5] = 0;
.
imgGrayComp.at<Vec3b>(5, 4) = 0;
但它给了我这个:
OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1DataType<_Tp>::channels) < (unsigned)(size.p[1]channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file c:\opencv\build\include\opencv2\core\mat.hpp, line 537
================================================ ============================================
编辑 - 这是代码:
调用classify():
classify("./src/0.jpg", contour, hierarchy, mDatabase, '0');
在分类()中:
void classify(std::string imageFile,
vector<vector<Point> > contour,
vector<Vec4i> hierarchy, float mDatabase [][charsToClassify],
char whichChar)
{
Mat image = imread(imageFile, 1);
Mat imageGrayClassify;
image.convertTo(imageGrayClassify, COLOR_BGR2GRAY);
int numPoints = computeNumContourPts(imageGrayClassify); // calling compute...()
}
在计算中...():
int computeNumContourPts(Mat imgGrayComp)
{
// dilation x1 (increases workload):
dilate(imgGrayComp, imgGrayComp, Mat(), Point(-1,-1), 2);
// erosion x1 (decreases workload):
erode(imgGrayComp, imgGrayComp, Mat(), Point(-1,-1), 1);
imgGrayComp.at<uchar>(5, 4) = 0;
}
【问题讨论】:
-
请提供更多代码。这似乎是 imgGrayComp 的问题,也许是一些大小/类型/深度不匹配?需要更多信息。
-
添加了更多代码。希望这会有所帮助。
标签: opencv visual-studio-2012 pixel pixels grayscale