Example usage for org.opencv.core Core add

List of usage examples for org.opencv.core Core add

Introduction

In this page you can find the example usage for org.opencv.core Core add.

Prototype

public static void add(Mat src1, Scalar src2, Mat dst) 

Source Link

Usage

From source file:Questao1.java

void soma() {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    Core.add(image1, image2, output);
    Imgcodecs.imwrite("soma.jpg", output);
    showResult("soma.jpg");
}

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

License:Open Source License

/**
 * Called for each new Camera Frame //from   w  w  w  .  j  a  v a2s . 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.shootoff.camera.Camera.java

License:Open Source License

public static Mat colorTransfer(Mat source, Mat target) {
    Mat src = new Mat();
    Mat dst = new Mat();

    Imgproc.cvtColor(source, src, Imgproc.COLOR_BGR2Lab);
    Imgproc.cvtColor(target, dst, Imgproc.COLOR_BGR2Lab);

    ArrayList<Mat> src_channels = new ArrayList<Mat>();
    ArrayList<Mat> dst_channels = new ArrayList<Mat>();
    Core.split(src, src_channels);/*from  w  w w .ja  va 2 s.c om*/
    Core.split(dst, dst_channels);

    for (int i = 0; i < 3; i++) {
        MatOfDouble src_mean = new MatOfDouble(), src_std = new MatOfDouble();
        MatOfDouble dst_mean = new MatOfDouble(), dst_std = new MatOfDouble();
        Core.meanStdDev(src_channels.get(i), src_mean, src_std);
        Core.meanStdDev(dst_channels.get(i), dst_mean, dst_std);

        dst_channels.get(i).convertTo(dst_channels.get(i), CvType.CV_64FC1);
        Core.subtract(dst_channels.get(i), dst_mean, dst_channels.get(i));
        Core.divide(dst_std, src_std, dst_std);
        Core.multiply(dst_channels.get(i), dst_std, dst_channels.get(i));
        Core.add(dst_channels.get(i), src_mean, dst_channels.get(i));
        dst_channels.get(i).convertTo(dst_channels.get(i), CvType.CV_8UC1);
    }

    Core.merge(dst_channels, dst);

    Imgproc.cvtColor(dst, dst, Imgproc.COLOR_Lab2BGR);

    return dst;
}

From source file:com.wallerlab.compcellscope.calcDPCTask.java

License:BSD License

protected Long doInBackground(Mat... matrix_list) {
    //int count = urls.length;
    Mat in1 = matrix_list[0];/*  www  .ja v a 2  s. co  m*/
    Mat in2 = matrix_list[1];
    Mat outputMat = matrix_list[2];

    Mat Mat1 = new Mat(in1.width(), in1.height(), in1.type());
    Mat Mat2 = new Mat(in2.width(), in2.height(), in2.type());
    in1.copyTo(Mat1);
    in2.copyTo(Mat2);

    Imgproc.cvtColor(Mat1, Mat1, Imgproc.COLOR_RGBA2GRAY, 1);
    Imgproc.cvtColor(Mat2, Mat2, Imgproc.COLOR_RGBA2GRAY, 1);

    Mat output = new Mat(Mat1.width(), Mat1.height(), CvType.CV_8UC4);
    Mat dpcSum = new Mat(Mat1.width(), Mat1.height(), CvType.CV_32FC1);
    Mat dpcDifference = new Mat(Mat1.width(), Mat1.height(), CvType.CV_32FC1);
    Mat dpcImgF = new Mat(Mat1.width(), Mat1.height(), CvType.CV_32FC1);

    /*
    Log.d(TAG,String.format("Mat1 format is %.1f-%.1f, type: %d",Mat1.size().width,Mat1.size().height,Mat1.type()));
    Log.d(TAG,String.format("Mat2 format is %.1f-%.1f, type: %d",Mat2.size().width,Mat2.size().height,Mat2.type()));
    */

    // Convert to Floats
    Mat1.convertTo(Mat1, CvType.CV_32FC1);
    Mat2.convertTo(Mat2, CvType.CV_32FC1);
    Core.add(Mat1, Mat2, dpcSum);
    Core.subtract(Mat1, Mat2, dpcDifference);
    Core.divide(dpcDifference, dpcSum, dpcImgF);
    Core.add(dpcImgF, new Scalar(1.0), dpcImgF); // Normalize to 0-2.0
    Core.multiply(dpcImgF, new Scalar(110), dpcImgF); // Normalize to 0-255
    dpcImgF.convertTo(output, CvType.CV_8UC1); // Convert back into RGB
    Imgproc.cvtColor(output, output, Imgproc.COLOR_GRAY2RGBA, 4);

    dpcSum.release();
    dpcDifference.release();
    dpcImgF.release();
    Mat1.release();
    Mat2.release();

    Mat maskedImg = Mat.zeros(output.rows(), output.cols(), CvType.CV_8UC4);
    int radius = maskedImg.width() / 2 + 25;
    Core.circle(maskedImg, new Point(maskedImg.width() / 2, maskedImg.height() / 2), radius,
            new Scalar(255, 255, 255), -1, 8, 0);
    output.copyTo(outputMat, maskedImg);
    output.release();
    maskedImg.release();
    return null;
}

