Package org.openpnp.spi

Examples of org.openpnp.spi.Camera


  private boolean step5() {
    MainFrame.machineControlsPanel.submitMachineTask(new Runnable() {
      public void run() {
        Head head = Configuration.get().getMachine().getHeads().get(0);
        try {
          Camera camera = MainFrame.cameraPanel
              .getSelectedCamera();
          Location location = jobPanel.getSelectedBoardLocation()
              .getLocation();
          MovableUtils.moveToLocationAtSafeZ(camera, location, 1.0);
        }
View Full Code Here


  private boolean step5() {
    MainFrame.machineControlsPanel.submitMachineTask(new Runnable() {
      public void run() {
        Head head = Configuration.get().getMachine().getHeads().get(0);
        try {
          Camera camera = MainFrame.cameraPanel
              .getSelectedCamera();
          Location location = jobPanel.getSelectedBoardLocation()
              .getLocation();
          MovableUtils.moveToLocationAtSafeZ(camera, location, 1.0);
        }
View Full Code Here

  }
 
  // TODO: This needs to happen on the machine executor, or just die completely.
  public void run() {
    try {
      Camera camera = MainFrame.cameraPanel.getSelectedCamera();
      // TODO: Make sure the units are native
      double startX = Double.parseDouble(txtStartX.getText());
      double startY = Double.parseDouble(txtStartY.getText());
      double endX = Double.parseDouble(txtEndX.getText());
      double endY = Double.parseDouble(txtEndY.getText());
      // Calculate bounding box
      double width = Math.abs(endX - startX);
      double height = Math.abs(endY - startY);
      // Determine how many images are needed
      BufferedImage image = camera.capture();
      // Figure out how many units per image we are getting
      Location unitsPerPixel = camera.getUnitsPerPixel();
      unitsPerPixel = unitsPerPixel.convertToUnits(Configuration.get().getSystemUnits());
      double imageWidthInUnits = unitsPerPixel.getX() * image.getWidth();
      double imageHeightInUnits = unitsPerPixel.getY() * image.getHeight();
      logger.info(String.format("Images are %d, %d pixels, %2.3f, %2.3f %s",
          image.getWidth(),
          image.getHeight(),
          imageWidthInUnits,
          imageHeightInUnits,
          unitsPerPixel.getUnits().getShortName()));
      int widthInImages = (int) (width / (imageWidthInUnits / 2));
      int heightInImages = (int) (height / (imageHeightInUnits / 2));
      int totalImages = (widthInImages * heightInImages);
      logger.info(String.format("Need to capture %d x %d images for a total of %d",
          widthInImages,
          heightInImages,
          totalImages));
      // Start loop, checking for cancelled
      File outputDirectory = new File(txtOutputDirectory.getText());
      if (!outputDirectory.exists()) {
        throw new Exception("Output directory does not exist.");
      }
      if (startX >= endX) {
        throw new Exception("End Position X must be greater than End Position X");
      }
      if (startY >= endY) {
        throw new Exception("End Position Y must be greater than End Position Y");
      }
      progressBar.setMinimum(0);
      progressBar.setMaximum(totalImages - 1);
      progressBar.setValue(0);
      int currentImageX = 0, currentImageY = 0, currentImage = 0;
      while (!cancelled) {
          Location location = camera.getLocation();
          location = location.derive(
                  startX + ((imageWidthInUnits / 2) * currentImageX),
                  startY + ((imageHeightInUnits / 2) * currentImageY),
                  null,
                  null);
          camera.moveTo(location, 1.0);
        // Give the head and camera 500ms to settle
        Thread.sleep(500);
        // We capture two images to make sure that the one we save is
        // not coming from a previous frame.
        image = camera.capture();
        image = camera.capture();
        File outputFile = new File(outputDirectory,
            String.format(Locale.US, "%2.3f,%2.3f.png", location.getX(), location.getY()));
        ImageIO.write(image, "png",outputFile);
        progressBar.setValue(currentImage);
        currentImage++;
View Full Code Here

                cameraSpecificConfigPanel.removeAll();
                visionProviderConfigPanel.removeAll();
               
        if (index != -1) {
          index = table.convertRowIndexToModel(index);
          Camera camera = tableModel.getCamera(index);
          Wizard generalConfigWizard = new CameraConfigurationWizard(camera);
          if (generalConfigWizard != null) {
            generalConfigWizard.setWizardContainer(CamerasPanel.this);
            JPanel panel = generalConfigWizard.getWizardPanel();
            generalConfigPanel.add(panel);
          }
         
                    Wizard cameraSpecificConfigWizard = camera.getConfigurationWizard();
                    if (cameraSpecificConfigWizard != null) {
                        cameraSpecificConfigWizard.setWizardContainer(CamerasPanel.this);
                        JPanel panel = cameraSpecificConfigWizard.getWizardPanel();
                        cameraSpecificConfigPanel.add(panel);
                    }
                   
                    VisionProvider visionProvider = camera.getVisionProvider();
                    if (visionProvider != null) {
                        Wizard visionProviderConfigWizard = visionProvider.getConfigurationWizard();
                        if (visionProviderConfigWizard != null) {
                            visionProviderConfigWizard.setWizardContainer(CamerasPanel.this);
                            JPanel panel = visionProviderConfigWizard.getWizardPanel();
View Full Code Here

      return selectedCameraView;
    }
    for (int i = 0; i < camerasCombo.getItemCount(); i++) {
      Object o = camerasCombo.getItemAt(i);
      if (o instanceof CameraItem) {
        Camera c = ((CameraItem) o).getCamera();
        if (c == camera) {
          camerasCombo.setSelectedIndex(i);
          return selectedCameraView;
        }
      }
View Full Code Here

    }
    return null;
  }
 
  public Location getSelectedCameraLocation() {
      Camera camera = getSelectedCamera();
      if (camera == null) {
          return null;
      }
      return camera.getLocation();
  }
View Full Code Here

    double Zoffset;
   
    //do camera magic
    Head head = nozzle.getHead();
    // Find the Camera to be used for vision
    Camera camera = null;
    for (Camera c : head.getCameras()) {
      if (c.getVisionProvider() != null) {
        camera = c;
      }
    }
   
    if (camera == null) {
      throw new Exception("No vision capable camera found on head.");
    }
    // Position the camera over the pick location.
    logger.debug("Move camera to mirror location.");

    //move to mirror position
    camera.moveTo(mirrorStartLocation, 1.0);
    camera.moveTo(mirrorMidLocation, 1.0);
    camera.moveTo(mirrorEndLocation, 1.0);

    //do camera magic
    visionX0Offset = visionMgr.getVisionOffsets(head, mirrorEndLocation.derive(null, null, null, 0.0),vision);
    visionY90Offset = visionMgr.getVisionOffsets(head, mirrorEndLocation.derive(null, null, null, 90.0),vision);
    visionX180Offset = visionMgr.getVisionOffsets(head, mirrorEndLocation.derive(null, null, null, 180.0),vision);
    visionY270Offset = visionMgr.getVisionOffsets(head, mirrorEndLocation.derive(null, null, null, 270.0),vision);
   
    Xoffset = visionX180Offset.subtract(visionX0Offset);
    Yoffset = visionY90Offset.subtract(visionY270Offset);
//    Zoffset = visionX0Offset.getY();
    Zoffset = 0.0; //TODO: fix Z offset
   
    //move away from mirror position
    camera.moveTo(mirrorEndLocation, 1.0);
    camera.moveTo(mirrorMidLocation, 1.0);
    camera.moveTo(mirrorStartLocation, 1.0);
   
    double offsetX = Xoffset.getX()/2;
    double offsetY = Yoffset.getX()/2;
   
    offsetX *= this.pixelComp; //compensate for calibration distance being different than pick distance
View Full Code Here

  // TODO: Throw an Exception if vision fails.
  private Location getVisionOffsets(Head head, Location pickLocation) throws Exception {
      logger.debug("getVisionOffsets({}, {})", head.getId(), pickLocation);
    // Find the Camera to be used for vision
    // TODO: Consider caching this
    Camera camera = null;
    for (Camera c : head.getCameras()) {
      if (c.getVisionProvider() != null) {
        camera = c;
      }
    }
   
    if (camera == null) {
      throw new Exception("No vision capable camera found on head.");
    }
   
    head.moveToSafeZ(1.0);
   
    // Position the camera over the pick location.
    logger.debug("Move camera to pick location.");
    camera.moveTo(pickLocation, 1.0);
   
    // Move the camera to be in focus over the pick location.
//    head.moveTo(head.getX(), head.getY(), z, head.getC());
   
    // Settle the camera
    // TODO: This should be configurable, or maybe just built into
    // the VisionProvider
    Thread.sleep(200);
   
    VisionProvider visionProvider = camera.getVisionProvider();
   
    Rectangle aoi = getVision().getAreaOfInterest();
   
    // Perform the template match
    logger.debug("Perform template match.");
    Point[] matchingPoints = visionProvider.locateTemplateMatches(
        aoi.getX(),
        aoi.getY(),
        aoi.getWidth(),
        aoi.getHeight(),
        0,
        0,
        vision.getTemplateImage());
   
    // Get the best match from the array
    Point match = matchingPoints[0];
   
    // match now contains the position, in pixels, from the top left corner
    // of the image to the top left corner of the match. We are interested in
    // knowing how far from the center of the image the center of the match is.
    BufferedImage image = camera.capture();
    double imageWidth = image.getWidth();
    double imageHeight = image.getHeight();
    double templateWidth = vision.getTemplateImage().getWidth();
    double templateHeight = vision.getTemplateImage().getHeight();
    double matchX = match.x;
    double matchY = match.y;

        logger.debug("matchX {}, matchY {}", matchX, matchY);

    // Adjust the match x and y to be at the center of the match instead of
    // the top left corner.
    matchX += (templateWidth / 2);
    matchY += (templateHeight / 2);
   
        logger.debug("centered matchX {}, matchY {}", matchX, matchY);

    // Calculate the difference between the center of the image to the
    // center of the match.
    double offsetX = (imageWidth / 2) - matchX;
    double offsetY = (imageHeight / 2) - matchY;

        logger.debug("offsetX {}, offsetY {}", offsetX, offsetY);
   
    // Invert the Y offset because images count top to bottom and the Y
    // axis of the machine counts bottom to top.
    offsetY *= -1;
   
        logger.debug("negated offsetX {}, offsetY {}", offsetX, offsetY);
   
    // And convert pixels to units
    Location unitsPerPixel = camera.getUnitsPerPixel();
    offsetX *= unitsPerPixel.getX();
    offsetY *= unitsPerPixel.getY();

        logger.debug("final, in camera units offsetX {}, offsetY {}", offsetX, offsetY);
   
View Full Code Here

  }

  @Override
  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    try {
      Camera camera = cameras.get(rowIndex);
      if (columnIndex == 1) {
        camera.setLooking((Looking) aValue);
      }
      else if (columnIndex == 2) {
          HeadCellValue value = (HeadCellValue) aValue;
          if (camera.getHead() == null) {
              Configuration.get().getMachine().removeCamera(camera);
          }
          else {
                    camera.getHead().removeCamera(camera);
          }
         
          if (value.getHead() == null) {
              Configuration.get().getMachine().addCamera(camera);
          }
          else {
              value.getHead().addCamera(camera);
          }
          camera.setHead(value.getHead());
      }
      configuration.setDirty(true);
    }
    catch (Exception e) {
      // TODO: dialog, bad input
View Full Code Here

      // TODO: dialog, bad input
    }
  }
 
  public Object getValueAt(int row, int col) {
    Camera camera = cameras.get(row);
    Location loc = camera.getLocation();
    switch (col) {
    case 0:
      return camera.getId();
    case 1:
      return camera.getLooking();
    case 2:
      return new HeadCellValue(camera.getHead());
     
    default:
      return null;
    }
  }
View Full Code Here

TOP

Related Classes of org.openpnp.spi.Camera

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.