com.nekomeshi312.whiteboardcorrection.DetectLines.java Source code

Java tutorial

Introduction

Here is the source code for com.nekomeshi312.whiteboardcorrection.DetectLines.java

Source

/*----------------------------------------------------------------------------
    
  WhiteBoardCorrection 
    
  This code is part of the following publication and was subject
  to peer review:
    
"WhiteBoardCorrection" by Nekomeshi
    
  Copyright (c) Nekomeshi <Nekomeshi312@gmail.com>
    
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.
    
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU Affero General Public License for more details.
    
  You should have received a copy of the GNU Affero General Public License
  along with this program. If not, see <http://www.gnu.org/licenses/>.
    
  ----------------------------------------------------------------------------*/
package com.nekomeshi312.whiteboardcorrection;

import org.opencv.core.Mat;

import android.util.Log;

public class DetectLines {
    private static final String LOG_TAG = "DetectLines";
    public static final int MAX_LINE_NUM = 500;
    boolean mIsInit = false;

    public DetectLines(int width, int height, int scale) {
        initLines(width, height, scale, MAX_LINE_NUM);
        mIsInit = true;
    }

    public int lineDetect(Mat inputImg, boolean isYUV, Mat outputImg, int lines[]) {
        if (!mIsInit)
            return -1;
        return detectLines(inputImg.getNativeObjAddr(), isYUV, outputImg == null ? 0 : outputImg.getNativeObjAddr(),
                lines);
    }

    public void cleanUp() {
        if (!mIsInit)
            return;
        cleanupLines();
        mIsInit = false;
    }

    static {
        try {
            System.loadLibrary("LineDetect");
        } catch (UnsatisfiedLinkError e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 
     * @param inputImg ???
     * @param isYUV??YUV???true RGB???false
     * @param outputImg RGB??? 0??YUV->RGB??????????
     * @param lines ???StartX, StartY, EndX, EndY, Width ????
     * @return ???
     */
    native private int detectLines(long inputImg, boolean isYUV, long outputImg, int lines[]);

    /**
     * ??
     * @param width??
     * @param height???
     * @param scale????2->? 4->1/4????Hough??
     * @param maxLineNum??
     */
    native private void initLines(int width, int height, int scale, int maxLineNum);

    /**
     * ?
     */
    native private void cleanupLines();

}