Throwing an error when scanning pixels in an image
I'm getting this error:
error: (-215) dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()
I'm scanning through an image to determine what color the pixels are inside a polygon. I'm completely stumped as to what is causing the error. Any assistance would be great.
This is the code that is throwing the error (CVGColor is just a structure to hold RGB values):
cv::Rect boundingRect = cv::boundingRect(aPolygon);
cv::Mat matCropped = matImage(boundingRect);
std::vector<cv::Point> aPolygonTranslated;
for(size_t i=0; i<aPolygon.size(); i++)
{
aPolygonTranslated.push_back(cv::Point(aPolygon[i].x - boundingRect.x, aPolygon[i].y - boundingRect.y));
}
for(int i=0; i<matCropped.cols; i++)
{
for(int j=0; j<matCropped.rows; j++)
{
if(cv::pointPolygonTest(aPolygonTranslated, cv::Point(i, j), false) > 0) // point is inside
{
CVGColor cvgPixel(matCropped.at<cv::Vec3b>(i, j)[2], matCropped.at<cv::Vec3b>(i, j)[1], matCropped.at<cv::Vec3b>(i, j)[0]);
}
}
}