Exemplo n.º 1
0
  public static void draw3dAxis(
      Mat frame, CameraParameters cp, Scalar color, double height, Mat Rvec, Mat Tvec) {
    //		Mat objectPoints = new Mat(4,3,CvType.CV_32FC1);
    MatOfPoint3f objectPoints = new MatOfPoint3f();
    Vector<Point3> points = new Vector<Point3>();
    points.add(new Point3(0, 0, 0));
    points.add(new Point3(height, 0, 0));
    points.add(new Point3(0, height, 0));
    points.add(new Point3(0, 0, height));
    objectPoints.fromList(points);

    MatOfPoint2f imagePoints = new MatOfPoint2f();
    Calib3d.projectPoints(
        objectPoints, Rvec, Tvec, cp.getCameraMatrix(), cp.getDistCoeff(), imagePoints);
    List<Point> pts = new Vector<Point>();
    Converters.Mat_to_vector_Point(imagePoints, pts);

    Core.line(frame, pts.get(0), pts.get(1), color, 2);
    Core.line(frame, pts.get(0), pts.get(2), color, 2);
    Core.line(frame, pts.get(0), pts.get(3), color, 2);

    Core.putText(frame, "X", pts.get(1), Core.FONT_HERSHEY_SIMPLEX, 0.5, color, 2);
    Core.putText(frame, "Y", pts.get(2), Core.FONT_HERSHEY_SIMPLEX, 0.5, color, 2);
    Core.putText(frame, "Z", pts.get(3), Core.FONT_HERSHEY_SIMPLEX, 0.5, color, 2);
  }
Exemplo n.º 2
0
  public static void draw_opticflow(Mat flow, Mat cflowmap, int step, Scalar color) {
    int i = 0, j = 0;
    for (int y = 0; y < cflowmap.rows(); y += step) {
      for (int x = 0; x < cflowmap.cols(); x += step) {

        double[] fxy = Sample1View.flow.get(50, 50);

        // for testing, getting change in values sa frames at point 50,50
        // result : fxy ng.change ang value, however, kun i.add na ang 50, mura xag ma.zero??
        i = (int) Math.round(fxy[0]);
        j = (int) (50.00 + fxy[1]);

        Core.putText(
            cflowmap,
            Double.toString(j),
            new Point(10, 100),
            3 /* CV_FONT_HERSHEY_COMPLEX */,
            2,
            new Scalar(255, 0, 0, 255),
            3);

        // Core.line(cflowmap, new Point(x,y), new Point(i,j), new Scalar(0,0,255), 4);
        // Core.circle(cflowmap, new Point(i,j), 2, new Scalar(0,0,255), -1);
        // Core.circle(cflowmap, new Point(x,y), 2, color, -1);
        // System.out.print("fxy"+i+" "+j+"\n");

        // Core.circle(cflowmap, new Point(cflowmap.width(), 50), 5, new Scalar(255,255,255), -1);
        if (i < (cflowmap.width() / 2) && i != 0.0) {
          Core.circle(cflowmap, new Point(i, j), 2, new Scalar(0, 0, 255), -1);
          Core.putText(
              cflowmap,
              "LEFT",
              new Point(10, 100),
              3 /* CV_FONT_HERSHEY_COMPLEX */,
              2,
              new Scalar(255, 255, 255, 255),
              3);

        } else if (i > (cflowmap.width() / 2) && i != x) {
          Core.circle(cflowmap, new Point(i, j), 2, new Scalar(0, 0, 255), -1);
          Core.putText(
              cflowmap,
              "RIGHT",
              new Point(10, 100),
              3 /* CV_FONT_HERSHEY_COMPLEX */,
              2,
              new Scalar(255, 255, 255, 255),
              3);
        }
      }
    }
  }
Exemplo n.º 3
0
 /**
  * Calculates the final resistance value for each Resistor object, based on its classified band
  * colours, and displays all values on the top right frame of the GUI.
  *
  * @param resistorList The list of Resistors to process. Each Resistor must have 3 associated
  *     ColourBands
  */
 private void calculateAndDisplayResistanceValues(List<Resistor> resistorList) {
   for (int x = 0; x < resistorList.size(); x++) {
     // ignore resistors which do not have 3 bands
     if (resistorList.get(x).bands.size() == 3) {
       Resistor r = resistorList.get(x);
       r.orderBands();
       r.calculateFinalResistanceValue(true);
       if (r.isValid) {
         if (SEARCH_STRING == null
             || SEARCH_STRING.length() == 0
             || r.finalValueHR.equals(SEARCH_STRING)) {
           // draw resistance value to screen
           Core.putText(
               finalDisplayImg,
               r.finalValueHR,
               r.center,
               Core.FONT_HERSHEY_PLAIN,
               2,
               new Scalar(255, 0, 0),
               2);
           // TODO: to try and reduce 'noise' of changing values keep the value for a given point
           // untill it changes.
         }
       }
     }
     paintTR(finalDisplayImg);
   }
 }
Exemplo n.º 4
0
 public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
   frame = inputFrame.rgba();
   outputFrame = frame.clone();
   if (homography != null) {
     if (markerValue != -1 && markerValue != oldMarkerValue) {
       oldMarkerValue = markerValue;
       outputLogo = logo.clone();
       Core.putText(
           outputLogo,
           Integer.toString(markerValue),
           new Point(5, 505),
           Core.FONT_HERSHEY_SIMPLEX,
           5,
           new Scalar(255, 0, 0),
           5);
     }
     Imgproc.warpPerspective(
         outputLogo,
         outputFrame,
         homography,
         new Size(WIDTH, HEIGHT),
         Imgproc.INTER_NEAREST,
         Imgproc.BORDER_TRANSPARENT,
         new Scalar(0));
   }
   return outputFrame;
 }
 private void displayMarkersDebug(Mat imgMat, Scalar contourColor, Scalar codesColor) {
   ArrayList<MatOfPoint> components = new ArrayList<MatOfPoint>();
   Mat hierarchy = new Mat();
   DtouchMarker marker = new DtouchMarker();
   boolean markerFound = findMarkers(imgMat, marker, components, hierarchy);
   if (markerFound) {
     String code = codeArrayToString(marker.getCode());
     Point codeLocation = new Point(imgMat.cols() / 4, imgMat.rows() / 8);
     Core.putText(mRgba, code, codeLocation, Core.FONT_HERSHEY_COMPLEX, 1, codesColor, 3);
     Imgproc.drawContours(
         mRgba,
         components,
         marker.getComponentIndex(),
         contourColor,
         3,
         8,
         hierarchy,
         2,
         new Point(0, 0));
   }
   if (components != null) components.clear();
   if (hierarchy != null) hierarchy.release();
   components = null;
   hierarchy = null;
 }