reset password
Author Message
afetiso
Posts: 84
Posted 22:14 Feb 03, 2015 |

Hello, I trying to use:

Mat mat = Highgui.imread((String)fc.getSelectedFile().getAbsolutePath());

but it doesn't work. Can you help me and tell me how I can create Mat from BufferImage.

lbriggs
Posts: 57
Posted 22:18 Feb 03, 2015 |

imgread accepts a file path, I use something like:

File input = new File("pic.jpg")

Mat mat = Highgui.imread(input.getPath())

lbriggs
Posts: 57
Posted 22:21 Feb 03, 2015 |

I see you have a variable "fc" I assume thats a file chooser?

FileChooser fileChooser = new FileChooser();

File input = fileChooser.showOpenDialog(null);  // opens a file chooser gui and returns a file

is what works for me. just be sure to check for null incase the user clicks cancel.

afetiso
Posts: 84
Posted 22:42 Feb 03, 2015 |

I am using opencv 2.4.10

LBRIGGS: 

I was trying doesn't work, but thank you.

Any suggestions?

afetiso
Posts: 84
Posted 22:44 Feb 03, 2015 |

final JFileChooser fc = new JFileChooser();    
int returnVal = fc.showOpenDialog(null);
System.out.println((String)fc.getSelectedFile().getAbsolutePath()); //output  C:\Users\aveni_000\Desktop\testdata\apple1.jpg
File file = fc.getSelectedFile();
System.out.println(file); //output   C:\Users\aveni_000\Desktop\testdata\apple1.jpg

Mat mat = Highgui.imread(file.getPath());

 

afetiso
Posts: 84
Posted 22:58 Feb 03, 2015 |

This is error that coming out:

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_1(Ljava/lang/String;)J
    at org.opencv.highgui.Highgui.imread_1(Native Method)
    at org.opencv.highgui.Highgui.imread(Highgui.java:362)
    at hw2.opencvGUI$2.actionPerformed(opencvGUI.java:106)

lbriggs
Posts: 57
Posted 23:02 Feb 03, 2015 |

Oh, you don't have opencv loaded

afetiso
Posts: 84
Posted 23:02 Feb 03, 2015 |
lbriggs wrote:

I see you have a variable "fc" I assume thats a file chooser?

FileChooser fileChooser = new FileChooser();

File input = fileChooser.showOpenDialog(null);  // opens a file chooser gui and returns a file

is what works for me. just be sure to check for null incase the user clicks cancel.

It can't be: File input = fileChooser.showOpenDialog(null); because .showOpenDialog(null) - need to be int

afetiso
Posts: 84
Posted 23:03 Feb 03, 2015 |

ok will try to download again

 

lbriggs
Posts: 57
Posted 23:07 Feb 03, 2015 |

you need to load your open cv libary in your main like this:

 

File opencvLibrary = new File(System.mapLibraryName("opencv_java300"));

System.load(opencvLibrary.getAbsolutePath());

lbriggs
Posts: 57
Posted 23:08 Feb 03, 2015 |

and that file needs to be the opencv binary you downloaded. on windows its a .dll file, on mac its a .dylib file

afetiso
Posts: 84
Posted 23:11 Feb 03, 2015 |
lbriggs wrote:

and that file needs to be the opencv binary you downloaded. on windows its a .dll file, on mac its a .dylib file

But I have opencv library add to eclipse and add to my project

lbriggs
Posts: 57
Posted 23:14 Feb 03, 2015 |

well are any opencv functions working? that error you were getting is what happens when you are not properly linking a library.

afetiso
Posts: 84
Posted 23:14 Feb 03, 2015 |

add to main:

System.loadLibrary( Core.NATIVE_LIBRARY_NAME );

now working, thank you, so much, i was debugging it a lot of time

lbriggs
Posts: 57
Posted 23:15 Feb 03, 2015 |

just adding the file to your eclipse works for jar files, but this is a native C++ library. It has to be loaded at run time I believe.

afetiso
Posts: 84
Posted 23:16 Feb 03, 2015 |

Yes, thank you, sooo much