dibw8u.copyTo(cleaned, digitsMask);
public void updateFromBufferedImage(BufferedImage bufferedImage) { switch (captureSource) { case JAVA_BUFFERED_IMAGES: OpenCVTools.convertBufferedImageToMat(bufferedImage).copyTo(currentCameraFrameMatInBGR); updateListOfCircles(); break; default: throw new RuntimeException("Cannot process BufferedImage when capturing from video stream or video file!"); } }
Mat m = ... // your smaller mat Mat submat= matOrig.submat(new Rect(x,y, m.cols(), m.rows()) ); m.copyTo(submat);
public void updateFromBufferedImage(BufferedImage bufferedImage) { switch (captureSource) { case JAVA_BUFFERED_IMAGES: OpenCVTools.convertBufferedImageToMat(bufferedImage).copyTo(currentCameraFrameMatInBGR); updateListOfCircles(); break; default: throw new RuntimeException("Cannot process BufferedImage when capturing from video stream or video file!"); } }
public Mat onCameraFrame(CvCameraViewFrame inputFrame) { Mat image = inputFrame.rgba(); Rect roi = new Rect(300, 50, 50, 10); Mat sub =image.submat(roi); Imgproc.cvtColor(sub, sub, Imgproc.COLOR_RGBA2GRAY); Imgproc.cvtColor(sub, sub, Imgproc.COLOR_GRAY2RGBA); sub.copyTo(image.submat(roi)); return image; }
private boolean updateCurrentFrameMaterialFromVideoCapture() { if(videoCapture == null || !videoCapture.isOpened()) { System.err.println("Video capture stream isn't open! Cannot update OpenCV Material for processing!"); return false; } boolean readSuccessful = videoCapture.read(tmpMat); if(!readSuccessful) { System.err.println("Reading from video capture stream failed, cannot update OpenCV Material for processing!"); return false; } tmpMat.copyTo(currentCameraFrameMatInBGR); return true; }
private boolean updateCurrentFrameMaterialFromVideoCapture() { if(videoCapture == null || !videoCapture.isOpened()) { System.err.println("Video capture stream isn't open! Cannot update OpenCV Material for processing!"); return false; } boolean readSuccessful = videoCapture.read(tmpMat); if(!readSuccessful) { System.err.println("Reading from video capture stream failed, cannot update OpenCV Material for processing!"); return false; } tmpMat.copyTo(currentCameraFrameMatInBGR); return true; }
Mat temp = new Mat(); Imgproc.cvtColor(mask, temp, Imgproc.COLOR_BGRA2GRAY,0); Mat temp_rgba = new Mat(); Imgproc.cvtColor(temp, temp_rgba, Imgproc.COLOR_GRAY2BGRA,0); temp_rgba.copyTo(mask);
... private Mat processedFrame; @Override public void onCameraViewStarted(int width, int height) { processedFrame = new Mat(); ... } @Override public Mat onCameraFrame(CvCameraViewFrame inputFrame) { final Mat frame = inputFrame.rgba(); Mat result = bs.process(frame); result.copyTo(processedFrame); result.release(); return processedFrame; }
public class ImageSegment { public static void main(String[] args) { System.loadLibrary("opencv_java244"); Mat image = null; image = Highgui.imread("syh.jpg"); Rect rectangle = new Rect(25,25,image.cols()-64,image.rows()-64); Mat result = new Mat(); Mat bgdModel = new Mat(); Mat fgdModel = new Mat(); Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3)); Imgproc.grabCut(image, result, rectangle, bgdModel, fgdModel, 1, 0); Core.compare(result, source,result, Core.CMP_EQ); Mat foreground= new Mat(image.size(), CvType.CV_8UC1, new Scalar(0, 0, 0)); image.copyTo(foreground, result); Highgui.imwrite("sucess1.jpg", foreground); System.out.println("grabcut sucess!"); } }
public static ImageCV applyShutter(Mat source, Shape shape, Color color) { Mat srcImg = Objects.requireNonNull(source); Mat mask = Mat.zeros(srcImg.size(), CvType.CV_8UC1); List<MatOfPoint> pts = transformShapeToContour(shape, true); Imgproc.fillPoly(mask, pts, new Scalar(1)); ImageCV dstImg = new ImageCV(srcImg.size(), srcImg.type(), new Scalar(color.getBlue(), color.getGreen(), color.getRed())); srcImg.copyTo(dstImg, mask); return dstImg; }
private static void writeRasterInRaw(PlanarImage image, FileRawImage[] newSeries, ImageCV[] builImgs, ViewParameter params, int dstHeight, int imgIndex) throws IOException { ImageCV img = ImageProcessor.getRotatedImage(image.toMat(), params.rotateCvType); if (newSeries != null && img != null && img.height() == newSeries.length) { if (newSeries[0] == null) { File dir = new File(MPR_CACHE_DIR, params.seriesUID); dir.mkdirs(); for (int i = 0; i < newSeries.length; i++) { newSeries[i] = new FileRawImage(new File(dir, "mpr_" + (i + 1) + ".wcv"));//$NON-NLS-1$ //$NON-NLS-2$ builImgs[i] = new ImageCV(dstHeight, img.width(), img.type()); } } for (int j = 0; j < newSeries.length; j++) { img.row(j).copyTo(builImgs[j].row(imgIndex - 1)); } } }
Mat b = Highgui.imread(Environment.getExternalStorageDirectory() + "/castle.jpg"); // Small watermark image Mat a = Highgui.imread(Environment.getExternalStorageDirectory() +"/square.png"); Mat bSubmat = b.submat(a.rows(), a.rows()*2, a.cols(), a.cols()*2); a.copyTo(bSubmat); Highgui.imwrite("mnt/sdcard/SubmatCopyToTest.png", b);
private Mat crop(Mat mat) { if (cropWidth != 0 || cropHeight != 0) { int cw = (cropWidth != 0) ? cropWidth : (int) mat.size().width; int ch = (cropHeight != 0) ? cropHeight : (int) mat.size().height; Rect roi = new Rect( (int) ((mat.size().width / 2) - (cw / 2)), (int) ((mat.size().height / 2) - (ch / 2)), cw, ch); Mat tmp = new Mat(mat, roi); tmp.copyTo(mat); tmp.release(); } return mat; }
@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); } }
private void copyTileToResultImage(Mat tileOutput, Mat resultImage, Rect srcTile, Rect dstTile) { Point br = dstTile.br(); if (br.x >= resultImage.cols()) { dstTile.width -= br.x - resultImage.cols(); srcTile.width -= br.x - resultImage.cols(); } if (br.y >= resultImage.rows()) { dstTile.height -= br.y - resultImage.rows(); srcTile.height -= br.y - resultImage.rows(); } Mat tileView = tileOutput.submat(srcTile); Mat dstView = resultImage.submat(dstTile); assert (tileView.rows() == dstView.rows()); assert (tileView.cols() == dstView.cols()); tileView.copyTo(dstView); }
private void copyTileToResultImage(Mat tileOutput, Mat resultImage, Rect dstTile) { Rect srcTile = new Rect(mPadding, mPadding, mTileSize, mTileSize); Point br = dstTile.br(); if (br.x >= resultImage.cols()) { dstTile.width -= br.x - resultImage.cols(); srcTile.width -= br.x - resultImage.cols(); } if (br.y >= resultImage.rows()) { dstTile.height -= br.y - resultImage.rows(); srcTile.height -= br.y - resultImage.rows(); } Mat tileView = tileOutput.submat(srcTile); Mat dstView = resultImage.submat(dstTile); assert (tileView.rows() == dstView.rows()); assert (tileView.cols() == dstView.cols()); tileView.copyTo(dstView); }
@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); } }
public static ImageCV applyCropMask(Mat source, Rectangle b, double alpha) { Mat srcImg = Objects.requireNonNull(source); ImageCV dstImg = new ImageCV(); source.copyTo(dstImg); if(b.getY() > 0) { Imgproc.rectangle(dstImg, new Point(0.0, 0.0), new Point(dstImg.width(), b.getMinY() ), new Scalar(0), -1); } if(b.getX() > 0) { Imgproc.rectangle(dstImg, new Point(0.0, b.getMinY()), new Point(b.getMinX(), b.getMaxY() ), new Scalar(0), -1); } if(b.getX() < dstImg.width()) { Imgproc.rectangle(dstImg, new Point(b.getMaxX(), b.getMinY()), new Point(dstImg.width(), b.getMaxY() ), new Scalar(0), -1); } if(b.getY() < dstImg.height()) { Imgproc.rectangle(dstImg, new Point(0.0, b.getMaxY()), new Point(dstImg.width(), dstImg.height() ), new Scalar(0), -1); } Core.addWeighted(dstImg, alpha, srcImg, 1- alpha, 0.0, dstImg); return dstImg; }