Java Code Examples for org.opencv.core.Core#transpose()

The following examples show how to use org.opencv.core.Core#transpose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MatOperation.java    From Android-Face-Recognition-with-Deep-Learning-Library with Apache License 2.0 6 votes vote down vote up
/***************************************************************************************
 *    Title: Rotate image by 90, 180 or 270 degrees
 *    Author: StereoMatching
 *    Date: 29.04.2013
 *    Code version: -
 *    Availability: http://stackoverflow.com
 *
 ***************************************************************************************/

public static void rotate_90n(Mat img, int angle)
{
    if(angle == 270 || angle == -90){
        // Rotate clockwise 270 degrees
        Core.transpose(img, img);
        Core.flip(img, img, 0);
    }else if(angle == 180 || angle == -180){
        // Rotate clockwise 180 degrees
        Core.flip(img, img, -1);
    }else if(angle == 90 || angle == -270){
        // Rotate clockwise 90 degrees
        Core.transpose(img, img);
        Core.flip(img, img, 1);
    }
}
 
Example 2
Source File: OldMainActivity.java    From pasm-yolov3-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected List<Classifier.Recognition> doInBackground(Mat... mats) {
    Mat mRgbaTemp = mats[0];
    if (myBitmap != null){
        smallBitmap = Bitmap.createScaledBitmap(myBitmap, INPUT_WIDTH, INPUT_HEIGHT, false);
    }else{

        smallBitmap = Bitmap.createBitmap(INPUT_WIDTH, INPUT_HEIGHT, Bitmap.Config.RGB_565);
        Bitmap bigBitmap = Bitmap.createBitmap(mRgbaF.width(), mRgbaF.height(), Bitmap.Config.RGB_565);
        Mat mRgbaFixedSize = new Mat(INPUT_WIDTH, INPUT_HEIGHT, CvType.CV_8UC4);

        Core.transpose(mRgbaTemp, mRgbaT);
        Imgproc.resize(mRgbaT, mRgbaF, mRgbaF.size(), 0,0, 0);
        Core.flip(mRgbaF, mRgbaTemp, 1 );

        Imgproc.resize(mRgbaTemp, mRgbaFixedSize, new Size(INPUT_WIDTH, INPUT_HEIGHT), 0,0, 0);

        Utils.matToBitmap(mRgbaFixedSize, smallBitmap);
        Utils.matToBitmap(mRgbaTemp, bigBitmap);

        this.publishProgress(bigBitmap);


        //OLD Toast.makeText(getApplicationContext(), "Nessuna immagine caricata", Toast.LENGTH_SHORT).show();
    }

    List<Classifier.Recognition> recognitions = classifier.recognizeImage(smallBitmap);
    return  recognitions;
}
 
Example 3
Source File: FaceFragment.java    From OpenCV-android with Apache License 2.0 5 votes vote down vote up
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    mRgba = inputFrame.rgba();
    // 解决预览视图逆时针90度
    Core.transpose(mRgba, mRgba);
    Core.flip(mRgba, mRgba, 1);

    Rect[] obj = face.detectObject(mRgba, matOfRect);
    for (Rect rect : obj) {
        Imgproc.rectangle(mRgba, rect.tl(), rect.br(), face.getRectColor(), 3);
    }

    return mRgba;
}
 
Example 4
Source File: MainActivity.java    From MOAAP with MIT License 5 votes vote down vote up
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

        //Get image size and draw a rectangle on the image for reference
        Mat temp = inputFrame.rgba();
        Imgproc.rectangle(temp, new Point(temp.cols()/2 - 200, temp.rows() / 2 - 200), new Point(temp.cols() / 2 + 200, temp.rows() / 2 + 200), new Scalar(255,255,255),1);
        Mat digit = temp.submat(temp.rows()/2 - 180, temp.rows() / 2 + 180, temp.cols() / 2 - 180, temp.cols() / 2 + 180).clone();
        Core.transpose(digit,digit);
        int predict_result = mnist.FindMatch(digit);
        Imgproc.putText(temp, Integer.toString(predict_result), new Point(50, 150), FONT_HERSHEY_SIMPLEX, 3.0, new Scalar(0, 0, 255), 5);

        return temp;
    }
 
Example 5
Source File: FtcTestOpenCv.java    From FtcSamples with MIT License 5 votes vote down vote up
/**
 * This method rotate the image to the specified angle.
 *
 * @param src specifies the image to be rotated.
 * @param dst specifies the destination to put the rotated image.
 * @param angle specifies the rotation angle.
 */
