public CarSnapshotGraph createCarSnapshotGraph(Bitmap bi) { CarSnapshotGraph graph = new CarSnapshotGraph(this); float[] peaks = new float[bi.getHeight()]; /** Graph at vertical position */ NativeGraphics.getHSVBrightness(bi, peaks); graph.addPeaks(peaks); return graph; }
public Bitmap verticalEdgeBi(Bitmap source) { int template[] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 }; return NativeGraphics.convolve(source, template, 3, 3, 1, 0); }
private ArrayList<Graph.Peak> computeGraph(Bitmap img) { Bitmap dest = verticalEdgeBi(img); dest = NativeGraphics.treshold(dest, 150); // Intelligence.console.consoleBitmap(dest); CarSnapshotGraph graphHandle = this.createCarSnapshotGraph(dest); graphHandle.rankFilter(carsnapshot_graphrankfilter); graphHandle.applyProbabilityDistributor(distributor); /** .40 - min .45 - ideal .50 - max */ graphHandle.findPeaks(2, 2, .40f); // We find two candidate // Intelligence.console.consoleBitmap(graphHandle.renderVertically(50, 300)); dest.recycle(); return graphHandle.peaks; }
public ArrayList<Band> getBands() { ArrayList<Band> out = new ArrayList<Band>(); CopyOnWriteArrayList<Challenger> out2 = new CopyOnWriteArrayList<Challenger>(); int imageWidth = this.image.getWidth(); /** ideal - 25 minimum - 20 maximum - 30 */ int step = 25; /** ideal - 4 minimum - 3 maximum - 5 */ int countPlates = 3; float stickyCoef = 0.2f; // Value in percents, show coincidence between two challenger-images int imageWidthIteration = imageWidth / step; int imageLength = imageWidthIteration * step; // Bitmap dest = NativeGraphics.convert565to8888(image); //Preprocessing for source image Bitmap dest = verticalEdgeBi(image); // Intelligence.console.consoleBitmap(image); dest = NativeGraphics.treshold(dest, 80); /** Render processing - console */ // ConsoleGraph cGraph = Intelligence.console.createConsoleGraph(dest, step); for (int i = 0; i < imageLength - step; i += step) { Bitmap bi = Bitmap.createBitmap(dest, i, 0, step, dest.getHeight()); ChallengerGraph graphHandle = this.createChallengerGraph(bi); graphHandle.rankFilter(carsnapshot_graphrankfilter); graphHandle.applyProbabilityDistributor(distributor); for (Peak p : graphHandle.findPeaks(numberOfCandidates, 6, .55f)) { // cGraph.drawLine(i, p.center); boolean isValidPeak = false; for (Challenger elm : out2) { if (elm.addPeak(p, i)) { isValidPeak = true; } else if ((elm.getStep() < (i - step)) && elm.elems.size() < countPlates) { out2.remove(elm); } } if (!isValidPeak) { Challenger chlgr = new Challenger(p, i, step); out2.add(chlgr); } } } /** Join equal images */ LinkedList<Challenger> out3 = new LinkedList<Challenger>(); for (Challenger elm : out2) { float elmSizeX = elm.maxX - elm.minX; float elmSizeY = elm.maxY - elm.minY; if (elm.elems.size() < countPlates) continue; if ((elm.maxX <= elm.minX) || (elm.maxY <= elm.minY)) continue; if (elmSizeX / elmSizeY < 1) continue; boolean isOk = false; for (Challenger elm2 : out3) { float elm2SizeX = elm2.maxX - elm2.minX; float elm2SizeY = elm2.maxY - elm2.minY; float diffX = 0; float diffY = 0; if (elm2.maxY > elm.maxY) { diffY = elm.maxY - elm2.minY; } else { diffY = elm2.maxY - elm.minY; } if (elm2.maxX > elm.maxX) { diffX = elm.maxX - elm2.minX; } else { diffX = elm2.maxX - elm.minX; } if (diffY > 0 && diffX > 0 && (((diffY / elm2SizeY) > stickyCoef) || ((diffY / elmSizeY) > stickyCoef)) && (((diffX / elm2SizeX) > stickyCoef) || ((diffX / elmSizeX) > stickyCoef))) { elm2.maxX = Math.max(elm.maxX, elm2.maxX); elm2.minX = Math.min(elm.minX, elm2.minX); elm2.maxY = Math.max(elm.maxY, elm2.maxY); elm2.minY = Math.min(elm.minY, elm2.minY); isOk = true; } } if (isOk == false) { out3.add(elm); } } int amplify = 3; /** * We find original picture with original dimensions and then we project work image to original * picture */ for (Challenger elm : out3) { Bitmap bi = null; int x = 0, y = 0, w = 0, h = 0; float power = 1.04f; if (originalImage != null) { float coefWidth = (float) originalImage.getWidth() / (float) dest.getWidth(); float coefHeight = (float) originalImage.getHeight() / (float) dest.getHeight(); x = (int) (Math.max(0, elm.minX - amplify) * coefWidth); y = (int) (Math.max(0, elm.minY - amplify) * coefHeight); w = (int) (Math.max(1, elm.maxX - elm.minX + amplify) * coefWidth * power); h = (int) (Math.max(1, elm.maxY - elm.minY + amplify) * coefHeight * power); } else { originalImage = image; x = Math.max(0, elm.minX - amplify); y = Math.max(0, elm.minY - amplify); w = (int) (Math.max(1, elm.maxX - elm.minX + amplify) * power); h = (int) (Math.max(1, elm.maxY - elm.minY + amplify) * power); } if (x + w >= originalImage.getWidth()) continue; if (y + h >= originalImage.getHeight()) continue; bi = Bitmap.createBitmap(originalImage, x, y, w, h); for (Graph.Peak p : computeGraph(bi)) { Bitmap bi2 = Bitmap.createBitmap(bi, 0, p.getLeft(), bi.getWidth(), p.getDiff()); out.add(new Band(bi2)); } } out2.clear(); out3.clear(); Intelligence.console.clear(); return out; }