public Mat getResizedMat(double factor) { Mat newMat = getContent(); if (isValid()) { newMat = getNewMat(); Size newS = new Size(w * factor, h * factor); Imgproc.resize(getContent(), newMat, newS, 0, 0, Imgproc.INTER_AREA); } return newMat; }
public static Mat detectEdges(Mat mSource) { Mat mSourceGray = Element.getNewMat(); Mat mDetectedEdges = Element.getNewMat(); int edgeThresh = 1; int lowThreshold = 100; int ratio = 3; int kernelSize = 5; int blurFilterSize = 3; if (mSource.channels() == 1) { mSourceGray = mSource; } else { Imgproc.cvtColor(mSource, mSourceGray, toGray); } Imgproc.blur(mSourceGray, mDetectedEdges, new Size(blurFilterSize, blurFilterSize)); Imgproc.Canny(mDetectedEdges, mDetectedEdges, lowThreshold, lowThreshold * ratio, kernelSize, false); return mDetectedEdges; } //</editor-fold>
for (double factor : resizeLevels) { rfactor = factor * imgFactor; sizeBase = new Size(this.mBase.cols() / rfactor, this.mBase.rows() / rfactor); sizePattern = new Size(target.getContent().cols() / rfactor, target.getContent().rows() / rfactor); Imgproc.resize(this.mBase, mBase, sizeBase, 0, 0, Imgproc.INTER_AREA); Imgproc.resize(target.getContentBGR(), mPattern, sizePattern, 0, 0, Imgproc.INTER_AREA);
public static List<Element> detectChanges(Mat base, Mat mChanged) { int PIXEL_DIFF_THRESHOLD = 3; int IMAGE_DIFF_THRESHOLD = 5; Mat mBaseGray = Element.getNewMat(); Mat mChangedGray = Element.getNewMat(); Mat mDiffAbs = Element.getNewMat(); Mat mDiffTresh = Element.getNewMat(); Mat mChanges = Element.getNewMat(); List<Element> rectangles = new ArrayList<>(); Imgproc.cvtColor(base, mBaseGray, toGray); Imgproc.cvtColor(mChanged, mChangedGray, toGray); Core.absdiff(mBaseGray, mChangedGray, mDiffAbs); Imgproc.threshold(mDiffAbs, mDiffTresh, PIXEL_DIFF_THRESHOLD, 0.0, Imgproc.THRESH_TOZERO); if (Core.countNonZero(mDiffTresh) > IMAGE_DIFF_THRESHOLD) { Imgproc.threshold(mDiffAbs, mDiffAbs, PIXEL_DIFF_THRESHOLD, 255, Imgproc.THRESH_BINARY); Imgproc.dilate(mDiffAbs, mDiffAbs, Element.getNewMat()); Mat se = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5)); Imgproc.morphologyEx(mDiffAbs, mDiffAbs, Imgproc.MORPH_CLOSE, se); List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Mat mHierarchy = Element.getNewMat(); Imgproc.findContours(mDiffAbs, contours, mHierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); rectangles = contoursToRectangle(contours); Core.subtract(mDiffAbs, mDiffAbs, mChanges); Imgproc.drawContours(mChanges, contours, -1, new Scalar(255)); //logShow(mDiffAbs); } return rectangles; }
public Size size() { Size retVal = new Size(n_size(nativeObj)); return retVal; }
public Size get_blockSize() { Size retVal = new Size(get_blockSize_0(nativeObj)); return retVal; }
public RotatedRect() { this.center = new Point(); this.size = new Size(); this.angle = 0; }
public Size getWinSize() { Size retVal = new Size(getWinSize_0(nativeObj)); return retVal; }
public Size get_cellSize() { Size retVal = new Size(get_cellSize_0(nativeObj)); return retVal; }
public Size get_blockStride() { Size retVal = new Size(get_blockStride_0(nativeObj)); return retVal; }
public Size getOriginalWindowSize() { Size retVal = new Size(getOriginalWindowSize_0(nativeObj)); return retVal; }
public static Size getTextSize(String text, int fontFace, double fontScale, int thickness, int[] baseLine) { if(baseLine != null && baseLine.length != 1) throw new java.lang.IllegalArgumentException("'baseLine' must be 'int[1]' or 'null'."); Size retVal = new Size(n_getTextSize(text, fontFace, fontScale, thickness, baseLine)); return retVal; }
/** * Perform an in place gaussian blur on the given Mat with a kernel of size kernel x kernel. * * @param mat * @param kernel * @return */ public static Mat gaussianBlur(Mat mat, int kernel) { Imgproc.GaussianBlur(mat, mat, new Size(kernel, kernel), 0); return mat; }
public Size getTilesGridSize() { Size retVal = new Size(getTilesGridSize_0(nativeObj)); return retVal; }
public Size get_winSize() { Size retVal = new Size(get_winSize_0(nativeObj)); return retVal; }
public Size getOriginalWindowSize() { Size retVal = new Size(getOriginalWindowSize_0(nativeObj)); return retVal; }
public Size get_winSize() { Size retVal = new Size(get_winSize_0(nativeObj)); return retVal; }
public Size get_blockSize() { Size retVal = new Size(get_blockSize_0(nativeObj)); return retVal; }
public Size getTilesGridSize() { Size retVal = new Size(getTilesGridSize_0(nativeObj)); return retVal; }
@Override public Result process(CvPipeline pipeline) throws Exception { Mat mat = pipeline.getWorkingImage(); Imgproc.GaussianBlur(mat, mat, new Size(kernelSize, kernelSize), 0); return null; } }