Example usage for org.opencv.core Mat total

List of usage examples for org.opencv.core Mat total

Introduction

In this page you can find the example usage for org.opencv.core Mat total.

Prototype

public long total() 

Source Link

Usage

From source file:syncleus.dann.data.video.TLDUtil.java

License:Apache License

public static int[] getIntArray(final Mat mat) {
    if (CvType.CV_32SC1 != mat.type())
        throw new IllegalArgumentException(
                "Expected type is CV_32SC1, we found: " + CvType.typeToString(mat.type()));

    final int size = (int) (mat.total() * mat.channels());
    if (_intBuff.length != size) {
        _intBuff = new int[size];
    }//  w  ww. j  av  a2 s.com
    mat.get(0, 0, _intBuff); // 0 for row and col means the WHOLE Matrix
    return _intBuff;
}

From source file:syncleus.dann.data.video.TLDUtil.java

License:Apache License

public static float[] getFloatArray(final Mat mat) {
    if (CvType.CV_32FC1 != mat.type())
        throw new IllegalArgumentException(
                "Expected type is CV_32FC1, we found: " + CvType.typeToString(mat.type()));

    final int size = (int) (mat.total() * mat.channels());
    if (_floatBuff.length != size) {
        _floatBuff = new float[size];
    }/*from  w  w  w.  jav  a2s .  c  om*/
    mat.get(0, 0, _floatBuff); // 0 for row and col means the WHOLE Matrix
    return _floatBuff;
}

From source file:syncleus.dann.data.video.TLDUtil.java

License:Apache License

public static double[] getDoubleArray(final Mat mat) {
    if (CvType.CV_64F != mat.type())
        throw new IllegalArgumentException(
                "Expected type is CV_64F, we found: " + CvType.typeToString(mat.type()));

    final int size = (int) (mat.total() * mat.channels());
    if (_doubleBuff.length != size) {
        _doubleBuff = new double[size];
    }/*ww  w.java  2s .  c  o  m*/
    mat.get(0, 0, _doubleBuff); // 0 for row and col means the WHOLE Matrix
    return _doubleBuff;
}

From source file:TarHadoop.TarToSeqFile.java

License:Apache License

/** Performs the conversion. */
public void execute(String inputFolder) throws Exception {
    SequenceFile.Writer output = null;
    try {//from w  ww  .  j  a va  2s .  c o m
        output = openOutputFile();
        DirectoryStructure obj = new DirectoryStructure();
        List<String> listOfImgPath = obj.getAllImgPaths(inputFolder);
        int i = 0;
        //String prevName="";
        //String value="";
        Text key = new Text();
        for (Iterator<String> iterator = listOfImgPath.iterator(); iterator.hasNext();) {
            String imgPath = (String) iterator.next();

            Mat img1 = Highgui.imread(imgPath);

            String[] tokens = imgPath.split("/");
            String currName = tokens[tokens.length - 2];
            System.out.println(i + " of imgPath = " + currName + "   " + listOfImgPath.size());

            byte[] data = new byte[(int) img1.total() * (int) img1.elemSize()];
            img1.get(0, 0, data);

            key = new Text(currName + "," + img1.rows() + "," + img1.cols());
            BytesWritable value = new BytesWritable(data);
            output.append(key, value);

            /*if(i==0)
               prevName=currName;
            if(currName.compareTo(prevName)==0){
               byte[] data=new byte[(int)img1.total()*(int)img1.elemSize()];
               img1.get(0,0,data);
               String x=new String(data,"UTF-8");
               value+=x+"###";
            }
            else{
               key=new Text(imgPath+","+img1.rows()+","+img1.cols());
               hadoopvalue=new Text(value);
               output.append(key, hadoopvalue);
               prevName=currName;
               value="";
            }*/
            ++i;
        }
    } finally {
        //if (input != null) { input.close(); }
        if (output != null) {
            output.close();
        }
    }
}

From source file:uk.ac.horizon.artcodes.process.WhiteBalanceImageProcessor.java

License:Open Source License

@Override
public void process(ImageBuffers buffers) {
    Mat image = buffers.getImageInBgr();
    if (this.histograms == null) {
        this.setup();
    }//from  w  ww.  j a  v  a2 s . co m
    List<Mat> listOfMat = new ArrayList<>();
    listOfMat.add(image);

    // create a histogram for each channel:
    // (oddly it seems ~10x faster to do 3 channels separately rather than all 3 in one calcHist call)
    for (int channel = 0; channel < image.channels(); ++channel) {
        Imgproc.calcHist(listOfMat, channels[channel], emptyMatMask, histograms[channel], size, range);
    }

    float[] a = new float[image.channels()];
    float[] b = new float[image.channels()];

    final int desiredHistogramBufferSize = histograms[0].rows() * histograms[0].cols()
            * histograms[0].channels();
    float[] pixelHistogramBuffer = new float[desiredHistogramBufferSize];

    // get the values to remap the histograms:
    for (int channel = 0; channel < image.channels(); ++channel) {
        histograms[channel].get(0, 0, pixelHistogramBuffer);
        getHistogramRemap(pixelHistogramBuffer, desiredHistogramBufferSize, image.total(), a, channel, b,
                channel);
    }

    // Use a Look Up Table to re-map values
    // (it's a lot faster to workout and save what the 256 possible values transform into
    // than to do the math image.cols*rows times)

    if (lut == null) {
        lut = new Mat(1, 256, CvType.CV_8UC3);
    }
    final int lutSize = lut.cols() * lut.rows() * lut.channels();
    int lutIndex = -1;
    if (lutBufferArray == null || lutBufferArray.length != lutSize) {
        lutBufferArray = new byte[lutSize];
    }
    for (int i = 0; i < 256; ++i) {
        for (int channel = 0; channel < image.channels(); ++channel) {
            lutBufferArray[++lutIndex] = (byte) Math.min(Math.max(a[channel] * ((i) - b[channel]), 0), 255);
        }
    }
    lut.put(0, 0, lutBufferArray);
    Core.LUT(image, lut, image);
    buffers.setImage(image);
}