CV_Assert fail error in ximgproc module
Problem : I have opencv 3.0 configured with extra modules on my system. I want to use the structured edge detector implemented in module ximgproc module.
link : http://docs.opencv.org/trunk/d0/da5/tutorial_ximgproc_prediction.html
But it is giving following assert fail error on every image I tried till now.
512 512
OpenCV Error: Assertion failed (y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0])) in cv::Mat::ptr, file C:\Program Files\OpenCV\opencv3.0\sources\modules\core\include\opencv2/core/mat.inl.hpp, line 750
Press any key to continue . . .
This error is caused by the function
detectEdges(src,dst)
Actual file path on my system is opencv3.0\sources\modules\core\include\opencv2/core/mat.inl.hpp .
I am using the model file given in samples ('model.yml.gz')
Thanks
All the code :Code used:
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/utility.hpp"
#include "ximgproc/include/opencv2/ximgproc.hpp"
#include "ximgproc\include\opencv2\ximgproc\structured_edge_detection.hpp"
using namespace std;
using namespace cv;
using namespace cv::ximgproc;
int main(int argc, const char** argv)
{
std::string modelFilename = "model.yml.gz";
std::string inFilename = "01.png"; // "lena.jpg"
std::string outFilename = "" ;//parser.get<std::string>("o");
Mat image = imread(inFilename,1);
if (image.empty())
{
printf("Cannot read image file: %s\n", inFilename.c_str());
return -1;
}
Size size = image.size();
std::cout << size.height << " " << size.width << std::endl;
if ((size.height < 31) || (size.width < 20)) {
if (size.height < 31)
size.height = 31;
if (size.width < 15)
size.width = 15;
resize(image, image, size, 0.0, 0.0, INTER_AREA);
}
size.width = 400;
size.height = 213;
resize(image, image, size, 0.0, 0.0, INTER_AREA);
image.convertTo(image, DataType<float>::type, 1.0 / 255.0);
Mat edges = Mat(image.rows,image.cols , image.type(), float(0.0));
Ptr<RFFeatureGetter> rfptr = createRFFeatureGetter();
Ptr<StructuredEdgeDetection> pDollar =
createStructuredEdgeDetection(modelFilename, rfptr);
//cerr << "reaching till here " << endl;
pDollar->detectEdges((const Mat)image , edges);
//cerr << " unreached " << endl;
if (outFilename == "")
{
namedWindow("edges", 1);
imshow("edges", edges);
waitKey(0);
}
else
imwrite(outFilename, 255 * edges);
return 0;
}