Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Convolucion {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- System.out.println("Cargar y mostrar imagen: ");
- System.loadLibrary("opencv_java247");
- System.out.println("Librería: "+Core.NATIVE_LIBRARY_NAME +" Version: " +Core.VERSION);
- //Convolucion c = new Convolucion();
- new Procesar();
- }
- }
- class Procesar{
- URL img_url = getClass().getResource("/resources/picasso.jpg");
- String ruta = img_url.getPath();
- public void Procesar(){
- Mat imagen;
- if (ruta.startsWith("/")) {
- ruta = ruta.substring(1);
- }
- imagen = Highgui.imread(ruta,Highgui.CV_LOAD_IMAGE_COLOR);
- if(!imagen.empty()){
- Image imagenMostrar = convertir(imagen);
- int width=imagenMostrar.getWidth(null);
- int height=imagenMostrar.getHeight(null);
- Ventana ventana = new Ventana(imagenMostrar);
- ventana.setSize(width,height);
- ventana.setLocationRelativeTo(null);
- ventana.setVisible(true);
- }
- }
- private Image convertir(Mat imagen) {
- MatOfByte matOfByte = new MatOfByte();
- Highgui.imencode(".jpg", imagen, matOfByte);
- byte[] byteArray = matOfByte.toArray();
- BufferedImage bufImage = null;
- try {
- InputStream in = new ByteArrayInputStream(byteArray);
- bufImage = ImageIO.read(in);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return (Image)bufImage;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement