LineSegmentDetector throws exception on resized image
Hi,
another question concerning the LineSegmentDetector. I have one image and detect lines in it with the LineSegmentDetector. After that I resize the image and try the same but I get the error:
OpenCV Error: Assertion failed ((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())) in cv::Mat::at, file C:\opencv\opencv-master\modules\core\include\opencv2/core/mat.inl.hpp, line 978
Here is my code:
#include "stdafx.h"
#include <opencv2/line_descriptor.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/xfeatures2d.hpp>
using namespace cv;
using namespace cv::xfeatures2d;
using namespace cv::line_descriptor;
int main(int argc, char** argv)
{
// Load two images and modify them
Mat img_1, img_2;
img_1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
img_2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
if (!img_1.data || !img_2.data) {
cout << "Error reading image" << endl;
return EXIT_FAILURE;
}
Mat img_1_half;
vector<Vec4f> lines_1, lines_1_half;
Ptr<LineSegmentDetector> Line_Detector = createLineSegmentDetector();
cout << "First image..." << endl;
Line_Detector->detect(img_1, lines_1);
cout << "Second image..." << endl;
resize(img_1, img_1_half, Size(img_1.cols / 2, img_1.rows / 2));
Line_Detector->detect(img_1_half, lines_1_half);
return 0;
}
Size(img_1.rows / 2, img_1.cols / 2)
i'm almost sure, you wantedSize(img_1.cols / 2, img_1.rows / 2)
(not that it matters here..)
Yes, I corrected it, but still the same error ;)
sorry, cannot reproduce it ;(
Really weird, I added my headerfiles and namespaces now. I get the same error if I follow the example on https://docs.opencv.org/3.1.0/df/dfa/...
Try applying a canny edge before running the detector.
Same error with Canny edge operation before using
Line_Detector->detect
Is the error thrown at the first image or the resized one? I'd so recommend checking your image as well. Confirm the number of channels, view them to see if they everything is working fine before running the detectors etc
I think I remember that a vector wasn't resized when the image is scaled down. So it's size was from calculation before and runs out of bound, but I can't find the place in source code.
let's switch to full-on paranoid mode :)
since you're obviously using widows: go and triple-check your linker settings. any chance you're using opencv debug libs with a release project (or other way round) ? crt not the same as the libs ?
your code probably runs fine for anyone else (assuming from a single sample: me) , there's no obvious flaw in it
@berak I can confirm as well that the code works on my mac