Exemple #1
0
 public static long getLastWriteTime(String filename) {
   try {
     java.io.File f = new java.io.File(filename);
     return f.lastModified();
   } catch (Exception ex) {
     return -1;
   }
 }
 private void stopButtonActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_stopButtonActionPerformed
   // TODO add your handling code here:
   pp.closeDown();
   startButton.setEnabled(true);
   stopButton.setEnabled(false);
   setpanel();
   java.io.File file = new java.io.File("").getAbsoluteFile();
   String name = file.getPath().replace('\\', '/') + '/';
   String path = name + "src/input/1.jpg";
   imp.set(path);
 } // GEN-LAST:event_stopButtonActionPerformed
Exemple #3
0
 private boolean CheckValidDir(String path) {
   java.io.File dir = new java.io.File(path);
   if (dir == null) {
     return false;
   }
   if (dir.isFile()) {
     return false;
   }
   if (!dir.exists()) {
     return false;
   }
   return true;
 }
 private void saveSnap(BufferedImage im, String fnm)
       // save image as JPG
     {
   fnm = i + fnm;
   // i++;
   java.io.File file = new java.io.File("").getAbsoluteFile();
   String name = file.getPath().replace('\\', '/') + '/';
   // System.out.println("Saving image to " + fnm);
   try {
     ImageIO.write(im, "jpg", new File(name + "src/input/" + fnm));
   } catch (IOException e) {
     System.out.println("Could not save image");
   }
 } // end of saveSnap()
 public java.net.URL getCodeBase() {
   if (codeBase == null) {
     try {
       java.io.File file = new java.io.File("");
       codeBase =
           new java.net.URL(
               "file",
               "", // no host
               file.getAbsolutePath().toString());
     } catch (java.net.MalformedURLException e) {
     }
   }
   return codeBase;
 }
Exemple #6
0
 /**
  * °´Â·¾¶±£´æ
  *
  * @param bufferImage
  * @param docNo
  * @throws Exception
  */
 public static void saveImageToPriview(
     java.awt.image.BufferedImage bufferImage, String path, String docNo) throws Exception {
   StringBuffer temp = new StringBuffer();
   java.io.File outFile = new java.io.File(path);
   if (!outFile.exists()) {
     outFile.mkdirs();
   }
   java.io.File file = new java.io.File(outFile, temp.append(docNo).append(".png").toString());
   if (!file.exists()) {
     java.io.FileOutputStream out = new java.io.FileOutputStream(file);
     javax.imageio.ImageIO.write(bufferImage, "png", out);
     out.close();
   }
 }
Exemple #7
0
 public static java.awt.Image loadImageFromFile(String path) {
   java.io.File file = new java.io.File(path);
   if (file.exists()) {
     java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
     java.awt.Image img = tk.createImage(path);
     try {
       java.awt.MediaTracker mt = new java.awt.MediaTracker(new javax.swing.JPanel());
       mt.addImage(img, 0);
       mt.waitForID(0);
     } catch (Exception ex) {
       return null;
     }
     return img;
   }
   return null;
 }
Exemple #8
0
  public static String getShortFileName(String filename) {
    if (filename.length() > 50) {
      java.io.File f = new java.io.File(filename);
      if (nvl(f.getParentFile(), "").length() > 10) {
        String dir = f.getParentFile().getPath() + java.io.File.separatorChar;

        String shortDir = dir.substring(0, dir.indexOf(java.io.File.separatorChar) + 1);
        dir = dir.substring(dir.indexOf(java.io.File.separatorChar) + 1);
        if (dir.indexOf(java.io.File.separatorChar) > 0) {
          shortDir += dir.substring(0, dir.indexOf(java.io.File.separatorChar) + 1);
        }
        return shortDir + "..." + java.io.File.separatorChar + f.getName();
      }
    }

    return filename;
  }
    /**
     * Main entry point. Loads the Swing elements on the "Event Dispatch Thread".
     *
     * @param args
     */
    public void run() {
      javax.swing.JFileChooser fc = new javax.swing.JFileChooser();
      fc.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
      int returnVal = fc.showOpenDialog(null);

      if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
        setpanel();
        buttonBar.removeAll();
        buttonBar.repaint();

        java.io.File file = fc.getSelectedFile();
        imagedir = file.getPath().replace('\\', '/') + '/';
        try (java.io.BufferedWriter out =
            new java.io.BufferedWriter(new java.io.FileWriter("imageload", false))) {
          out.write(imagedir);
          out.close();
        } catch (java.io.IOException ert) {
          javax.swing.JOptionPane.showMessageDialog(
              null, ert, "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
        }
        running();
      }
    }
    @Override
    public void run(String arg) {

      java.io.File file = new java.io.File("").getAbsoluteFile();
      String name = file.getPath().replace('\\', '/') + '/';

      ctd = new candidateTextDet();
      trl = new textRegLoca();
      ce = new characExtract();
      int chardata[] = new int[35];

      ImagePlus im = Im.duplicate();
      ImagePlus finish = Im.duplicate();

      IJ.run(im, "8-bit", "");

      ImagePlus featuremap = ctd.candidateTextDet(im);

      int l = trl.textRegLoca(featuremap, finish);
      ce.spaceset(l);

      c = new int[l];

      c = ce.characExtract(l);

      // mn.load_actionPerformed(null);
      // mn.train_actionPerformed(null);

      int total = 0;

      for (int i = 0; i < l; i++) {
        total += c[i];
      }

      int i = 0;
      for (int count = 0; count < total; count++) {
        if (c[i] == count) {
          outputTextarea.setText(outputTextarea.getText() + " ");
          i++;
          c[i] += c[i - 1];
        }
        String path = name + "src/cache/ocr/" + (count + 1) + ".jpg";
        chardata = extractBytes(path);
        int flag = 0;
        int m = 0;
        for (m = 0; m < position; m++) {
          for (int j = 0; j < 35; j++) {
            if (data[m][j] != chardata[j]) {
              flag--;
              break;
            } else {
              flag++;
            }
          }
          if (flag == 35) {
            break;
          } else {
            flag = 0;
          }
        }

        char recognized = ' ';
        if (flag == 35) {
          recognized = ch[m];
        } else {
          recognized = '?';
        }

        outputTextarea.setText(outputTextarea.getText() + "" + recognized);

        // java.io.File fileocr = new java.io.File(name + "src/cache/ocr/" + (count + 1) + ".jpg");
        // fileocr.delete();
      }
    }