OpenCV4Android - findChessboardCorners找不到角落

时间:2015-03-27 14:08:10

标签: android opencv camera-calibration

我想使用opencv函数在图像上找到棋盘角。为此,我使用下面的代码。我有一个Android应用程序。它获取框架并显示它。当用户单击设备屏幕时,此代码会尝试在所选框架上查找角落。

我的电路板有6x5平方。 代码:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    if(!isClick) {
        mRgba = inputFrame.rgba();
    }
    else {

        Imgproc.cvtColor(mRgba, mRgb, Imgproc.COLOR_RGBA2RGB);
        findChessBoard();
        return mRgb;
    }
    return mRgba;
}

public void findChessBoard()
{
    int boardH = 5,
        boardW = 4;
    Size board_sz = new Size(boardW, boardH);
    MatOfPoint2f corners = new MatOfPoint2f();
    boolean found = Calib3d.findChessboardCorners(mRgb, board_sz, corners, Calib3d.CALIB_CB_ADAPTIVE_THRESH | Calib3d.CALIB_CB_FILTER_QUADS);

    if (found)
    {
        // Refines the corner locations
        Mat gray = new Mat(mRgb.size(), Imgproc.COLOR_RGB2GRAY);
        Imgproc.cornerSubPix(gray, corners, new Size(11, 11), new Size(-1, -1),new TermCriteria(TermCriteria.EPS, 0, 0.01));
                                                        //new TermCriteria(CV_T CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
        Calib3d.drawChessboardCorners(mRgb, board_sz, corners, found);
    }
    Log.i(TAG, "Found " + corners.size() + " " + found);
}

0 个答案:

没有答案