Example usage for org.opencv.core CvType CV_8UC1

List of usage examples for org.opencv.core CvType CV_8UC1

Introduction

In this page you can find the example usage for org.opencv.core CvType CV_8UC1.

Prototype

int CV_8UC1

To view the source code for org.opencv.core CvType CV_8UC1.

Click Source Link

Usage

From source file:OCV_Canny.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    // srcdst//from www  . j a v a  2s  .co  m
    int imw = ip.getWidth();
    int imh = ip.getHeight();
    byte[] srcdst_bytes = (byte[]) ip.getPixels();

    // mat
    Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
    Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1);

    // run
    src_mat.put(0, 0, srcdst_bytes);
    Imgproc.Canny(src_mat, dst_mat, thr1, thr2, SIZE_VAL[ind_size], l2grad);
    dst_mat.get(0, 0, srcdst_bytes);
}

From source file:OCV_Threshold.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    int imw = ip.getWidth();
    int imh = ip.getHeight();

    if (ip.getBitDepth() == 8) {
        // srcdst
        byte[] srcdst_bytes = (byte[]) ip.getPixels();

        // mat//from w  w w  .  j  a  v a 2 s .  c om
        Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1);

        // run
        src_mat.put(0, 0, srcdst_bytes);
        Imgproc.threshold(src_mat, dst_mat, thresh, maxVal, INT_TYPE[idxType]);
        dst_mat.get(0, 0, srcdst_bytes);
    } else if (ip.getBitDepth() == 32) {
        // srcdst
        float[] srcdst_floats = (float[]) ip.getPixels();

        // mat
        Mat src_mat = new Mat(imh, imw, CvType.CV_32F);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_32F);

        // run
        src_mat.put(0, 0, srcdst_floats);
        Imgproc.threshold(src_mat, dst_mat, thresh, maxVal, INT_TYPE[idxType]);
        dst_mat.get(0, 0, srcdst_floats);
    } else {
        IJ.error("Wrong image format");
    }
}

From source file:OCV_MatchTemplate.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    // src/*from  ww  w.j a v  a 2s  .  co  m*/
    byte[] arr_src = (byte[]) imp_src.getChannelProcessor().getPixels();
    int imw_src = imp_src.getWidth();
    int imh_src = imp_src.getHeight();
    Mat mat_src = new Mat(imh_src, imw_src, CvType.CV_8UC1);
    mat_src.put(0, 0, arr_src);

    // tmp
    byte[] arr_tmp = (byte[]) imp_tmp.getChannelProcessor().getPixels();
    int imw_tmp = imp_tmp.getWidth();
    int imh_tmp = imp_tmp.getHeight();
    Mat mat_tmp = new Mat(imh_tmp, imw_tmp, CvType.CV_8UC1);
    mat_tmp.put(0, 0, arr_tmp);

    // dst
    String title_dst = WindowManager.getUniqueName(title_src + "_MatchTemplate");
    int imw_dst = imw_src - imw_tmp + 1;
    int imh_dst = imh_src - imh_tmp + 1;
    ImagePlus imp_dst = new ImagePlus(title_dst, new FloatProcessor(imw_dst, imh_dst));
    float[] arr_dst = (float[]) imp_dst.getChannelProcessor().getPixels();
    Mat mat_dst = new Mat();

    // run
    Imgproc.matchTemplate(mat_src, mat_tmp, mat_dst, TYPE_VAL[ind_type]);
    mat_dst.get(0, 0, arr_dst);
    imp_dst.show();

    if (TYPE_VAL[ind_type] == Imgproc.TM_SQDIFF_NORMED) {
        substracted_from_one(arr_dst);
    }

    IJ.run(imp_dst, "Enhance Contrast", "saturated=0.35");

    // show data
    if (enResult) {
        if (enSearchMax) {
            showData_enSearchMaxPoint(imp_dst, thr_res, imw_tmp, imh_tmp);
        } else {
            showData(arr_dst, imw_dst, imh_dst, imw_tmp, imh_tmp);
        }
    }
}

