List of usage examples for org.opencv.imgproc Imgproc LINE_AA
int LINE_AA
To view the source code for org.opencv.imgproc Imgproc LINE_AA.
Click Source Link
From source file:org.akvo.caddisfly.sensor.colorimetry.strip.util.ResultUtil.java
License:Open Source License
/** * Create a Mat to show the point at which the matched color occurs. * * @param colors the range of colors * @param result the result//from w w w . j ava 2 s.c om * @param colorDetected the colors extracted from the patch * @param width the width of the mat to be returned * @return the Mat with the point or arrow drawn */ @NonNull public static Mat createValueMeasuredMatSingle(@NonNull JSONArray colors, double result, @NonNull ColorDetected colorDetected, int width) { Mat mat = new Mat(MEASURE_LINE_HEIGHT, width, CvType.CV_8UC3, LAB_WHITE); double xTranslate = (double) width / (double) colors.length(); try { // determine where the circle should be placed for (int d = 0; d < colors.length(); d++) { double nextValue = colors.getJSONObject(Math.min(d + 1, colors.length() - 1)) .getDouble(SensorConstants.VALUE); if (result <= nextValue) { Scalar resultColor = colorDetected.getLab(); double value = colors.getJSONObject(d).getDouble(SensorConstants.VALUE); //calculate number of pixels needed to translate in x direction double transX = xTranslate * ((result - value) / (nextValue - value)); double left = xTranslate * d; double right = left + xTranslate - X_MARGIN; Point circleCenter = new Point(Math.max(10d, left + (right - left) / 2 + transX), SINGLE_MEASURE_LINE_TOP_MARGIN); MatOfPoint matOfPoint = new MatOfPoint( new Point((circleCenter.x - ARROW_TRIANGLE_LENGTH), circleCenter.y + ARROW_TRIANGLE_LENGTH - 2), new Point((circleCenter.x + ARROW_TRIANGLE_LENGTH), circleCenter.y + ARROW_TRIANGLE_LENGTH - 2), new Point(circleCenter.x, (circleCenter.y + ARROW_TRIANGLE_LENGTH * 2) - 2), new Point((circleCenter.x - ARROW_TRIANGLE_LENGTH), circleCenter.y + ARROW_TRIANGLE_LENGTH - 2)); Imgproc.fillConvexPoly(mat, matOfPoint, resultColor); Imgproc.circle(mat, circleCenter, CIRCLE_RADIUS, resultColor, -1, Imgproc.LINE_AA, 0); break; } } } catch (JSONException e) { Timber.e(e); } return mat; }
From source file:org.akvo.caddisfly.sensor.colorimetry.strip.util.ResultUtil.java
License:Open Source License
/** * Create a Mat to show the point at which the matched color occurs for group patch test. * * @param colors the range of colors * @param result the result//from www . j a v a2 s . c o m * @param colorsDetected the colors extracted from the patch * @param width the width of the mat to be returned * @return the Mat with the point or arrow drawn */ @NonNull public static Mat createValueMeasuredMatGroup(@NonNull JSONArray colors, double result, @NonNull ColorDetected[] colorsDetected, int width) { int height = COLOR_INDICATOR_SIZE * colorsDetected.length; Mat valueMeasuredMat = new Mat(height, width, CvType.CV_8UC3, LAB_WHITE); double xTranslate = (double) width / (double) colors.length(); try { // determine where the circle should be placed for (int d = 0; d < colors.length(); d++) { double nextValue = colors.getJSONObject(Math.min(d + 1, colors.length() - 1)) .getDouble(SensorConstants.VALUE); Scalar resultColor = null; if (result < nextValue) { double value = colors.getJSONObject(d).getDouble(SensorConstants.VALUE); //calculate number of pixels needed to translate in x direction double transX = xTranslate * ((result - value) / (nextValue - value)); double left = xTranslate * d; double right = left + xTranslate - X_MARGIN; Point point = (transX) + xTranslate * d < X_MARGIN ? new Point(X_MARGIN, MEASURE_LINE_TOP_MARGIN) : new Point(left + (right - left) / 2 + transX, MEASURE_LINE_TOP_MARGIN); double offset = 5; for (ColorDetected aColorsDetected : colorsDetected) { resultColor = aColorsDetected.getLab(); Imgproc.rectangle(valueMeasuredMat, new Point(point.x - ARROW_TRIANGLE_LENGTH, point.y + offset), new Point(point.x + ARROW_TRIANGLE_LENGTH, point.y + (ARROW_TRIANGLE_LENGTH * 2) + offset), resultColor, -1, Imgproc.LINE_AA, 0); offset += 2 * ARROW_TRIANGLE_LENGTH; } MatOfPoint matOfPoint = new MatOfPoint( new Point((point.x - ARROW_TRIANGLE_LENGTH), point.y + offset), new Point((point.x + ARROW_TRIANGLE_LENGTH), point.y + offset), new Point(point.x, point.y + ARROW_TRIANGLE_LENGTH + offset), new Point((point.x - ARROW_TRIANGLE_LENGTH), point.y + offset)); Imgproc.fillConvexPoly(valueMeasuredMat, matOfPoint, resultColor); break; } } } catch (JSONException e) { Timber.e(e); } return valueMeasuredMat; }