Java Code Examples for org.opencv.core.CvType.CV_8UC3

The following are Jave code examples for showing how to use CV_8UC3 of the org.opencv.core.CvType class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: fingerblox   File: ImageProcessing.java   View Source Code Vote up 7 votes
private Mat bytesToMat(byte[] data) {
    // Scale down the image for performance
    Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
    int targetWidth = 1200;
    if (bmp.getWidth() > targetWidth) {
        float scaleDownFactor = (float)targetWidth / bmp.getWidth();
        bmp = Bitmap.createScaledBitmap(bmp,
                (int)(bmp.getWidth()*scaleDownFactor),
                (int)(bmp.getHeight()*scaleDownFactor),
                true);
    }
    Mat BGRImage = new Mat (bmp.getWidth(), bmp.getHeight(), CvType.CV_8UC3);
    Utils.bitmapToMat(bmp, BGRImage);

    return BGRImage;
}
 
Example 2
Project: Face-detection-and-recognition-desktop-application   File: FaceRecognizeFrame.java   View Source Code Vote up 6 votes
private Mat conv_Mat(BufferedImage img) {
    byte[] data = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
    Mat mat = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3);
    mat.put(0, 0, data);
    Mat mat1 = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3);
    Imgproc.cvtColor(mat, mat1, Imgproc.COLOR_RGB2HSV);

    return mat1;
}
 
Example 3
Project: Face-detection-and-recognition-desktop-application   File: FaceDetectCropTest.java   View Source Code Vote up 6 votes
private Mat conv_Mat(BufferedImage img) {
    byte[] data = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
    Mat mat = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3);
    mat.put(0, 0, data);
    Mat mat1 = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3);
    Imgproc.cvtColor(mat, mat1, Imgproc.COLOR_RGB2HSV);

    return mat1;
}
 
Example 4
Project: SudoCAM-Ku   File: CameraView.java   View Source Code Vote up 6 votes
@Override
public void onPictureTaken(byte[] data, Camera camera) {
    Log.i(TAG, "Saving a bitmap to file");
    // The camera preview was automatically stopped. Start it again.
    mCamera.startPreview();
    mCamera.setPreviewCallback(this);

    // Write the image in a file (in jpeg format)
    try {
        /*FileOutputStream fos = new FileOutputStream(mPictureFileName);

        fos.write(data);
        fos.close();*/

        Bitmap bmp = BitmapFactory.decodeByteArray(data , 0, data.length);
        Mat orig = new Mat(bmp.getHeight(),bmp.getWidth(),CvType.CV_8UC3);
        Bitmap myBitmap32 = bmp.copy(Bitmap.Config.ARGB_8888, true);
        Utils.bitmapToMat(myBitmap32, orig);
        mImage = new Mat();
        Imgproc.cvtColor(orig,mImage,Imgproc.COLOR_RGB2GRAY);
        /*Imgproc.cvtColor(orig, orig, Imgproc.COLOR_BGR2RGB,4);
        Mat frame = new Mat(mFrameHeight+mFrameHeight/2,mFrameWidth, CvType.CV_8UC1);
        frame.put(0,0,data);
        //Imgcodecs.imdecode(frame,0);
        Imgproc.cvtColor(frame,mImage,Imgproc.COLOR_YUV2RGBA_NV21);//frame.submat(0, mFrameHeight, 0, mFrameWidth);*/

    } catch (Exception e) {
        Log.e("PictureDemo", "Exception in photoCallback", e);
    }

}
 
Example 5
Project: AquamarineLake   File: CVUtility.java   View Source Code Vote up 6 votes
public static Scalar hsvToBgrScalar(Scalar hsvin)
{
    Mat bgr = new Mat();
    Mat hsv = new Mat(1, 1, CvType.CV_8UC3, hsvin);
    Imgproc.cvtColor(hsv, bgr, Imgproc.COLOR_HSV2BGR);
    byte[] bgr_data = new byte[(int)(bgr.total() * bgr.channels())];
    bgr.get(0,0, bgr_data);
    return new Scalar(bgr_data[0], bgr_data[1], bgr_data[2]);
}
 
Example 6
Project: FlashLib   File: CvProcessing.java   View Source Code Vote up 6 votes
/**
 * Converts a mat to gray.
 * @param mat a mat to convert
 * @param gray a mat to fill with gray data
 * @return the gray mat 
 * @see Imgproc#cvtColor(Mat, Mat, int)
 */
public static Mat rgbToGray(Mat mat, Mat gray){
	if(mat.type() == CvType.CV_8UC1)
		mat.copyTo(gray);
	else if(mat.type() == CvType.CV_8UC3)
		Imgproc.cvtColor(mat, gray, Imgproc.COLOR_RGB2GRAY);
	return gray;
}
 
Example 7
Project: FlashLib   File: CvProcessing.java   View Source Code Vote up 6 votes
/**
 * Converts a buffered image object in to an openCV mat.
 * @param image buffered image
 * @return mat
 */
public static Mat bufferedImage2Mat(BufferedImage image){
	byte[] data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();  		  
	Mat mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC3);  		  
	mat.put(0, 0, data);  		  		  
	return mat;  
}
 
Example 8
Project: kronometer   File: Utility.java   View Source Code Vote up 5 votes
public Mat bufferedImageToMat(BufferedImage bi) {
    Mat mat = new Mat(bi.getHeight(), bi.getWidth(), CvType.CV_8UC3);
    byte[] data = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData();
    mat.put(0, 0, data);
    return mat;
}
 
Example 9
Project: pdi   File: ImgWindow.java   View Source Code Vote up 5 votes
public Mat createBuffer() {
    return new Mat(getHeight(), getWidth(), CvType.CV_8UC3);
}