-1

i´ve been trying to find the best and the easiest way at JAVA - how to detect labyrinth at image using OpenCV and calculate corner points and angle for image rotate to horizontal position.

The labyrinth is defined by 3 small yellow paper squares placed at corners.

I found this partial solution: How can I detect registration markers on paper using OpenCV? - but i have no skills to modify it to working for me :-/

Two testing image situations:

Example image

Example image 2

Thanks all for help!

Community
  • 1
  • 1
Filip
  • 228
  • 2
  • 11
  • Seriously? Are you expecting somebody will invent algorithm here for you? – Andremoniy Jan 19 '17 at 16:55
  • 1
    This is a cool project to learn computer vision, don't let anyone give you the solution, if you find it yourself it will mean you know a bit more computer vision :) If you have specific questions of how to do something, we will help. This is to broad a problem. – Pedro Batista Jan 19 '17 at 17:31

1 Answers1

1

Ok, thanks for encouragement with my problem. Thanks to it i found this partially soloution:

    Mat mazeImage = Imgcodecs.imread("vzory/real_5.jpg"); //, Imgcodecs.CV_LOAD_IMAGE_COLOR
    Mat hsv = new Mat();
    Mat treshold = new Mat();
    Mat hierarchy = new Mat();
    Imgproc.cvtColor(mazeImage, hsv, Imgproc.COLOR_BGR2HSV);
    Core.inRange(hsv, new Scalar(20,135,135), new Scalar(30, 255, 255), treshold);

    List<MatOfPoint> contours = new ArrayList<>();
    Imgproc.findContours(treshold, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

    PointContourCollection pointContourCollection = new PointContourCollection(new PointContourComparator());

    for (MatOfPoint contour : contours) {
        Point center = new Point();
        Moments moments = Imgproc.moments(contour);
        center.x = (int) (moments.m10/moments.m00);
        center.y = (int) (moments.m01/moments.m00);

        double area = Imgproc.contourArea(contour);

        if(area > 0.1){
            pointContourCollection.add(new PointContour(center, area, contour));
        }
    }

    Imgproc.drawContours(mazeImage, contours, -1, new Scalar(0, 255, 0), 5);

Class PointContourCollection - extension of ArrayList - for store only yellow corners with center position and their area. Corners are sorted with PointContourComparator by area size. Partial result

Filip
  • 228
  • 2
  • 11
  • Looks good to me! Why partial? – Rick M. Jan 20 '17 at 19:20
  • Because i now need to found some soloution for rotate image to horizontal position. But there is "small" problem - labyrint can be rotated for four different rotations. I have calculated (now) all angles of lines - but now i need to found soloution how to decide what angle is "best" way for good rotation. :-) – Filip Jan 20 '17 at 20:18
  • How do you want to rotate it? – Rick M. Jan 24 '17 at 00:32