List of usage examples for org.opencv.core Mat dataAddr
public long dataAddr()
From source file:edu.wpi.cscore.RawCVMatSource.java
License:Open Source License
/** * Put an OpenCV image and notify sinks. * * <p>Only 8-bit single-channel or 3-channel (with BGR channel order) images * are supported. If the format, depth or channel order is different, use * Mat.convertTo() and/or cvtColor() to convert it first. * * @param image OpenCV image/* w ww . j a va 2 s .c o m*/ */ public void putFrame(Mat image) { int channels = image.channels(); if (channels != 1 && channels != 3) { throw new VideoException("Unsupported Image Type"); } int imgType = channels == 1 ? PixelFormat.kGray.getValue() : PixelFormat.kBGR.getValue(); CameraServerJNI.putRawSourceFrame(m_handle, image.dataAddr(), image.width(), image.height(), imgType, (int) image.total() * channels); }
From source file:LetsStart.App.java
public static void main(String[] args) throws Exception { String filePath = "src/resources/images/1.jpg"; Mat newImage = Imgcodecs.imread(filePath); Mat im = new Mat(800, 1540, CvType.CV_32F); Mat x = new Mat(); Mat y = new Mat(); Mat n = new Mat(800, 1540, CvType.CV_32F); if (newImage.dataAddr() == 0) { System.out.println("Couldn't open file " + filePath); } else {//from w w w . j a va2s . c o m Size sz = new Size(1540, 800); Imgproc.resize(newImage, newImage, sz); //Mat image=newImage.clone(); Imgproc.blur(newImage, im, new Size(3, 3)); //Imgproc.GaussianBlur(newImage, im, new Size(10,10),0); //Imgproc.bilateralFilter(newImage, im, 9, 10, 10); Imgproc.cvtColor(im, n, Imgproc.COLOR_BGR2GRAY); Imgproc.equalizeHist(n, n); //Imgproc.Sobel(im, x, -10, 0, 1); //Imgproc.Sobel(im, y, -10, 1, 0); //Core.add(x, y, n); Imgproc.Canny(n, n, 70, 130, 3, false); /*Mat lines = new Mat(); Imgproc.HoughLines(n, lines, 1, Math.PI/180, 200); for(int i =0; i<lines.cols(); i++) { double rho = lines.get(0,i)[0]; double theta = lines.get(0,i)[1]; Point pt1 = new Point(), pt2 = new Point(); double a = Math.cos(theta), b=Math.sin(theta); double x0 = a*rho, y0=b*rho; pt1.x = Math.round(x0 + 1000*(-b)); pt1.y = Math.round(y0 + 1000*(a)); pt2.x = Math.round(x0 - 1000*(-b)); pt2.y = Math.round(y0 - 1000*(a)); Imgproc.line(image, pt1, pt2, new Scalar(255,0,0),2,Core.LINE_AA,0); }*/ /*Mat kernel = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(3,3)); Imgproc.morphologyEx(n, n, Imgproc.MORPH_CLOSE, kernel);*/ //close morph //Imgproc.threshold(n, n, 80, 255, Imgproc.THRESH_BINARY); // binary image /*Core.pow(y, 2, y); Core.pow(x, 2, x); Core.add(x, y, n); Core.pow(n, 0.5, im);*/ Imgcodecs.imwrite("src/resources/images/output/2.jpg", n); GUI gui = new GUI("Smooth Filter Example", n); gui.init(); } return; }
From source file:net.hydex11.opencvinteropexample.MainActivity.java
License:Open Source License
private void example() { RenderScript mRS = RenderScript.create(this); // Loads input image Bitmap inputBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.houseimage); // Puts input image inside an OpenCV mat Mat inputMat = new Mat(); Utils.bitmapToMat(inputBitmap, inputMat); Mat outputMat = new Mat(inputMat.size(), inputMat.type()); // Testing bitmap, used to test that the OpenCV mat actually has bitmap data inside Bitmap initialBitmap = Bitmap.createBitmap(inputMat.width(), inputMat.height(), Bitmap.Config.ARGB_8888); Utils.matToBitmap(inputMat, initialBitmap); // Retrieve OpenCV mat data address long inputMatDataAddress = inputMat.dataAddr(); long outputMatDataAddress = outputMat.dataAddr(); // Creates a RS type that matches the input mat one. Element element = Element.RGBA_8888(mRS); Type.Builder tb = new Type.Builder(mRS, element); tb.setX(inputMat.width());//from w ww. j a v a2s . c o m tb.setY(inputMat.height()); Type inputMatType = tb.create(); // Creates a RenderScript allocation that uses directly the OpenCV input mat address Allocation inputAllocation = createTypedAllocationWithDataPointer(mRS, inputMatType, inputMatDataAddress); Allocation outputAllocation = createTypedAllocationWithDataPointer(mRS, inputMatType, outputMatDataAddress); // Define a simple convolve script // Note: here, ANY kernel can be applied! ScriptIntrinsicConvolve3x3 convolve3x3 = ScriptIntrinsicConvolve3x3.create(mRS, element); float convolveCoefficients[] = new float[9]; convolveCoefficients[0] = 1; convolveCoefficients[2] = 1; convolveCoefficients[5] = 1; convolveCoefficients[6] = 1; convolveCoefficients[8] = 1; convolve3x3.setCoefficients(convolveCoefficients); convolve3x3.setInput(inputAllocation); convolve3x3.forEach(outputAllocation); mRS.finish(); // Converts the result to a bitmap Bitmap cvOutputBitmap = Bitmap.createBitmap(outputMat.width(), outputMat.height(), Bitmap.Config.ARGB_8888); Utils.matToBitmap(outputMat, cvOutputBitmap); // Testing bitmap, used to test the RenderScript ouput allocation contents // Note: it is placed here because the copyTo function clears the input buffer Bitmap rsOutputBitmap = Bitmap.createBitmap(outputMat.width(), outputMat.height(), Bitmap.Config.ARGB_8888); outputAllocation.copyTo(rsOutputBitmap); // Testing bitmap, used to test that RenderScript input allocation pointed to the OpenCV mat // Note: it is placed here because the copyTo function clears the input buffer Bitmap rsInitialBitmap = Bitmap.createBitmap(inputMat.width(), inputMat.height(), Bitmap.Config.ARGB_8888); inputAllocation.copyTo(rsInitialBitmap); // Display input and output ImageView originalImageIV = (ImageView) findViewById(R.id.imageView); ImageView inputRSImageIV = (ImageView) findViewById(R.id.imageView2); ImageView outputRSImageIV = (ImageView) findViewById(R.id.imageView3); ImageView outputCVIV = (ImageView) findViewById(R.id.imageView4); originalImageIV.setImageBitmap(initialBitmap); inputRSImageIV.setImageBitmap(rsInitialBitmap); outputRSImageIV.setImageBitmap(rsOutputBitmap); outputCVIV.setImageBitmap(cvOutputBitmap); }