List of usage examples for org.opencv.imgproc Imgproc circle
public static void circle(Mat img, Point center, int radius, Scalar color, int thickness, int lineType, int shift)
From source file:contador_de_moedas.Reconhecimento.java
public Mat CriaMascara(Point pt, double raio, Mat img_Original) { // Cria uma img toda preta com as mesmas dimenses da original Mat mask = zeros(img_Original.rows(), img_Original.cols(), CV_8U); // Cria um circulo branco preenchido Imgproc.circle(mask, pt, (int) raio, new Scalar(255, 255, 255), -1, 8, 0); return (mask); }
From source file:digimesh.xbee.gui.SensorMap.java
private void drawSensor(SmartSensor sensor) { Point sensorLocation = new Point(sensor.getPositionXY().positionX - 50, sensor.getPositionXY().positionY + 30); int measNr = sensor.getMeasurmentToDraw(); String id = sensor.getId();/*from w w w .j a v a 2 s . c om*/ String sTextName = "Sensor ID : " + id.substring(id.length() - 4, id.length()); int fontFace = Core.FONT_HERSHEY_PLAIN; double fontScale = 0.7; Imgproc.putText(map, sTextName, sensorLocation, fontFace, fontScale, Scalar.all(255)); Scalar circleColor = new Scalar(255, 255, 255); if (sensor.hasMeasurements) { double value = sensor.m_measurments.get(measNr).value; String measName = sensor.m_measurments.get(measNr).name; String unit = sensor.m_measurments.get(measNr).unit; String sTextMeas = measName + " = " + value + "[" + unit + "]"; Imgproc.putText(map, sTextMeas, new Point(sensor.getPositionXY().positionX - 50, (sensor.getPositionXY().positionY + 50)), fontFace, fontScale, Scalar.all(255)); double upperLimit = sensor.m_measurments.get(measNr).upperLimit; double lowerLimit = sensor.m_measurments.get(measNr).lowerLimit; //check value if (value > upperLimit) { circleColor = new Scalar(0, 0, 255); } else if (value < lowerLimit) { circleColor = new Scalar(255, 0, 0); } else { circleColor = new Scalar(0, 255, 0); } } else { Imgproc.putText(map, HUB_LABEL, new Point(sensor.getPositionXY().positionX - 50, (sensor.getPositionXY().positionY + 12)), fontFace, fontScale, Scalar.all(255)); } Imgproc.circle(map, sensorLocation, 10, circleColor, 2, fontFace, 0); }
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/* w w w . j a v a 2 s. com*/ * @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:templatematching.ProcessFrame.java
public Image processFrame(VideoCapture capture) { while (k < 2) { capture.grab();// w ww.j ava 2 s . c om capture.retrieve(frame); capture.retrieve(frame); //treat each frame of the capture individually // retives the grabbed frame into Mat obj int frame_width = frame.rows(); int frame_height = frame.cols(); MatOfRect faces1 = new MatOfRect(); Mat frame_gray = new Mat(); Mat ImageROI; //change the frame to gray-scale Imgproc.cvtColor(frame, frame_gray, Imgproc.COLOR_BGR2GRAY);//gray scale conversion //use histogram equilization //Imgproc.equalizeHist(frame_gray, frame_gray ); //use the face classifie faceHaar.detectMultiScale(frame_gray, faces1, 1.1, 2, 2, new Size(30, 30), new Size()); Rect[] faces = faces1.toArray(); for (int i = 0; i < faces.length; i++) { // System.out.println("Processing faces"); Point center = new Point(faces[i].x + faces[i].width * 0.5, faces[i].y + faces[i].height * 0.5); Imgproc.ellipse(frame, center, new Size(faces[i].width * 0.5, faces[i].height * 0.5), 0, 0, 360, new Scalar(0, 0, 255), 4, 8, 0); Mat faceROI = frame_gray.submat(faces[i]); MatOfRect eyes1 = new MatOfRect(); eyesHaar.detectMultiScale(faceROI, eyes1, 1.15, 2, 2, new Size(30, 30), new Size()); //eyesHaar.detectMultiScale(faceROI, eyes1, 1.1, 2, Objdetect.CASCADE_FIND_BIGGEST_OBJECT|Objdetect.CASCADE_SCALE_IMAGE, new Size(30,30),new Size()); Rect[] eyes = eyes1.toArray(); // System.out.println("Processing eyes"); for (int j = 0; j < eyes.length; j++) { Mat eyeROI = frame_gray.submat(eyes[i]); Point center1 = new Point(faces[i].x + eyes[j].x + eyes[j].width * 0.5, faces[i].y + eyes[j].y + eyes[j].height * 0.5); int radius = (int) ((eyes[j].width + eyes[j].height) * 0.005); Imgproc.circle(frame, center1, radius, new Scalar(255, 0, 0), 4, 8, 0); Pupilx = (int) center1.x; Pupily = (int) center1.y; ROIwidth = eyes[j].width; ROIheight = eyes[j].height; Point centerX[] = new Point[2]; centerX[k] = center1; //performing the scaling of the coordintaes to fir to the screen dimensions if (k == 0) { scaledPupilx = Pupilx; scaledPupily = Pupily; k++; } else { System.out.println("In else part"); deltax = (int) Math.abs((centerX[k].x - centerX[k - 1].x)); deltay = (int) Math.abs((centerX[k].y - centerX[k - 1].y)); scaled_deltax = (deltax * (65535 / ROIwidth)); scaled_deltay = (deltay * (65535 / ROIheight)); scaledPupilx = centerX[k - 1].x + scaled_deltax; scaledPupily = centerX[k - 1].y + scaled_deltay; } if (k == 2) k = 0; //set the cursor position to the scaled coordinates try { Robot robot = new Robot(); robot.mouseMove((int) (1366 - scaledPupilx), (int) (768 - scaledPupily)); } catch (AWTException ex) { } } //define a window for displaying the frame //release window if any key is hit } MatOfByte mem = new MatOfByte(); Imgcodecs.imencode(".bmp", frame, mem); Image im = null; try { im = ImageIO.read(new ByteArrayInputStream(mem.toArray())); } catch (IOException ex) { ex.printStackTrace(); } return im; } return null; }