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
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()
/** * 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(); } }