From source file:com.wallerlab.compcellscope.MultiModeViewActivity.java

License:BSD License

public Mat calcDPC(Mat in1, Mat in2, Mat out) {
    Mat Mat1 = new Mat(in1.width(), in1.height(), in1.type());
    Mat Mat2 = new Mat(in2.width(), in2.height(), in2.type());
    in1.copyTo(Mat1);//  w  w  w  . j a  va 2  s. co  m
    in2.copyTo(Mat2);

    Imgproc.cvtColor(Mat1, Mat1, Imgproc.COLOR_RGBA2GRAY, 1);
    Imgproc.cvtColor(Mat2, Mat2, Imgproc.COLOR_RGBA2GRAY, 1);

    Mat output = new Mat(Mat1.width(), Mat1.height(), CvType.CV_8UC4);
    Mat dpcSum = new Mat(Mat1.width(), Mat1.height(), CvType.CV_32FC1);
    Mat dpcDifference = new Mat(Mat1.width(), Mat1.height(), CvType.CV_32FC1);
    Mat dpcImgF = new Mat(Mat1.width(), Mat1.height(), CvType.CV_32FC1);

    /*
    Log.d(TAG,String.format("Mat1 format is %.1f-%.1f, type: %d",Mat1.size().width,Mat1.size().height,Mat1.type()));
    Log.d(TAG,String.format("Mat2 format is %.1f-%.1f, type: %d",Mat2.size().width,Mat2.size().height,Mat2.type()));
    */

    // Convert to Floats
    Mat1.convertTo(Mat1, CvType.CV_32FC1);
    Mat2.convertTo(Mat2, CvType.CV_32FC1);
    Core.add(Mat1, Mat2, dpcSum);
    Core.subtract(Mat1, Mat2, dpcDifference);
    Core.divide(dpcDifference, dpcSum, dpcImgF);
    Core.add(dpcImgF, new Scalar(1.0), dpcImgF); // Normalize to 0-2.0
    Core.multiply(dpcImgF, new Scalar(110), dpcImgF); // Normalize to 0-255
    dpcImgF.convertTo(output, CvType.CV_8UC1); // Convert back into RGB
    Imgproc.cvtColor(output, output, Imgproc.COLOR_GRAY2RGBA, 4);

    dpcSum.release();
    dpcDifference.release();
    dpcImgF.release();
    Mat1.release();
    Mat2.release();

    Mat maskedImg = Mat.zeros(output.rows(), output.cols(), CvType.CV_8UC4);
    int radius = maskedImg.width() / 2 + 25;
    Core.circle(maskedImg, new Point(maskedImg.width() / 2, maskedImg.height() / 2), radius,
            new Scalar(255, 255, 255), -1, 8, 0);
    output.copyTo(out, maskedImg);
    output.release();
    maskedImg.release();
    return out;
}

From source file:com.wallerlab.processing.tasks.ComputeRefocusTask.java

License:BSD License

