Java Code Examples for org.opencv.core.Core.flip()

The following are Jave code examples for showing how to use flip() of the org.opencv.core.Core class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: TinyPlanetMaker   File: PlanetMaker.java   Source Code and License Vote up 7 votes
public void setCropRect(RectF cropRect) {

        mCropRect = cropRect;

        if (mIsPlanetInverted)
            Core.flip(mInputImage, mInterimImage, -1);
        else
            mInterimImage = mInputImage.clone();

        if (mCropRect != null) {
//            Take care here, because the images are flipped after they have been loaded:
            Rect flippedRect = flipCropRect(mInterimImage.width(), mInterimImage.height());
            mInterimImage = mInterimImage.submat(flippedRect).clone();
        }

//        // mInterimImage is null if no cropping or invert is done yet:
//        if (mInterimImage == null)
//            mInterimImage = mInputImage.clone();

        if (mIsFaded)
            mInterimImage = getFadeImg(mInterimImage);


        updatePlanet();
    }
 
Example 2
Project: mao-android   File: FdActivity.java   Source Code and License Vote up 7 votes
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

        mRgba = inputFrame.rgba();
        mGray = inputFrame.gray();

        if (mAbsoluteFaceSize == 0) {
            int height = mGray.rows();
            if (Math.round(height * mRelativeFaceSize) > 0) {
                mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
            }
            mNativeDetector.setMinFaceSize(mAbsoluteFaceSize);
        }

        MatOfRect faces = new MatOfRect();

        if (mDetectorType == JAVA_DETECTOR) {
            if (mJavaDetector != null)
                mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
                        new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
        } else if (mDetectorType == NATIVE_DETECTOR) {
            if (mNativeDetector != null)
                mNativeDetector.detect(mGray, faces);
        } else {
            Log.e(TAG, "Detection method is not selected!");
        }

        Rect[] facesArray = faces.toArray();
        for (int i = 0; i < facesArray.length; i++) {
            Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
        }

        //转置90度
        Mat rotateMat = Imgproc.getRotationMatrix2D(new Point(mRgba.rows() / 2, mRgba.cols() / 2), 90, 1);
        Imgproc.warpAffine(mRgba, mRgba, rotateMat, mRgba.size());

        //以y轴翻转
        Core.flip(mRgba, mRgba, 1);

        return mRgba;
    }
 
Example 3
Project: android-imaging-utils   File: ImagingUtils.java   Source Code and License Vote up 6 votes
private static Mat rotateFrame(Mat in, PreviewResizeParams.Rotation rotation)
{
    Mat out = in;

    if (rotation == PreviewResizeParams.Rotation.Clockwise_90)
    {
        out = in.t();
        Core.flip(out, out, -1);
    }
    else if (rotation == PreviewResizeParams.Rotation.Clockwise_180)
    {
        out = in;
    }
    else if (rotation == PreviewResizeParams.Rotation.Clockwise_270)
    {
        out = in.t();
        Core.flip(out, out, 1);
    }
    else
    {
        Core.flip(in, out, 1);
    }

    return out;
}
 
Example 4
Project: AndroidCameraSudokuSolver   File: PortraitCameraView.java   Source Code and License Vote up 6 votes
public Mat rgba() {
    Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2BGR_NV12, 4);
    if (mRotated != null) mRotated.release();
    mRotated = mRgba.t();
    Core.flip(mRotated, mRotated, 1);
    return mRotated;
}
 
Example 5
Project: MOAAP   File: MainActivity.java   Source Code and License Vote up 6 votes
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    //Rotating the input frame
    Mat mGray = inputFrame.gray();
    mRgba = inputFrame.rgba();
    if (mIsFrontCamera)
    {
        Core.flip(mRgba, mRgba, 1);
        Core.flip(mGray, mGray, 1);
    }

    //Detecting face in the frame
    MatOfRect faces = new MatOfRect();
    if(haarCascade != null)
    {
        haarCascade.detectMultiScale(mGray, faces, 1.1, 2, 2, new Size(200,200), new Size());
    }

    Rect[] facesArray = faces.toArray();
    for (int i = 0; i < facesArray.length; i++)
        Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), new Scalar(100), 3);
    return mRgba;
}
 
