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

The following are Jave code examples for showing how to use CV_8UC1 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: Machine-Learning-End-to-Endguide-for-Java-developers   File: OpenCVNonMavenExamples.java   View Source Code Vote up 6 votes
public static void denoise() {
        String imgInPath = "captchaExample.jpg";
        imgInPath = "MyCaptcha.PNG";
        imgInPath = "blurredtext.jpg";
        String imgOutPath = "captchaNoiseRemovedExample.png";
        imgOutPath = "MyNoiseRemovedCaptcha.PNG";

        Mat image = Imgcodecs.imread(imgInPath);
        Mat out = new Mat();
        Mat tmp = new Mat();
        Mat kernel = new Mat(new Size(3, 3), CvType.CV_8UC1, new Scalar(255));
//        Mat kernel = new Mat(image.size(), CvType.CV_8UC1, new Scalar(255));
        Imgproc.morphologyEx(image, tmp, Imgproc.MORPH_OPEN, kernel);
        Imgproc.morphologyEx(tmp, out, Imgproc.MORPH_CLOSE, kernel);
        Imgcodecs.imwrite(imgOutPath, out);
    }
 
Example 2
Project: SpotSpotter   File: ROI_Irregular.java   View Source Code Vote up 5 votes
public static Mat irregularQuadrangle_Simplified(Mat irrInput, Point p1, Point p2, Point p3, Point p4,
		double shift_x, double shift_y, boolean noULandLRcorner, double ulCornerRatio, double lrCornerRatio) {
	final Mat maskCopyTo = Mat.zeros(irrInput.size(), CvType.CV_8UC1); // ����copyTo������mask����С��ԭͼ����һ��

	// �����ĵ���Ϊ��ʼ����
	final double centerX = (p1.x + p2.x + p3.x + p4.x) / 4;
	final double centerY = (p1.y + p2.y + p3.y + p4.y) / 4;
	final Point cc = new Point(centerX, centerY);

	final List<MatOfPoint> counter = new ArrayList<>();
	final Point aP1 = new Point(p1.x + shift_x, p1.y + shift_y);
	final Point aP2 = new Point(p2.x - shift_x, p2.y + shift_y);
	final Point aP3 = new Point(p3.x + shift_x, p3.y - shift_y);
	final Point aP4 = new Point(p4.x - shift_x, p4.y - shift_y);

	if (noULandLRcorner) {
		final Point aP1L = new Point(aP1.x, aP1.y + (aP3.y - aP1.y) * ulCornerRatio);
		final Point aP1R = new Point(aP1.x + (aP2.x - aP1.x) * ulCornerRatio, aP1.y);
		final Point aP4L = new Point(aP4.x - (aP4.x - aP3.x) * lrCornerRatio, aP4.y);
		final Point aP4R = new Point(aP4.x, aP4.y - (aP4.y - aP2.y) * lrCornerRatio);

		counter.add(new MatOfPoint(aP1L, aP1R, aP2, aP4R, aP4L, aP3)); // ����һ��������Ķ���Σ�û�����ϽǺ����½�
	} else
		counter.add(new MatOfPoint(aP1, aP2, aP4, aP3)); // ����һ��������Ķ����

	// floodFill��mask��width��height�����������ͼ��������������أ��������ᱨ��
	Imgproc.drawContours(maskCopyTo, counter, -1, Scalar.all(255)); // ��������
	// MatView.imshow(maskCopyTo, "Irregular shape edge");
	final Mat maskFloodFill = new Mat(irrInput.rows() + 2, irrInput.cols() + 2, CvType.CV_8UC1); // ����floodFill������mask���ߴ��ԭͼ��һЩ
	Imgproc.floodFill(maskCopyTo, maskFloodFill, new Point(centerX, centerY), Scalar.all(255), null, Scalar.all(20),
			Scalar.all(20), 4); // ��ˮ��䷨����ڲ�
	// MatView.imshow(maskFloodFill, "Irregular shape��Mask of floodFill"); //
	// ����copyTo������mask
	// MatView.imshow(maskCopyTo, "Irregular shape��Mask of copyTo"); //
	// ����floodFill������mask
	final Mat imgIrregularROI = new Mat();
	irrInput.copyTo(imgIrregularROI, maskCopyTo); // ��ȡ��������״��ROI
	// MatView.imshow(imgIrregularROI, "Irregular shape ROI");
	return imgIrregularROI;
}
 
