Java Code Examples for org.opencv.core.Scalar

The following are top voted examples for showing how to use org.opencv.core.Scalar. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Java-for-Data-Science   File: OpenCVNonMavenExamples.java   View source code 6 votes vote down vote up
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: opencv-documentscanner-android   File: Imgproc.java   View source code 5 votes vote down vote up
public static int floodFill(Mat image, Mat mask, Point seedPoint, Scalar newVal, Rect rect, Scalar loDiff, Scalar upDiff, int flags)
{
    double[] rect_out = new double[4];
    int retVal = floodFill_0(image.nativeObj, mask.nativeObj, seedPoint.x, seedPoint.y, newVal.val[0], newVal.val[1], newVal.val[2], newVal.val[3], rect_out, loDiff.val[0], loDiff.val[1], loDiff.val[2], loDiff.val[3], upDiff.val[0], upDiff.val[1], upDiff.val[2], upDiff.val[3], flags);
    if(rect!=null){ rect.x = (int)rect_out[0]; rect.y = (int)rect_out[1]; rect.width = (int)rect_out[2]; rect.height = (int)rect_out[3]; } 
    return retVal;
}
 
Example 3
Project: NotifyTools   File: Dnn.java   View source code 5 votes vote down vote up
public static Mat blobFromImages(List<Mat> images, double scalefactor, Size size, Scalar mean, boolean swapRB, boolean crop)
{
    Mat images_mat = Converters.vector_Mat_to_Mat(images);
    Mat retVal = new Mat(blobFromImages_0(images_mat.nativeObj, scalefactor, size.width, size.height, mean.val[0], mean.val[1], mean.val[2], mean.val[3], swapRB, crop));
    
    return retVal;
}
 
Example 4
Project: DNNLibrary   File: Imgproc.java   View source code 5 votes vote down vote up
public static void drawContours(Mat image, List<MatOfPoint> contours, int contourIdx, Scalar color, int thickness, int lineType, Mat hierarchy, int maxLevel, Point offset)
{
    List<Mat> contours_tmplm = new ArrayList<Mat>((contours != null) ? contours.size() : 0);
    Mat contours_mat = Converters.vector_vector_Point_to_Mat(contours, contours_tmplm);
    drawContours_0(image.nativeObj, contours_mat.nativeObj, contourIdx, color.val[0], color.val[1], color.val[2], color.val[3], thickness, lineType, hierarchy.nativeObj, maxLevel, offset.x, offset.y);
    
    return;
}
 
Example 5
Project: MOAAP   File: Aruco.java   View source code 5 votes vote down vote up
public static void drawDetectedMarkers(Mat image, List<Mat> corners, Mat ids, Scalar borderColor)
{
    Mat corners_mat = Converters.vector_Mat_to_Mat(corners);
    drawDetectedMarkers_0(image.nativeObj, corners_mat.nativeObj, ids.nativeObj, borderColor.val[0], borderColor.val[1], borderColor.val[2], borderColor.val[3]);
    
    return;
}
 
Example 6
Project: EyeShopping   File: Imgproc.java   View source code 5 votes vote down vote up
public static int floodFill(Mat image, Mat mask, Point seedPoint, Scalar newVal, Rect rect, Scalar loDiff, Scalar upDiff, int flags)
{
    double[] rect_out = new double[4];
    int retVal = floodFill_0(image.nativeObj, mask.nativeObj, seedPoint.x, seedPoint.y, newVal.val[0], newVal.val[1], newVal.val[2], newVal.val[3], rect_out, loDiff.val[0], loDiff.val[1], loDiff.val[2], loDiff.val[3], upDiff.val[0], upDiff.val[1], upDiff.val[2], upDiff.val[3], flags);
    if(rect!=null){ rect.x = (int)rect_out[0]; rect.y = (int)rect_out[1]; rect.width = (int)rect_out[2]; rect.height = (int)rect_out[3]; } 
    return retVal;
}
 
Example 7
Project: RobotIGS   File: ColorBlobDetector.java   View source code 5 votes vote down vote up
private void setColorRadius(Color lowerBound, Color upperBound) {
    isRadiusSet = false;
    Scalar lower = lowerBound.convertColorScalar(ColorSpace.HSV);
    Scalar upper = upperBound.convertColorScalar(ColorSpace.HSV);

    this.lowerBound = new ColorHSV(lower);
    this.upperBound = new ColorHSV(upper);
}
 