private void rotateImage(Mat src, Mat dst, double angle)
{
    angle %= 360.0;
    if (angle == 0.0)
    {
        src.copyTo(dst);
    }
    else if (angle == 90.0 || angle == -270.0)
    {
        Core.transpose(src, dst);
        Core.flip(dst, dst, 1);
    }
    else if (angle == 180.0 || angle == -180.0)
    {
        Core.flip(src, dst, -1);
    }
    else if (angle == 270.0 || angle == -90.0)
    {
        Core.transpose(src, dst);
        Core.flip(dst, dst, 0);
    }
    else
    {
        Mat rotMat = Imgproc.getRotationMatrix2D(
                new Point(src.cols()/2.0, src.rows()/2.0), angle, 1.0);
        Imgproc.warpAffine(src, dst, rotMat, src.size());
    }
}
 
Example 6
Source File: MainActivity.java    From pasm-yolov3-Android with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Mat doInBackground(Mat... mats) {
    Mat mRgbaTemp = mats[0];
    ImageProcessor processor = new ImageProcessor(getApplicationContext(), classifier.getLabels());
    if (myBitmap != null){
        smallBitmap = Bitmap.createScaledBitmap(myBitmap, INPUT_SIZE, INPUT_SIZE, false);
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;
        int height = size.y;

        float ratio = (float)myBitmap.getWidth() / (float)myBitmap.getHeight();
        Bitmap reducedBitmap = Bitmap.createScaledBitmap(myBitmap, (int) (height * ratio), height, false);

        this.publishProgress(reducedBitmap);
        processor.loadImage(myBitmap, INPUT_SIZE, INPUT_SIZE);
    }else{
        smallBitmap = Bitmap.createBitmap(INPUT_SIZE, INPUT_SIZE, Bitmap.Config.RGB_565);
        Bitmap bigBitmap = Bitmap.createBitmap(mRgbaF.width(), mRgbaF.height(), Bitmap.Config.RGB_565);
        Mat mRgbaFixedSize = new Mat(INPUT_SIZE, INPUT_SIZE, CvType.CV_8UC4);

        Core.transpose(mRgbaTemp, mRgbaT);
        Imgproc.resize(mRgbaT, mRgbaF, mRgbaF.size(), 0,0, 0);
        Core.flip(mRgbaF, mRgbaTemp, 1 );

        Imgproc.resize(mRgbaTemp, mRgbaFixedSize, new Size(INPUT_SIZE, INPUT_SIZE), 0,0, 0);

        Utils.matToBitmap(mRgbaFixedSize, smallBitmap);
        Utils.matToBitmap(mRgbaTemp, bigBitmap);

        this.publishProgress(bigBitmap);
        processor.loadImage(bigBitmap, INPUT_SIZE, INPUT_SIZE);
        //OLD Toast.makeText(getApplicationContext(), "Nessuna immagine caricata", Toast.LENGTH_SHORT).show();
    }

    List<Classifier.Recognition> recognitions = classifier.recognizeImage(smallBitmap);
    Mat mat = processor.drawBoxes(recognitions, 0.2);
    imageSaver.save(mat); // remove for realtime processing!
    return mat;
}
 
Example 7
Source File: FaceRecognitionAppActivity.java    From FaceRecognitionApp with GNU General Public License v2.0 4 votes vote down vote up
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    Mat mGrayTmp = inputFrame.gray();
    Mat mRgbaTmp = inputFrame.rgba();

    // Flip image to get mirror effect
    int orientation = mOpenCvCameraView.getScreenOrientation();
    if (mOpenCvCameraView.isEmulator()) // Treat emulators as a special case
        Core.flip(mRgbaTmp, mRgbaTmp, 1); // Flip along y-axis
    else {
        switch (orientation) { // RGB image
            case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
            case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
                if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_FRONT)
                    Core.flip(mRgbaTmp, mRgbaTmp, 0); // Flip along x-axis
                else
                    Core.flip(mRgbaTmp, mRgbaTmp, -1); // Flip along both axis
                break;
            case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
            case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
                if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_FRONT)
                    Core.flip(mRgbaTmp, mRgbaTmp, 1); // Flip along y-axis
                break;
        }
        switch (orientation) { // Grayscale image
            case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
                Core.transpose(mGrayTmp, mGrayTmp); // Rotate image
                if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_FRONT)
                    Core.flip(mGrayTmp, mGrayTmp, -1); // Flip along both axis
                else
                    Core.flip(mGrayTmp, mGrayTmp, 1); // Flip along y-axis
                break;
            case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
                Core.transpose(mGrayTmp, mGrayTmp); // Rotate image
                if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_BACK)
                    Core.flip(mGrayTmp, mGrayTmp, 0); // Flip along x-axis
                break;
            case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
                if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_FRONT)
                    Core.flip(mGrayTmp, mGrayTmp, 1); // Flip along y-axis
                break;
            case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
                Core.flip(mGrayTmp, mGrayTmp, 0); // Flip along x-axis
                if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_BACK)
                    Core.flip(mGrayTmp, mGrayTmp, 1); // Flip along y-axis
                break;
        }
    }

    mGray = mGrayTmp;
    mRgba = mRgbaTmp;

    return mRgba;
}