I need to crop an image according to the edges i find(with a given epsilon)
I have following the following instructions: Opencv c++ detect and crop white region on image
with one change - i am trying to find the rectangle according to the edges image i receive from the canny edge detector:
cv::Mat in = cv::imread("c:/cropping/myImage.png");
cv::Mat _imgGray;
cv::Mat edges;
std::vector<cv::Point> nonBlackList;
cv::cvtColor(in, _imgGray, CV_BGR2GRAY);
cv::Canny(_imgGray, edges, 5, 50, 3);
for(int j=0; j<edges.rows; ++j)
for(int i=0; i<edges.cols; ++i)
{
// if not black: add to the list
if(edges.at<cv::Vec3b>(j,i) != cv::Vec3b(0,0,0))
{
nonBlackList.push_back(cv::Point(i,j));
}
}
The problem i encounter is that when I get to column #139 it crashes over the following exception:
Microsoft C++ exception: cv::Exception at memory location 0x000000EB35DEF170.
but when i use the original image(not the edges image) it works as expected.
any ideas? What i would like is to crop according to the edges of the image and not the actual image
Thanks