public static BufferedImage loadImage(String directory , String fileName) { return loadImage(new File(directory,fileName).getPath()); }
private synchronized void process( BufferedImage left , BufferedImage right ) { if( simulationTime > previousTime + period ) { // System.out.println("####### saving image time "+simulationTime); if( right == null ) System.out.println("WTF"); previousTime = simulationTime; UtilImageIO.saveImage(left, String.format("%s/left%05d.ppm",directory,numFrames)); UtilImageIO.saveImage(right, String.format("%s/right%05d.ppm",directory,numFrames)); numFrames++; } } }
/** * A function that load the specified image. If anything goes wrong it returns a * null. */ public static BufferedImage loadImage(String fileName) { BufferedImage img; try { img = ImageIO.read(new File(fileName)); if( img == null) { if( fileName.endsWith("ppm") || fileName.endsWith("PPM") ) { return loadPPM(fileName,null); } else if( fileName.endsWith("pgm") || fileName.endsWith("PGM") ) { return loadPGM(fileName, null); } } } catch (IOException e) { return null; } return img; }
/** * Loads a PGM image from an {@link InputStream}. * * @param fileName InputStream for PGM image * @param storage (Optional) Storage for output image. Must be the width and height of the image being read. * If null a new image will be declared. * @return The read in image * @throws IOException */ public static GrayU8 loadPGM_U8(String fileName , GrayU8 storage ) throws IOException { return loadPGM_U8(new FileInputStream(fileName),storage); }
/** * Loads a PGM image from a file. * * @param fileName Location of PGM image * @param storage (Optional) Storage for output image. Must be the width and height of the image being read. * Better performance of type BufferedImage.TYPE_BYTE_GRAY. If null or width/height incorrect a new image * will be declared. * @return The read in image * @throws IOException */ public static BufferedImage loadPGM( String fileName , BufferedImage storage ) throws IOException { return loadPGM(new FileInputStream(fileName), storage); }
/** * Loads a PPM image from a file. * * @param fileName Location of PPM image * @param storage (Optional) Storage for output image. Must be the width and height of the image being read. * Better performance of type BufferedImage.TYPE_INT_RGB. If null or width/height incorrect a new image * will be declared. * @return The read in image * @throws IOException */ public static BufferedImage loadPPM( String fileName , BufferedImage storage ) throws IOException { return loadPPM(new FileInputStream(fileName),storage); }
public static <T extends ImageGray> T loadImage(String directory , String fileName, Class<T> imageType ) { return loadImage(new File(directory,fileName).getPath(),imageType); }
protected void saveInputImage() { synchronized (bufferedImageLock) { String fileName = String.format("saved_input%03d.png",saveCounter++); System.out.println("Input image saved to "+fileName); UtilImageIO.saveImage(original, fileName); } }
public static void main( String args[] ) { BufferedImage input = UtilImageIO.loadImage(fileName); doStuff(GrayF32.class,input); // doStuff(GrayU8.class,input); } }
@Override public void mouseClicked(MouseEvent e) { if( e.getButton() == 2 ) { System.out.println("Image saved "+saveCounter); UtilImageIO.saveImage(img, String.format("saved_image%03d.png",saveCounter++)); } } });
@Override public BufferedImage openImage(String fileName) { BufferedImage b = cachedImage.get(fileName); if( b == null ) { b = UtilImageIO.loadImage(fileName); if( b == null ) throw new RuntimeException("Image cannot be found! "+fileName); cachedImage.put(fileName,b); } // return a copy of the image so that if it is modified strangeness won't happen BufferedImage c = new BufferedImage(b.getWidth(),b.getHeight(),b.getType()); Graphics2D g2 = c.createGraphics(); g2.drawImage(b,0,0,null); return c; }
@Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == 'p') { paused = false; } else if (e.getKeyChar() == 's') { System.out.println("Saving image"); String name = String.format("image%05d.jpg", savedIndex++); UtilImageIO.saveImage(image, name); } else { paused = true; step = true; } }
private void loadImage( String imagePath ) { BufferedImage in = UtilImageIO.loadImage(imagePath); image = ConvertBufferedImage.convertFrom(in,(GrayF32)null); }
@Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == 'p') { paused = false; } else if (e.getKeyChar() == 's') { System.out.println("Saving image"); String name = String.format("image%05d.jpg", savedIndex++); UtilImageIO.saveImage(image, name); } else { paused = true; step = true; } }
/** * Loads all the image in the specified directory which match the provided regex * @param directory File directory * @param regex Regex used to match file names * @return List of found images. */ public static List<BufferedImage> loadImages( String directory , final String regex ) { File[] files = new File(directory).listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.matches(regex); } }); List<BufferedImage> ret = new ArrayList<>(); for( File f : files ) { BufferedImage img = loadImage(f.getAbsolutePath()); if( img != null ) ret.add( img ); } return ret; }
/** * * <p>Saves the BoofCV formatted image. This is identical to the following code:</p> * * <pre> * BufferedImage out = ConvertBufferedImage.convertTo(image,null,true); * saveImage(out,fileName); * </pre> * * @param image Image which is to be saved. * @param fileName Name of the output file. The type is determined by the extension. */ public static void saveImage( ImageBase image , String fileName ) { BufferedImage out = ConvertBufferedImage.convertTo(image,null,true); saveImage(out,fileName); }
@Override public BufferedImage openImage(String fileName) { BufferedImage b = cachedImage.get(fileName); if( b == null ) { b = UtilImageIO.loadImage(fileName); if( b == null ) return null; cachedImage.put(fileName,b); } // return a copy of the image so that if it is modified strangeness won't happen BufferedImage c = new BufferedImage(b.getWidth(),b.getHeight(),b.getType()); Graphics2D g2 = c.createGraphics(); g2.drawImage(b,0,0,null); return c; }
public void log( BufferedImage image , long timeStamp ) { DenseMatrix64F R = CommonOps.identity(3, 3); Vector3D T = new Vector3D(); // Matrix3d Rm = new Matrix3d(); // rosTransformFromHeadBaseToCamera.get(Rm); // MatrixTools.matrix3DToDenseMatrix(Rm,R,0,0); Quaternion_F64 quad = ConvertRotation3D_F64.matrixToQuaternion(R, null); // rosTransformFromHeadBaseToCamera.get(T); logPose.printf("%d %15f %15f %15f %15f %15f %15f %15f\n", timeStamp, quad.x, quad.y, quad.z, quad.w, T.getX(), T.getY(), T.getZ()); logPose.flush(); UtilImageIO.saveImage(image, String.format("%s/image%06d.png", outputDir.getAbsolutePath(), tick)); tick++; }