Java Code Examples for org.opencv.core.Core.bitwise_and()

The following are Jave code examples for showing how to use bitwise_and() of the org.opencv.core.Core class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: fingerblox   File:   Source Code and License Vote up 10 votes
public Mat skinDetection(Mat src) {
        // define the upper and lower boundaries of the HSV pixel
        // intensities to be considered 'skin'
        Scalar lower = new Scalar(0, 48, 80);
        Scalar upper = new Scalar(20, 255, 255);

        // Convert to HSV
        Mat hsvFrame = new Mat(src.rows(), src.cols(), CvType.CV_8U, new Scalar(3));
        Imgproc.cvtColor(src, hsvFrame, Imgproc.COLOR_RGB2HSV, 3);

        // Mask the image for skin colors
        Mat skinMask = new Mat(hsvFrame.rows(), hsvFrame.cols(), CvType.CV_8U, new Scalar(3));
        Core.inRange(hsvFrame, lower, upper, skinMask);
//        currentSkinMask = new Mat(hsvFrame.rows(), hsvFrame.cols(), CvType.CV_8U, new Scalar(3));
//        skinMask.copyTo(currentSkinMask);

        // apply a series of erosions and dilations to the mask
        // using an elliptical kernel
        final Size kernelSize = new Size(11, 11);
        final Point anchor = new Point(-1, -1);
        final int iterations = 2;

        Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, kernelSize);
        Imgproc.erode(skinMask, skinMask, kernel, anchor, iterations);
        Imgproc.dilate(skinMask, skinMask, kernel, anchor, iterations);

        // blur the mask to help remove noise, then apply the
        // mask to the frame
        final Size ksize = new Size(3, 3);

        Mat skin = new Mat(skinMask.rows(), skinMask.cols(), CvType.CV_8U, new Scalar(3));
        Imgproc.GaussianBlur(skinMask, skinMask, ksize, 0);
        Core.bitwise_and(src, src, skin, skinMask);

        return skin;
Example 2
Project: SpotSpotter   File:   Source Code and License Vote up 3 votes
public static Mat[] iRCF_NH_ME(Mat image, int blurVal, double minAreaSize, int offset) {
	Mat[] matSet = new Mat[3];

	// MatView.imshow(image, "Ori");

	final Mat gray = new Mat();
	Imgproc.cvtColor(image, gray, Imgproc.COLOR_RGB2GRAY);

	final double percentOfCrop = 0.5;
	final Rect rect = new Rect((int) (gray.width() * percentOfCrop / 2), (int) (gray.height() * percentOfCrop / 2),
			(int) (gray.width() * (1 - percentOfCrop)), (int) (gray.height() * (1 - percentOfCrop)));

	final Mat findThresh = gray.clone().submat(rect);
	final double thresh = Imgproc.threshold(findThresh, findThresh, 0, 255, Imgproc.THRESH_OTSU + Imgproc.THRESH_BINARY);

	Mat roi = ROI_Irregular.RectangleSubROI(gray, rect);

	Imgproc.GaussianBlur(roi, roi, new Size(blurVal, blurVal), 0);

	// MatView.imshow(roi, "ROI");

	Imgproc.threshold(roi, roi, thresh, 255, Imgproc.THRESH_BINARY);
	// MatView.imshow(roi, "Bin");

	matSet = largestContour(image.clone(), roi, minAreaSize, offset);

	final Mat emptyBox = matSet[2];
	// MatView.imshow(emptyBox, "EmptyBox");

	roi = matSet[0];
	// MatView.imshow(roi, "Contour");

	Core.subtract(roi, emptyBox, roi);

	// Core.bitwise_xor(roi, emptyBox, roi);
	// MatView.imshow(roi, "Contour2");

	final Mat box = matSet[1];
	// MatView.imshow(box, "Box");

	Core.bitwise_and(image, roi, roi);
	// MatView.imshow(roi, "Final ROI1");

	return matSet;