Example 8
Project: fingerblox   File: Imgproc.java   View source code 5 votes vote down vote up
public static void polylines(Mat img, List<MatOfPoint> pts, boolean isClosed, Scalar color, int thickness, int lineType, int shift)
{
    List<Mat> pts_tmplm = new ArrayList<Mat>((pts != null) ? pts.size() : 0);
    Mat pts_mat = Converters.vector_vector_Point_to_Mat(pts, pts_tmplm);
    polylines_0(img.nativeObj, pts_mat.nativeObj, isClosed, color.val[0], color.val[1], color.val[2], color.val[3], thickness, lineType, shift);
    
    return;
}
 
Example 9
Project: real_time_circle_detection_android   File: Imgproc.java   View source code 5 votes vote down vote up
public static void drawContours(Mat image, List<MatOfPoint> contours, int contourIdx, Scalar color)
{
    List<Mat> contours_tmplm = new ArrayList<Mat>((contours != null) ? contours.size() : 0);
    Mat contours_mat = Converters.vector_vector_Point_to_Mat(contours, contours_tmplm);
    drawContours_2(image.nativeObj, contours_mat.nativeObj, contourIdx, color.val[0], color.val[1], color.val[2], color.val[3]);
    
    return;
}
 
Example 10
Project: opencv-documentscanner-android   File: Imgproc.java   View source code 5 votes vote down vote up
public static void fillPoly(Mat img, List<MatOfPoint> pts, Scalar color, int lineType, int shift, Point offset)
{
    List<Mat> pts_tmplm = new ArrayList<Mat>((pts != null) ? pts.size() : 0);
    Mat pts_mat = Converters.vector_vector_Point_to_Mat(pts, pts_tmplm);
    fillPoly_0(img.nativeObj, pts_mat.nativeObj, color.val[0], color.val[1], color.val[2], color.val[3], lineType, shift, offset.x, offset.y);
    
    return;
}
 
Example 11
Project: mao-android   File: Imgproc.java   View source code 5 votes vote down vote up
public static void fillConvexPoly(Mat img, MatOfPoint points, Scalar color)
{
    Mat points_mat = points;
    fillConvexPoly_1(img.nativeObj, points_mat.nativeObj, color.val[0], color.val[1], color.val[2], color.val[3]);
    
    return;
}
 
Example 12
Project: Android-Code-Demos   File: Imgproc.java   View source code 5 votes vote down vote up
public static void polylines(Mat img, List<MatOfPoint> pts, boolean isClosed, Scalar color, int thickness)
{
    List<Mat> pts_tmplm = new ArrayList<Mat>((pts != null) ? pts.size() : 0);
    Mat pts_mat = Converters.vector_vector_Point_to_Mat(pts, pts_tmplm);
    polylines_1(img.nativeObj, pts_mat.nativeObj, isClosed, color.val[0], color.val[1], color.val[2], color.val[3], thickness);
    
    return;
}
 
Example 13
Project: Ftc2018RelicRecovery   File: Imgproc.java   View source code 5 votes vote down vote up
public static void drawContours(Mat image, List<MatOfPoint> contours, int contourIdx, Scalar color, int thickness)
{
    List<Mat> contours_tmplm = new ArrayList<Mat>((contours != null) ? contours.size() : 0);
    Mat contours_mat = Converters.vector_vector_Point_to_Mat(contours, contours_tmplm);
    drawContours_1(image.nativeObj, contours_mat.nativeObj, contourIdx, color.val[0], color.val[1], color.val[2], color.val[3], thickness);
    
    return;
}
 
Example 14
Project: OpenCV   File: Imgproc.java   View source code 5 votes vote down vote up
public static void fillConvexPoly(Mat img, MatOfPoint points, Scalar color)
{
    Mat points_mat = points;
    fillConvexPoly_1(img.nativeObj, points_mat.nativeObj, color.val[0], color.val[1], color.val[2], color.val[3]);
    
    return;
}
 
Example 15
Project: android-imaging-utils   File: Imgproc.java   View source code 5 votes vote down vote up
public static void fillPoly(Mat img, List<MatOfPoint> pts, Scalar color)
{
    List<Mat> pts_tmplm = new ArrayList<Mat>((pts != null) ? pts.size() : 0);
    Mat pts_mat = Converters.vector_vector_Point_to_Mat(pts, pts_tmplm);
    fillPoly_1(img.nativeObj, pts_mat.nativeObj, color.val[0], color.val[1], color.val[2], color.val[3]);
    
    return;
}
 