Example 3
Project: react-native-scan-doc   File: Converters.java   View Source Code Vote up 5 votes
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 4
Project: android-age-estimator   File: Converters.java   View Source Code Vote up 5 votes
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 5
Project: fingerblox   File: Converters.java   View Source Code Vote up 5 votes
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 6
Project: fingerblox   File: ImageProcessing.java   View Source Code Vote up 5 votes
private Mat getSkeletonImage(Mat src, int rows, int cols) {
    // step 1: get ridge segment by padding then do block process
    int blockSize = 24;
    double threshold = 0.05;
    Mat padded = imagePadding(src, blockSize);

    int imgRows = padded.rows();
    int imgCols = padded.cols();

    Mat matRidgeSegment = new Mat(imgRows, imgCols, CvType.CV_32FC1);
    Mat segmentMask = new Mat(imgRows, imgCols, CvType.CV_8UC1);
    ridgeSegment(padded, matRidgeSegment, segmentMask, blockSize, threshold);

    // step 2: get ridge orientation
    int gradientSigma = 1;
    int blockSigma = 13;
    int orientSmoothSigma = 15;
    Mat matRidgeOrientation = new Mat(imgRows, imgCols, CvType.CV_32FC1);
    ridgeOrientation(matRidgeSegment, matRidgeOrientation, gradientSigma, blockSigma, orientSmoothSigma);

    // step 3: get ridge frequency
    int fBlockSize = 36;
    int fWindowSize = 5;
    int fMinWaveLength = 5;
    int fMaxWaveLength = 25;
    Mat matFrequency = new Mat(imgRows, imgCols, CvType.CV_32FC1);
    double medianFreq = ridgeFrequency(matRidgeSegment, segmentMask, matRidgeOrientation, matFrequency, fBlockSize, fWindowSize, fMinWaveLength, fMaxWaveLength);

    // step 4: get ridge filter
    Mat matRidgeFilter = new Mat(imgRows, imgCols, CvType.CV_32FC1);
    double filterSize = 1.9;
    int padding = ridgeFilter(matRidgeSegment, matRidgeOrientation, matFrequency, matRidgeFilter, filterSize, filterSize, medianFreq);
    paddingSize = padding;

    // step 5: enhance image after ridge filter
    Mat matEnhanced = new Mat(imgRows, imgCols, CvType.CV_8UC1);
    enhancement(matRidgeFilter, matEnhanced, blockSize, rows, cols, padding);

    return matEnhanced;
}
 
Example 7
Project: Android-Crop-Receipt   File: Converters.java   View Source Code Vote up 5 votes
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 8
Project: MOAAP   File: Converters.java   View Source Code Vote up 5 votes
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 9
Project: mao-android   File: Converters.java   View Source Code Vote up 5 votes
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 10
Project: OpenCV_Android_Plus   File: Converters.java   View Source Code Vote up 5 votes
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
Project: OpenCV   File: Converters.java   View Source Code Vote up 5 votes
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 12
Project: MOAAP   File: Converters.java   View Source Code Vote up 5 votes
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 13
Project: renderscript_examples   File: Converters.java   View Source Code Vote up 5 votes
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 14
Project: Ftc2018RelicRecovery   File: Converters.java   View Source Code Vote up 5 votes
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 15
Project: android-imaging-utils   File: Converters.java   View Source Code Vote up 5 votes
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 16
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 17
Project: MOAAP   File: Converters.java   View Source Code Vote up 5 votes
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 18
Project: Sikulix2opencv   File: Converters.java   View Source Code Vote up 5 votes
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 19
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 20
Project: FTC2016   File: Color.java   View Source Code Vote up 2 votes
/**
 * Create a blank Grayscale matrix (8-bit color info)
 *
 * @param width  Matrix width
 * @param height Matrix height
 * @return Grayscale matrix
 */
public static Mat createMatGRAY(int width, int height) {
    return new Mat(height, width, CvType.CV_8UC1);
}