Example 6
Project: fingerblox   File: ImageProcessing.java   Source Code and License Vote up 5 votes
/**
 * OpenCV only supports landscape pictures, so we gotta rotate 90 degrees.
 */
private Mat rotateImage(Mat image) {
    Mat result = emptyMat(image.rows(), image.cols(), 3);

    Core.transpose(image, result);
    Core.flip(result, result, 1);

    return result;
}
 
Example 7
Project: fingerblox   File: ImageProcessing.java   Source Code and License Vote up 5 votes
static Bitmap preprocess(Mat frame, int width, int height) {
    // convert to grayscale
    Mat frameGrey = new Mat(height, width, CvType.CV_8UC1);
    Imgproc.cvtColor(frame, frameGrey, Imgproc.COLOR_BGR2GRAY, 1);

    // rotate
    Mat rotatedFrame = new Mat(width, height, frameGrey.type());
    Core.transpose(frameGrey, rotatedFrame);
    Core.flip(rotatedFrame, rotatedFrame, Core.ROTATE_180);

    // resize to match the surface view
    Mat resizedFrame = new Mat(width, height, rotatedFrame.type());
    Imgproc.resize(rotatedFrame, resizedFrame, new Size(width, height));

    // crop
    Mat ellipseMask = getEllipseMask(width, height);
    Mat frameCropped = new Mat(resizedFrame.rows(), resizedFrame.cols(), resizedFrame.type(), new Scalar(0));
    resizedFrame.copyTo(frameCropped, ellipseMask);

    // histogram equalisation
    Mat frameHistEq = new Mat(frame.rows(), frameCropped.cols(), frameCropped.type());
    Imgproc.equalizeHist(frameCropped, frameHistEq);

    // convert back to rgba
    Mat frameRgba = new Mat(frameHistEq.rows(), frameHistEq.cols(), CvType.CV_8UC4);
    Imgproc.cvtColor(frameHistEq, frameRgba, Imgproc.COLOR_GRAY2RGBA);

    // crop again to correct alpha
    Mat frameAlpha = new Mat(frameRgba.rows(), frameRgba.cols(), CvType.CV_8UC4, new Scalar(0, 0, 0, 0));
    frameRgba.copyTo(frameAlpha, ellipseMask);

    // convert to bitmap
    Bitmap bmp = Bitmap.createBitmap(frameAlpha.cols(), frameAlpha.rows(), Bitmap.Config.ARGB_4444);
    Utils.matToBitmap(frameAlpha, bmp);

    return bmp;
}
 
Example 8
Project: FaceDetectDemo   File: DetectActivity.java   Source Code and License Vote up 5 votes
@Override
// 这里执行人脸检测的逻辑, 根据OpenCV提供的例子实现(face-detection)
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    mRgba = inputFrame.rgba();
    mGray = inputFrame.gray();
    // 翻转矩阵以适配前后置摄像头
    if (isFrontCamera) {
        Core.flip(mRgba, mRgba, 1);
        Core.flip(mGray, mGray, 1);
    } else {
        Core.flip(mRgba, mRgba, -1);
        Core.flip(mGray, mGray, -1);
    }
    float mRelativeFaceSize = 0.2f;
    if (mAbsoluteFaceSize == 0) {
        int height = mGray.rows();
        if (Math.round(height * mRelativeFaceSize) > 0) {
            mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
        }
    }
    MatOfRect faces = new MatOfRect();
    if (classifier != null)
        classifier.detectMultiScale(mGray, faces, 1.1, 2, 2,
                new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
    Rect[] facesArray = faces.toArray();
    Scalar faceRectColor = new Scalar(0, 255, 0, 255);
    for (Rect faceRect : facesArray)
        Imgproc.rectangle(mRgba, faceRect.tl(), faceRect.br(), faceRectColor, 3);
    return mRgba;
}
 
Example 9
Project: RobotIGS   File: Transform.java   Source Code and License Vote up 5 votes
public static void flip(Mat img, FlipType flipType) {
    Core.flip(img, img, flipType.val);
}
 