Example 16
Project: Team9261-2017-2018   File: Imgproc.java   View source code 5 votes vote down vote up
public static void drawContours(Mat image, List<MatOfPoint> contours, int contourIdx, Scalar color)
{
    List<Mat> contours_tmplm = new ArrayList<Mat>((contours != null) ? contours.size() : 0);
    Mat contours_mat = Converters.vector_vector_Point_to_Mat(contours, contours_tmplm);
    drawContours_2(image.nativeObj, contours_mat.nativeObj, contourIdx, color.val[0], color.val[1], color.val[2], color.val[3]);
    
    return;
}
 
Example 17
Project: renderscript_examples   File: Imgproc.java   View source code 5 votes vote down vote up
public static void fillConvexPoly(Mat img, MatOfPoint points, Scalar color)
{
    Mat points_mat = points;
    fillConvexPoly_1(img.nativeObj, points_mat.nativeObj, color.val[0], color.val[1], color.val[2], color.val[3]);
    
    return;
}
 
Example 18
Project: Image-Detection-Samples   File: Imgproc.java   View source code 5 votes vote down vote up
public static void polylines(Mat img, List<MatOfPoint> pts, boolean isClosed, Scalar color, int thickness)
{
    List<Mat> pts_tmplm = new ArrayList<Mat>((pts != null) ? pts.size() : 0);
    Mat pts_mat = Converters.vector_vector_Point_to_Mat(pts, pts_tmplm);
    polylines_1(img.nativeObj, pts_mat.nativeObj, isClosed, color.val[0], color.val[1], color.val[2], color.val[3], thickness);
    
    return;
}
 
Example 19
Project: RobotIGS   File: ColorRGBA.java   View source code 5 votes vote down vote up
private static Scalar parseHexCode(String hexCode) {
    //remove hex key #
    if (!hexCode.startsWith("#"))
        hexCode = "#" + hexCode;
    //ensure that the length is correct
    if (hexCode.length() != 7 && hexCode.length() != 9)
        throw new IllegalArgumentException("Hex code must be of length 6 or 8 characters.");
    //get the integer representation
    int color = android.graphics.Color.parseColor(hexCode);
    //get the r,g,b,a values
    return new Scalar(android.graphics.Color.red(color),
            android.graphics.Color.green(color),
            android.graphics.Color.blue(color),
            android.graphics.Color.alpha(color));
}
 
Example 20
Project: react-native-scan-doc   File: Imgproc.java   View source code 5 votes vote down vote up
public static void drawContours(Mat image, List<MatOfPoint> contours, int contourIdx, Scalar color)
{
    List<Mat> contours_tmplm = new ArrayList<Mat>((contours != null) ? contours.size() : 0);
    Mat contours_mat = Converters.vector_vector_Point_to_Mat(contours, contours_tmplm);
    drawContours_2(image.nativeObj, contours_mat.nativeObj, contourIdx, color.val[0], color.val[1], color.val[2], color.val[3]);
    
    return;
}
 
Example 21
Project: Sikulix2opencv   File: Imgproc.java   View source code 5 votes vote down vote up
public static int floodFill(Mat image, Mat mask, Point seedPoint, Scalar newVal, Rect rect, Scalar loDiff, Scalar upDiff, int flags)
{
    double[] rect_out = new double[4];
    int retVal = floodFill_0(image.nativeObj, mask.nativeObj, seedPoint.x, seedPoint.y, newVal.val[0], newVal.val[1], newVal.val[2], newVal.val[3], rect_out, loDiff.val[0], loDiff.val[1], loDiff.val[2], loDiff.val[3], upDiff.val[0], upDiff.val[1], upDiff.val[2], upDiff.val[3], flags);
    if(rect!=null){ rect.x = (int)rect_out[0]; rect.y = (int)rect_out[1]; rect.width = (int)rect_out[2]; rect.height = (int)rect_out[3]; } 
    return retVal;
}
 
Example 22
Project: Sikulix2opencv   File: Imgproc.java   View source code 5 votes vote down vote up
public static void drawContours(Mat image, List<MatOfPoint> contours, int contourIdx, Scalar color)
{
    List<Mat> contours_tmplm = new ArrayList<Mat>((contours != null) ? contours.size() : 0);
    Mat contours_mat = Converters.vector_vector_Point_to_Mat(contours, contours_tmplm);
    drawContours_2(image.nativeObj, contours_mat.nativeObj, contourIdx, color.val[0], color.val[1], color.val[2], color.val[3]);
    
    return;
}
 
