问题
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
- Detect edges using canny edge detector.
- 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:
pDollar->detectEdges(src, edges);
edges
type is CV_32F. you must convert it to 8-bit single-channel image
来源:https://stackoverflow.com/questions/33620293/opencv-structured-forest-edge-detection-and-findcontours