0
votes

I am trying to use opencv via visual c++ to extract contours of an image. I was able to do that using the opencv tutorial for findcontours. findcontours works in two steps

  1. Detect edges using canny edge detector.
  2. Feed the output of canny to findcontours.

I want to try out the same with 'Structured Forest Edge Detection' (Zitnick et al). I am able to extract the edges and display them, but when I try to feed the output to findcontours. I am getting a 'cv::Exception at memory location 0x0020EE9C' error. (see code below). What am I doing wrong?

Mat src = imread("image.jpg");

src.convertTo(src, CV_32F, 1.0 / 255.0);

Mat edges(src.size(), src.type());

Ptr<StructuredEdgeDetection> pDollar = createStructuredEdgeDetection("model.yml.gz");

pDollar->detectEdges(src, edges);

findContours(edges, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
1
I tried converting the edges from CV_32F to CV_8U as follows edges.convertTo(edges_cv8u, CV_8U, 255.0 / (max - min), -255.0 / min) and then passed edges_cv8u into findContours. still the same exception.Subu

1 Answers

0
votes
pDollar->detectEdges(src, edges);

edges type is CV_32F. you must convert it to 8-bit single-channel image