简体   繁体   English

JavaCV / OpenCV:cvLoadImage无法正常工作

[英]JavaCV/OpenCV: cvLoadImage not working

I installed the JavaCV/OpenCV libraries, and I'm having a problem with the basic example code. 我安装了JavaCV / OpenCV库,我遇到了基本示例代码的问题。

According to several examples that I have looked at, this code should load an image: 根据我看过的几个例子,这段代码应该加载一个图像:

IplImage image = cvLoadImage("C:\\img.jpg");

But, when I run that I get a "cannot find symbol" error. 但是,当我运行时,我得到一个“找不到符号”的错误。

Since this is my first time using it, I'm not sure if I messed the install up or not. 由于这是我第一次使用它,我不确定我是否搞砸了安装。

According to the newest JavaCV readme, I do have the correct version of OpenCV. 根据最新的JavaCV自述文件,我确实拥有正确版本的OpenCV。 I also have all the JavaCV jar files imported. 我还导入了所有JavaCV jar文件。 As far as I can tell, I also have all the paths set correctly too. 据我所知,我也正确设置了所有路径。

Anyone know what the problem is? 谁知道问题是什么?

Edit: 编辑:

Full code: 完整代码:

import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import java.io.File;


public class demo {

    public static void main(String[] args) 
    {
        IplImage image = cvLoadImage("C:\\img.jpg");

        final CanvasFrame canvas = new CanvasFrame("Demo");
        canvas.showImage(image);
        canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
    }

}

Error when I try to run it: 我尝试运行它时出错:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: cvLoadImage at javacv.demo.main(demo.java:17) 线程“main”中的异常java.lang.RuntimeException:无法编译的源代码 - 错误的sym类型:javacv.demo.main中的cvLoadImage(demo.java:17)

Java Result: 1 Java结果:1

Seems like it is claiming cvLoadImage doesn't take a string as an argument. 似乎它声称cvLoadImage不接受字符串作为参数。

A walk around that i find for you is to load the image by ImageIO and passe it later to IplImage 我找到的是你可以通过ImageIO加载图像并稍后将其IplImageIplImage

eg: 例如:

 BufferedImage img =  ImageIO.read(new File("C:\\img.jpg") );
 IplImage origImg = IplImage.createFrom(img);

这解决了我的问题: import static org.bytedeco.javacpp.opencv_imgcodecs.*;

You have to add this import statement: 您必须添加此import语句:
import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage; This is required so that the static method cvLoadImage can be used without using the class name. 这是必需的,以便可以在不使用类名的情况下使用静态方法cvLoadImage

你必须import com.googlecode.javacv.cpp.opencv_highgui.*;

使用javacv 0,9,您必须import static org.bytedeco.javacpp.opencv_highgui.*;

我得到了同样的错误,我导入了以下包,问题解决了。

import static com.googlecode.javacv.cpp.opencv_highgui.*;

This might be old but for those who stumbled upon this problem like me just now, here is how I solved it and why: 这可能是旧的,但对于那些像我一样偶然发现这个问题的人来说,这就是我解决它的原因以及原因:

First OP's error: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: cvLoadImage at javacv.demo.main(demo.java:17) 第一个OP的错误:线程“main”中的异常java.lang.RuntimeException:无法编译的源代码 - 错误的sym类型:javacv.demo.main中的cvLoadImage(demo.java:17)

This indicates that the compiler cannot find the cvLoadImage method that you are trying to call. 这表示编译器找不到您尝试调用的cvLoadImage方法。

cvLoadImage is a static method under JavaCPP. cvLoadImage是JavaCPP下的静态方法。 Specifically it is a static method under opencv_imgcodecs class. 具体来说,它是opencv_imgcodecs类下的静态方法。

To solve this issue one must first specify the import of the opencv_imgcodecs class. 要解决此问题,必须首先指定opencv_imgcodecs类的导入。

This can be done by adding the import: 这可以通过添加导入来完成:
import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage; import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage;

This in turn would result for the opencv_imgcodecs class to be usable within your class along with its static methods and other functions. 这反过来会导致opencv_imgcodecs类在其类中及其静态方法和其他函数中可用。

I hope this helps. 我希望这有帮助。

Got the same problem recently. 最近遇到了同样的问题。 if you are using javacv-0.10 (more recent at the moment), import manually this one: 如果你正在使用javacv-0.10(目前更新),请手动导入这个:

import static org.bytedeco.javacpp.opencv_highgui.*;

but the source of JRE of the project should be higher than 1.5 但该项目的JRE来源应高于1.5

In my case, the problem happened when the squeegee in debug mode. 在我的情况下,当刮刀处于调试模式时发生问题。 Try to run in normal mode. 尝试以正常模式运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM