當前位置: 首頁>>代碼示例>>Java>>正文


Java Mat.elemSize方法代碼示例

本文整理匯總了Java中org.opencv.core.Mat.elemSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Mat.elemSize方法的具體用法?Java Mat.elemSize怎麽用?Java Mat.elemSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.opencv.core.Mat的用法示例。


在下文中一共展示了Mat.elemSize方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: mat2BI

import org.opencv.core.Mat; //導入方法依賴的package包/類
public static BufferedImage mat2BI(Mat matrix) {
	final int cols = matrix.cols();
	final int rows = matrix.rows();
	final int elemSize = (int) matrix.elemSize();
	final byte[] data = new byte[cols * rows * elemSize];
	int type;
	matrix.get(0, 0, data);
	switch (matrix.channels()) {
	case 1:
		type = BufferedImage.TYPE_BYTE_GRAY;
		break;
	case 3:
		type = BufferedImage.TYPE_3BYTE_BGR;
		// bgr to rgb
		byte b;
		for (int i = 0; i < data.length; i = i + 3) {
			b = data[i];
			data[i] = data[i + 2];
			data[i + 2] = b;
		}
		break;
	default:
		return null;
	}
	final BufferedImage image2 = new BufferedImage(cols, rows, type);
	image2.getRaster().setDataElements(0, 0, cols, rows, data);
	return image2;
}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:29,代碼來源:Mat2BufferedImage.java

示例2: getRaster

import org.opencv.core.Mat; //導入方法依賴的package包/類
public static byte[] getRaster(Mat input) {
	final Mat gray = new Mat();
	Imgproc.cvtColor(input, gray, Imgproc.COLOR_RGB2GRAY);
	final int cols = gray.cols();
	final int rows = gray.rows();
	final int elemSize = (int) gray.elemSize();
	final byte[] data = new byte[cols * rows * elemSize];
	gray.get(0, 0, data);

	return data;
}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:12,代碼來源:GetPixelArray.java

示例3: matToJson

import org.opencv.core.Mat; //導入方法依賴的package包/類
public static String matToJson(Mat mat){        
        JsonObject obj = new JsonObject();

        if(mat.isContinuous()){
            int cols = mat.cols();
            int rows = mat.rows();
            int elemSize = (int) mat.elemSize();    

            byte[] data = new byte[cols * rows * elemSize];

            mat.get(0, 0, data);

            obj.addProperty("rows", mat.rows()); 
            obj.addProperty("cols", mat.cols()); 
            obj.addProperty("type", mat.type());

            // We cannot set binary data to a json object, so:
            // Encoding data byte array to Base64.
            String dataString = DatatypeConverter.printBase64Binary(data);
//            String dataString = new String(Base64.encode(data, Base64.DEFAULT));

            obj.addProperty("data", dataString);            

            Gson gson = new Gson();
            String json = gson.toJson(obj);

            return json;
        } else {
            System.err.println("mat not continuous");
        }
        return "{}";
    }
 
開發者ID:fossasia,項目名稱:zooracle,代碼行數:33,代碼來源:OpenCVUtils.java

示例4: matToBufferedImage

import org.opencv.core.Mat; //導入方法依賴的package包/類
public static BufferedImage matToBufferedImage(Mat matrix) {
    int cols = matrix.cols();
    int rows = matrix.rows();
    int elemSize = (int) matrix.elemSize();
    byte[] data = new byte[cols * rows * elemSize];
    int type;
    matrix.get(0, 0, data);
    switch (matrix.channels()) {
        case 1:
            type = BufferedImage.TYPE_BYTE_GRAY;
            break;
        case 3:
            type = BufferedImage.TYPE_3BYTE_BGR;
            // bgr to rgb  
            byte b;
            for (int i = 0; i < data.length; i = i + 3) {
                b = data[i];
                data[i] = data[i + 2];
                data[i + 2] = b;
            }
            break;
        default:
            return null;
    }
    BufferedImage bimg = new BufferedImage(cols, rows, type);
    bimg.getRaster().setDataElements(0, 0, cols, rows, data);
    return bimg;
}
 
開發者ID:lupino22,項目名稱:kronometer,代碼行數:29,代碼來源:Utility.java

示例5: matToJSON

import org.opencv.core.Mat; //導入方法依賴的package包/類
public static String matToJSON(Mat mat){
    JsonObject obj = new JsonObject();

    int cols = mat.cols();
    int rows = mat.rows();
    int elemSize = (int) mat.elemSize();

    byte[] data = new byte[cols * rows * elemSize];

    mat.get(0, 0, data);

    obj.addProperty("rows", mat.rows());
    obj.addProperty("cols", mat.cols());
    obj.addProperty("type", mat.type());

    String dataString = new String(Base64.encode(data, Base64.DEFAULT));

    obj.addProperty("data", dataString);

    Gson gson = new Gson();

    return gson.toJson(obj);
}
 
開發者ID:jorenham,項目名稱:fingerblox,代碼行數:24,代碼來源:ImageDisplayActivity.java

示例6: matToBufferedImage

import org.opencv.core.Mat; //導入方法依賴的package包/類
public static BufferedImage matToBufferedImage(Mat matrix) {
    if (matrix.channels() == 1) {
        int cols = matrix.cols();
        int rows = matrix.rows();
        int elemSize = (int) matrix.elemSize();
        byte[] data = new byte[cols * rows * elemSize];
        int type;
        matrix.get(0, 0, data);
        switch (matrix.channels()) {
            case 1:
                type = BufferedImage.TYPE_BYTE_GRAY;
                break;
            case 3:
                type = BufferedImage.TYPE_3BYTE_BGR;
                // bgr to rgb
                byte b;
                for (int i = 0; i < data.length; i = i + 3) {
                    b = data[i];
                    data[i] = data[i + 2];
                    data[i + 2] = b;
                }
                break;
            default:
                return null;
        }

        BufferedImage image2 = new BufferedImage(cols, rows, type);
        image2.getRaster().setDataElements(0, 0, cols, rows, data);
        return image2;
    }

    if (matrix.channels() == 3) {
        int width = matrix.width(), height = matrix.height(), channels = matrix.channels();
        byte[] sourcePixels = new byte[width * height * channels];
        matrix.get(0, 0, sourcePixels);
        // create new image and get reference to backing data
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
        final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
        System.arraycopy(sourcePixels, 0, targetPixels, 0, sourcePixels.length);
        return image;
    }

    return null;
}
 
開發者ID:nbfontana,項目名稱:pdi,代碼行數:45,代碼來源:ImgWindow.java


注:本文中的org.opencv.core.Mat.elemSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。