Ask Your Question
0

Throwing an error when scanning pixels in an image

asked 2013-04-26 13:30:06 -0600

codemonkey gravatar image

updated 2013-04-26 13:34:23 -0600

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]);
      }
    }
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-04-26 13:56:33 -0600

berak gravatar image

it's:

 mat.at<type>(row,col);

not :

 mat.at<type>(x,y);

i think you need to reverse mat.at(i,j) to mat.at(j,i)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-26 13:30:06 -0600

Seen: 243 times

Last updated: Apr 26 '13