Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Type of lines in LineSegmentDetector

Hi,

I am using the LineSegmentDetector (https://docs.opencv.org/3.2.0/db/d73/classcv_1_1LineSegmentDetector.html) to find lines in my images. It works really well but I am little bit confused by the documentation. There it says the lines I detect are

"A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly oriented depending on the gradient."

But when I use the definition Vec4f lines; I get the error:

Assertion failed (channels() == CV_MAT_CN(dtype)) in cv::Mat::copyTo, file C:\opencv\opencv-master\modules\core\src\copy.cpp, line 259

When I use Mat lines instead it works. Here is my code:

int main(int argc, char** argv)
{

     Mat img_1,
     img_1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);


      if (!img_1.data || !img_2.data) {
          cout << "Error reading image" << endl;
           return EXIT_FAILURE;
      }

      Ptr<LineSegmentDetector> det = createLineSegmentDetector();
      //Vec4f lines;  // Error
      Mat lines // no Error
      det->detect(img_1, lines);

      return 0;
}

My question is: Why do I get this error and how can I extract the beginning and end of the line out of my Mat? Are every 4 values one line?