From source file:OCV_WarpPerspective.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    int imw = ip.getWidth();
    int imh = ip.getHeight();
    Size size = new Size((double) imw, (double) imh);
    Mat mat = new Mat(3, 3, CvType.CV_64FC1);

    for (int i = 0; i < 3; i++) {
        mat.put(i, 0, new double[] { Double.valueOf(rt.getStringValue(0, i).replaceAll("\"|'", "")) });
        mat.put(i, 1, new double[] { Double.valueOf(rt.getStringValue(1, i).replaceAll("\"|'", "")) });
        mat.put(i, 2, new double[] { Double.valueOf(rt.getStringValue(2, i).replaceAll("\"|'", "")) });
    }//w w w.j  av  a 2 s  . c o m

    if (ip.getBitDepth() == 8) {
        byte[] srcdst_ar = (byte[]) ip.getPixels();
        Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1);

        src_mat.put(0, 0, srcdst_ar);
        Imgproc.warpPerspective(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]);
        dst_mat.get(0, 0, srcdst_ar);
    } else if (ip.getBitDepth() == 16) {
        short[] srcdst_ar = (short[]) ip.getPixels();
        Mat src_mat = new Mat(imh, imw, CvType.CV_16UC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_16UC1);

        src_mat.put(0, 0, srcdst_ar);
        Imgproc.warpPerspective(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]);
        dst_mat.get(0, 0, srcdst_ar);
    } else if (ip.getBitDepth() == 24) {
        int[] srcdst_ar = (int[]) ip.getPixels();
        Mat src_mat = new Mat(imh, imw, CvType.CV_8UC3);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC3);

        OCV__LoadLibrary.intarray2mat(srcdst_ar, src_mat, imw, imh);
        Imgproc.warpPerspective(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]);
        OCV__LoadLibrary.mat2intarray(dst_mat, srcdst_ar, imw, imh);
    } else if (ip.getBitDepth() == 32) {
        float[] srcdst_ar = (float[]) ip.getPixels();
        Mat src_mat = new Mat(imh, imw, CvType.CV_32FC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_32FC1);

        src_mat.put(0, 0, srcdst_ar);
        Imgproc.warpPerspective(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]);
        dst_mat.get(0, 0, srcdst_ar);
    } else {
        IJ.error("Wrong image format");
    }
}

From source file:OCV_ConnectedComponentsWithStats.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    // src//from w w  w.j  av  a  2  s  .  c o  m
    int imw = ip.getWidth();
    int imh = ip.getHeight();
    byte[] src_arr = (byte[]) ip.getPixels();
    Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);

    // dst
    String titleDst = WindowManager
            .getUniqueName(impSrc.getTitle() + "_Connect" + String.valueOf(TYPE_INT[type_ind]));
    ImagePlus impDst = new ImagePlus(titleDst, new FloatProcessor(imw, imh));
    float[] dst_arr = (float[]) impDst.getChannelProcessor().getPixels();
    Mat dst_mat_32s = new Mat(imh, imw, CvType.CV_32S);
    Mat dst_mat_32f = new Mat(imh, imw, CvType.CV_32F);
    Mat stats_mat = new Mat();
    Mat cens_mat = new Mat();

    // run
    src_mat.put(0, 0, src_arr);
    int output_con = Imgproc.connectedComponentsWithStats(src_mat, dst_mat_32s, stats_mat, cens_mat,
            TYPE_INT[type_ind], CvType.CV_32S);
    dst_mat_32s.convertTo(dst_mat_32f, CvType.CV_32F);
    dst_mat_32f.get(0, 0, dst_arr);

    // show data
    if (1 < output_con) {
        showData(dst_arr, imw, imh, output_con, stats_mat, cens_mat);
    }

    // finish
    if (1 < output_con && enOutImg) {
        impDst.show();
    } else {
        impDst.close();
    }
}

From source file:OCV_LinearPolar.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    // srcdst/*from  ww w .  j  av a2s.com*/
    int imw = ip.getWidth();
    int imh = ip.getHeight();
    byte[] srcdst_ar = (byte[]) ip.getPixels();

    // mat
    Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
    Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1);

    // run
    src_mat.put(0, 0, srcdst_ar);
    Imgproc.linearPolar(src_mat, dst_mat, new Point(cx, cy), (double) rmax, TYPE_INT[type_ind]);
    dst_mat.get(0, 0, srcdst_ar);
}

