java JavaCV/OpenCV:cvLoadImage 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15867696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaCV/OpenCV: cvLoadImage not working
提问by Lucas
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. I also have all the JavaCV jar files imported. As far as I can tell, I also have all the paths set correctly too.
根据最新的 JavaCV 自述文件,我确实有正确版本的 OpenCV。我还导入了所有 JavaCV jar 文件。据我所知,我也正确设置了所有路径。
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:无法编译的源代码 - 错误的符号类型:javacv.demo.main(demo.java:17) 处的 cvLoadImage
Java Result: 1
Java 结果:1
Seems like it is claiming cvLoadImage doesn't take a string as an argument.
似乎它声称 cvLoadImage 不接受字符串作为参数。
回答by Festus Tamakloe
A walk around that i find for you is to load the image by ImageIO and passe it later to IplImage
我为您找到的四处走走是通过 ImageIO 加载图像并稍后将其传递给 IplImage
e.g.:
例如:
BufferedImage img = ImageIO.read(new File("C:\img.jpg") );
IplImage origImg = IplImage.createFrom(img);
回答by Fernando
This solved my problem: import static org.bytedeco.javacpp.opencv_imgcodecs.*;
这解决了我的问题: import static org.bytedeco.javacpp.opencv_imgcodecs.*;
回答by 404error
You have to add this import statement: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.
您必须添加此导入语句:import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage;
这是必需的,以便cvLoadImage
可以在不使用类名的情况下使用静态方法。
回答by bmkay
You have to import com.googlecode.javacv.cpp.opencv_highgui.*;
你必须 import com.googlecode.javacv.cpp.opencv_highgui.*;
回答by grzebyk
With javacv 0,9 you have to import static org.bytedeco.javacpp.opencv_highgui.*;
使用 javacv 0,9 你必须 import static org.bytedeco.javacpp.opencv_highgui.*;
回答by nuzree
I got the same error then, i imported the following package, problem solved.
然后我遇到了同样的错误,我导入了以下包,问题解决了。
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
回答by Jero Dungog
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:无法编译的源代码 - 错误的符号类型:javacv.demo.main(demo.java:17) 处的 cvLoadImage
This indicates that the compiler cannot find the cvLoadImage method that you are trying to call.
这表明编译器找不到您尝试调用的 cvLoadImage 方法。
cvLoadImage is a static method under JavaCPP. Specifically it is a static method under opencv_imgcodecs class.
cvLoadImage 是 JavaCPP 下的静态方法。具体来说它是 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.
我希望这有帮助。
回答by Glauber Barboza
In my case, the problem happened when the squeegee in debug mode. Try to run in normal mode.
就我而言,问题发生在刮刀处于调试模式时。尝试在正常模式下运行。
回答by Edess Elder
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