@Override @SuppressWarnings("unchecked") public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs, Optional<?> data) { final Mat input = ((InputSocket<Mat>) inputs[0]).getValue().get(); final Mat tmp = ((Optional<Mat>) data).get(); final boolean externalOnly = ((InputSocket<Boolean>) inputs[1]).getValue().get(); if (input.empty()) { return; } // findContours modifies its input, so we pass it a temporary copy of the input image input.copyTo(tmp); // OpenCV has a few different things it can return from findContours, but for now we only use // EXTERNAL and LIST. // The other ones involve hierarchies of contours, which might be useful in some situations, but // probably only // when processing the contours manually in code (so, not in a graphical pipeline). MatVector contours = new MatVector(); findContours( tmp, contours, externalOnly ? CV_RETR_EXTERNAL : CV_RETR_LIST, CV_CHAIN_APPROX_TC89_KCOS); final OutputSocket<ContoursReport> contoursSocket = (OutputSocket<ContoursReport>) outputs[0]; contoursSocket.setValue(new ContoursReport(contours, input.rows(), input.cols())); }
public static BufferedImage bufferedImage(Mat m) { int type = BufferedImage.TYPE_BYTE_GRAY; if (m.channels() > 1) { type = BufferedImage.TYPE_3BYTE_BGR; } BufferedImage image = new BufferedImage(m.cols(), m.rows(), type); m.get( 0, 0, ((DataBufferByte) image.getRaster().getDataBuffer()).getData()); // get all the pixels return image; }
public Mat getNext(int aMazeLevel) { Mat lResult = null; Mat lFound = new Mat(); lFound.material = fMat; lFound.data = baseMaterialData; for (Mat lMat : this) { if (lMat.mazeLevel < 0 || lMat.mazeLevel == aMazeLevel) { lFound = lMat; if (fRnd.nextInt(100) < lMat.chanceToUse) { lResult = lMat; } } } return lResult == null ? lFound : lResult; }
/** * @param source * @param delta * @return Mat */ public static Mat Sobel(Mat source, int delta) { Mat grey = new Mat(); Imgproc.cvtColor(source, grey, Imgproc.COLOR_BGR2GRAY); Mat sobelx = new Mat(); Imgproc.Sobel(grey, sobelx, CvType.CV_32F, 1, delta); double minVal, maxVal; Core.MinMaxLocResult minMaxLocResult = Core.minMaxLoc(sobelx); minVal = minMaxLocResult.minVal; maxVal = minMaxLocResult.maxVal; Mat draw = new Mat(); sobelx.convertTo( draw, CvType.CV_8U, 255.0 / (maxVal - minVal), -minVal * 255.0 / (maxVal - minVal)); return draw; }
public void fromSectionValue(Object aValue) { if (aValue instanceof ArrayList) { for (Object lItem : ((ArrayList) aValue)) { Mat lMat = new Mat(); lMat.quest = quest; if (lItem instanceof HashMap) { lMat.fromSectionValue(lItem); } else if (lItem instanceof String) { String lStr = lItem.toString().toUpperCase(); lMat.material = Material.getMaterial(lStr); if (lMat.material == null) { lMat.material = Material.getMaterial(Integer.parseInt(lStr)); } } add(lMat); } } }
public static Mat Histogram(Mat im) { Mat img = im; Mat equ = new Mat(); img.copyTo(equ); // Imgproc.blur(equ, equ, new Size(3, 3)); Imgproc.cvtColor(equ, equ, Imgproc.COLOR_BGR2YCrCb); List<Mat> channels = new ArrayList<Mat>(); Core.split(equ, channels); Imgproc.equalizeHist(channels.get(0), channels.get(0)); Core.merge(channels, equ); Imgproc.cvtColor(equ, equ, Imgproc.COLOR_YCrCb2BGR); Mat gray = new Mat(); Imgproc.cvtColor(equ, gray, Imgproc.COLOR_BGR2GRAY); Mat grayOrig = new Mat(); Imgproc.cvtColor(img, grayOrig, Imgproc.COLOR_BGR2GRAY); System.out.println("Histogram work ///"); return grayOrig; }
public void templateMatching() { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); int match_method = 5; int max_Trackbar = 5; Mat data = Highgui.imread("images/training_data/1" + "/data (" + 1 + ").jpg"); Mat temp = Highgui.imread("images/template.jpg"); Mat img = data.clone(); int result_cols = img.cols() - temp.cols() + 1; int result_rows = img.rows() - temp.rows() + 1; Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1); Imgproc.matchTemplate(img, temp, result, match_method); Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat()); double minVal; double maxVal; Point minLoc; Point maxLoc; Point matchLoc; // minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() ); Core.MinMaxLocResult res = Core.minMaxLoc(result); if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) { matchLoc = res.minLoc; } else { matchLoc = res.maxLoc; } // / Show me what you got Core.rectangle( img, matchLoc, new Point(matchLoc.x + temp.cols(), matchLoc.y + temp.rows()), new Scalar(0, 255, 0)); // Save the visualized detection. Highgui.imwrite("images/samp.jpg", img); }
// Transform the json-type feature to mat-type public static Mat json2mat(String json) { JsonParser parser = new JsonParser(); JsonElement parseTree = parser.parse(json); // Verify the input is JSON type if (!parseTree.isJsonObject()) { System.out.println("The input is not a JSON type...\nExiting..."); System.exit(1); } JsonObject jobj = parser.parse(json).getAsJsonObject(); if (jobj == null || !jobj.isJsonObject() || jobj.isJsonNull()) { return null; } // Detect broken/null features JsonElement r = jobj.get("rows"); if (r == null) { return null; } int rows = jobj.get("rows").getAsInt(); int cols = jobj.get("cols").getAsInt(); int type = jobj.get("type").getAsInt(); String data = jobj.get("data").getAsString(); String[] pixs = data.split(","); Mat descriptor = new Mat(rows, cols, type); for (String pix : pixs) { String[] tmp = pix.split(" "); int r_pos = Integer.valueOf(tmp[0]); int c_pos = Integer.valueOf(tmp[1]); double rgb = Double.valueOf(tmp[2]); descriptor.put(r_pos, c_pos, rgb); } return descriptor; }
public static void extractQueryFeatures2HDFS(String filename, Job job) throws IOException { // Read the local image.jpg as a Mat Mat query_mat_float = Highgui.imread(LOCAL_USER_DIR + ID + INPUT + "/" + filename, CvType.CV_32FC3); // Convert RGB to GRAY Mat query_gray = new Mat(); Imgproc.cvtColor(query_mat_float, query_gray, Imgproc.COLOR_RGB2GRAY); // Convert the float type to unsigned integer(required by SIFT) Mat query_mat_byte = new Mat(); query_gray.convertTo(query_mat_byte, CvType.CV_8UC3); // // Resize the image to 1/FACTOR both width and height // Mat query_mat_byte = FeatureExtraction.resize(query_mat_byte); // Extract the feature from the (Mat)image Mat query_features = FeatureExtraction.extractFeature(query_mat_byte); System.out.println(PREFIX + "Extracting the query image feature..."); System.out.println("query_mat(float,color):" + query_mat_float); System.out.println("query_mat(float,gray):" + query_gray); System.out.println("query_mat(byte,gray):" + query_mat_byte); System.out.println("query_mat_features:" + query_features); System.out.println(); // Store the feature to the hdfs in order to use it later in different map tasks System.out.println(PREFIX + "Generating the feature file for the query image in HDFS..."); FileSystem fs = FileSystem.get(job.getConfiguration()); String featureFileName = filename.substring(0, filename.lastIndexOf(".")) + ".json"; FSDataOutputStream fsDataOutputStream = fs.create(new Path(HDFS_HOME + USER + ID + INPUT + "/" + featureFileName)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fsDataOutputStream, StandardCharsets.UTF_8)); bw.write(FeatureExtraction.mat2json(query_features)); bw.close(); System.out.println(PREFIX + "Query feature extraction finished..."); System.out.println(); }
/** Capture images and run color processing through here */ public void capture() { VideoCapture camera = new VideoCapture(); camera.set(12, -20); // change contrast, might not be necessary // CaptureImage image = new CaptureImage(); camera.open(0); // Useless if (!camera.isOpened()) { System.out.println("Camera Error"); // Determine whether to use System.exit(0) or return } else { System.out.println("Camera OK"); } boolean success = camera.read(capturedFrame); if (success) { try { processWithContours(capturedFrame, processedFrame); } catch (Exception e) { System.out.println(e); } // image.processFrame(capturedFrame, processedFrame); // processedFrame should be CV_8UC3 // image.findCaptured(processedFrame); // image.determineKings(capturedFrame); int bufferSize = processedFrame.channels() * processedFrame.cols() * processedFrame.rows(); byte[] b = new byte[bufferSize]; processedFrame.get(0, 0, b); // get all the pixels // This might need to be BufferedImage.TYPE_INT_ARGB img = new BufferedImage( processedFrame.cols(), processedFrame.rows(), BufferedImage.TYPE_INT_RGB); int width = (int) camera.get(Highgui.CV_CAP_PROP_FRAME_WIDTH); int height = (int) camera.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT); // img.getRaster().setDataElements(0, 0, width, height, b); byte[] a = new byte[bufferSize]; System.arraycopy(b, 0, a, 0, bufferSize); Highgui.imwrite("camera.jpg", processedFrame); System.out.println("Success"); } else System.out.println("Unable to capture image"); camera.release(); }
public void copyMat(Mat src, Mat dest) { int srcRows = src.rows(); int srcCols = src.cols(); int destRows = dest.rows(); int destCols = dest.cols(); for (int i = 0; i < srcRows; i++) { for (int j = 0; j < srcCols; j++) { double bit = src.get(i, j)[0]; dest.put(i, j, bit); System.out.println(bit); } } }
public static Mat getCCH(Mat image) { ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Mat hierarchy = new Mat(); Imgproc.findContours( image, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE); Mat chainHistogram = Mat.zeros(1, 8, CvType.CV_32F); int n = 0; MatOfPoint2f approxCurve = new MatOfPoint2f(); for (MatOfPoint contour : contours) { // get the freeman chain code from the contours int rows = contour.rows(); // System.out.println("\nrows"+rows+"\n"+contour.dump()); int direction = 7; Mat prevPoint = contours.get(0).row(0); n += rows - 1; for (int i = 1; i < rows; i++) { // get the current point double x1 = contour.get(i - 1, 0)[1]; double y1 = contour.get(i - 1, 0)[0]; // get the second point double x2 = contour.get(i, 0)[1]; double y2 = contour.get(i, 0)[0]; if (x2 == x1 && y2 == y1 + 1) direction = 0; else if (x2 == x1 - 1 && y2 == y1 + 1) direction = 1; else if (x2 == x1 - 1 && y2 == y1) direction = 2; else if (x2 == x1 - 1 && y2 == y1 - 1) direction = 3; else if (x2 == x1 && y2 == y1 - 1) direction = 4; else if (x2 == x1 + 1 && y2 == y1 - 1) direction = 5; else if (x2 == x1 + 1 && y2 == y1) direction = 6; else if (x2 == x1 + 1 && y2 == y1 + 1) direction = 7; else System.out.print("err"); double counter = chainHistogram.get(0, direction)[0]; chainHistogram.put(0, direction, ++counter); System.out.print(direction); } } System.out.println("\n" + chainHistogram.dump()); Scalar alpha = new Scalar(n); // the factor Core.divide(chainHistogram, alpha, chainHistogram); System.out.println("\nrows=" + n + " " + chainHistogram.dump()); return chainHistogram; }
public static double compare(Mat m1, Mat m2) { return VisionProxyJNI.Vision_compare(Mat.getCPtr(m1), m1, Mat.getCPtr(m2), m2); }
/** * @param inputImg * @return Mat */ public static Mat watershed(Mat inputImg) { Mat target = new Mat(inputImg.rows(), inputImg.cols(), CvType.CV_8UC3); Imgproc.cvtColor(inputImg, target, Imgproc.COLOR_BGR2RGB); // Conversion to 8UC1 grayscale image Mat grayScale = new Mat(inputImg.rows(), inputImg.cols(), CvType.CV_32SC1); Imgproc.cvtColor(inputImg, grayScale, Imgproc.COLOR_BGR2GRAY); // constructing a 3x3 kernel for morphological opening Mat openingKernel = Mat.ones(9, 9, CvType.CV_8U); // яскравість // target.convertTo(target, -1, 10d * 12 / 100, 0); // Imgproc.dilate(target, target, new Mat(), new Point(-1, -1), 1); Size s = new Size(27, 27); Imgproc.GaussianBlur(target, target, s, 1.7); Imgproc.morphologyEx(target, target, Imgproc.MORPH_OPEN, openingKernel); // dilation operation for extracting the background // Imgproc.dilate(target, target, openingKernel); // Imgproc.erode(target, target, new Mat(), new Point(-1, -1), 1); Mat seeds = new Mat(target.rows(), target.cols(), CvType.CV_32SC1); for (int i = 0; i < 10; i++) { seeds.put(((int) Math.random()) % target.rows(), ((int) Math.random()) % target.cols(), i); } Imgproc.watershed(target, seeds); // Imgproc.threshold(target,target, 50, 155, Imgproc.THRESH_BINARY ); return target; }
/** * @param inputImg * @return Mat */ public static Mat kmeans(Mat inputImg) { Mat rgba = inputImg; Mat tempMat = inputImg; rgba = new Mat(inputImg.cols(), inputImg.rows(), CvType.CV_8UC3); inputImg.copyTo(rgba); List<Mat> hsv_planes_temp = new ArrayList<Mat>(3); Core.split(tempMat, hsv_planes_temp); double threshValue1 = PreProcessingOperation.getHistAverage(inputImg, hsv_planes_temp.get(0)); sample.util.Estimate.setFirstHistAverageValue(threshValue1); System.out.println("Defore eqau " + threshValue1); System.out.println( Estimate.getBlueAverage() + " ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"); if (threshValue1 > 140) { if (Estimate.getBlueAverage() > 110) { rgba.convertTo(rgba, -1, 10d * 31 / 100, 0); System.out.println("11"); } else { rgba.convertTo(rgba, -1, 10d * 40 / 100, 0); System.out.println("12"); } } else if (threshValue1 > 135) { rgba.convertTo(rgba, -1, 10d * 32 / 100, 0); System.out.println("21"); } else if (threshValue1 > 125) { if (Estimate.getBlueAverage() > 110) { rgba.convertTo(rgba, -1, 10d * 30 / 100, 0); rgba = PreProcessing.Dilate(rgba, 5); System.out.println("31"); } else { rgba.convertTo(rgba, -1, 10d * 37 / 100, 0); System.out.println("32"); } } else if (threshValue1 > 120) { rgba.convertTo(rgba, -1, 10d * 35 / 100, 0); System.out.println("41"); } else if (threshValue1 > 110) { if (Estimate.getBlueAverage() > 110) { rgba.convertTo(rgba, -1, 10d * 35 / 100, 0); rgba = PreProcessing.Dilate(rgba, 5); System.out.println("51"); } } else if (threshValue1 > 100) { if (Estimate.getBlueAverage() > 107) { rgba.convertTo(rgba, -1, 10d * 24 / 100, 0); rgba = PreProcessing.Dilate(rgba, 5); System.out.println("61"); } else if (Estimate.getBlueAverage() > 90) { rgba.convertTo(rgba, -1, 10d * 30 / 100, 0); rgba = PreProcessing.Dilate(rgba, 5); System.out.println("62"); } } else if (threshValue1 > 50) { if (Estimate.getBlueAverage() > 160) { rgba.convertTo(rgba, -1, 10d * 30 / 100, 0); rgba = PreProcessing.Dilate(rgba, 3); System.out.println("81"); } else if (Estimate.getBlueAverage() > 160) { rgba.convertTo(rgba, -1, 10d * 27 / 100, 0); rgba = PreProcessing.Dilate(rgba, 9); System.out.println("82"); } else if (Estimate.getBlueAverage() > 130) { rgba.convertTo(rgba, -1, 10d * 30 / 100, 0); rgba = PreProcessing.Dilate(rgba, 9); System.out.println("83"); } else if (Estimate.getBlueAverage() > 70) { rgba.convertTo(rgba, -1, 10d * 29 / 100, 0); rgba = PreProcessing.Dilate(rgba, 9); System.out.println("84"); } } else if (threshValue1 > 30) { if (Estimate.getBlueAverage() > 190) { rgba.convertTo(rgba, -1, 10d * 25 / 100, 0); System.out.println("91"); } else if (Estimate.getBlueAverage() > 160) { rgba.convertTo(rgba, -1, 10d * 35 / 100, 0); System.out.println("92"); } } else { if (Estimate.getBlueAverage() > 240) { rgba.convertTo(rgba, -1, 10d * 24 / 100, 0); System.out.println("7"); } else { rgba.convertTo(rgba, -1, 10d * 17 / 100, 0); System.out.println("7"); } } tempMat.release(); Mat mHSV = new Mat(); Imgproc.cvtColor(rgba, mHSV, Imgproc.COLOR_RGBA2RGB, 3); Imgproc.cvtColor(rgba, mHSV, Imgproc.COLOR_RGB2HSV, 3); List<Mat> hsv_planes = new ArrayList<Mat>(3); Core.split(mHSV, hsv_planes); Mat channel = hsv_planes.get(0); channel = Mat.zeros(mHSV.rows(), mHSV.cols(), CvType.CV_8UC1); hsv_planes.set(2, channel); Core.merge(hsv_planes, mHSV); mHSV.convertTo(mHSV, CvType.CV_8UC1); mHSV = Histogram(mHSV); /* Mat clusteredHSV = new Mat(); mHSV.convertTo(mHSV, CvType.CV_32FC3); TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER,100,0.1); Core.kmeans(mHSV, 1, clusteredHSV, criteria, 20, Core.KMEANS_PP_CENTERS); Mat hsvImg = new Mat(); List<Mat> hsvPlanes = new ArrayList<>(); Mat thresholdImg = new Mat(); int thresh_type = Imgproc.THRESH_BINARY_INV; hsvImg.create(mHSV.size(), CvType.CV_8U); Imgproc.cvtColor(mHSV, hsvImg, Imgproc.COLOR_BGR2HSV); Core.split(hsvImg, hsvPlanes); Imgproc.threshold(hsvPlanes.get(1), thresholdImg, 0 , 200 , thresh_type); double threshValue = PreProcessingOperation.getHistAverage(hsvImg, hsvPlanes.get(0)); Estimate.setSecondHistAverageValue(threshValue); System.out.println("After equa " + Estimate.getSecondHistAverageValue());*/ Imgproc.threshold(mHSV, mHSV, 0, 150, Imgproc.THRESH_BINARY_INV); // mHSV.convertTo(mHSV, CvType.CV_8UC1); return mHSV; }
/** * Determines where captured pieces are * * @param in Mat image of the board */ public void findCaptured(Mat in) { int vsegment = in.rows() / 8; // only accounts 8 playable int hsegment = in.cols() / 12; // 8 playable, 2 capture, 2 extra int offset; // offset for playable board int capSquares = 12; // number of capture squares int rowNum = 1; // starting row number for capture squares int rightdx = 48; int leftdx = 0; offset = hsegment; int count = 0; // keep track of captured squares // left: end user, right: system for (int i = 0; i < capSquares; i++) { // find where roi should be Point p1 = new Point( offset + count * hsegment, rowNum * vsegment); // top left point of rectangle (x,y) Point p2 = new Point( offset + (count + 1) * hsegment, (rowNum + 1) * vsegment); // bottom right point of rectangle (x,y) // create rectangle that is board square Rect bound = new Rect(p1, p2); char color; // frame only includes rectangle Mat roi = new Mat(in, bound); // get the color color = identifyColor(roi); switch (color) { case COLOR_BLUE: // Imgproc.rectangle(in, p1, p2, new Scalar(255, 0, 0), 3); Core.rectangle(in, p1, p2, new Scalar(255, 0, 0), 2); captured[i] = 1; break; case COLOR_ORANGE: // Imgproc.rectangle(in, p1, p2, new Scalar(0, 128, 255), 3); Core.rectangle(in, p1, p2, new Scalar(0, 128, 255), 2); captured[i] = 1; break; case COLOR_WHITE: // Imgproc.rectangle(in, p1, p2, new Scalar(255, 255, 255), 3); Core.rectangle(in, p1, p2, new Scalar(255, 255, 255), 2); captured[i] = 0; break; case COLOR_BLACK: // Imgproc.rectangle(in, p1, p2, new Scalar(0, 0, 0), 3); Core.rectangle(in, p1, p2, new Scalar(255, 255, 255), 2); captured[i] = 0; break; } count++; if (count == 1) { offset = hsegment * 10 - rightdx; } else if (count == 2) { count = 0; rightdx -= 6; leftdx += 6; offset = hsegment - leftdx; rowNum++; } } }
public static String recognizeWord(Mat image) { return VisionProxyJNI.Vision_recognizeWord(Mat.getCPtr(image), image); }
public void processWithContours(Mat in, Mat out) { int playSquares = 32; // number of playable game board squares // keep track of starting row square int parity = 0; // 0 is even, 1 is odd, tied to row number int count = 0; // row square int rowNum = 0; // row number, starting at 0 int vsegment = in.rows() / 8; // only accounts 8 playable int hsegment = in.cols() / 10; // 8 playable, 2 capture int hOffset = hsegment * 2; // offset for playable board int vOffset = vsegment + 40; // For angle of camera int dx = 80; int ddx = 0; hsegment -= 16; int dy = 20; vsegment -= 24; int ddy = 0; // Go through all playable squares for (int i = 0; i < playSquares; i++) { // change offset depending on the row if (parity == 0) // playable squares start on 2nd square from left { if (rowNum >= 5) dx -= 3; hOffset = hsegment * 2 + dx; } else // playable squares start on immediate left { if (rowNum >= 5) dx -= 3; hOffset = hsegment + dx; } if (rowNum == 0) ddy = 5; if (rowNum == 4) if (count == 6) ddx = 10; if (rowNum == 5) { if (count == 0) ddx = -6; else if (count == 2) ddx = 6; else if (count == 4) ddx = 12; else if (count == 6) ddx = 20; } if (rowNum == 6) { if (count == 0) ddx = 0; else if (count == 2) ddx = 16; else if (count == 4) ddx = 32; else if (count == 6) ddx = 40; } if (rowNum == 7) { if (count == 0) ddx = 6; else if (count == 2) ddx = 24; else if (count == 4) ddx = 40; else ddx = 52; } // find where roi should be // System.out.println("" + vOffset); Point p1 = new Point( hOffset + count * hsegment + ddx + 5, vOffset + rowNum * vsegment - dy - 5 - ddy); // top left point of rectangle (x,y) Point p2 = new Point( hOffset + (count + 1) * hsegment + ddx - 5, vOffset + (rowNum + 1) * vsegment - dy - 5 - ddy); // bottom right point of rectangle (x,y) // create rectangle that is board square Rect bound = new Rect(p1, p2); Mat roi; char color; if (i == 0) { // frame only includes rectangle roi = new Mat(in, bound); // get the color color = identifyColor(roi); // copy input image to output image in.copyTo(out); } else { // frame only includes rectangle roi = new Mat(out, bound); // get the color color = identifyColor(roi); } Imgproc.cvtColor(roi, roi, Imgproc.COLOR_BGR2GRAY); // change to single color Mat canny = new Mat(); Imgproc.Canny(roi, canny, 20, 40); // make image a canny image that is only edges; 2,4 // lower threshold values find more edges List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Mat hierarchy = new Mat(); // holds nested contour information Imgproc.findContours( canny, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); // Imgproc.RETR_LIST, TREE System.out.println(++test + "\t" + contours.size()); if (contours.size() > 3) // or error value for color is below 1 { switch (color) { case COLOR_BLUE: // Imgproc.rectangle(out, p1, p2, new Scalar(255, 0, 0), 2); Core.rectangle(out, p1, p2, new Scalar(255, 0, 0), 2); board[i] = CheckersBoard.BLACK; // end user's piece break; case COLOR_ORANGE: // Imgproc.rectangle(out, p1, p2, new Scalar(0, 128, 255), 2); Core.rectangle(out, p1, p2, new Scalar(0, 128, 255), 2); board[i] = CheckersBoard.WHITE; // system's piece break; case COLOR_WHITE: // Imgproc.rectangle(out, p1, p2, new Scalar(255, 255, 255), 2); Core.rectangle(out, p1, p2, new Scalar(255, 255, 255), 2); board[i] = CheckersBoard.EMPTY; break; case COLOR_BLACK: // this is black // Imgproc.rectangle(out, p1, p2, new Scalar(0, 0, 0), 2); Core.rectangle( out, p1, p2, new Scalar(0, 0, 0), 2); // maybe add 8, 0 as line type and fractional bits board[i] = CheckersBoard.EMPTY; break; } } System.out.println("in color switch " + board[i]); count += 2; if (count == 8) { parity = ++parity % 2; // change odd or even count = 0; rowNum++; hsegment += 2; dx -= 10; dy += 10; vsegment += 3; ddy = 0; } } }
/** * Identifies the color in the frame * * @param in the Mat image in the region of interest * @return the color */ public char identifyColor(Mat in) { // Mat blue = new Mat(in.rows(), in.cols(), CvType.CV_8UC1); // Mat green = new Mat(in.rows(), in.cols(), CvType.CV_8UC1); // Mat red = new Mat(in.rows(), in.cols(), CvType.CV_8UC1); // split the channels of the image Mat blue = new Mat(); // default is CV_8UC3 Mat green = new Mat(); Mat red = new Mat(); List<Mat> channels = new ArrayList<Mat>(3); Core.split(in, channels); blue = channels.get(0); // makes all 3 CV_8UC1 green = channels.get(1); red = channels.get(2); // System.out.println(blue.toString()); // add the intensities Mat intensity = new Mat(in.rows(), in.cols(), CvType.CV_32F); // Mat mask = new Mat(); Core.add(blue, green, intensity); // , mask, CvType.CV_32F); Core.add(intensity, red, intensity); // , mask, CvType.CV_32F); // not sure if correct from here to ... Mat inten = new Mat(); Core.divide(intensity, Scalar.all(3.0), inten); // System.out.println(intensity.toString()); // Core.divide(3.0, intensity, inten); // if intensity = intensity / 3.0; means element-wise division // use intensity.muls(Mat m) // so make new Mat m of same size that has each element of 1/3 /* * or * About per-element division you can use Core.divide() Core.divide(A,Scalar.all(d), B); It's equivalent to B=A/d */ // find normalized values Mat bnorm = new Mat(); Mat gnorm = new Mat(); Mat rnorm = new Mat(); // blue.convertTo(blue, CvType.CV_32F); // green.convertTo(green, CvType.CV_32F); // red.convertTo(red, CvType.CV_32F); Core.divide(blue, inten, bnorm); Core.divide(green, inten, gnorm); Core.divide(red, inten, rnorm); // find average norm values Scalar val = new Scalar(0); val = Core.mean(bnorm); String value[] = val.toString().split(","); String s = value[0].substring(1); double bavg = Double.parseDouble(s); val = Core.mean(gnorm); String value1[] = val.toString().split(","); String s1 = value1[0].substring(1); double gavg = Double.parseDouble(s1); val = Core.mean(rnorm); String value2[] = val.toString().split(","); String s2 = value2[0].substring(1); double ravg = Double.parseDouble(s2); // ... here // original values /* // define the reference color values //double RED[] = {0.4, 0.5, 1.8}; //double GREEN[] = {1.0, 1.2, 1.0}; double BLUE[] = {1.75, 1.0, 0.5}; //double YELLOW[] = {0.82, 1.7, 1.7}; double ORANGE[] = {0.2, 1.0, 2.0}; double WHITE[] = {2.0, 1.7, 1.7}; //double BLACK[] = {0.0, 0.3, 0.3}; */ // define the reference color values // double RED[] = {0.4, 0.5, 1.8}; // double GREEN[] = {1.0, 1.2, 1.0}; double BLUE[] = {1.75, 1.0, 0.5}; // double YELLOW[] = {0.82, 1.7, 1.7}; double ORANGE[] = {0.2, 1.0, 2.0}; double WHITE[] = {2.0, 1.7, 1.7}; // double BLACK[] = {0.0, 0.3, 0.3}; // compute the square error relative to the reference color values // double minError = 3.0; double minError = 2.0; double errorSqr; char bestFit = 'x'; // test++; // System.out.print("\n\n" + test + "\n\n"); // check BLUE fitness errorSqr = normSqr(BLUE[0], BLUE[1], BLUE[2], bavg, gavg, ravg); System.out.println("Blue: " + errorSqr); if (errorSqr < minError) { minError = errorSqr; bestFit = COLOR_BLUE; } // check ORANGE fitness errorSqr = normSqr(ORANGE[0], ORANGE[1], ORANGE[2], bavg, gavg, ravg); System.out.println("Orange: " + errorSqr); if (errorSqr < minError) { minError = errorSqr; bestFit = COLOR_ORANGE; } // check WHITE fitness errorSqr = normSqr(WHITE[0], WHITE[1], WHITE[2], bavg, gavg, ravg); System.out.println("White: " + errorSqr); if (errorSqr < minError) { minError = errorSqr; bestFit = COLOR_WHITE; } // check BLACK fitness /*errorSqr = normSqr(BLACK[0], BLACK[1], BLACK[2], bavg, gavg, ravg); System.out.println("Black: " + errorSqr); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_BLACK; }*/ // return the best fit color label return bestFit; }
/** * Processes the board image * * @param in image captured of board * @param out processed image of board */ public void processFrame(Mat in, Mat out) { // multiple regions of interest int playSquares = 32; // number of playable game board squares // keep track of starting row square int parity = 0; // 0 is even, 1 is odd, tied to row number int count = 0; // row square int rowNum = 0; // row number, starting at 0 int vsegment = in.rows() / 8; // only accounts 8 playable int hsegment = in.cols() / 10; // 8 playable, 2 capture int hOffset = hsegment * 2; // offset for playable board int vOffset = vsegment + 40; // For angle of camera int dx = 80; int ddx = 0; hsegment -= 16; int dy = 20; vsegment -= 24; // Go through all playable squares for (int i = 0; i < playSquares; i++) { // change offset depending on the row if (parity == 0) // playable squares start on 2nd square from left { if (rowNum >= 5) dx -= 3; hOffset = hsegment * 2 + dx; } else // playable squares start on immediate left { if (rowNum >= 5) dx -= 3; hOffset = hsegment + dx; } if (rowNum == 4) if (count == 6) ddx = 10; if (rowNum == 5) { if (count == 0) ddx = -6; else if (count == 2) ddx = 6; else if (count == 4) ddx = 12; else if (count == 6) ddx = 20; } if (rowNum == 6) { if (count == 0) ddx = 0; else if (count == 2) ddx = 16; else if (count == 4) ddx = 32; else if (count == 6) ddx = 40; } if (rowNum == 7) { if (count == 0) ddx = 0; else if (count == 2) ddx = 24; else if (count == 4) ddx = 40; else ddx = 52; } // find where roi should be // System.out.println("" + vOffset); Point p1 = new Point( hOffset + count * hsegment + ddx, vOffset + rowNum * vsegment - dy); // top left point of rectangle (x,y) Point p2 = new Point( hOffset + (count + 1) * hsegment + ddx, vOffset + (rowNum + 1) * vsegment - dy); // bottom right point of rectangle (x,y) // create rectangle that is board square Rect bound = new Rect(p1, p2); char color; if (i == 0) { // frame only includes rectangle Mat roi = new Mat(in, bound); // get the color color = identifyColor(roi); // copy input image to output image in.copyTo(out); } else { // frame only includes rectangle Mat roi = new Mat(out, bound); // get the color color = identifyColor(roi); } // annotate the output image // scalar values as (blue, green, red) switch (color) { case COLOR_BLUE: // Imgproc.rectangle(out, p1, p2, new Scalar(255, 0, 0), 2); Core.rectangle(out, p1, p2, new Scalar(255, 0, 0), 2); board[i] = CheckersBoard.BLACK; // end user's piece break; case COLOR_ORANGE: // Imgproc.rectangle(out, p1, p2, new Scalar(0, 128, 255), 2); Core.rectangle(out, p1, p2, new Scalar(0, 128, 255), 2); board[i] = CheckersBoard.WHITE; // system's piece break; case COLOR_WHITE: // Imgproc.rectangle(out, p1, p2, new Scalar(255, 255, 255), 2); Core.rectangle(out, p1, p2, new Scalar(255, 255, 255), 2); board[i] = CheckersBoard.EMPTY; break; case COLOR_BLACK: // this is black // Imgproc.rectangle(out, p1, p2, new Scalar(0, 0, 0), 2); Core.rectangle( out, p1, p2, new Scalar(0, 0, 0), 2); // maybe add 8, 0 as line type and fractional bits board[i] = CheckersBoard.EMPTY; break; } count += 2; if (count == 8) { parity = ++parity % 2; // change odd or even count = 0; rowNum++; hsegment += 2; dx -= 10; dy += 10; vsegment += 3; } } }
/** * Determines which pieces are kings * * @param in Mat image of board */ public void determineKings(Mat in) { int playSquares = 32; Mat dst = new Mat(in.rows(), in.cols(), in.type()); in.copyTo(dst); Imgproc.cvtColor(dst, dst, Imgproc.COLOR_BGR2GRAY); // change to single color Mat canny = new Mat(); Imgproc.Canny(dst, canny, 100, 200); // make image a canny image that is only edges; 2,4 // lower threshold values find more edges List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Mat hierarchy = new Mat(); // holds nested contour information Imgproc.findContours( canny, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); // Imgproc.RETR_LIST, TREE // draw contour image Mat mask = new Mat(); mask = Mat.zeros(dst.size(), dst.type()); Imgproc.drawContours( mask, contours, -1, new Scalar(255, 255, 255), 1, 8, hierarchy, 2, new Point()); Highgui.imwrite("contours.jpg", mask); ArrayList occupied = new ArrayList<Integer>(); for (int i = 0; i < playSquares; i++) { if (board[i] != 0) occupied.add(i); } for (int i = 0; i < contours.size(); i++) // assuming only contours are checker pieces { // determine if it should be a king // use Rect r = Imgproc.boundingRect then find height of it by r.height // Get bounding rect of contour Rect bound = Imgproc.boundingRect(contours.get(i)); if (bound.height > in.rows() / 8) { // board[(int) occupied.get(0)]++; // make it a king // occupied.remove(0); } } // or apply to each region of interest /* // keep track of starting row square int parity = 0; // 0 is even, 1 is odd, tied to row number int count = 0; // row square int rowNum = 0; // row number, starting at 0 int vsegment = in.rows() / 8; // only accounts 8 playable int hsegment = in.cols() / 12; // 8 playable, 2 capture, 2 extra int offset = hsegment * 2; // offset for playable board // For angle of camera int dx = 48; hsegment -= 8; // Go through all playable squares for (int i = 0; i < playSquares; i++) { // change offset depending on the row if (parity == 0) // playable squares start on immediate left offset = hsegment * 3 + dx; else // playable squares start on 2nd square from left offset = hsegment * 2 + dx; // find where roi should be Point p1 = new Point(offset + count * hsegment, rowNum * vsegment); // top left point of rectangle (x,y) Point p2 = new Point(offset + (count + 1) * hsegment, (rowNum + 1) * vsegment); // bottom right point of rectangle (x,y) // create rectangle that is board square Rect bound = new Rect(p1, p2); // frame only includes rectangle Mat roi = new Mat(in, bound); Imgproc.cvtColor(roi, roi, Imgproc.COLOR_BGR2GRAY); // change to single color Mat canny = new Mat(); Imgproc.Canny(roi, canny, 2, 4); // make image a canny image that is only edges; 2,4 // lower threshold values find more edges List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Mat hierarchy = new Mat(); // holds nested contour information Imgproc.findContours(canny, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); // Imgproc.RETR_LIST, TREE // Get bounding rect of contour Rect rect = Imgproc.boundingRect(contours.get(0)); if (rect.height > in.rows() / 8) { board[i]++; // make it a king } count += 2; if (count == 8) { parity = ++parity % 2; // change odd or even count = 0; rowNum++; hsegment += 1; dx -= 6; } }*/ }
public static OCRText recognize_as_ocrtext(Mat image) { return new OCRText(VisionProxyJNI.Vision_recognize_as_ocrtext(Mat.getCPtr(image), image), true); }
public void alloc(int elemNumber) { if (elemNumber > 0) super.create(elemNumber, 1, CvType.makeType(_depth, _channels)); }
public static void main(String[] args) { Mat pFrame = imread("image0.png", CV_LOAD_IMAGE_GRAYSCALE); Mat cFrame = imread("image1.png", CV_LOAD_IMAGE_GRAYSCALE); Mat pGray = new Mat(); Mat cGray = new Mat(); pFrame.convertTo(pGray, CV_32FC1); cFrame.convertTo(cGray, CV_32FC1); Mat Optical_Flow = new Mat(); DenseOpticalFlow tvl1 = createOptFlow_DualTVL1(); tvl1.calc(pGray, cGray, Optical_Flow); Mat OF = new Mat(pGray.rows(), pGray.cols(), CV_32FC1); FloatBuffer in = Optical_Flow.getFloatBuffer(); FloatBuffer out = OF.getFloatBuffer(); int height = pGray.rows(); int width = pGray.cols(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float xVelocity = in.get(); float yVelocity = in.get(); float pixelVelocity = (float) Math.sqrt(xVelocity * xVelocity + yVelocity * yVelocity); out.put(pixelVelocity); } } imwrite("OF.png", OF); }
/** * O algoritmo de retropropagação matricial (Ver a interface Mat) * * @param entradas as entradas da rede * @param e o erro obtido durante o feedForward da rede com 'entradas' */ private void backward(double[] entradas, double[] e) { double[][] m = new double[1][0]; double[][] deltaW; double[] deltaB; m[0] = e; for (int i = camada.length - 1; i > 0; i--) { m = Mat.produto(Mat.diag(Mat.dfSigmoide(camada[i].getSaida())), m); deltaB = m[0]; deltaW = Mat.transp(Mat.kProduto(Mat.transp(camada[i - 1].getSaida()), m)); m = Mat.produto(camada[i].w, m); atualizaCamada(i, deltaW, deltaB); } m = Mat.produto(Mat.diag(Mat.dfSigmoide(camada[0].getSaida())), m); deltaB = m[0]; deltaW = Mat.transp(Mat.kProduto(Mat.transp(entradas), m)); atualizaCamada(0, deltaW, deltaB); }
public static void main(String[] args) { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 ); // System.out.println( "mat = " + mat.dump() ); Sample n = new Sample(); // n.templateMatching(); // put text in image // Mat data= Highgui.imread("images/erosion.jpg"); // Core.putText(data, "Sample", new Point(50,80), Core.FONT_HERSHEY_SIMPLEX, 1, new // Scalar(0,0,0),2); // // Highgui.imwrite("images/erosion2.jpg", data); // getting dct of an image String path = "images/croppedfeature/go (20).jpg"; path = "images/wordseg/img1.png"; Mat image = Highgui.imread(path, Highgui.IMREAD_GRAYSCALE); ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_OTSU); Imgproc.threshold(image, image, 220, 128, Imgproc.THRESH_BINARY_INV); Mat newImg = new Mat(45, 100, image.type()); newImg.setTo(new Scalar(0)); n.copyMat(image, newImg); int vgap = 25; int hgap = 45 / 3; Moments m = Imgproc.moments(image, false); Mat hu = new Mat(); Imgproc.HuMoments(m, hu); System.out.println(hu.dump()); // //divide the mat into 12 parts then get the features of each part // int count=1; // for(int j=0; j<45; j+=hgap){ // for(int i=0;i<100;i+=vgap){ // Mat result = newImg.submat(j, j+hgap, i, i+vgap); // // // Moments m= Imgproc.moments(result, false); // double m01= m.get_m01(); // double m00= m.get_m00(); // double m10 = m.get_m10(); // int x= m00!=0? (int)(m10/m00):0; // int y= m00!=0? (int)(m01/m00):0; // Mat hu= new Mat(); // Imgproc.HuMoments(m, hu); // System.out.println(hu.dump()); // System.out.println(count+" :"+x+" and "+y); // Imgproc.threshold(result, result, 0,254, Imgproc.THRESH_BINARY_INV); // Highgui.imwrite("images/submat/"+count+".jpg", result); // count++; // // } // } // // for(int i=vgap;i<100;i+=vgap){ // Point pt1= new Point(i, 0); // Point pt2= new Point(i, 99); // Core.line(newImg, pt1, pt2, new Scalar(0,0,0)); // } // for(int i=hgap;i<45;i+=hgap){ // Point pt1= new Point(0, i); // Point pt2= new Point(99, i); // Core.line(newImg, pt1, pt2, new Scalar(0,0,0)); // } // Highgui.imwrite("images/submat/copyto.jpg", newImg); }
/** * @param inputImg * @param minValue * @param maxValue * @return Mat */ public static Mat thresholding(Mat inputImg, Integer minValue, Integer maxValue) { Mat frame = inputImg; // яскравість // frame.convertTo(frame , -1, 10d * 33 / 100, 0); // Imgproc.medianBlur(frame,frame, 17); // Core.bitwise_not(frame,frame ); // Mat frame = new Mat(image.rows(), image.cols(), image.type()); // frame.convertTo(frame, -1, 10d * 20 / 100, 0); Mat hsvImg = new Mat(); List<Mat> hsvPlanes = new ArrayList<>(); Mat thresholdImg = new Mat(); int thresh_type = Imgproc.THRESH_BINARY_INV; // if (this.inverse.isSelected()) // thresh_type = Imgproc.THRESH_BINARY; // threshold the image with the average hue value // System.out.println("size " +frame.size()); hsvImg.create(frame.size(), CvType.CV_8U); // Imgproc.cvtColor(frame, hsvImg, Imgproc.COLOR_BGR2HSV); Core.split(hsvImg, hsvPlanes); // get the average hue value of the image // double threshValue = PreProcessingOperation.getHistAverage(hsvImg, hsvPlanes.get(0)); // System.out.println(threshValue); /* if(threshValue > 40){ maxValue = 160; }else{ maxValue = 40; }*/ // Imgproc.threshold(hsvPlanes.get(1), thresholdImg, minValue , maxValue , thresh_type); Imgproc.blur(thresholdImg, thresholdImg, new Size(27, 27)); // dilate to fill gaps, erode to smooth edges Imgproc.dilate(thresholdImg, thresholdImg, new Mat(), new Point(-1, -1), 1); Imgproc.erode(thresholdImg, thresholdImg, new Mat(), new Point(-1, -1), 1); Imgproc.threshold(thresholdImg, thresholdImg, minValue, maxValue, Imgproc.THRESH_BINARY); // create the new image Mat foreground = new Mat(frame.size(), CvType.CV_8UC3, new Scalar(255, 255, 255)); Core.bitwise_not(thresholdImg, foreground); frame.copyTo(foreground, thresholdImg); /////////////////////////////////////////////////////////////////////////////////////// /// //// return foreground; /*Mat hsvImg = new Mat(); List<Mat> hsvPlanes = new ArrayList<>(); Mat thresholdImg = new Mat(); int thresh_type = Imgproc.THRESH_BINARY_INV; // threshold the image with the average hue value hsvImg.create(inputImg.size(), CvType.CV_8U); Imgproc.cvtColor(inputImg, hsvImg, Imgproc.COLOR_BGR2HSV); Core.split(hsvImg, hsvPlanes); // get the average hue value of the image double threshValue = PreProcessingOperation.getHistAverage(hsvImg, hsvPlanes.get(0)); Imgproc.threshold(hsvPlanes.get(0), thresholdImg, minValue, maxValue, thresh_type); Imgproc.blur(thresholdImg, thresholdImg, new Size(3, 3)); // dilate to fill gaps, erode to smooth edges Imgproc.dilate(thresholdImg, thresholdImg, new Mat(), new Point(-1, -1), 3); Imgproc.erode(thresholdImg, thresholdImg, new Mat(), new Point(-1, -1), 1); Imgproc.threshold(thresholdImg, thresholdImg, minValue, maxValue, Imgproc.THRESH_BINARY); // create the new image Mat foreground = new Mat(inputImg.size(), CvType.CV_8UC3, new Scalar(255, 255, 255)); inputImg.copyTo(foreground, thresholdImg); Core.bitwise_not(foreground,foreground); return foreground;*/ }
public void map(Text key, Text value, Context context) throws InterruptedException, IOException { String filename = key.toString(); String json = value.toString(); // Make sure the input is valid if (!(filename.isEmpty() || json.isEmpty())) { // Change the json-type feature to Mat-type feature Mat descriptor = json2mat(json); if (descriptor != null) { // Read the query feature from the cache in Hadoop Mat query_features; String pathStr = context.getConfiguration().get("featureFilePath"); FileSystem fs = FileSystem.get(context.getConfiguration()); FSDataInputStream fsDataInputStream = fs.open(new Path(pathStr)); StringBuilder sb = new StringBuilder(); // Use a buffer to read the query_feature int remain = fsDataInputStream.available(); while (remain > 0) { int read; byte[] buf = new byte[BUF_SIZE]; read = fsDataInputStream.read(buf, fsDataInputStream.available() - remain, BUF_SIZE); sb.append(new String(buf, 0, read, StandardCharsets.UTF_8)); remain = remain - read; System.out.println("remain:" + remain + "\tread:" + read + "\tsb.size:" + sb.length()); } // Read the query_feature line by line // Scanner sc = new Scanner(fsDataInputStream, "UTF-8"); // StringBuilder sb = new StringBuilder(); // while (sc.hasNextLine()) { // sb.append(sc.nextLine()); // } // String query_json = sb.toString(); // String query_json = new String(buf, StandardCharsets.UTF_8); String query_json = sb.toString(); fsDataInputStream.close(); query_features = json2mat(query_json); // Get the similarity of the current database image against the query image DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED); MatOfDMatch matches = new MatOfDMatch(); // Ensure the two features have same length of cols (the feature extracted are all 128 // cols(at least in this case)) if (query_features.cols() == descriptor.cols()) { matcher.match(query_features, descriptor, matches); DMatch[] dMatches = matches.toArray(); // Calculate the max/min distances // double max_dist = Double.MAX_VALUE; // double min_dist = Double.MIN_VALUE; double max_dist = 0; double min_dist = 100; for (int i = 0; i < dMatches.length; i++) { double dist = dMatches[i].distance; if (min_dist > dist) min_dist = dist; if (max_dist < dist) max_dist = dist; } // Only distances ≤ threshold are good matches double threshold = max_dist * THRESHOLD_FACTOR; // double threshold = min_dist * 2; LinkedList<DMatch> goodMatches = new LinkedList<DMatch>(); for (int i = 0; i < dMatches.length; i++) { if (dMatches[i].distance <= threshold) { goodMatches.addLast(dMatches[i]); } } // Get the ratio of good_matches to all_matches double ratio = (double) goodMatches.size() / (double) dMatches.length; System.out.println("*** current_record_filename:" + filename + " ***"); System.out.println("feature:" + descriptor + "\nquery_feature:" + query_features); System.out.println( "min_dist of keypoints:" + min_dist + " max_dist of keypoints:" + max_dist); System.out.println( "total_matches:" + dMatches.length + "\tgood_matches:" + goodMatches.size()); // System.out.println("type:" + descriptor.type() + " channels:" + // descriptor.channels() + " rows:" + descriptor.rows() + " cols:" + descriptor.cols()); // System.out.println("qtype:" + query_features.type() + " // qchannels:" + query_features.channels() + " qrows:" + query_features.rows() + " // qcols:" + query_features.cols()); System.out.println(); if (ratio > PERCENTAGE_THRESHOLD) { // Key:1 Value:filename|ratio context.write(ONE, new Text(filename + "|" + ratio)); // context.write(ONE, new Text(filename + "|" + // String.valueOf(goodMatches.size()))); } } else { System.out.println("The size of the features are not equal"); } } else { // a null pointer, do nothing System.out.println("A broken/null feature:" + filename); System.out.println(); } } }