Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用Opnecv在我的java项目中调用imread()_Java_Image_Opencv_Imread - Fatal编程技术网

无法使用Opnecv在我的java项目中调用imread()

无法使用Opnecv在我的java项目中调用imread(),java,image,opencv,imread,Java,Image,Opencv,Imread,我试图从图像中获取一张垫子,但每次我调用imread()时,应用程序都会崩溃! 下面是我的代码,我使用JFileChooser获取文件路径 JFileChooser jfc=new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jfc.setFileFilter(new FileFilter() { @Override public String getDescr

我试图从图像中获取一张垫子,但每次我调用imread()时,应用程序都会崩溃! 下面是我的代码,我使用JFileChooser获取文件路径

JFileChooser jfc=new JFileChooser();  
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);  
jfc.setFileFilter(new FileFilter() {
    @Override
    public String getDescription() {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public boolean accept(File file) {
        // TODO Auto-generated method stub
        if (file.getName().toLowerCase().endsWith(".jpg") || 
                file.getName().toLowerCase().endsWith(".jpeg") || 
                file.getName().toLowerCase().endsWith(".png"))
            return true;
        else if (file.isDirectory())
            return true;
        return false;
    }
});
jfc.showDialog(new JLabel(), "choose");  
File file=jfc.getSelectedFile();  
if(file != null && file.isFile()){
    System.out.println(file.toString());
    Mat A = Imgcodecs.imread(file.toString()); // Here exits problems
}
日志如下:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.control.MenuItem.fire(Unknown Source)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(Unknown Source)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.lambda$createChildren$343(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$355(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

任何答案都会有帮助!谢谢

你能得到一个带有行号的stacktrace,这样你就可以验证它是否真的在imread()崩溃了吗?在做任何opencv之前,您是否根据您的opencv版本做过这样或类似的事情?System.loadLibrary(Core.NATIVE\u LIBRARY\u NAME);为什么在一个显然是JavaFX应用程序中使用Swing
JFileChooser
?我不确定您是如何得出结论,认为问题是由上面堆栈跟踪中的
imread()
引起的。我很确定它不是。你能得到一个带有行号的stacktrace,这样你就可以验证它是否真的在imread()崩溃了吗?在做任何opencv之前,您是否根据您的opencv版本做过这样或类似的事情?System.loadLibrary(Core.NATIVE\u LIBRARY\u NAME);为什么在一个显然是JavaFX应用程序中使用Swing
JFileChooser
?我不确定您是如何得出结论,认为问题是由上面堆栈跟踪中的
imread()
引起的。我敢肯定不是。