List of usage examples for org.opencv.core Mat height
public int height()
From source file:cmib_4_4.Feature.java
public int[] featureVector(Mat image1) { Mat image = new Mat(); Size sz = new Size(30, 30); Imgproc.resize(image1, image, sz);//from ww w .j av a 2s .com int size = (int) (image1.total() * image1.channels()); int size2 = (image.width() * image.height()); double[][] spec1 = new double[size2][3]; FeatureVector A = new FeatureVector(); int k = 0; for (int i = 0; i < image.rows(); i++) { for (int j = 0; j < image.cols(); j++) { //image.get(i, j, rgb); double[] rgb = image.get(i, j); double[] a = A.cartToSpec(rgb[0], rgb[1], rgb[2]); double x = Math.toRadians(90); spec1[k][0] = a[0] / x; spec1[k][1] = a[1] / x; spec1[k][2] = a[2] / x; //System.out.println(rgb[0]); //System.out.println(spec1[k][2]); k++; } } int[][] b = new int[11][11]; for (int i = 0; i < 11; i++) { for (int j = 0; j < 11; j++) { b[i][j] = 0; } } for (int i = 0; i < 900; i++) { int x1 = (int) (Math.round(spec1[i][1] * 10)); int y1 = (int) (Math.round(spec1[i][2] * 10)); b[x1][y1] = b[x1][y1] + 1; //System.out.println(x1+"and"+y1); } int l = 0; int[] c = new int[121]; for (int i = 0; i < 11; i++) { for (int j = 0; j < 11; j++) { c[l] = b[i][j]; l++; //System.out.println(c[l-1]); } } return c; }
From source file:com.blogspot.thedsweb.engine.Brightness.java
License:Open Source License
private boolean backlitDetection(Mat yCrCb, Scalar mainMean, int mainMeanLumaValue) { // Save the mean brightness and chroma value of the whole frame. Plus // the width and height of the frame. final int mainMeanChromaValue = (int) mainMean.val[2]; final int PARTS = 8; final int w = yCrCb.width(); final int h = yCrCb.height(); final int wStep = w >> 2; final int hStep = h >> 1; // Separate the image into 8 equal parts. final Mat[] tiles = new Mat[PARTS]; tiles[0] = yCrCb.submat(0, hStep, 0, wStep); tiles[1] = yCrCb.submat(0, hStep, wStep, wStep * 2); tiles[2] = yCrCb.submat(hStep, h, 0, wStep); tiles[3] = yCrCb.submat(hStep, h, wStep, wStep * 2); tiles[4] = yCrCb.submat(0, hStep, wStep * 2, wStep * 3); tiles[5] = yCrCb.submat(0, hStep, wStep * 2, w); tiles[6] = yCrCb.submat(hStep, h, wStep * 2, wStep * 3); tiles[7] = yCrCb.submat(hStep, h, wStep * 2, w); // Calculate the mean value of all parts. final Scalar[] tileMean = new Scalar[PARTS]; for (int i = 0; i < tileMean.length; i++) { tileMean[i] = Core.mean(tiles[i]); }/*from ww w . j a v a 2s .c om*/ // Save the mean brightness and chroma of all parts. final int[] tileMeanLuma = new int[PARTS]; final int[] tileMeanChroma = new int[PARTS]; // Save min and max value in container MinMaxContainer con = null; for (int j = 0; j < tileMean.length; j++) { tileMeanLuma[j] = (int) tileMean[j].val[0]; if (j == 0) { con = new MinMaxContainer(tileMeanLuma[j]); } else { con.add(tileMeanLuma[j]); } tileMeanChroma[j] = (int) tileMean[j].val[2]; } // Get the highest and lowest brightness value of all frame tiles. final int min = con.getMin(); final int max = con.getMax() >> 1; // Check if their is a consistent chroma distribution and a brightness // spike to detect backlit conditions. if (checkChroma(tileMeanChroma, mainMeanChromaValue) && min < max) { return true; } return false; }
From source file:com.carver.paul.truesight.ImageRecognition.RecognitionModel.java
License:Open Source License
public static List<HeroImageAndPosition> CalculateHeroImages(List<Mat> linesList, Mat backgroundImage) { List<HeroImageAndPosition> heroImages = new ArrayList<>(); /* for( Mat lines : linesList ) { HeroFromPhoto hero = new HeroFromPhoto(lines); heroes.add(hero);/*w ww . jav a 2 s. co m*/ }*/ // Doing it this slow way so that I can remoove unusal lines List<HeroLine> heroLines = new ArrayList<>(); for (Mat lines : linesList) { heroLines.add(new HeroLine(lines)); } if (heroLines.size() > 1) HeroLine.FixHeroLines(heroLines, backgroundImage.width(), backgroundImage.height()); /* LinesHorizontally(heroLines, backgroundImage); HeroLine.FixHeroLinesWithBadHeights(heroLines); */ int positionInPhoto = 0; for (HeroLine hLine : heroLines) { HeroImageAndPosition heroImage = new HeroImageAndPosition( calculateHeroImageFromPhoto(hLine, backgroundImage), positionInPhoto); positionInPhoto++; heroImages.add(heroImage); } return heroImages; }
From source file:com.carver.paul.truesight.ImageRecognition.RecognitionModel.java
License:Open Source License
public static List<Mat> findHeroTopLinesInImage(Mat photo, List<List<Integer>> colourRanges, int lowerHsvS, int lowerHsvV, int upperHsvS, int upperHsvV) { List<Mat> linesList = new ArrayList<>(); int pos = 0;//w ww .ja va2 s.co m int photoWidth = photo.width(); for (List<Integer> colourRange : colourRanges) { int minX; int maxX; if (colourRanges.size() == 1) { minX = 0; maxX = photoWidth; } else { minX = pos * photoWidth / 6; maxX = (2 + pos) * photoWidth / 6; } Scalar lowerHsv = new Scalar(colourRange.get(0), lowerHsvS, lowerHsvV); Scalar upperHsv = new Scalar(colourRange.get(1), upperHsvS, upperHsvV); Mat subMat = photo.submat(0, photo.height() / 2, minX, maxX); Mat mask = new Mat(); ImageTools.MaskAColourFromImage(subMat, lowerHsv, upperHsv, mask); Mat lines = new Mat(); // note, this is the part that takes most time. ImageTools.getLineFromTopRectMask(mask, lines, photoWidth / 7); //USED TO BE 8!!!! adjustXPosOfLines(lines, minX); linesList.add(lines); // Main.DrawMatInImageBox(mask, maskImage); // just for debug pos++; } return linesList; }
From source file:com.carver.paul.truesight.ImageRecognition.RecognitionModel.java
License:Open Source License
private static Mat calculateHeroImageFromPhoto(HeroLine line, Mat backgroundImage) { if (line.isRealLine == false) { return makeFakeHeroFromPhoto(backgroundImage); }// w w w . ja va2s . co m final double rationHeightToWidthbeforeCuts = 1.8; final double ratioToCutFromSide = 0.05; final double ratioToCutFromTop = 0.05; // ratioToCutFromBottom may need to be larger because a red box with MMR at the bottom may obscure the image final double ratioToCutFromBottom = 0.05; double heightWithoutCuts = line.rect.width() / rationHeightToWidthbeforeCuts; int left = line.rect.left + (int) (line.rect.width() * ratioToCutFromSide); int width = line.rect.width() - (int) (line.rect.width() * 2 * ratioToCutFromSide); int top = line.rect.top + line.rect.height() + (int) (heightWithoutCuts * ratioToCutFromTop); int finalHeight = (int) heightWithoutCuts - (int) (heightWithoutCuts * ratioToCutFromBottom); Log.d("AA", "width " + width + ", height" + finalHeight); if (left + width > backgroundImage.width()) width = backgroundImage.width() - left; if (top + finalHeight > backgroundImage.height()) finalHeight = backgroundImage.height() - top; if (left < 0) left = 0; if (top < 0) top = 0; if (left > backgroundImage.width() || top > backgroundImage.height()) { return makeFakeHeroFromPhoto(backgroundImage); } Rect rect = new Rect(left, top, width, finalHeight); return new Mat(backgroundImage, rect); }
From source file:com.github.mbillingr.correlationcheck.ImageProcessor.java
License:Open Source License
public Bitmap getRawBitmap(int w, int h) { Log.i("info", "reading " + mImageFile.getAbsolutePath()); Mat image = Imgcodecs.imread(mImageFile.getAbsolutePath()); raw_width = image.width();/*from w ww.ja va 2 s . c o m*/ raw_height = image.height(); Imgproc.resize(image, image, new Size(h, w)); return matToBitmap(image); }
From source file:com.github.rosjava_catkin_package_a.ARLocROS.Utils.java
License:Apache License
static public void tresholdContrastBlackWhite(Mat image2, double d) { int width = image2.width(); int height = image2.height(); for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { double[] rgb = image2.get(j, i); double[] rgbnew = new double[rgb.length]; if (rgb[0] + rgb[1] + rgb[2] < d) rgbnew[0] = rgbnew[1] = rgbnew[2] = 0.0; else//from w w w. j a v a2s. c o m rgbnew[0] = rgbnew[1] = rgbnew[2] = 255.0; image2.put(j, i, rgbnew); } }
From source file:com.ibm.streamsx.edgevideo.device.edgent.JsonMat.java
License:Open Source License
public static JsonObject toJsonObject(Mat mat) { JsonObject jo = new JsonObject(); jo.addProperty("width", mat.width()); jo.addProperty("height", mat.height()); jo.addProperty("type", mat.type()); jo.addProperty("channels", mat.channels()); jo.addProperty("depth", mat.depth()); jo.addProperty("mat", base64MimeEncodeMat(mat)); return jo;//from ww w . j av a2 s .c om }
From source file:com.ibm.streamsx.edgevideo.device.edgent.JsonMat.java
License:Open Source License
private static String base64MimeEncodeMat(Mat mat) { int width = mat.width(), height = mat.height(), channels = mat.channels(); // resize if needed // With initial resize factor of 4 and being within 2' of the MBP camera, // a face image seems to be on the order of 15Kb. if (width * height * channels > 50 * 1024) { Mat smallerFace = new Mat(); int resizeFactor = 2; Imgproc.resize(mat, smallerFace, new Size(mat.width() / resizeFactor, mat.height() / resizeFactor)); mat = smallerFace;//from w ww. j av a 2s. co m width = mat.width(); height = mat.height(); channels = mat.channels(); } byte[] sourcePixels = new byte[width * height * channels]; mat.get(0, 0, sourcePixels); // Base64 encode the image to be able to package in JsonObject // java.utils.Base64 since 1.8, otherwise use Apache Commons Encoder encoder = Base64.getMimeEncoder(); String base64 = encoder.encodeToString(sourcePixels); //System.out.println("pub face bytes size: " + sourcePixels.length + " base64 size:" + base64.length()); return base64; }
From source file:com.ibm.streamsx.edgevideo.device.FaceDetector.java
License:Open Source License
public Mat resize(Mat frame) { Mat resized = new Mat(); Imgproc.resize(frame, resized, new Size(frame.width() / resizeFactor, frame.height() / resizeFactor)); return resized; }