Example 23
Project: Robot-Vision-API   File: HSVFilter.java   View source code 5 votes vote down vote up
@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;
}
 
Example 24
Project: Checkerboard-IMU-Comparator   File: Imgproc.java   View source code 5 votes vote down vote up
public static void drawContours(Mat image, List<MatOfPoint> contours, int contourIdx, Scalar color, int thickness, int lineType, Mat hierarchy, int maxLevel, Point offset)
{
    List<Mat> contours_tmplm = new ArrayList<Mat>((contours != null) ? contours.size() : 0);
    Mat contours_mat = Converters.vector_vector_Point_to_Mat(contours, contours_tmplm);
    drawContours_0(image.nativeObj, contours_mat.nativeObj, contourIdx, color.val[0], color.val[1], color.val[2], color.val[3], thickness, lineType, hierarchy.nativeObj, maxLevel, offset.x, offset.y);
    
    return;
}
 
Example 25
Project: fingerblox   File: Imgproc.java   View source code 5 votes vote down vote up
public static void drawContours(Mat image, List<MatOfPoint> contours, int contourIdx, Scalar color, int thickness)
{
    List<Mat> contours_tmplm = new ArrayList<Mat>((contours != null) ? contours.size() : 0);
    Mat contours_mat = Converters.vector_vector_Point_to_Mat(contours, contours_tmplm);
    drawContours_1(image.nativeObj, contours_mat.nativeObj, contourIdx, color.val[0], color.val[1], color.val[2], color.val[3], thickness);
    
    return;
}
 
Example 26
Project: MOAAP   File: Features2d.java   View source code 5 votes vote down vote up
public static void drawKeypoints(Mat image, MatOfKeyPoint keypoints, Mat outImage, Scalar color, int flags)
{
    Mat keypoints_mat = keypoints;
    drawKeypoints_0(image.nativeObj, keypoints_mat.nativeObj, outImage.nativeObj, color.val[0], color.val[1], color.val[2], color.val[3], flags);
    
    return;
}
 
Example 27
Project: SudoCAM-Ku   File: Processing.java   View source code 4 votes vote down vote up
public static Scalar getNumberColor(){
	return Processing.numberColor;
}
 
Example 28
Project: EyeShopping   File: Imgproc.java   View source code 3 votes vote down vote up
public static void rectangle(Mat img, Point pt1, Point pt2, Scalar color, int thickness, int lineType, int shift)
{
    
    rectangle_0(img.nativeObj, pt1.x, pt1.y, pt2.x, pt2.y, color.val[0], color.val[1], color.val[2], color.val[3], thickness, lineType, shift);
    
    return;
}
 
Example 29
Project: OpenCV   File: Core.java   View source code 3 votes vote down vote up
public static Scalar mean(Mat src, Mat mask)
{
    
    Scalar retVal = new Scalar(mean_0(src.nativeObj, mask.nativeObj));
    
    return retVal;
}
 
Example 30
Project: Team9261-2017-2018   File: Core.java   View source code 3 votes vote down vote up
public static void absdiff(Mat src1, Scalar src2, Mat dst)
{
    
    absdiff_1(src1.nativeObj, src2.val[0], src2.val[1], src2.val[2], src2.val[3], dst.nativeObj);
    
    return;
}
 
Example 31
Project: DNNLibrary   File: Core.java   View source code 3 votes vote down vote up
public static void multiply(Mat src1, Scalar src2, Mat dst, double scale)
{
    
    multiply_4(src1.nativeObj, src2.val[0], src2.val[1], src2.val[2], src2.val[3], dst.nativeObj, scale);
    
    return;
}
 
Example 32
Project: Sikulix2opencv   File: Imgproc.java   View source code 3 votes vote down vote up
public static void line(Mat img, Point pt1, Point pt2, Scalar color)
{
    
    line_2(img.nativeObj, pt1.x, pt1.y, pt2.x, pt2.y, color.val[0], color.val[1], color.val[2], color.val[3]);
    
    return;
}
 
Example 33
Project: EyeShopping   File: Imgproc.java   View source code 3 votes vote down vote up
public static void ellipse(Mat img, Point center, Size axes, double angle, double startAngle, double endAngle, Scalar color, int thickness)
{
    
    ellipse_1(img.nativeObj, center.x, center.y, axes.width, axes.height, angle, startAngle, endAngle, color.val[0], color.val[1], color.val[2], color.val[3], thickness);
    
    return;
}
 
