Example usage for org.opencv.core Mat inv

List of usage examples for org.opencv.core Mat inv

Introduction

In this page you can find the example usage for org.opencv.core Mat inv.

Prototype

public Mat inv() 

Source Link

Usage

From source file:com.nekomeshi312.whiteboardcorrection.WhiteBoardDetect.java

License:Open Source License

/**
 * ????????// ww  w.  ja v a 2s .  co  m
 * @param lineEq ?????(ax+by=1) ??[angle][section]
 * @param points ?ArrayList
 * @param img ????null??????
 * @return true:? false:
 */
private boolean calcSquare(StraightLineEquation lineEq[][], ArrayList<Point> points, Mat img) {
    //2??
    Mat mat = new Mat(2, 2, CvType.CV_32F);
    mPointCenterX = 0.0f;
    mPointCenterY = 0.0f;
    int counter = 0;
    for (int ang0sec = 0; ang0sec < 2; ang0sec++) {
        mat.put(0, 0, lineEq[0][ang0sec].a);
        mat.put(0, 1, lineEq[0][ang0sec].b);
        for (int ang1sec = 0; ang1sec < 2; ang1sec++) {
            mat.put(1, 0, lineEq[1][ang1sec].a);
            mat.put(1, 1, lineEq[1][ang1sec].b);
            Mat matAns;
            try {
                matAns = mat.inv();
                if (matAns == null)
                    return false;
            } catch (Exception e) {//??????????
                e.printStackTrace();
                return false;
            }
            float x = (float) (matAns.get(0, 0)[0] + matAns.get(0, 1)[0] + mCenterX);
            float y = (float) (matAns.get(1, 0)[0] + matAns.get(1, 1)[0] + mCenterY);
            Point p = new Point(x, y);
            points.add(p);
            mPointCenterX += x;
            mPointCenterY += y;
            counter++;
        }
    }
    mPointCenterX /= (float) counter;
    mPointCenterY /= (float) counter;
    //????
    Collections.sort(points, new PointComparator());
    if (img != null) {
        Scalar color[] = new Scalar[4];
        color[0] = new Scalar(0xff, 0x00, 0x00);
        color[1] = new Scalar(0x00, 0xff, 0x00);
        color[2] = new Scalar(0x00, 0x00, 0xff);
        color[3] = new Scalar(0xff, 0x00, 0xff);

        for (int i = 0; i < 4; i++) {
            Core.circle(img, points.get(i), 30, color[i], 5);
        }
    }
    if (MyDebug.DEBUG) {
        for (int i = 0; i < 4; i++) {
            Log.d(LOG_TAG, "point(" + i + ") = " + points.get(i).x + ":" + points.get(i).y);
        }
    }

    return true;
}