Example usage for org.opencv.imgproc Imgproc warpPerspective

List of usage examples for org.opencv.imgproc Imgproc warpPerspective

Introduction

In this page you can find the example usage for org.opencv.imgproc Imgproc warpPerspective.

Prototype

public static void warpPerspective(Mat src, Mat dst, Mat M, Size dsize) 

Source Link

Usage

From source file:at.entenbaer.gui.CameraViewFragment.java

License:Open Source License

/**
 * Called for each new Camera Frame //from   www.java 2 s .c  o  m
 * If in RealTimeMode this evaluates if the camera is still or is beeing moved and starts the image processing
 * @param inputFrame InputFrame fetched from the camera
 * @return returns a Mat with the picture that is produced to display (could be just the inputFrame or a picture with a poem rendered)
 */
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    if (!processing) {
        if (this.rgba != null) {
            //this.rgba.release();
        }
        this.rgba = inputFrame.rgba();

        if (realTimeMode) {

            Mat returnThis = rgba.clone();
            boolean comparedFrames;

            if (!frameCompare.getFirstFrameSet()) {
                frameCompare.setFirstFrame(returnThis);
            } else {
                comparedFrames = frameCompare.compareFrames(returnThis);
                if (processingFinished || comparedFrames) {
                    Log.d(TAG, "Frame compare: camera is still");
                    if (!processing && !processingFinished) {
                        Log.d(TAG, "processing image now");
                        context = this.getActivity();
                        processingThread = null;
                        processingThread = new ProcessImageThread(realTimeMode, this);
                        processingThread.execute(rgba.clone());
                        processing = true;
                        Log.d(TAG, "Started Image Processing");
                    } else if (processingFinished) {

                        if (frameCompare.getAffineTransform() != null) {
                            Imgproc.warpPerspective(poemMat, poemMat, frameCompare.getHomography(),
                                    poemMat.size());
                        }

                        Core.add(returnThis, poemMat, returnThis);

                        if (saveNextFrame) {
                            SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
                            Date now = new Date();
                            TPAUtils.saveMatToBitmap(returnThis, formatter.format(now) + "_texturepeomapp.jpg");
                            Toast toast = Toast.makeText(context, getString(R.string.statusSaved),
                                    Toast.LENGTH_LONG);
                            toast.setGravity(Gravity.TOP, 25, 400);
                            toast.show();
                            saveNextFrame = false;
                        }

                        processingFinished = comparedFrames;

                    }
                } else {
                    Log.d(TAG, "Frame compare: camera is moving");
                    processingFinished = false;

                }

            }
            return returnThis;
        }

        return this.rgba;
    } else
        return inputFrame.rgba();
}

From source file:com.jonwohl.Attention.java

License:Open Source License

private Mat warpPerspective(ArrayList<PVector> inputPoints, int w, int h) {
    Mat transform = getPerspectiveTransformation(inputPoints, w, h);
    Mat unWarpedMarker = new Mat(w, h, CvType.CV_8UC1);
    Imgproc.warpPerspective(ocv.getColor(), unWarpedMarker, transform, new Size(w, h));
    return unWarpedMarker;
}

From source file:org.akvo.caddisfly.sensor.colorimetry.strip.util.OpenCVUtil.java

License:Open Source License

public static Mat perspectiveTransform(double[] topLeft, double[] topRight, double[] bottomLeft,
        double[] bottomRight, Mat bgr) {

    // determine the size of the destination Mat: use the positions of the finder patterns to determine the width and height.
    // look out: the horizontal direction now refers again to the actual calibration card
    int verSize = (int) Math.round(
            Math.sqrt(Math.pow((topLeft[0] - topRight[0]), 2) + Math.pow((topLeft[1] - topRight[1]), 2)));
    int horSize = (int) Math.round(
            Math.sqrt(Math.pow((topLeft[0] - bottomLeft[0]), 2) + Math.pow((topLeft[1] - bottomLeft[1]), 2)));

    // we rotate the resulting image, so we go from a portrait view to the regular calibration card in landscape
    // so the mapping is:
    // top left source => top right destination
    // top right source => bottom right destination
    // bottom right source => bottom left destination
    // bottom left source => top left destination

    double[] trDest = new double[] { horSize - 1, 0 };
    double[] brDest = new double[] { horSize - 1, verSize - 1 };
    double[] blDest = new double[] { 0, verSize - 1 };
    double[] tlDest = new double[] { 0, 0 };

    Mat transformMatrix = transformMatrix(topLeft, topRight, bottomRight, bottomLeft, trDest, brDest, blDest,
            tlDest);/*  w  ww . j  a v  a2 s . com*/

    //make a destination mat for a warp
    Mat warpMat = Mat.zeros(verSize, horSize, bgr.type());

    //do the warp
    Imgproc.warpPerspective(bgr, warpMat, transformMatrix, warpMat.size());
    return warpMat;
}