Example 34
Project: fingerblox   File: Core.java   View source code 3 votes vote down vote up
public static Scalar mean(Mat src, Mat mask)
{
    
    Scalar retVal = new Scalar(mean_0(src.nativeObj, mask.nativeObj));
    
    return retVal;
}
 
Example 35
Project: MOAAP   File: Imgproc.java   View source code 3 votes vote down vote up
public static int floodFill(Mat image, Mat mask, Point seedPoint, Scalar newVal)
{
    
    int retVal = floodFill_1(image.nativeObj, mask.nativeObj, seedPoint.x, seedPoint.y, newVal.val[0], newVal.val[1], newVal.val[2], newVal.val[3]);
    
    return retVal;
}
 
Example 36
Project: real_time_circle_detection_android   File: Core.java   View source code 3 votes vote down vote up
public static void min(Mat src1, Scalar src2, Mat dst)
{
    
    min_1(src1.nativeObj, src2.val[0], src2.val[1], src2.val[2], src2.val[3], dst.nativeObj);
    
    return;
}
 
Example 37
Project: Android-Code-Demos   File: Core.java   View source code 3 votes vote down vote up
public static Scalar sumElems(Mat src)
{
    
    Scalar retVal = new Scalar(sumElems_0(src.nativeObj));
    
    return retVal;
}
 
Example 38
Project: OpenCV_Android_Plus   File: Imgproc.java   View source code 3 votes vote down vote up
/**
* <p>Applies a perspective transformation to an image.</p>
*
* <p>The function <code>warpPerspective</code> transforms the source image using
* the specified matrix:</p>
*
* <p><em>dst(x,y) = src((M_11 x + M_12 y + M_13)/(M_(31) x + M_32 y +
* M_33),&ltBR&gt(M_21 x + M_22 y + M_23)/(M_(31) x + M_32 y + M_33))</em></p>
*
* <p>when the flag <code>WARP_INVERSE_MAP</code> is set. Otherwise, the
* transformation is first inverted with "invert" and then put in the formula
* above instead of <code>M</code>.
* The function cannot operate in-place.</p>
*
* @param src input image.
* @param dst output image that has the size <code>dsize</code> and the same
* type as <code>src</code>.
* @param M <em>3x 3</em> transformation matrix.
* @param dsize size of the output image.
* @param flags combination of interpolation methods (<code>INTER_LINEAR</code>
* or <code>INTER_NEAREST</code>) and the optional flag <code>WARP_INVERSE_MAP</code>,
* that sets <code>M</code> as the inverse transformation (<em>dst->src</em>).
* @param borderMode pixel extrapolation method (<code>BORDER_CONSTANT</code> or
* <code>BORDER_REPLICATE</code>).
* @param borderValue value used in case of a constant border; by default, it
* equals 0.
*
* @see <a href="http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#warpperspective">org.opencv.imgproc.Imgproc.warpPerspective</a>
* @see org.opencv.imgproc.Imgproc#warpAffine
* @see org.opencv.imgproc.Imgproc#remap
* @see org.opencv.core.Core#perspectiveTransform
* @see org.opencv.imgproc.Imgproc#getRectSubPix
* @see org.opencv.imgproc.Imgproc#resize
*/
   public static void warpPerspective(Mat src, Mat dst, Mat M, Size dsize, int flags, int borderMode, Scalar borderValue)
   {

       warpPerspective_0(src.nativeObj, dst.nativeObj, M.nativeObj, dsize.width, dsize.height, flags, borderMode, borderValue.val[0], borderValue.val[1], borderValue.val[2], borderValue.val[3]);

       return;
   }
 
Example 39
Project: mao-android   File: Core.java   View source code 3 votes vote down vote up
public static void inRange(Mat src, Scalar lowerb, Scalar upperb, Mat dst)
{
    
    inRange_0(src.nativeObj, lowerb.val[0], lowerb.val[1], lowerb.val[2], lowerb.val[3], upperb.val[0], upperb.val[1], upperb.val[2], upperb.val[3], dst.nativeObj);
    
    return;
}
 
Example 40
Project: Microsphere   File: Imgproc.java   View source code 3 votes vote down vote up
public static void putText(Mat img, String text, Point org, int fontFace, double fontScale, Scalar color, int thickness)
{
    
    putText_1(img.nativeObj, text, org.x, org.y, fontFace, fontScale, color.val[0], color.val[1], color.val[2], color.val[3], thickness);
    
    return;
}