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

The following are Jave code examples for showing how to use CV_8UC4 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 6 votes
private Bitmap mat2Bitmap(Mat src, int code) {
    Mat rgbaMat = new Mat(src.width(), src.height(), CvType.CV_8UC4);
    Imgproc.cvtColor(src, rgbaMat, code, 4);
    Bitmap bmp = Bitmap.createBitmap(rgbaMat.cols(), rgbaMat.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(rgbaMat, bmp);
    return bmp;
}
 
Example 2
Project: Paper-Melody   File: ImageUtil.java   View Source Code Vote up 6 votes
public static Mat yuvToBgr(Image image, Mat yuvMat) {
    Mat bgrMat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC4);
    //Log.d("TESTCALL", bgrMat.rows() + " " + bgrMat.cols());
    Imgproc.cvtColor(yuvMat, bgrMat, Imgproc.COLOR_YUV2BGR_I420);
    //Log.d("TESTCALL", yuvMat.rows() + " " + yuvMat.cols());
    return bgrMat;
}
 
Example 3
Project: MOAAP   File: PyramidActivity.java   View Source Code Vote up 6 votes
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    switch(requestCode) {
        case SELECT_PHOTO:
            if(resultCode == RESULT_OK){
                try {
                    final Uri imageUri = imageReturnedIntent.getData();
                    final InputStream imageStream = getContentResolver().openInputStream(imageUri);
                    final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
                    src = new Mat(selectedImage.getHeight(), selectedImage.getWidth(), CvType.CV_8UC4);
                    Utils.bitmapToMat(selectedImage, src);
                    srcSelected = true;
                    bGaussianPyrUp.setEnabled(true);
                    bGaussianPyrDown.setEnabled(true);
                    bLaplacianPyr.setEnabled(true);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
            break;
    }
}
 
Example 4
Project: opencv-documentscanner-android   File: OpenCvCamera.java   View Source Code Vote up 5 votes
@Override
public void onCameraViewStarted(int width, int height) {
    Log.d("Width", width + "\t" + height);
    mRgba = new Mat(height, width, CvType.CV_8UC4);
    mIntermediateMat = new Mat(height, width, CvType.CV_8UC4);
    mGray = new Mat(height, width, CvType.CV_8UC1);
}
 
Example 5
Project: fingerblox   File: ImageProcessing.java   View Source Code Vote up 5 votes
static Bitmap preprocess(Mat frame, int width, int height) {
    // convert to grayscale
    Mat frameGrey = new Mat(height, width, CvType.CV_8UC1);
    Imgproc.cvtColor(frame, frameGrey, Imgproc.COLOR_BGR2GRAY, 1);

    // rotate
    Mat rotatedFrame = new Mat(width, height, frameGrey.type());
    Core.transpose(frameGrey, rotatedFrame);
    Core.flip(rotatedFrame, rotatedFrame, Core.ROTATE_180);

    // resize to match the surface view
    Mat resizedFrame = new Mat(width, height, rotatedFrame.type());
    Imgproc.resize(rotatedFrame, resizedFrame, new Size(width, height));

    // crop
    Mat ellipseMask = getEllipseMask(width, height);
    Mat frameCropped = new Mat(resizedFrame.rows(), resizedFrame.cols(), resizedFrame.type(), new Scalar(0));
    resizedFrame.copyTo(frameCropped, ellipseMask);

    // histogram equalisation
    Mat frameHistEq = new Mat(frame.rows(), frameCropped.cols(), frameCropped.type());
    Imgproc.equalizeHist(frameCropped, frameHistEq);

    // convert back to rgba
    Mat frameRgba = new Mat(frameHistEq.rows(), frameHistEq.cols(), CvType.CV_8UC4);
    Imgproc.cvtColor(frameHistEq, frameRgba, Imgproc.COLOR_GRAY2RGBA);

    // crop again to correct alpha
    Mat frameAlpha = new Mat(frameRgba.rows(), frameRgba.cols(), CvType.CV_8UC4, new Scalar(0, 0, 0, 0));
    frameRgba.copyTo(frameAlpha, ellipseMask);

    // convert to bitmap
    Bitmap bmp = Bitmap.createBitmap(frameAlpha.cols(), frameAlpha.rows(), Bitmap.Config.ARGB_4444);
    Utils.matToBitmap(frameAlpha, bmp);

    return bmp;
}
 
Example 6
Project: android-imaging-utils   File: ImagingUtils.java   View Source Code Vote up 5 votes
/**
 * Resize, crop and rotate the camera preview frame
 *
 * @param bytes  preview data
 * @param width  original width
 * @param height original height
 * @param params image processing parameters
 * @return
 */
public static Bitmap rotateCropAndResizePreview(byte[] bytes, int width, int height, PreviewResizeParams params)
{
    Size finalSize = new Size(params.newWidth, params.newHeight);
    Rect cropRect = new Rect(params.cropX, params.cropY, params.cropWidth, params.cropHeight);

    Mat rawMat = new Mat(height * 3 / 2, width, CvType.CV_8UC1); // YUV data
    rawMat.put(0, 0, bytes);
    Mat rgbMat = new Mat(height, width, CvType.CV_8UC4); // RGBA image
    Imgproc.cvtColor(rawMat, rgbMat, Imgproc.COLOR_YUV2RGBA_NV21);

    //rotate clockwise
    Mat rotatedMat = rotateFrame(rgbMat, params.rotation);

    //crop rect from image
    Mat croppedMat = new Mat(rotatedMat, cropRect);

    //resize
    if (finalSize.area() > 0)
        Imgproc.resize(croppedMat, croppedMat, finalSize);


    Bitmap bmp = Bitmap.createBitmap(croppedMat.cols(), croppedMat.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(croppedMat, bmp);

    return bmp;
}
 
Example 7
Project: android-age-estimator   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public void onCameraViewStarted(int width, int height) {
    // FIXME:Don't like this... I get it... don't need to initialize a variable each time, but..
    // maybe create an image object with syncronization for thread safety...
    grayscaleImage = new Mat(height, width, CvType.CV_8UC4);

    // The faces will be a 20% of the height of the screen
    // TODO: resize for each face
    absoluteFaceSize = (int) (height * 0.2);
}
 
Example 8
Project: MOAAP   File: MainActivity.java   View Source Code Vote up 5 votes
public void onCameraViewStarted(int width, int height) {
        mRgba = new Mat(height, width, CvType.CV_8UC4);
        mIntermediateMat = new Mat(height, width, CvType.CV_8UC4);
        mGray = new Mat(height, width, CvType.CV_8UC1);
//        Log.d(TAG, "\nRows: "+height+"\nCols: "+width+"\n");
        resetVars();
    }
 
Example 9
Project: AndroidCameraSudokuSolver   File: ShowCameraActivity.java   View Source Code Vote up 4 votes
public void onCameraViewStarted(int width, int height) {
    mRgba = new Mat(height, width, CvType.CV_8UC4);
    mIntermediateMat = new Mat(height, width, CvType.CV_8UC4);
    mGray = new Mat(height, width, CvType.CV_8UC1);
    hierarchy = new Mat();
}
 
Example 10
Project: MOAAP   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
public void onCameraViewStarted(int width, int height) {
    mRgba = new Mat(height, width, CvType.CV_8UC4);
}
 
Example 11
Project: MOAAP   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    //Put it there, just in case:)
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    switch(requestCode) {
        case SELECT_PHOTO:
            if(resultCode == RESULT_OK && read_external_storage_granted){
                try {
                    final Uri imageUri = imageReturnedIntent.getData();
                    final InputStream imageStream = getContentResolver().openInputStream(imageUri);
                    final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
                    src = new Mat(selectedImage.getHeight(), selectedImage.getWidth(), CvType.CV_8UC4);
                    Utils.bitmapToMat(selectedImage, src);
                    src_gray = new Mat(selectedImage.getHeight(), selectedImage.getWidth(), CvType.CV_8UC1);
                    switch (ACTION_MODE) {
                        case HomeActivity.GAUSSIAN_BLUR:
                            Imgproc.GaussianBlur(src, src, new Size(9, 9), 0);
                            break;
                        case HomeActivity.MEAN_BLUR:
                            Imgproc.blur(src, src, new Size(9, 9));
                            break;
                        case HomeActivity.MEDIAN_BLUR:
                            Imgproc.medianBlur(src, src, 9);
                            break;
                        case HomeActivity.SHARPEN:
                            Mat kernel = new Mat(3, 3, CvType.CV_16SC1);
                            //int[] values = {0, -1, 0, -1, 5, -1, 0, -1, 0};
                            Log.d("imageType", CvType.typeToString(src.type()) + "");
                            kernel.put(0, 0, 0, -1, 0, -1, 5, -1, 0, -1, 0);
                            Imgproc.filter2D(src, src, src_gray.depth(), kernel);
                            break;
                        case HomeActivity.DILATE:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY);
                            Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3, 3));
                            Imgproc.dilate(src_gray, src_gray, kernelDilate);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                        case HomeActivity.ERODE:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY);
                            Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5));
                            Imgproc.erode(src_gray, src_gray, kernelErode);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                        case HomeActivity.THRESHOLD:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                        case HomeActivity.ADAPTIVE_THRESHOLD:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.adaptiveThreshold(src_gray, src_gray, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 3, 0);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                    }
                    Bitmap processedImage = Bitmap.createBitmap(src.cols(), src.rows(), Bitmap.Config.ARGB_8888);
                    Log.i("imageType", CvType.typeToString(src.type()) + "");
                    Utils.matToBitmap(src, processedImage);
                    ivImage.setImageBitmap(selectedImage);
                    ivImageProcessed.setImageBitmap(processedImage);
                    Log.i("process", "process done");
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
            break;
    }
}
 
Example 12
Project: FTC2016   File: Color.java   View Source Code Vote up 2 votes
/**
 * Create a blank RGBA matrix (8-bit color info * 4 channels)
 *
 * @param width  Matrix width
 * @param height Matrix height
 * @return RGBA image matrix
 */
public static Mat createMatRGBA(int width, int height) {
    return new Mat(height, width, CvType.CV_8UC4);
}
 
Example 13
Project: RobotIGS   File: Color.java   View Source Code Vote up 2 votes
/**
 * Create a blank RGBA matrix (8-bit color info * 4 channels)
 *
 * @param width  Matrix width
 * @param height Matrix height
 * @return RGBA image matrix
 */
public static Mat createMatRGBA(int width, int height) {
    return new Mat(height, width, CvType.CV_8UC4);
}