public Element next() { Element match = null; if (hasNext()) { match = new Element(new Element(currentX + offX, currentY + offY, target.w, target.h), currentScore); int margin = getPurgeMargin(); Range rangeX = new Range(Math.max(currentX - margin, 0), currentX + 1); Range rangeY = new Range(Math.max(currentY - margin, 0), currentY + 1); result.colRange(rangeX).rowRange(rangeY).setTo(new Scalar(0f)); } return match; }
mMask = new Mat(shot.getContent().size(), CvType.CV_8UC1); if (!maskingToggle) { mMask.setTo(new Scalar(0)); Imgproc.fillPoly(mMask, elementToPoints(mask), new Scalar(255)); innerMask = true; } else { mMask.setTo(new Scalar(255)); Imgproc.fillPoly(mMask, elementToPoints(mask), new Scalar(0)); innerMask = false;
@Override public Result process(CvPipeline pipeline) throws Exception { Mat mat = pipeline.getWorkingImage(); mat.setTo(FluentCv.colorToScalar(color)); return null; } }
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.CvType; import org.opencv.core.Scalar; class SimpleSample { static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } public static void main(String[] args) { System.out.println("Welcome to OpenCV " + Core.VERSION); Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0)); System.out.println("OpenCV Mat: " + m); Mat mr1 = m.row(1); mr1.setTo(new Scalar(1)); Mat mc5 = m.col(5); mc5.setTo(new Scalar(5)); System.out.println("OpenCV Mat data:\n" + m.dump()); } }
private void resetImage() { image = originalImage.clone(); mask.setTo(new Scalar(0)); Imgproc.cvtColor(originalImage, grayImage,Imgproc.COLOR_BGR2GRAY); updateView(); }
private Mat negative(Mat foregroundThresh) { Mat result = new Mat(); Mat white = foregroundThresh.clone(); white.setTo(new Scalar(255.0)); Core.subtract(white, foregroundThresh, result); return result; }
private void resetImage() { image = originalImage.clone(); mask.setTo(new Scalar(0)); Imgproc.cvtColor(originalImage, grayImage,Imgproc.COLOR_BGR2GRAY); updateView(); }
Core.add(procImage_, new Scalar(192, 192, 192), procImage_); procImage_.setTo(new Scalar(0, 0, 255), edgesImage_);
previewImage_.setTo(new Scalar(255)); previewImageCurveCount_ = 0;
public GUI(String windowName, Mat newImage) { super(); this.windowName = windowName; this.image = newImage; originalImage = newImage.clone(); binary.create(new Size(image.cols(), image.rows()), CvType.CV_8UC1); binary.setTo(new Scalar(0)); }
@Override public Result process(CvPipeline pipeline) throws Exception { Mat mat = pipeline.getWorkingImage(); Mat mask = mat.clone(); Mat masked = mat.clone(); Scalar color = FluentCv.colorToScalar(Color.black); mask.setTo(color); masked.setTo(color); Imgproc.circle(mask, new Point(mat.cols() / 2, mat.rows() / 2), Math.abs(diameter) / 2, new Scalar(255, 255, 255), -1); if(diameter < 0) { Core.bitwise_not(mask,mask); } mat.copyTo(masked, mask); mask.release(); return new Result(masked); } }
public GUI(String windowName, Mat newImage) { super(); this.windowName = windowName; this.image = newImage; originalImage = newImage.clone(); mask.create(new Size(image.cols()+2, image.rows()+2), CvType.CV_8UC1); mask.setTo(new Scalar(0)); Imgproc.cvtColor(newImage, grayImage,Imgproc.COLOR_BGR2GRAY); processOperation(); }
public GUI(String windowName, Mat newImage) { super(); this.windowName = windowName; this.image = newImage; originalImage = newImage.clone(); mask.create(new Size(image.cols()+2, image.rows()+2), CvType.CV_8UC1); mask.setTo(new Scalar(0)); Imgproc.cvtColor(newImage, grayImage,Imgproc.COLOR_BGR2GRAY); processOperation(); }
@Override public Result process(CvPipeline pipeline) throws Exception { Mat mat = pipeline.getWorkingImage(); Mat mask = mat.clone(); Mat masked = mat.clone(); Scalar color = FluentCv.colorToScalar(Color.black); mask.setTo(color); masked.setTo(color); // FCA Change to have the possibility to work inside the interval or outside (when min>max) Scalar min; Scalar max; if (hueMin <= hueMax) { min = new Scalar(hueMin, saturationMin, valueMin); max = new Scalar(hueMax, saturationMax, valueMax); } else { min = new Scalar(hueMax, saturationMin, valueMin); max = new Scalar(hueMin, saturationMax, valueMax); } Core.inRange(mat, min, max, mask); if (hueMin <= hueMax) { Core.bitwise_not(mask, mask); } mat.copyTo(masked, mask); return new Result(masked); } }
private void clear() { // Resize to native resolution divided by blur factor. float scale = LINE_WIDTH_TO_IMAGE_WIDTH / blur_ / srcImage_.cols(); Imgproc.resize(srcImage_, imageResidue_, new Size(), scale, scale, Imgproc.INTER_AREA); // Negative. final Mat scalar = new Mat(1, 1, CvType.CV_64FC1).setTo(new Scalar(255)); Core.subtract(scalar, imageResidue_, imageResidue_); // Convert to S16. imageResidue_.convertTo(imageResidue_, CvType.CV_16SC1); // Full scale is now blur * GRAY_RESOLUTION. Core.multiply(imageResidue_, new Scalar(blur_ * GRAY_RESOLUTION / 255), imageResidue_); // Clear map. curves_.clear(); kernelFactory_.setDimensions(imageResidue_.width(), imageResidue_.height()); }
private void addNoise() { image = originalImage.clone(); Mat grayRnd = new Mat(image.rows(), image.cols(), image.type()); double noise = 128; grayRnd.setTo(new Scalar(noise/2, noise/2, noise/2)); Core.subtract(image, grayRnd, image); Core.randu(grayRnd, 0, noise); Core.add(image, grayRnd, image); processOperation(); updateView(); }
result.setTo(new Scalar(0));
@Override public Result process(CvPipeline pipeline) throws Exception { Mat mat = pipeline.getWorkingImage(); Mat mask = mat.clone(); Mat masked = mat.clone(); Scalar color = FluentCv.colorToScalar(Color.black); mask.setTo(color); masked.setTo(color); Point low = new Point(mat.cols() / 2 - getWidth() / 2, mat.rows() / 2 - getHeight() / 2); Point high = new Point(mat.cols() / 2 + getWidth() / 2, mat.rows() / 2 + getHeight() / 2); Imgproc.rectangle(mask, low, high, new Scalar(255, 255, 255), -1); if (getWidth() * getHeight() < 0) { Core.bitwise_not(mask, mask); } mat.copyTo(masked, mask); mask.release(); return new Result(masked); } }
private KernelInstance nextKernalInstance(Mat image, int numAttempts, Object context) { Mat mask = Mat.zeros(image.size(), CvType.CV_8U); Mat bestMask = Mat.zeros(image.size(), CvType.CV_8U); KernelInstance bestInstance = null; double bestScore = Float.NEGATIVE_INFINITY; for (int i = 0; i < numAttempts; ++i) { KernelInstance instance = kernelFactory_.createKernelInstance(context); mask.setTo(new Scalar(0)); instance.shape_.renderToMat(mask, new Scalar(GRAY_RESOLUTION)); double score = Core.mean(image, mask).val[0]; if (score > bestScore) { bestScore = score; Mat t = mask; mask = bestMask; bestMask = t; bestInstance = instance; } } Core.subtract(image, bestMask, image, bestMask, image.type()); return bestInstance; }
maskedImage.setTo(new Scalar(0,0,0)); colorImage.copyTo(maskedImage,disparityThreshold); maskedImage.copyTo(workingBackground,maskedImage);