SHOW:
|
|
- or go back to the newest paste.
1 | public class Convolucion { | |
2 | ||
3 | /** | |
4 | * @param args the command line arguments | |
5 | */ | |
6 | public static void main(String[] args) { | |
7 | // TODO code application logic here | |
8 | System.out.println("Cargar y mostrar imagen: "); | |
9 | System.loadLibrary("opencv_java247"); | |
10 | System.out.println("Librería: "+Core.NATIVE_LIBRARY_NAME +" Version: " +Core.VERSION); | |
11 | //Convolucion c = new Convolucion(); | |
12 | new Procesar(); | |
13 | } | |
14 | } | |
15 | ||
16 | class Procesar{ | |
17 | URL img_url = getClass().getResource("/resources/picasso.jpg"); | |
18 | String ruta = img_url.getPath(); | |
19 | ||
20 | public void Procesar(){ | |
21 | Mat imagen; | |
22 | if (ruta.startsWith("/")) { | |
23 | ruta = ruta.substring(1); | |
24 | } | |
25 | imagen = Highgui.imread(ruta,Highgui.CV_LOAD_IMAGE_COLOR); | |
26 | if(!imagen.empty()){ | |
27 | Image imagenMostrar = convertir(imagen); | |
28 | int width=imagenMostrar.getWidth(null); | |
29 | int height=imagenMostrar.getHeight(null); | |
30 | Ventana ventana = new Ventana(imagenMostrar); | |
31 | ventana.setSize(width,height); | |
32 | ventana.setLocationRelativeTo(null); | |
33 | ventana.setVisible(true); | |
34 | } | |
35 | } | |
36 | ||
37 | private Image convertir(Mat imagen) { | |
38 | MatOfByte matOfByte = new MatOfByte(); | |
39 | Highgui.imencode(".jpg", imagen, matOfByte); | |
40 | ||
41 | byte[] byteArray = matOfByte.toArray(); | |
42 | BufferedImage bufImage = null; | |
43 | ||
44 | try { | |
45 | InputStream in = new ByteArrayInputStream(byteArray); | |
46 | bufImage = ImageIO.read(in); | |
47 | } catch (Exception e) { | |
48 | e.printStackTrace(); | |
49 | } | |
50 | return (Image)bufImage; | |
51 | } | |
52 | } |