private Bitmap[] computeFocus(float z) {
    int width = mDataset.WIDTH - 2 * mDataset.XCROP;
    int height = mDataset.HEIGHT - 2 * mDataset.YCROP;

    Mat result = new Mat(height, width, CvType.CV_32FC4);
    Mat result8 = new Mat(height, width, CvType.CV_8UC4);

    Mat dpc_result_tb = new Mat(height, width, CvType.CV_32FC4);
    Mat dpc_result_tb8 = new Mat(height, width, CvType.CV_8UC4);

    Mat dpc_result_lr = new Mat(height, width, CvType.CV_32FC4);
    Mat dpc_result_lr8 = new Mat(height, width, CvType.CV_8UC4);

    Mat img;/*from  w w w . j  a v a 2s  . co  m*/
    Mat img32 = new Mat(height, width, CvType.CV_32FC4);
    Mat shifted;

    for (int idx = 0; idx < mDataset.fileCount; idx++) {
        img = ImageUtils.toMat(BitmapFactory.decodeByteArray(fileByteList[idx], 0, fileByteList[idx].length));
        img = img.submat(mDataset.YCROP, mDataset.HEIGHT - mDataset.YCROP, mDataset.XCROP,
                mDataset.WIDTH - mDataset.XCROP);
        img.convertTo(img32, result.type());

        // Grab actual hole number from filename
        String fName = mDataset.fileList[idx].toString();
        String hNum = fName.substring(fName.indexOf("_scanning_") + 10, fName.indexOf(".jpeg"));
        int holeNum = Integer.parseInt(hNum);
        //Log.d(TAG,String.format("BF Scan Header is: %s", hNum));

        // Calculate these based on array coordinates
        int xShift = (int) Math.round(z * tanh_lit[holeNum]);
        int yShift = (int) Math.round(z * tanv_lit[holeNum]);

        shifted = ImageUtils.circularShift(img32, yShift, xShift);

        if (mDataset.leftList.contains(holeNum)) //add LHS
        {
            Core.add(dpc_result_lr, shifted, dpc_result_lr);
        } else //subtract RHS
        {
            Core.subtract(dpc_result_lr, shifted, dpc_result_lr);
        }

        if (mDataset.topList.contains(holeNum)) //add Top
        {
            Core.add(dpc_result_tb, shifted, dpc_result_tb);
        } else //subtract bottom
        {
            Core.subtract(dpc_result_tb, shifted, dpc_result_tb);
        }

        Core.add(result, shifted, result);

        float progress = ((idx + 1) / (float) mDataset.fileCount);
        onProgressUpdate((int) (progress * 100), -1);
        Log.d(TAG, String.format("progress: %f", progress));
    }

    Core.MinMaxLocResult minMaxLocResult1 = Core.minMaxLoc(result.reshape(1));
    result.convertTo(result8, CvType.CV_8UC4, 255 / minMaxLocResult1.maxVal);

    Core.MinMaxLocResult minMaxLocResult2 = Core.minMaxLoc(dpc_result_lr.reshape(1));
    dpc_result_lr.convertTo(dpc_result_lr8, CvType.CV_8UC4,
            255 / (minMaxLocResult2.maxVal - minMaxLocResult2.minVal),
            -minMaxLocResult2.minVal * 255.0 / (minMaxLocResult2.maxVal - minMaxLocResult2.minVal));

    Core.MinMaxLocResult minMaxLocResult3 = Core.minMaxLoc(dpc_result_tb.reshape(1));
    dpc_result_tb.convertTo(dpc_result_tb8, CvType.CV_8UC4,
            255 / (minMaxLocResult3.maxVal - minMaxLocResult3.minVal),
            -minMaxLocResult3.minVal * 255.0 / (minMaxLocResult3.maxVal - minMaxLocResult3.minVal));

    /*
    Log.d(TAG,String.format("result_min: %f, max: %f",minMaxLocResult1.minVal,minMaxLocResult1.maxVal));
    Log.d(TAG,String.format("lr_min: %f, max: %f",minMaxLocResult2.minVal,minMaxLocResult2.maxVal));
    Log.d(TAG,String.format("tb_min: %f, max: %f",minMaxLocResult3.minVal,minMaxLocResult3.maxVal));
    */

    // remove transparency in DPC images
    Scalar alphaMask = new Scalar(new double[] { 1.0, 1.0, 1.0, 255.0 });

    Core.multiply(dpc_result_lr8, alphaMask, dpc_result_lr8);
    Core.multiply(dpc_result_tb8, alphaMask, dpc_result_tb8);

    if (!mDataset.USE_COLOR_DPC) {
        Imgproc.cvtColor(dpc_result_lr8, dpc_result_lr8, Imgproc.COLOR_BGR2GRAY);
        Imgproc.cvtColor(dpc_result_tb8, dpc_result_tb8, Imgproc.COLOR_BGR2GRAY);
    }

    /*
    // Cut off edges in DPC images
    Point centerPt = new Point();
    centerPt.x = Math.round((float)width/2.0);
    centerPt.y = Math.round((float)height/2.0);
    Mat circleMat = new Mat(dpc_result_lr8.size(), dpc_result_lr8.type());
    Scalar color = new Scalar(255);
    Core.circle(circleMat, centerPt, 200, color);
    //Core.bitwise_and(circleMat, dpc_result_lr8, dpc_result_lr8);
    //Core.bitwise_and(circleMat, dpc_result_tb8, dpc_result_tb8);
    * 
    * 
    */

    Bitmap[] outputBitmaps = new Bitmap[3];
    outputBitmaps[0] = ImageUtils.toBitmap(result8);
    outputBitmaps[1] = ImageUtils.toBitmap(dpc_result_lr8);
    outputBitmaps[2] = ImageUtils.toBitmap(dpc_result_tb8);

    return outputBitmaps;
}