Example 10
Project: AndroidCameraSudokuSolver   File: PortraitCameraView.java   Source Code and License Vote up 5 votes
public Mat gray() {
    if (mRotated != null) mRotated.release();
    mRotated = mYuvFrameData.submat(0, mWidth, 0, mHeight); //submat with reversed width and height because its done on the landscape frame
    mRotated = mRotated.t();
    Core.flip(mRotated, mRotated, 1);
    return mRotated;
}
 
Example 11
Project: FTC2016   File: Transform.java   Source Code and License Vote up 4 votes
public static void flip(Mat img, FlipType flipType) {
    Core.flip(img, img, flipType.val);
}
 
Example 12
Project: TinyPlanetMaker   File: PlanetMaker.java   Source Code and License Vote up 4 votes
public void fade(boolean isFaded) {

        mIsFaded = isFaded;

        if (!mIsImageLoaded)
            return;

        if (mIsPlanetInverted)
            Core.flip(mInputImage, mInterimImage, -1);
        else
            mInterimImage = mInputImage.clone();

        if (mCropRect != null) {
            Rect flippedRect = flipCropRect(mInterimImage.width(), mInterimImage.height());
            mInterimImage = mInterimImage.submat(flippedRect).clone();
        }


        if (mIsFaded)
            mInterimImage = getFadeImg(mInterimImage);

        updatePlanet();

    }
 
Example 13
Project: TinyPlanetMaker   File: PlanetMaker.java   Source Code and License Vote up 4 votes
private void initImages() {

        Imgproc.resize(mInputImage, mInputImage, new Size(mOutputSize, mOutputSize), 0, 0, Imgproc.INTER_CUBIC);


//        Creates the planet and inverts it:
        Core.flip(mInputImage.t(), mInputImage, 1);

        if (mIsPlanetInverted)
            Core.flip(mInputImage, mInputImage, -1);

        mOutputImage = new Mat(mInputImage.rows(), mInputImage.cols(), mInputImage.type());
        mOutputImage = mInputImage.clone();
        mInterimImage = mInputImage.clone();

        if (mIsFaded)
            mInterimImage = getFadeImg(mInterimImage);

        updatePlanet();

    }
 
Example 14
Project: AquamarineLake   File: Controller.java   Source Code and License Vote up 4 votes
private void process(Mat f)
{
    Mat gen = new Mat();
    
    if (flipActive) Core.flip(f, f, 1);
    
    Imgproc.cvtColor(f, gen, Imgproc.COLOR_BGR2RGB);
    
    if (weirdRenderActive) Imgproc.cvtColor(gen, gen, Imgproc.COLOR_HSV2RGB);
    
    Point mid = new Point(gen.size().width/2, gen.size().height/2);
    
    midPoint = gen.get((int)mid.y, (int)mid.x);
    
    Imgproc.circle(gen, mid, 5, new Scalar(255-(int)(midPoint[0]), 255-(int)(midPoint[1]), 255-(int)(midPoint[2])), 2);

    Imgproc.cvtColor(gen, f, Imgproc.COLOR_RGB2BGR);
    
}
 
Example 15
Project: AquamarineLake   File: Controller.java   Source Code and License Vote up 4 votes
private void process(Mat f, Mat a, Mat b) {
    if (renderAlphaActive) Core.flip(f, a, 1);
    if (renderBetaActive) Core.flip(f, b, 0);
}
 
Example 16
Project: TinyPlanetMaker   File: PlanetMaker.java   Source Code and License Vote up 3 votes
public void reset() {

        setInitValues();

        if (mIsPlanetInverted && mInputImage != null)
            Core.flip(mInputImage, mInputImage, -1);

        mIsPlanetInverted = false;
        updatePlanet();

    }
 
Example 17
Project: TinyPlanetMaker   File: PlanetMaker.java   Source Code and License Vote up 3 votes
public void invert(boolean isInverted) {

        mIsPlanetInverted = isInverted;

        if (!mIsImageLoaded)
            return;

        Core.flip(mInterimImage, mInterimImage, -1);
        updatePlanet();

    }