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


Java Core.inRange方法代碼示例

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


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

示例1: skinDetection

import org.opencv.core.Core; //導入方法依賴的package包/類
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;
    }
 
開發者ID:jorenham,項目名稱:fingerblox,代碼行數:37,代碼來源:ImageProcessing.java

示例2: process

import org.opencv.core.Core; //導入方法依賴的package包/類
@Override
public void process(Mat input, Mat mask) {
    Imgproc.cvtColor(input,input,Imgproc.COLOR_RGB2HSV_FULL);
    Imgproc.GaussianBlur(input,input,new Size(3,3),0);

    Scalar lower = new Scalar(perfect.val[0] - range.val[0], perfect.val[1] - range.val[1],perfect.val[2] - range.val[2]);
    Scalar upper = new Scalar(perfect.val[0] + range.val[0], perfect.val[1] + range.val[1],perfect.val[2] + range.val[2]);
    Core.inRange(input,lower,upper,mask);
    input.release();
}
 
開發者ID:GTHSRobotics,項目名稱:DogeCV,代碼行數:11,代碼來源:HSVColorFilter.java

示例3: findAllColors

import org.opencv.core.Core; //導入方法依賴的package包/類
public static Point[] findAllColors(ImageWrapper image, int color, int threshold, Rect rect) {
    Mat bi = new Mat();
    Scalar lowerBound = new Scalar(Color.red(color) - threshold, Color.green(color) - threshold,
            Color.blue(color) - threshold, 255);
    Scalar upperBound = new Scalar(Color.red(color) + threshold, Color.green(color) + threshold,
            Color.blue(color) + threshold, 255);
    if (rect != null) {
        Core.inRange(new Mat(image.getMat(), rect), lowerBound, upperBound, bi);
    } else {
        Core.inRange(image.getMat(), lowerBound, upperBound, bi);
    }
    Mat nonZeroPos = new Mat();
    Core.findNonZero(bi, nonZeroPos);
    if (nonZeroPos.rows() == 0 || nonZeroPos.cols() == 0) {
        return new Point[0];
    }
    Point[] points = new MatOfPoint(nonZeroPos).toArray();
    if (rect != null) {
        for (int i = 0; i < points.length; i++) {
            points[i].x += rect.x;
            points[i].y += rect.y;
        }
    }
    return points;
}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:26,代碼來源:ColorFinder.java

示例4: process

import org.opencv.core.Core; //導入方法依賴的package包/類
/**
 * Process an rgba image. The results can be drawn on retrieved later.
 * This method does not modify the image.
 *
 * @param rgbaImage An RGBA image matrix
 */
