Ask Your Question
0

Help with line segment detection in java

asked 2015-12-08 12:15:58 -0600

DD690 gravatar image

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();
        }

    }
edit retag flag offensive close merge delete

Comments

you should apply the line segment detector directly on the image and NOT preprocess it using the canny edge detector. Both algorithms are designed to extract lines/edges from a grayscale image.

takahashi gravatar imagetakahashi ( 2016-03-21 03:50:09 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-12-14 05:25:18 -0600

DD690 gravatar image

Mat lines = new Mat();

should be

MatOfFloat4 lines = new MatOfFloat4();
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-12-08 12:15:58 -0600

Seen: 1,488 times

Last updated: Dec 14 '15