List of usage examples for org.opencv.imgproc Imgproc putText
public static void putText(Mat img, String text, Point org, int fontFace, double fontScale, Scalar color)
From source file:com.projectcs2103t.openglestest.OpenGLES20Activity.java
License:Apache License
@Override public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) { Mat rgba = inputFrame.rgba();//w w w . j a va2 s . c o m float projection[] = mCameraProjectionAdapter.getProjectionGL(); Mat CameraMat = mCameraProjectionAdapter.getCVCameraMat(); Mat DistortionMat = mCameraProjectionAdapter.getCVDistortionMat(); Mat ModelViewMat = new Mat(4, 4, CvType.CV_64FC1); int detected = nl.processFrame(rgba.getNativeObjAddr(), CameraMat.getNativeObjAddr(), DistortionMat.getNativeObjAddr(), ModelViewMat.getNativeObjAddr()); float mGLModelView[] = null; if (detected == 1) { mGLModelView = new float[16]; mGLModelView[0] = (float) ModelViewMat.get(0, 0)[0]; mGLModelView[1] = (float) ModelViewMat.get(0, 1)[0]; mGLModelView[2] = (float) ModelViewMat.get(0, 2)[0]; mGLModelView[3] = (float) ModelViewMat.get(0, 3)[0]; mGLModelView[4] = (float) ModelViewMat.get(1, 0)[0]; mGLModelView[5] = (float) ModelViewMat.get(1, 1)[0]; mGLModelView[6] = (float) ModelViewMat.get(1, 2)[0]; mGLModelView[7] = (float) ModelViewMat.get(1, 3)[0]; mGLModelView[8] = (float) ModelViewMat.get(2, 0)[0]; mGLModelView[9] = (float) ModelViewMat.get(2, 1)[0]; mGLModelView[10] = (float) ModelViewMat.get(2, 2)[0]; mGLModelView[11] = (float) ModelViewMat.get(2, 3)[0]; mGLModelView[12] = (float) ModelViewMat.get(3, 0)[0]; mGLModelView[13] = (float) ModelViewMat.get(3, 1)[0]; mGLModelView[14] = (float) ModelViewMat.get(3, 2)[0]; mGLModelView[15] = (float) ModelViewMat.get(3, 3)[0]; //showMatrices(rgba, ModelViewMat); } mCameraProjectionAdapter.setModelViewGL(mGLModelView); Imgproc.putText(rgba, mCameraProjectionAdapter.toString(), new Point(50, 50), Core.FONT_HERSHEY_PLAIN, 1.0, new Scalar(0, 255, 0)); Imgproc.putText(rgba, mGLView.toString(), new Point(50, 75), Core.FONT_HERSHEY_PLAIN, 1.0, new Scalar(0, 255, 0)); return rgba; }
From source file:com.projectcs2103t.openglestest.OpenGLES20Activity.java
License:Apache License
private void showMatrices(Mat rgba, Mat mat) { double m00 = mat.get(0, 0)[0]; double m01 = mat.get(0, 1)[0]; double m02 = mat.get(0, 2)[0]; double m03 = mat.get(0, 3)[0]; double m10 = mat.get(1, 0)[0]; double m11 = mat.get(1, 1)[0]; double m12 = mat.get(1, 2)[0]; double m13 = mat.get(1, 3)[0]; double m20 = mat.get(2, 0)[0]; double m21 = mat.get(2, 1)[0]; double m22 = mat.get(2, 2)[0]; double m23 = mat.get(2, 3)[0]; double m30 = mat.get(3, 0)[0]; double m31 = mat.get(3, 1)[0]; double m32 = mat.get(3, 2)[0]; double m33 = mat.get(3, 3)[0]; //String camMatStr = cameraMat.dump(); String mRow0 = "|" + m00 + "," + m01 + "," + m02 + "," + m03 + "|"; String mRow1 = "|" + m10 + "," + m11 + "," + m12 + "," + m13 + "|"; String mRow2 = "|" + m20 + "," + m21 + "," + m22 + "," + m23 + "|"; String mRow3 = "|" + m30 + "," + m31 + "," + m32 + "," + m33 + "|"; Imgproc.putText(rgba, "Model-View-Mat:", new Point(50, 100), Core.FONT_HERSHEY_PLAIN, 1.0, new Scalar(0, 255, 0)); Imgproc.putText(rgba, mRow0, new Point(50, 125), Core.FONT_HERSHEY_PLAIN, 1.0, new Scalar(0, 255, 0)); Imgproc.putText(rgba, mRow1, new Point(50, 150), Core.FONT_HERSHEY_PLAIN, 1.0, new Scalar(0, 255, 0)); Imgproc.putText(rgba, mRow2, new Point(50, 175), Core.FONT_HERSHEY_PLAIN, 1.0, new Scalar(0, 255, 0)); Imgproc.putText(rgba, mRow3, new Point(50, 200), Core.FONT_HERSHEY_PLAIN, 1.0, new Scalar(0, 255, 0)); }
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 ww . j a va 2s. co m*/ 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:emotion.EyeRegion.java
public static void showLegend() { StaticFunctions.drawCross(EyeRegion._face, new Point(5, 5), StaticFunctions.Features.EYEBROWS_ENDS); Imgproc.putText(EyeRegion._face, "Eyebrows ends", new Point(12, 7), Core.FONT_HERSHEY_SIMPLEX, 0.3, new Scalar(255, 255, 255)); StaticFunctions.drawCross(EyeRegion._face, new Point(5, 15), StaticFunctions.Features.EYE_CORNERS); Imgproc.putText(EyeRegion._face, "Eyes' corners", new Point(12, 17), Core.FONT_HERSHEY_SIMPLEX, 0.3, new Scalar(255, 255, 255)); StaticFunctions.drawCross(EyeRegion._face, new Point(5, 25), StaticFunctions.Features.EYELIDS); Imgproc.putText(EyeRegion._face, "Eyelids", new Point(12, 27), Core.FONT_HERSHEY_SIMPLEX, 0.3, new Scalar(255, 255, 255)); }
From source file:io.github.jakejmattson.facialrecognition.FacialRecognition.java
License:Open Source License
private static Mat detectFaces(Mat image, CascadeClassifier faceDetector, ImageFrame frame) { MatOfRect faceDetections = new MatOfRect(); faceDetector.detectMultiScale(image, faceDetections); Rect[] faces = faceDetections.toArray(); boolean shouldSave = frame.shouldSave(); String name = frame.getFileName(); Scalar color = frame.getTextColor(); for (Rect face : faces) { Mat croppedImage = new Mat(image, face); if (shouldSave) saveImage(croppedImage, name); Imgproc.putText(image, "ID: " + identifyFace(croppedImage), face.tl(), Font.BOLD, 1.5, color); Imgproc.rectangle(image, face.tl(), face.br(), color); }//from ww w . j a v a 2s.com int faceCount = faces.length; String message = faceCount + (faceCount == 1 ? "face" : "faces") + " detected!"; Imgproc.putText(image, message, new Point(3, 25), Font.BOLD, 2, color); return image; }
From source file:org.technowolves.vision.TowerTracker.java
License:Open Source License
/** * /*w w w .j ava 2 s . c o m*/ * reads an image from a live image capture and outputs information to the SmartDashboard or a file */ public static void processImage() { ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); double x, y, targetX, targetY, distance, azimuth; // frame counter int FrameCount = 0; long before = System.currentTimeMillis(); // only run for the specified time while (FrameCount < 100) { contours.clear(); // capture from the axis camera videoCapture.read(matOriginal); // captures from a static file for testing // matOriginal = Imgcodecs.imread("someFile.png"); Imgproc.cvtColor(matOriginal, matHSV, Imgproc.COLOR_BGR2HSV); Core.inRange(matHSV, LOWER_BOUNDS, UPPER_BOUNDS, matThresh); Imgproc.findContours(matThresh, contours, matHeirarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); // make sure the contours that are detected are at least 20x20 // pixels with an area of 400 and an aspect ration greater then 1 for (Iterator<MatOfPoint> iterator = contours.iterator(); iterator.hasNext();) { MatOfPoint matOfPoint = (MatOfPoint) iterator.next(); Rect rec = Imgproc.boundingRect(matOfPoint); if (rec.height < 25 || rec.width < 25) { iterator.remove(); continue; } float aspect = (float) rec.width / (float) rec.height; if (aspect < 1.0) iterator.remove(); } for (MatOfPoint mop : contours) { Rect rec = Imgproc.boundingRect(mop); Imgproc.rectangle(matOriginal, rec.br(), rec.tl(), BLACK); } // if there is only 1 target, then we have found the target we want if (contours.size() == 1) { Rect rec = Imgproc.boundingRect(contours.get(0)); // "fun" math brought to you by miss daisy (team 341)! y = rec.br().y + rec.height / 2; y = -((2 * (y / matOriginal.height())) - 1); distance = (TOP_TARGET_HEIGHT - TOP_CAMERA_HEIGHT) / Math.tan((y * VERTICAL_FOV / 2.0 + CAMERA_ANGLE) * Math.PI / 180); // angle to target...would not rely on this targetX = rec.tl().x + rec.width / 2; targetX = (2 * (targetX / matOriginal.width())) - 1; azimuth = normalize360(targetX * HORIZONTAL_FOV / 2.0 + 0); // drawing info on target Point center = new Point(rec.br().x - rec.width / 2 - 15, rec.br().y - rec.height / 2); Point centerw = new Point(rec.br().x - rec.width / 2 - 15, rec.br().y - rec.height / 2 - 20); Imgproc.putText(matOriginal, "" + (int) distance, center, Core.FONT_HERSHEY_PLAIN, 1, BLACK); Imgproc.putText(matOriginal, "" + (int) azimuth, centerw, Core.FONT_HERSHEY_PLAIN, 1, BLACK); } // output an image for debugging Imgcodecs.imwrite("output.png", matOriginal); FrameCount++; } shouldRun = false; }
From source file:org.usfirst.frc.team2084.CMonster2016.vision.CameraCalibration.java
License:Open Source License
/** * Draws checkerboard corners on an image. * /*from w w w . j a v a 2 s . c om*/ * @param image the image to process * @param addToCalibration if true, add this image to the corner list */ public void process(Mat image, boolean addToCalibration) { boolean patternFound = Calib3d.findChessboardCorners(image, boardSize, boardCorners, Calib3d.CALIB_CB_ADAPTIVE_THRESH | Calib3d.CALIB_CB_NORMALIZE_IMAGE | Calib3d.CALIB_CB_FAST_CHECK); if (patternFound) { // Refine corner positions to be more accurate Imgproc.cvtColor(image, grayImage, Imgproc.COLOR_BGR2GRAY); Imgproc.cornerSubPix(grayImage, boardCorners, new Size(6, 6), new Size(-1, -1), new TermCriteria(TermCriteria.EPS + TermCriteria.COUNT, 30, 0.1)); if (addToCalibration) { calibrationCorners.add(boardCorners); } } image.copyTo(boardImage); Calib3d.drawChessboardCorners(boardImage, boardSize, boardCorners, patternFound); if (!addToCalibration) { debugImage("Board", boardImage); } Imgproc.undistort(image, undistortImage, cameraMatrix, distCoeffs); undistortImage.copyTo(image); Imgproc.putText(image, "Error: " + error, new Point(20, 20), Core.FONT_HERSHEY_PLAIN, 1.5, new Scalar(0, 255, 0)); }
From source file:org.usfirst.frc.team2084.CMonster2016.vision.Utils.java
License:Open Source License
public static void drawText(Mat image, String text, double x, double y) { Imgproc.putText(image, text, new Point(x, y), Core.FONT_HERSHEY_PLAIN, TEXT_SIZE, TEXT_COLOR); }
From source file:org.usfirst.frc.team2084.CMonster2016.vision.Utils.java
License:Open Source License
public static void drawText(Mat image, String text, double x, double y, double textSize) { Imgproc.putText(image, text, new Point(x, y), Core.FONT_HERSHEY_PLAIN, textSize, TEXT_COLOR); }
From source file:org.usfirst.frc.team2084.CMonster2016.vision.Utils.java
License:Open Source License
public static void drawText(Mat image, String text, double x, double y, Scalar textColor) { Imgproc.putText(image, text, new Point(x, y), Core.FONT_HERSHEY_PLAIN, TEXT_SIZE, textColor); }