public void process(Mat rgbaImage) {
    Imgproc.pyrDown(rgbaImage, mPyrDownMat);
    Imgproc.pyrDown(mPyrDownMat, mPyrDownMat);

    Imgproc.cvtColor(mPyrDownMat, mHsvMat, Imgproc.COLOR_RGB2HSV_FULL);

    //Test whether we need two inRange operations (only if the hue crosses over 255)
    if (upperBound.getScalar().val[0] <= 255) {
        Core.inRange(mHsvMat, lowerBound.getScalar(), upperBound.getScalar(), mMask);
    } else {
        //We need two operations - we're going to OR the masks together
        Scalar lower = lowerBound.getScalar().clone();
        Scalar upper = upperBound.getScalar().clone();
        while (upper.val[0] > 255)
            upper.val[0] -= 255;
        double tmp = lower.val[0];
        lower.val[0] = 0;
        //Mask 1 - from 0 to n
        Core.inRange(mHsvMat, lower, upper, mMaskOne);
        //Mask 2 - from 255-n to 255
        lower.val[0] = tmp;
        upper.val[0] = 255;

        Core.inRange(mHsvMat, lower, upper, mMask);
        //OR the two masks
        Core.bitwise_or(mMaskOne, mMask, mMask);
    }

    //Dilate (blur) the mask to decrease processing power
    Imgproc.dilate(mMask, mDilatedMask, new Mat());

    List<MatOfPoint> contourListTemp = new ArrayList<>();

    Imgproc.findContours(mDilatedMask, contourListTemp, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

    // Filter contours by area and resize to fit the original image size
    contours.clear();
    for (MatOfPoint c : contourListTemp) {
        Core.multiply(c, new Scalar(4, 4), c);
        contours.add(new Contour(c));
    }
}
 
開發者ID:TheBigBombman,項目名稱:RobotIGS,代碼行數:49,代碼來源:ColorBlobDetector.java

示例5: filter

import org.opencv.core.Core; //導入方法依賴的package包/類
@Override
public Mat filter(Mat image) {
    Mat out = new Mat();
    Scalar lower = new Scalar(blue.getLow(), green.getLow(), red.getLow());
    Scalar upper = new Scalar(blue.getHigh(), green.getHigh(), red.getHigh());
    Core.inRange(image, lower, upper, out);
    return out;
}
 
開發者ID:kylecorry31,項目名稱:Robot-Vision-API,代碼行數:9,代碼來源:RGBFilter.java

示例6: filter

import org.opencv.core.Core; //導入方法依賴的package包/類
@Override
public Mat filter(Mat image) {
    Mat hsvImg = new Mat();
    Imgproc.cvtColor(image, hsvImg, Imgproc.COLOR_BGR2HSV);
    Scalar lower = new Scalar(hue.getLow(), saturation.getLow(), value.getLow());
    Scalar upper = new Scalar(hue.getHigh(), saturation.getHigh(), value.getHigh());
    Core.inRange(hsvImg, lower, upper, hsvImg);
    return hsvImg;
}
 
開發者ID:kylecorry31,項目名稱:Robot-Vision-API,代碼行數:10,代碼來源:HSVFilter.java

示例7: filter

import org.opencv.core.Core; //導入方法依賴的package包/類
@Override
public Mat filter(Mat image) {
    Mat out = new Mat();
    Imgproc.cvtColor(image, out, Imgproc.COLOR_BGR2GRAY);
    Scalar lower = new Scalar(brightness.getLow());
    Scalar upper = new Scalar(brightness.getHigh());
    Core.inRange(out, lower, upper, out);
    return out;
}
 
開發者ID:kylecorry31,項目名稱:Robot-Vision-API,代碼行數:10,代碼來源:BrightnessFilter.java

示例8: getRedMask

import org.opencv.core.Core; //導入方法依賴的package包/類
public Mat getRedMask(Mat input){
    Scalar lower1 = new Scalar(0,150,100);
    Scalar upper1 = new Scalar(20,255,255);
    Scalar lower2 = new Scalar(140,100,100);
    Scalar upper2 = new Scalar(179,255,255);
    Core.inRange(input,lower1,upper1,mask1);
    Core.inRange(input,lower2,upper2,mask2);
    Core.addWeighted(mask1,1.0, mask2,1.0, 0.0, mask);
    return mask;
}
 
開發者ID:SCHS-Robotics,項目名稱:Team9261-2017-2018,代碼行數:11,代碼來源:NewCryptobox.java

示例9: getBeaconConfig

import org.opencv.core.Core; //導入方法依賴的package包/類
public static int getBeaconConfig(Image img, VuforiaTrackableDefaultListener beacon, CameraCalibration camCal) {

        OpenGLMatrix pose = beacon.getRawPose();

        if (pose != null && img != null && img.getPixels() != null) {

            Matrix34F rawPose = new Matrix34F();
            float[] poseData = Arrays.copyOfRange(pose.transposed().getData(), 0, 12);

            rawPose.setData(poseData);

            float[][] corners = new float[4][2];

            corners[0] = Tool.projectPoint(camCal, rawPose, new Vec3F(-127, 276, 0)).getData(); //upper left of beacon
            corners[1] = Tool.projectPoint(camCal, rawPose, new Vec3F(127, 276, 0)).getData(); //upper right of beacon
            corners[2] = Tool.projectPoint(camCal, rawPose, new Vec3F(127, -92, 0)).getData(); //lower right of beacon
            corners[3] = Tool.projectPoint(camCal, rawPose, new Vec3F(-127, -92, 0)).getData(); //lower left of beacon

            //getting camera image...
            Bitmap bm = Bitmap.createBitmap(img.getWidth(), img.getHeight(), Bitmap.Config.RGB_565);
            bm.copyPixelsFromBuffer(img.getPixels());

            //turning the corner pixel coordinates into a proper bounding box
            Mat crop = bitmapToMat(bm, CvType.CV_8UC3);
            float x = Math.min(Math.min(corners[1][0], corners[3][0]), Math.min(corners[0][0], corners[2][0]));
            float y = Math.min(Math.min(corners[1][1], corners[3][1]), Math.min(corners[0][1], corners[2][1]));
            float width = Math.max(Math.abs(corners[0][0] - corners[2][0]), Math.abs(corners[1][0] - corners[3][0]));
            float height = Math.max(Math.abs(corners[0][1] - corners[2][1]), Math.abs(corners[1][1] - corners[3][1]));


            //make sure our bounding box doesn't go outside of the image
            //OpenCV doesn't like that...
            x = Math.max(x, 0);
            y = Math.max(y, 0);
            width = (x + width > crop.cols())? crop.cols() - x : width;
            height = (y + height > crop.rows())? crop.rows() - y : height;

            //cropping bounding box out of camera image
            final Mat cropped = new Mat(crop, new Rect((int) x, (int) y, (int) width, (int) height));

            //filtering out non-beacon-blue colours in HSV colour space
            Imgproc.cvtColor(cropped, cropped, Imgproc.COLOR_RGB2HSV_FULL);

            //get filtered mask
            //if pixel is within acceptable blue-beacon-colour range, it's changed to white.
            //Otherwise, it's turned to black
            Mat mask = new Mat();

            Core.inRange(cropped, BEACON_BLUE_LOW, BEACON_BLUE_HIGH, mask);
            Moments mmnts = Imgproc.moments(mask, true);

            //calculating centroid of the resulting binary mask via image moments
            Log.i("CentroidX", "" + ((mmnts.get_m10() / mmnts.get_m00())));
            Log.i("CentroidY", "" + ((mmnts.get_m01() / mmnts.get_m00())));

            //checking if blue either takes up the majority of the image (which means the beacon is all blue)
            //or if there's barely any blue in the image (which means the beacon is all red or off)
//            if (mmnts.get_m00() / mask.total() > 0.8) {
//                return VortexUtils.BEACON_ALL_BLUE;
//            } else if (mmnts.get_m00() / mask.total() < 0.1) {
//                return VortexUtils.BEACON_NO_BLUE;
//            }//elseif

            //Note: for some reason, we end up with a image that is rotated 90 degrees
            //if centroid is in the bottom half of the image, the blue beacon is on the left
            //if the centroid is in the top half, the blue beacon is on the right
            if ((mmnts.get_m01() / mmnts.get_m00()) < cropped.rows() / 2) {
                return BEACON_RED_BLUE;
            } else {
                return BEACON_BLUE_RED;
            }
        }

        return NOT_VISIBLE;
    }
 
開發者ID:ykarim,項目名稱:FTC2016,代碼行數:76,代碼來源:BeaconUtils.java

示例10: getBlueMask

import org.opencv.core.Core; //導入方法依賴的package包/類
public Mat getBlueMask(Mat input){
    Scalar lower = new Scalar(90, 135, 25);
    Scalar upper = new Scalar(130, 250, 150);
    Core.inRange(input,lower,upper,mask);
    return mask;
}
 
開發者ID:SCHS-Robotics,項目名稱:Team9261-2017-2018,代碼行數:7,代碼來源:NewCryptobox.java

示例11: rgbThreshold

import org.opencv.core.Core; //導入方法依賴的package包/類
/**
 * Segment an image based on color ranges.
 * 
 * @param input
 *            The image on which to perform the RGB threshold.
 * @param red
 *            The min and max red.
 * @param green
 *            The min and max green.
 * @param blue
 *            The min and max blue.
 * @param output
 *            The image in which to store the output.
 */
private void rgbThreshold (Mat input, double[] red, double[] green,
        double[] blue,
        Mat out)
{
    Imgproc.cvtColor(input, out, Imgproc.COLOR_BGR2RGB);
    Core.inRange(out, new Scalar(red[0], green[0], blue[0]),
            new Scalar(red[1], green[1], blue[1]), out);
}
 
開發者ID:FIRST-Team-339,項目名稱:2017,代碼行數:23,代碼來源:GripPipeline.java

示例12: hslThreshold

import org.opencv.core.Core; //導入方法依賴的package包/類
/**
 * Segment an image based on hue, saturation, and luminance ranges.
 *
 * @param input The image on which to perform the HSL threshold.
 * @param hue The min and max hue
 * @param sat The min and max saturation
 * @param lum The min and max luminance
 * @param out The image in which to store the output.
 */
private void hslThreshold(Mat input, double[] hue, double[] sat, double[] lum,
	Mat out) {
	Imgproc.cvtColor(input, out, Imgproc.COLOR_BGR2HLS);
	Core.inRange(out, new Scalar(hue[0], lum[0], sat[0]),
		new Scalar(hue[1], lum[1], sat[1]), out);
}
 
開發者ID:trc492,項目名稱:Ftc2018RelicRecovery,代碼行數:16,代碼來源:GripPipeline.java

示例13: hsvThreshold

import org.opencv.core.Core; //導入方法依賴的package包/類
/**
 * Segment an image based on hue, saturation, and value ranges.
 *
 * @param input The image on which to perform the HSL threshold.
 * @param hue The min and max hue
 * @param sat The min and max saturation
 * @param val The min and max value
 * @param output The image in which to store the output.
 */
private void hsvThreshold(Mat input, double[] hue, double[] sat, double[] val,
    Mat out) {
	Imgproc.cvtColor(input, out, Imgproc.COLOR_BGR2HSV);
	Core.inRange(out, new Scalar(hue[0], sat[0], val[0]),
		new Scalar(hue[1], sat[1], val[1]), out);
}
 
開發者ID:mustafamertunali,項目名稱:FRC-6416-frc2017,代碼行數:16,代碼來源:GripPipeline.java

示例14: rgbThreshold

import org.opencv.core.Core; //導入方法依賴的package包/類
/**
 * Segment an image based on color ranges.
 * @param input The image on which to perform the RGB threshold.
 * @param red The min and max red.
 * @param green The min and max green.
 * @param blue The min and max blue.
 * @param output The image in which to store the output.
 */
private void rgbThreshold(Mat input, double[] red, double[] green, double[] blue,
	Mat out) {
	Imgproc.cvtColor(input, out, Imgproc.COLOR_BGR2RGB);
	Core.inRange(out, new Scalar(red[0], green[0], blue[0]),
		new Scalar(red[1], green[1], blue[1]), out);
}
 
開發者ID:KHS-Robotics,項目名稱:DemonVision,代碼行數:15,代碼來源:DefaultPipeline.java

示例15: filterMatColors

import org.opencv.core.Core; //導入方法依賴的package包/類
/**
 * Filters mat data by colors. Data within the color boundary now represents a contour.  
 * 
 * @param mat the mat data
 * @param threshold the resulting binary image
 * @param min1 min boundary 1: min hue/red
 * @param max1 max boundary 1: max hue/red
 * @param min2 min boundary 2: min saturation/green
 * @param max2 max boundary 2: max saturation/green
 * @param min3 min boundary 3: min value/blue
 * @param max3 max boundary 3: max value/blue
 * @return the binary image
 * @see Core#inRange(Mat, Scalar, Scalar, Mat)
 */
public static Mat filterMatColors(Mat mat, Mat threshold, int min1, int max1, int min2, int max2, int min3, int max3){
	Core.inRange(mat, 
			new Scalar(min1, min2, min3), 
			new Scalar(max1, max2, max3), 
			threshold);
	return threshold;
}
 
開發者ID:Flash3388,項目名稱:FlashLib,代碼行數:22,代碼來源:CvProcessing.java


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