Ask Your Question

Revision history [back]

Help with line segment detection in java

Hi all,

I am having a problem with line segment detection. I am using openCV 3. The output file sometimes has lines in the wrong places and sometimes is blank depending on the input image. I think its something to do with my variable called lines. I have tried to implement this from this example. The problem is I dont know c++ at all so it has been hard to understand. I am doing a project on emotion detection from an image. Am i on the right track with this?

Any help appreciated.

 public void lineSegment(File file) {
        new Event().fireEvent(new EventItem(
              this, 1, "Begining line segmentation . . . \n"));

        new Event().fireEvent(new EventItem(
                this, 1, "File path:\n" + file.getAbsolutePath() + "\n"));

        Mat image = Imgcodecs.imread(file.getAbsolutePath());


        try {
            Imgproc.Canny(image,image,50,200);
            LineSegmentDetector ls = Imgproc.createLineSegmentDetector();

            double start = Core.getTickCount();

            Mat lines = new Mat();

            ls.detect(image, lines);

            double duration_ms = (Core.getTickCount() - start) * 1000 / Core.getTickFrequency();


            Mat lineImage = Imgcodecs.imread(
             "/Users/DarrylThorne/IdeaProjects/Face Detection Project/pics/blank.jpg");


            ls.drawSegments(lineImage, lines);


            Imgcodecs.imwrite("lineSegImage.jpg", lineImage);
            new Event().fireEvent(new EventItem(this, 1, "Time taken: " + duration_ms + "ms.\n"));



        } catch (CvException e) {
         e.printStackTrace();
        }

    }