Java Code Examples for org.opencv.core.Mat#cols()

The following examples show how to use org.opencv.core.Mat#cols() . 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: Converters.java    From opencv-documentscanner-android with Apache License 2.0 6 votes vote down vote up
public static void Mat_to_vector_KeyPoint(Mat m, List<KeyPoint> kps) {
    if (kps == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC(7) != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC(7) != m.type() ||  m.cols()!=1\n" + m);

    kps.clear();
    double[] buff = new double[7 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        kps.add(new KeyPoint((float) buff[7 * i], (float) buff[7 * i + 1], (float) buff[7 * i + 2], (float) buff[7 * i + 3],
                (float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6]));
    }
}
 
Example 2
Source File: Converters.java    From react-native-documentscanner-android with MIT License 6 votes vote down vote up
public static void Mat_to_vector_Mat(Mat m, List<Mat> mats) {
    if (mats == null)
        throw new java.lang.IllegalArgumentException("mats == null");
    int count = m.rows();
    if (CvType.CV_32SC2 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC2 != m.type() ||  m.cols()!=1\n" + m);

    mats.clear();
    int[] buff = new int[count * 2];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        long addr = (((long) buff[i * 2]) << 32) | (((long) buff[i * 2 + 1]) & 0xffffffffL);
        mats.add(new Mat(addr));
    }
}
 
Example 3
Source File: Converters.java    From FtcSamples with MIT License 6 votes vote down vote up
public static void Mat_to_vector_Mat(Mat m, List<Mat> mats) {
    if (mats == null)
        throw new java.lang.IllegalArgumentException("mats == null");
    int count = m.rows();
    if (CvType.CV_32SC2 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC2 != m.type() ||  m.cols()!=1\n" + m);

    mats.clear();
    int[] buff = new int[count * 2];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        long addr = (((long) buff[i * 2]) << 32) | (((long) buff[i * 2 + 1]) & 0xffffffffL);
        mats.add(new Mat(addr));
    }
}
 
Example 4
Source File: Converters.java    From Form-N-Fun with MIT License 6 votes vote down vote up
public static void Mat_to_vector_KeyPoint(Mat m, List<KeyPoint> kps) {
    if (kps == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC(7) != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC(7) != m.type() ||  m.cols()!=1\n" + m);

    kps.clear();
    double[] buff = new double[7 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        kps.add(new KeyPoint((float) buff[7 * i], (float) buff[7 * i + 1], (float) buff[7 * i + 2], (float) buff[7 * i + 3],
                (float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6]));
    }
}
 
Example 5
Source File: Converters.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 5 votes vote down vote up
public static void Mat_to_vector_double(Mat m, List<Double> ds) {
    if (ds == null)
        throw new java.lang.IllegalArgumentException("ds == null");
    int count = m.rows();
    if (CvType.CV_64FC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC1 != m.type() ||  m.cols()!=1\n" + m);

    ds.clear();
    double[] buff = new double[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        ds.add(buff[i]);
    }
}
 
Example 6
Source File: Converters.java    From real_time_circle_detection_android with MIT License 5 votes vote down vote up
public static void Mat_to_vector_float(Mat m, List<Float> fs) {
    if (fs == null)
        throw new java.lang.IllegalArgumentException("fs == null");
    int count = m.rows();
    if (CvType.CV_32FC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32FC1 != m.type() ||  m.cols()!=1\n" + m);

    fs.clear();
    float[] buff = new float[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        fs.add(buff[i]);
    }
}
 
Example 7
Source File: Converters.java    From MOAAP with MIT License 5 votes vote down vote up
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
    if (matches == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC4 != m.type() ||  m.cols()!=1\n" + m);

    matches.clear();
    double[] buff = new double[4 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
    }
}
 
Example 8
Source File: ContoursFinder.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Mat process(@NonNull Mat frame) {
    if (frame.empty()) {
        Log.e("Invalid input frame.");
        return null;
    }
    Mat tmp = frame.clone();
    // Finding outer contours
    contourList.clear();
    Imgproc.findContours(tmp, contourList, hierarchy,
            Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
    // Filter bees
    Mat contours = new Mat(tmp.rows(), tmp.cols(), CvType.CV_8UC3);
    tmp.release();
    double area;
    Scalar color;
    numBees = 0;
    for (int i = 0; i < contourList.size(); i++) {
        area = Imgproc.contourArea(contourList.get(i));
        if (area > minArea && area < maxArea) {
            color = GREEN;
            numBees++;
        } else {
            color = RED;
        }
        // Draw contour
        Imgproc.drawContours(contours, contourList, i, color, -1);
    }
    return contours;
}
 
Example 9
Source File: Converters.java    From LicensePlateDiscern with MIT License 5 votes vote down vote up
public static void Mat_to_vector_RotatedRect(Mat m, List<RotatedRect> rs) {
    if (rs == null)
        throw new java.lang.IllegalArgumentException("rs == null");
    int count = m.rows();
    if (CvType.CV_32FC(5) != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32FC5 != m.type() ||  m.rows()!=1\n" + m);

    rs.clear();
    float[] buff = new float[5 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        rs.add(new RotatedRect(new Point(buff[5 * i], buff[5 * i + 1]), new Size(buff[5 * i + 2], buff[5 * i + 3]), buff[5 * i + 4]));
    }
}
 
Example 10
Source File: Converters.java    From MOAAP with MIT License 5 votes vote down vote up
public static void Mat_to_vector_uchar(Mat m, List<Byte> us) {
    if (us == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_8UC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_8UC1 != m.type() ||  m.cols()!=1\n" + m);

    us.clear();
    byte[] buff = new byte[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        us.add(buff[i]);
    }
}
 
Example 11
Source File: Converters.java    From opencv-documentscanner-android with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_float(Mat m, List<Float> fs) {
    if (fs == null)
        throw new java.lang.IllegalArgumentException("fs == null");
    int count = m.rows();
    if (CvType.CV_32FC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32FC1 != m.type() ||  m.cols()!=1\n" + m);

    fs.clear();
    float[] buff = new float[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        fs.add(buff[i]);
    }
}
 
Example 12
Source File: Converters.java    From SmartPaperScan with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_double(Mat m, List<Double> ds) {
    if (ds == null)
        throw new java.lang.IllegalArgumentException("ds == null");
    int count = m.rows();
    if (CvType.CV_64FC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC1 != m.type() ||  m.cols()!=1\n" + m);

    ds.clear();
    double[] buff = new double[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        ds.add(buff[i]);
    }
}
 
Example 13
Source File: Converters.java    From VIA-AI with MIT License 5 votes vote down vote up
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
    if (matches == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC4 != m.type() ||  m.cols()!=1\n" + m);

    matches.clear();
    double[] buff = new double[4 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
    }
}
 
Example 14
Source File: MainActivity.java    From MOAAP with MIT License 5 votes vote down vote up
void HoughCircles() {
    Mat grayMat = new Mat();
    Mat cannyEdges = new Mat();
    Mat circles = new Mat();

    //Converting the image to grayscale
    Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);

    Imgproc.Canny(grayMat, cannyEdges, 10, 100);

    Imgproc.HoughCircles(cannyEdges, circles, Imgproc.CV_HOUGH_GRADIENT, 1, cannyEdges.rows() / 15);//, grayMat.rows() / 8);

    Mat houghCircles = new Mat();
    houghCircles.create(cannyEdges.rows(), cannyEdges.cols(), CvType.CV_8UC1);

    //Drawing lines on the image
    for (int i = 0; i < circles.cols(); i++) {
        double[] parameters = circles.get(0, i);
        double x, y;
        int r;

        x = parameters[0];
        y = parameters[1];
        r = (int) parameters[2];

        Point center = new Point(x, y);

        //Drawing circles on an image
        Imgproc.circle(houghCircles, center, r, new Scalar(255, 0, 0), 1);
    }

    //Converting Mat back to Bitmap
    Utils.matToBitmap(houghCircles, currentBitmap);
    imageView.setImageBitmap(currentBitmap);
}
 
Example 15
Source File: Converters.java    From sudokufx with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_uchar(Mat m, List<Byte> us) {
    if (us == null)
        throw new IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_8UC1 != m.type() || m.cols() != 1)
        throw new IllegalArgumentException(
                "CvType.CV_8UC1 != m.type() ||  m.cols()!=1\n" + m);

    us.clear();
    byte[] buff = new byte[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        us.add(buff[i]);
    }
}
 
Example 16
Source File: Converters.java    From MOAAP with MIT License 5 votes vote down vote up
public static void Mat_to_vector_uchar(Mat m, List<Byte> us) {
    if (us == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_8UC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_8UC1 != m.type() ||  m.cols()!=1\n" + m);

    us.clear();
    byte[] buff = new byte[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        us.add(buff[i]);
    }
}
 
Example 17
Source File: Converters.java    From sudokufx with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_double(Mat m, List<Double> ds) {
    if (ds == null)
        throw new IllegalArgumentException("ds == null");
    int count = m.rows();
    if (CvType.CV_64FC1 != m.type() || m.cols() != 1)
        throw new IllegalArgumentException(
                "CvType.CV_64FC1 != m.type() ||  m.cols()!=1\n" + m);

    ds.clear();
    double[] buff = new double[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        ds.add(buff[i]);
    }
}
 
Example 18
Source File: Converters.java    From PixaToon with GNU General Public License v3.0 5 votes vote down vote up
public static void Mat_to_vector_double(Mat m, List<Double> ds) {
    if (ds == null)
        throw new java.lang.IllegalArgumentException("ds == null");
    int count = m.rows();
    if (CvType.CV_64FC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC1 != m.type() ||  m.cols()!=1\n" + m);

    ds.clear();
    double[] buff = new double[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        ds.add(buff[i]);
    }
}
 
Example 19
Source File: Converters.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_float(Mat m, List<Float> fs) {
    if (fs == null)
        throw new java.lang.IllegalArgumentException("fs == null");
    int count = m.rows();
    if (CvType.CV_32FC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32FC1 != m.type() ||  m.cols()!=1\n" + m);

    fs.clear();
    float[] buff = new float[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        fs.add(buff[i]);
    }
}
 
Example 20
Source File: DctConverter.java    From BlindWatermark with Apache License 2.0 5 votes vote down vote up
@Override
public void addImageWatermark(Mat com, Mat watermark) {
    Mat mask = new Mat();
    inRange(watermark, new Scalar(0, 0, 0, 0), new Scalar(0, 0, 0, 0), mask);
    Mat i2 = new Mat(watermark.size(), watermark.type(), new Scalar(2, 2, 2, 0));
    i2.copyTo(watermark, mask);
    watermark.convertTo(watermark, CV_32F);
    int row = (com.rows() - watermark.rows()) >> 1;
    int col = (com.cols() - watermark.cols()) >> 1;
    copyMakeBorder(watermark, watermark, row, row, col, col, BORDER_CONSTANT, Scalar.all(0));
    Utils.fixSize(watermark, com);
    addWeighted(watermark, 0.03, com, 1, 0.0, com);
}