From source file:ctPrincipal.Operacoes.java

String realizarOperacoes(int op) {
    String resultImgOutput = "";
    switch (op) {
    case 1://and
        imagemBinaria();/* ww w .j  a  v a  2 s  .c om*/
        Core.bitwise_and(image1bin, image2bin, output);
        normalizarBinario();
        Imgcodecs.imwrite("OutputImg/and.jpg", output);
        resultImgOutput = "OutputImg/and.jpg";
        break;
    case 2://or
        imagemBinaria();
        Core.bitwise_or(image1bin, image2bin, output);
        normalizarBinario();
        Imgcodecs.imwrite("OutputImg/or.jpg", output);
        resultImgOutput = "OutputImg/or.jpg";
        break;
    case 3://xor
        imagemBinaria();
        Core.bitwise_xor(image1bin, image2bin, output);
        normalizarBinario();
        Imgcodecs.imwrite("OutputImg/xor.jpg", output);
        resultImgOutput = "OutputImg/xor.jpg";
        break;
    case 4://not
        Core.bitwise_not(image1bin, output);
        Imgcodecs.imwrite("OutputImg/not.jpg", output);
        resultImgOutput = "OutputImg/not.jpg";
        break;
    case 5://soma
        Core.add(image1, image2, output);
        Imgcodecs.imwrite("OutputImg/soma.jpg", output);
        resultImgOutput = "OutputImg/soma.jpg";
        break;
    case 6://subtracao
        Core.subtract(image1, image2, output);
        Imgcodecs.imwrite("OutputImg/subtracao.jpg", output);
        resultImgOutput = "OutputImg/subtracao.jpg";
        break;
    case 7:// multiplicacao
        Core.multiply(image1, image2, output);
        Imgcodecs.imwrite("OutputImg/multiplicacao.jpg", output);
        resultImgOutput = "OutputImg/multiplicacao.jpg";
        break;
    case 8://divisao
        Core.divide(image1, image2, output);
        Imgcodecs.imwrite("OutputImg/divisao.jpg", output);
        resultImgOutput = "OutputImg/divisao.jpg";
        break;
    }

    return resultImgOutput;
}

From source file:cx.uni.jk.mms.iaip.brush.BrushModel.java

License:Open Source License

private void updateValueMat() {
    this.valueMat = Mat.zeros(this.size, this.size, MatModel.MAT_TYPE);
    Core.add(this.valueMat, new Scalar(this.value), this.valueMat);
}

From source file:cx.uni.jk.mms.iaip.brush.BrushModel.java

License:Open Source License

private void updateAlphaMat() {
    this.alphaMat = Mat.zeros(this.size, this.size, MatModel.MAT_TYPE);
    switch (this.shape) {
    case SQUARE:/*from w ww . j a v  a  2  s  .com*/
        Core.add(this.alphaMat, new Scalar(1.0f), this.alphaMat);
        break;
    case CIRCLE:
        Core.circle(this.alphaMat, new Point((this.size - 1) * 0.5d, (this.size - 1) * 0.5d),
                (this.size - 1) / 2, new Scalar(1.0f), -1);
        break;
    case SOFT_CIRCLE: {
        Mat temp = this.alphaMat.clone();
        Core.circle(temp, new Point((this.size - 1) * 0.5d, (this.size - 1) * 0.5d), (this.size - 1) / 4,
                new Scalar(1.0f), -1);
        Imgproc.blur(temp, this.alphaMat, new Size(this.size * 0.5d, this.size * 0.5d));
    }
        break;
    default:
        /** this must not happen, die */
        throw new RuntimeException("unexpected BrushModel.Shape = " + this.shape);
    }
}

From source file:cx.uni.jk.mms.iaip.filter.LogOfOnePlusAbs.java

License:Open Source License

@Override
public Mat convert(Mat mat) {

    /** make absolute values and log */
    Mat tempMat = mat.clone();//  w w  w . ja v  a 2s  . com
    Core.absdiff(tempMat, new Scalar(0.0d), tempMat);
    Core.add(tempMat, new Scalar(1.0d), tempMat);
    Core.log(tempMat, tempMat);

    /** find contrast and brightness to fit into 8 bit */
    MinMaxLocResult mmlr = Core.minMaxLoc(tempMat);
    double min = Math.min(mmlr.minVal, 0);
    double max = mmlr.maxVal;
    double alpha = 256.0d / (max - min);
    double beta = -min * alpha;

    /** conversion to 8 bit Mat applying contrast alpha and brightness beta */
    Mat byteMat = new MatOfByte();
    tempMat.convertTo(byteMat, CvType.CV_8U, alpha, beta);

    return byteMat;
}