From source file:OCV_Sobel.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    if (ip.getBitDepth() == 8) {
        // srcdst
        int imw = ip.getWidth();
        int imh = ip.getHeight();
        byte[] srcdst_bytes = (byte[]) ip.getPixels();

        // mat/*from   www.j  a v a 2s.  c  o  m*/
        Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1);

        // run
        src_mat.put(0, 0, srcdst_bytes);
        Imgproc.Sobel(src_mat, dst_mat, src_mat.depth(), dx, dy, ksize, scale, delta,
                INT_BORDERTYPE[indBorderType]);
        dst_mat.get(0, 0, srcdst_bytes);
    } else if (ip.getBitDepth() == 16) {
        // srcdst
        int imw = ip.getWidth();
        int imh = ip.getHeight();
        short[] srcdst_shorts = (short[]) ip.getPixels();

        // mat
        Mat src_mat = new Mat(imh, imw, CvType.CV_16S);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_16S);

        // run
        src_mat.put(0, 0, srcdst_shorts);
        Imgproc.Sobel(src_mat, dst_mat, src_mat.depth(), dx, dy, ksize, scale, delta,
                INT_BORDERTYPE[indBorderType]);
        dst_mat.get(0, 0, srcdst_shorts);
    } else if (ip.getBitDepth() == 32) {
        // srcdst
        int imw = ip.getWidth();
        int imh = ip.getHeight();
        float[] srcdst_floats = (float[]) ip.getPixels();

        // mat
        Mat src_mat = new Mat(imh, imw, CvType.CV_32F);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_32F);

        // run
        src_mat.put(0, 0, srcdst_floats);
        Imgproc.Sobel(src_mat, dst_mat, src_mat.depth(), dx, dy, ksize, scale, delta,
                INT_BORDERTYPE[indBorderType]);
        dst_mat.get(0, 0, srcdst_floats);
    } else {
        IJ.error("Wrong image format");
    }
}

From source file:OCV_HoughLines.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    // src/*from   ww w  . j  a v a 2s .com*/
    int imw = ip.getWidth();
    int imh = ip.getHeight();
    byte[] src_ar = (byte[]) ip.getPixels();

    // mat
    Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
    Mat dst_lines = new Mat();

    // run
    src_mat.put(0, 0, src_ar);

    double resAng = CV_PI / resAngFact;
    double minTheta = CV_PI / 360.0 * minDeg;
    double maxTheta = CV_PI / 360.0 * maxDeg;
    Imgproc.HoughLines(src_mat, dst_lines, resDist, resAng, minVotes, divDist, divAng, minTheta, maxTheta);

    // fin
    showData(dst_lines, imw, imh);
}

From source file:OCV_AdaptiveThreshold.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    int imw = ip.getWidth();
    int imh = ip.getHeight();

    // srcdst//ww w  .  jav  a 2s .  co  m
    byte[] srcdst_ar = (byte[]) ip.getPixels();

    // mat
    Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
    Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1);

    // run
    src_mat.put(0, 0, srcdst_ar);
    Imgproc.adaptiveThreshold(src_mat, dst_mat, maxValue, INT_ADAPTIVEMETHOD[indMethod],
            INT_THRESHOLDTYPE[indType], blockSize, subC);
    dst_mat.get(0, 0, srcdst_ar);
}

From source file:OCV_WarpAffine.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    int imw = ip.getWidth();
    int imh = ip.getHeight();
    Size size = new Size((double) imw, (double) imh);
    Mat mat = new Mat(2, 3, CvType.CV_64FC1);

    for (int i = 0; i < 2; i++) {
        mat.put(i, 0, new double[] { Double.valueOf(rt.getStringValue(0, i).replaceAll("\"|'", "")) });
        mat.put(i, 1, new double[] { Double.valueOf(rt.getStringValue(1, i).replaceAll("\"|'", "")) });
        mat.put(i, 2, new double[] { Double.valueOf(rt.getStringValue(2, i).replaceAll("\"|'", "")) });
    }/*from   w  ww. ja v  a 2  s.  co  m*/

    if (ip.getBitDepth() == 8) {
        byte[] srcdst_ar = (byte[]) ip.getPixels();
        Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1);

        src_mat.put(0, 0, srcdst_ar);
        Imgproc.warpAffine(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]);
        dst_mat.get(0, 0, srcdst_ar);
    } else if (ip.getBitDepth() == 16) {
        short[] srcdst_ar = (short[]) ip.getPixels();
        Mat src_mat = new Mat(imh, imw, CvType.CV_16UC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_16UC1);

        src_mat.put(0, 0, srcdst_ar);
        Imgproc.warpAffine(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]);
        dst_mat.get(0, 0, srcdst_ar);
    } else if (ip.getBitDepth() == 24) {
        int[] srcdst_ar = (int[]) ip.getPixels();
        Mat src_mat = new Mat(imh, imw, CvType.CV_8UC3);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC3);

        OCV__LoadLibrary.intarray2mat(srcdst_ar, src_mat, imw, imh);
        Imgproc.warpAffine(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]);
        OCV__LoadLibrary.mat2intarray(dst_mat, srcdst_ar, imw, imh);
    } else if (ip.getBitDepth() == 32) {
        float[] srcdst_ar = (float[]) ip.getPixels();
        Mat src_mat = new Mat(imh, imw, CvType.CV_32FC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_32FC1);

        src_mat.put(0, 0, srcdst_ar);
        Imgproc.warpAffine(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]);
        dst_mat.get(0, 0, srcdst_ar);
    } else {
        IJ.error("Wrong image format");
    }
}