List of usage examples for org.opencv.imgcodecs Imgcodecs imdecode
public static Mat imdecode(Mat buf, int flags)
From source file:com.jeremydyer.nifi.CropImageProcessor.java
License:Apache License
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { final FlowFile original = session.get(); if (original == null) { return;//from ww w. j a v a 2 s . c o m } session.read(original, new InputStreamCallback() { @Override public void process(InputStream inputStream) throws IOException { try { byte[] imgData = IOUtils.toByteArray(inputStream); Mat image = Imgcodecs.imdecode(new MatOfByte(imgData), Imgcodecs.CV_LOAD_IMAGE_COLOR); cropImage(session, context, original, image); } catch (Exception ex) { getLogger().error(ex.getMessage()); ex.printStackTrace(); } } }); session.transfer(original, REL_ORIGINAL); }
From source file:com.jeremydyer.nifi.FaceDetectionProcessor.java
License:Apache License
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { final FlowFile original = session.get(); if (original == null) { return;//from w w w .j a v a 2s. c om } session.read(original, new InputStreamCallback() { @Override public void process(InputStream inputStream) throws IOException { try { byte[] imgData = IOUtils.toByteArray(inputStream); Mat image = Imgcodecs.imdecode(new MatOfByte(imgData), Imgcodecs.CV_LOAD_IMAGE_COLOR); detectFaces(session, context, original, image); } catch (Exception ex) { getLogger().error(ex.getMessage()); ex.printStackTrace(); } } }); session.transfer(original, REL_ORIGINAL); }
From source file:com.jeremydyer.nifi.ObjectDetectionProcessor.java
License:Apache License
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { final FlowFile original = session.get(); if (original == null) { return;//from w ww .ja v a2 s . com } final JSONObject JSON = new JSONObject(context.getProperty(DETECTION_DEFINITION_JSON).getValue()); session.read(original, new InputStreamCallback() { @Override public void process(InputStream inputStream) throws IOException { try { byte[] imgData = IOUtils.toByteArray(inputStream); Mat image = Imgcodecs.imdecode(new MatOfByte(imgData), Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE); //Loops through all of the detection definitions JSONArray dds = JSON.getJSONArray("DetectionDefinition"); for (int i = 0; i < dds.length(); i++) { JSONObject dd = dds.getJSONObject(i); detectObjects(session, original, dd, image); } } catch (Exception ex) { getLogger().error(ex.getMessage()); ex.printStackTrace(); } } }); session.transfer(original, REL_ORIGINAL); }
From source file:com.oetermann.imageclassifier.ImageClassifier.java
License:Open Source License
public String matchName(String matcherName, byte[] data, int minMatches) { return matchName(matcherName, Imgcodecs.imdecode(new MatOfByte(data), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED), minMatches);/*from w w w. jav a2 s .c om*/ }
From source file:es.upv.riromu.platanus.image.ImageUtil.java
License:Open Source License
public static Mat readInputStreamIntoMat(InputStream inputStream) throws IOException { // Read into byte-array byte[] temporaryImageInMemory = readStream(inputStream); // Decode into mat. Use any IMREAD_ option that describes your image appropriately Mat outputImage = Imgcodecs.imdecode(new MatOfByte(temporaryImageInMemory), Imgcodecs.IMREAD_GRAYSCALE); return outputImage; }
From source file:ru.caramel.juniperbot.web.service.OpenCVService.java
License:Open Source License
public static Mat getMat(BufferedImage image) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", byteArrayOutputStream); byteArrayOutputStream.flush();//from w ww. j av a 2 s. c o m return Imgcodecs.imdecode(new MatOfByte(byteArrayOutputStream.toByteArray()), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED); }