Package de.offis.faint.model

Examples of de.offis.faint.model.ImageModel


  public Region[] detectFaces(String file, int minScanWindowSize) {
   
    try {
      byte[] bytes = null;
      double scaleFactor = 1;
      ImageModel image = new ImageModel(file);
      image.getImage(true);

     
      // Prepare byte array to send
      if (downScale){
       
        int height = image.getHeight();
        int width = image.getWidth();

        if (height > MAXSIZE.getHeight() || width > MAXSIZE.getWidth()){
          double aspect = (double) width / (double) height;
          scaleFactor = width;
          if (aspect > (MAXSIZE.getWidth() / MAXSIZE.getHeight())) {
            width = (int) Math.round(MAXSIZE.getWidth());
            height = (int) Math.round((1.0 /aspect) * width);
          }
          else
          {
            height = (int) Math.round(MAXSIZE.getHeight());
            width = (int) Math.round(aspect * height);
          }
          scaleFactor = (double) width / scaleFactor; // scale = newWidth / oldWidth
          minScanWindowSize = (int) Math.round(minScanWindowSize * scaleFactor);
        }
       
        BufferedImage i = Utilities.getScaledCopy(image.getImage(false),width, height, Image.SCALE_SMOOTH);
        ByteArrayOutputStream o = new ByteArrayOutputStream();
        ImageIO.write(i ,"jpg", o);
        o.close();
        bytes = o.toByteArray();
      }
      else {
       
        bytes = new byte[(int) image.getFile().length()];
       
        InputStream is = new FileInputStream(file);
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
View Full Code Here


    }
   
    // Open Image
    else if (incomingEvent instanceof EventOpenImage){
      EventOpenImage event = (EventOpenImage) incomingEvent;
      ImageModel image = event.getImage();
     
     
      if (image == null || image.isAvailable()){
      mainFrame.setEnabled(false);
     
      if (currentImage == null || !currentImage.equals(image)) {
        currentImage = image;
       
        // Cache BufferedImage
        if (image != null)
          MainController.getInstance().getBufferedImageCache().cacheImage(image.getFile().getPath());
       
        // Update Image
        mainFrame.browserTab.getImagePanel().setImage(image);

        // Update AnnotationTable and selected region
        mainFrame.browserTab.getAnnotationPanel().setImage(currentImage);
       
        // Make sure that the right folder is opened.
        if (currentImage!=null)
          dispatchEvent(new EventOpenFolder(currentImage.getFolder()));
       
        // Make sure that the right thumbnail is selected
        mainFrame.browserTab.getThumbnailPanel().setSelectedImage(image);
       
        // Update Buttons
        dispatchEvent(new EventUpdateMenuBar(currentImage != null));
      }
     
      mainFrame.setEnabled(true);
      }
      else {
        new InfoDialog(mainFrame," Image "+image.getFile().getPath()+" not available!");       
      }
    }
   
    // Delete Person
    else if (incomingEvent instanceof EventDeletePerson){
      EventDeletePerson event = (EventDeletePerson) incomingEvent;
     
      String[] options = { "Ok", "Cancel"};
      int n = JOptionPane.showOptionDialog( mainFrame,
          "Remove "+event.getName()+" from database?",
          "Delete Person",
          JOptionPane.YES_NO_OPTION,
          JOptionPane.QUESTION_MESSAGE,
          null, options,options[0] );
      if ( n == JOptionPane.YES_OPTION )
      {
        MainController.getInstance().getFaceDB().deleteAnnotation(event.getName());
        mainFrame.browserTab.getAnnotationPanel().updateFromModel();
        mainFrame.browserTab.getImagePanel().getClassificationPanel().updateFromModel();
        mainFrame.faceDBTab.getPersonPanel().updateFromModel();       
      }
    }
   
        // Set the classification of a region
    else if (incomingEvent instanceof EventClassifyRegion){
      EventClassifyRegion event = (EventClassifyRegion) incomingEvent;     
               
      // Save classification in database
      MainController.getInstance().getFaceDB().put(event.getRegion(),event.getAnnotation());
     
      // Update view
      mainFrame.browserTab.getAnnotationPanel().repaint();
      mainFrame.browserTab.getImagePanel().getClassificationPanel().repaint();
    }
   
    // Rename a person
    else if (incomingEvent instanceof EventRenamePerson){
      EventRenamePerson event = (EventRenamePerson) incomingEvent;
      MainController.getInstance().getFaceDB().renameAnnotation(event.getOldName(), event.getNewName());
      mainFrame.browserTab.getAnnotationPanel().updateFromModel();
      mainFrame.browserTab.getImagePanel().getClassificationPanel().updateFromModel();
      mainFrame.faceDBTab.getPersonPanel().updateFromModel();
    }
   
        // Change training flag of region
    else if (incomingEvent instanceof EventModifyTrainingData){
      EventModifyTrainingData event = (EventModifyTrainingData) incomingEvent;
      event.getRegion().setUsedForTraining(event.getValue())
    }

   
    // Add a new person to the database
    else if (incomingEvent instanceof EventAddKnownPerson){
      EventAddKnownPerson event = (EventAddKnownPerson) incomingEvent;
      MainController.getInstance().getFaceDB().put(null, event.getName());
    }
   
    // Selected region changed
    else if (incomingEvent instanceof EventRegionSelectionChanged){
      EventRegionSelectionChanged event = (EventRegionSelectionChanged) incomingEvent;
      Region newRegion = event.getRegion();
     
      if (newRegion != null){
        ImageModel image = new ImageModel(newRegion.getImage());
        if (currentImage == null || !currentImage.equals(image))
        {
          dispatchEvent(new EventOpenImage(image));
         
          if (currentImage == null || !currentImage.equals(image))
View Full Code Here

 
  @Override
  public void run() {
    while(true){
      while(!thumbNailsToPreload.isEmpty()){
        ImageModel model = thumbNailsToPreload.firstElement();
        model.initThumbnail();
        thumbModel.reportThumbnailUpdate();
        thumbNailsToPreload.remove(model);
      }
      suspended = true;
      synchronized(this) {
View Full Code Here

  /* (non-Javadoc)
   * @see javax.swing.table.TableModel#getValueAt(int, int)
   */
  public Object getValueAt(int rowIndex, int columnIndex) {
    ImageModel image = this.images.get(rowIndex);
    switch (columnIndex){
    case 0:
      if (image.getTumbnail()==null) return thumbPlaceholder;
      else return image.getTumbnail();
    case 1:
      if (image.getWidth()==null||image.getHeight()==null)
          return "<html><b>"+image.getFileName()+"</b><br>"
              +"unknown size"
              +"</html>";
      else
          return "<html><b>"+image.getFileName()+"</b><br>"
              +image.getWidth()+" x "+image.getHeight()
              +"</html>";
    }
    return null;
  }
View Full Code Here

  public void setFolder(File folder) {
    thumbnailloadingThread.clearRequestedThumbNails();
    File[] imageFiles = folder.listFiles(new Utilities.FileTypeFilter(Constants.IMAGE_SUFFIXES));
    this.images = new ArrayList<ImageModel>(imageFiles.length);
    for (File imageFile : imageFiles){
      ImageModel imageModel = new ImageModel(imageFile);
      this.images.add(imageModel);
      this.thumbnailloadingThread.preloadThumbnail(imageModel);
    }
    fireTableDataChanged();
  }
View Full Code Here

TOP

Related Classes of de.offis.faint.model.ImageModel

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.