I installed the JavaCV/OpenCV libraries, and I'm having a problem with the basic example code.
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.
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)
Java Result: 1
Seems like it is claiming cvLoadImage doesn't take a string as an argument.
A walk around that i find for you is to load the image by ImageIO and passe it later to IplImage
e.g.:
BufferedImage img = ImageIO.read(new File("C:\\img.jpg") );
IplImage origImg = IplImage.createFrom(img);
This solved my problem: import static org.bytedeco.javacpp.opencv_imgcodecs.*;
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.
You have to import com.googlecode.javacv.cpp.opencv_highgui.*;
With javacv 0,9 you have to import static org.bytedeco.javacpp.opencv_highgui.*;
I got the same error then, i imported the following package, problem solved.
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)
This indicates that the compiler cannot find the cvLoadImage method that you are trying to call.
cvLoadImage is a static method under JavaCPP.
Specifically it is a static method under opencv_imgcodecs class.
To solve this issue one must first specify the import of the opencv_imgcodecs class.
This can be done by adding the import:
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.
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:
import static org.bytedeco.javacpp.opencv_highgui.*;
but the source of JRE of the project should be higher than 1.5
In my case, the problem happened when the squeegee in debug mode.
Try to run in normal mode.
Related
I downloaded bytedeco's JavaCV from github and have included it into my dependencies for my IntelliJ project.
I then read through the documentation and the readme file and then figure out what I think were the proper import statements.
I have tried "import org.bytedeco.javacv.*;" from what I found in the package in the package names.
That did not work, IntelliJ could not resolve symbol "bytedeco". This happened even in the JavaCV classes that are a part of the org.bytedeco.javacv package did not resolve the import statements. I then went onto stack overflow to look for anyone who had the same problem or could solve my problem. I couldn't find any useful information at all about what is wrong.
I found this very confusing and could not find any other information onto why this is happening. This is my first project, I do not know if this is a limitation with IntelliJ or that I am missing some other package that isn't part of JavaCV or some other problem I do not yet know of.
That's right the correct package name should be org.bytedeco.opencv.global.opencv_core.*.
Here is a sample code taken from the GitHub:
import org.bytedeco.opencv.opencv_core.*;
import org.bytedeco.opencv.opencv_imgproc.*;
import static org.bytedeco.opencv.global.opencv_core.*;
import static org.bytedeco.opencv.global.opencv_imgproc.*;
import static org.bytedeco.opencv.global.opencv_imgcodecs.*;
public class Smoother {
public static void smooth(String filename) {
Mat image = imread(filename);
if (image != null) {
GaussianBlur(image, image, new Size(3, 3), 0);
imwrite(filename, image);
}
}
}
You may find the sample code on the official GitHub project site helpful for a fast start:
https://github.com/bytedeco/javacv/tree/master/samples
https://github.com/bytedeco/javacv#manual-installation
So I want to make a java application in eclipse which the user i will be able to import .zip files. Each .zip file will represent a cat breed. I will click on a "train" button and my program will contact IBM Watson services and create a classifier. Then from a different window, i will import random cat images and the program will show what cat breed is in the image. Everything with the SDKs is fine since I ran some examples from the official Watson site and everything ran smoothly. Problem comes when I try to create my own classifiers. The code you are about to see is also from their site. For some reason the createClassifier method won't take the CreateClassifierOptions object as an argument.
import java.io.File;
import com.ibm.watson.developer_cloud.http.ServiceCall;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognitionCallback;
import com.ibm.watson.developer_cloud.visual_recognition.v3.*;
import com.ibm.watson.developer_cloud.visual_recognition.v3.model.*;
public class TrainningClassifier{
public static void main(String[] args) {
VisualRecognition service = new VisualRecognition(
VisualRecognition.VERSION_DATE_2016_05_20
);
service.setApiKey("aca4433597018de62edafdeebceb2bdc1482496a");
CreateClassifierOptions createClassifierOptions = new CreateClassifierOptions.Builder()
.name("dogs")
.addClass("beagle", new File("./beagle.zip"))
.addClass("goldenretriever",new File("./golden-retriever.zip"))
.addClass("husky", new File("./husky.zip"))
.negativeExamples(new File("./cats.zip"))
.build();
Classifier dogs = service.createClassifier(createClassifierOptions).execute();
System.out.println(dogs); /*error is in the above line.
the createClassifier method.*/
}
}
Error: Exception in thread "main" java.lang.Error: Unresolved
compilation problem: The method createClassifier(ClassifierOptions)
in the type VisualRecognition is not applicable for the arguments
(CreateClassifierOptions)
at testVisualRec.ForAssignment.main(ForAssignment.java:31)
Any ideas?
Found the solution. For some reason eclipse wouldn't recommend this solution I had to experiment. I just added throws IOException in main method. I also put inside the main method System.out.println(new File(".").getAbsoluteFile()); to make sure the path was correct, and it was. (SDK used for this project is 4.0.0, not the newest one. SDK found here: https://github.com/watson-developer-cloud/java-sdk/releases)
Disclaimer Not native English speaker, feel free to edit if needed.
I'm having a similar issue that the one explained here :
java.lang.UnsatisfiedLinkError: Native Library XXX.so already loaded in another classloader
I'm trying to follow the answer of user2543253. But I really lacks of knowledge in Java and the context is a bit different.
Links
.dll already loaded in another classloader? Seems also related to this question.
https://github.com/PatternConsulting/opencv/issues/7 Similar.
https://cycling74.com/articles/mxj-class-loading Explains the class loader behavior of MXJ
Context
Edit : Not sure if that context is really important, it seems to be the same problem described in link 1.
I want to use OpenCV inside an Application called Max/MSP.
To give an idea, it looks like this :
Max/MSP allows user to assemble Patch by cabling some objects together that are called externals, most of them are coded in C but you can also create externals in Java. To do so you need to instantiate them through an object called "mxj". For example, if my Java class is called TestOpenCV, I will create a box and put "mxj TestOpenCV" inside.
OpenCV seems correctly implemented, for exemple, I can instantiate a Mat object and post its content to Max console.
Problems appears when I change the Java code of the mxj object. To update my object, I delete it and recreate it again. Then, the same issue that explained here appears...
Max console return this error message :
java.lang.UnsatisfiedLinkError: Native Library
C:\Windows\System32\opencv_java300.dll already loaded in another
classloader at java.lang.ClassLoader.loadLibrary1(Unknown Source) at
java.lang.ClassLoader.loadLibrary0(Unknown Source) at
java.lang.ClassLoader.loadLibrary(Unknown Source) at
java.lang.Runtime.loadLibrary0(Unknown Source) at
java.lang.System.loadLibrary(Unknown Source) at
OpenCVClassLoad.loadNativeLibrary(OpenCVClassLoad.java:5) at
TestOpenCV.(TestOpenCV.java:22) (mxj) unable to alloc instance
of TestOpenCV
What I tried
I tried to implement the answer of user2543253. He advices to create a tiny classes that import the native library and export it as a JAR. So I created a new Eclipse project added a source file to it
import org.opencv.core.Core;
public class OpenCVClassLoad {
public static void loadNativeLibrary() {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
}
I added the openCV JAR to that project and exported it as a JAR.
Then I changed my code according to what user2543253 explained (there is more code,I kept the essential) :
import com.cycling74.max.*;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
public class TestOpenCV extends MaxObject {
static {
// System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
OpenCVClassLoad.loadNativeLibrary();
}
public TestOpenCV(Atom[] args)
{
// ...
}
public void notifyDeleted()
{
// ...
}
public void bang() {
// Executed when I trig the little bang button you can see
Mat m = new Mat(5, 9, CvType.CV_8UC4, new Scalar(0));
post("OpenCV Mat: " + m);
Mat mr1 = m.row(1);
mr1.setTo(new Scalar(1));
Mat mc5 = m.col(3);
mc5.setTo(new Scalar(5));
post("OpenCV Mat data:\n" + m.dump());
}
}
Of course, but that's a bit weird, in order to build correctly that project I kept the JAR from OpenCV in the build path :
As you can see, I also added the tiny class in the project build path.
After all of theses modifications, the mxj object stille loads correctly the first time and the bang() method still works but the problem still there. In fact it doesn't change anything from the past situation : If I modify the Java code, delete the object in Max and create a new one, error appears...
Question
There is a lot of SO questions addressing the same type of prob but context is always different and its hard to figure out what to do, especially with my basic knowledge of Java.
A workaround should be to simply reuse that library already loaded, no ? but how to achieve this ? Because if I check the library has already being loaded, I do it using a Try / Catch, if I do nothing else. The externals acts like if the library had never been loaded...
How to reuse that native library ? (Of course, any alternative solution to this is welcome)
Just remove the second OpenCVClassLoad.loadNativeLibrary(); in your bang() method. In a plain Java application the code in a static block is only executed once.
Alternatively, you can specify the native library location in Eclipse instead of loading the library through Java source code.
i have been searching around for a few days for the answer to this and i just can't seem to get it to work. I have seen exact examples where it is working for them and I try exactly what they do and it is just not working for me.
Basically what i am trying to do is open a local access DB. I have tried numerous methods and this Jackcess seems by far the best library to use, so i am trying to get it to work with that. I have read their cookbook and gone through all of that, and still no luck so i am coming to you guys in the hope of finding a good solution (i have not posted this question anywhere yet). Here is my code (the relevant part)
The only syntax error i am getting is "DatabaseBuilder.Open" and the error is it cannot find the method, even though i have the libraries included for IO
import com.healthmarketscience.jackcess.*;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Database db = DatabaseBuilder.open(new File("my.mdb"));
try {
Table table = db.getTable("Teams");
} catch (IOException ex) {
Logger.getLogger(Teams.class.getName()).log(Level.SEVERE, null, ex);
}
}
Any help would be greatly appreciated!
The program fails to debug once I have click this buttone the only actual message i can fine is
"Cannot find symbol
Symbol : Method Open(file)
Location : variable.DatabaseBuilder of type Object"
To use Jackcess you must have at least the following items in the build path for your Java project (or on your CLASSPATH):
the Jackcess JAR file itself, and
the JAR files for its two mandatory compile-time dependencies from Apache: commons-lang and commons-logging.
In the Eclipse IDE that will look something like this:
I'm using this code:
for (final String code : Locale.getISOCountries())
{
//stuff here
}
But on compile I get this error:
[ERROR] Line 21: No source code is available for type java.util.Locale; did you forget to inherit a required module?
And then a stack trace of compiler errors.
I'm doing both of these imports at the beginning of the class:
package com.me.example;
import java.util.Locale;
import java.util.*;
What can be wrong?
In Netbeans i see the autocomplete options and no syntax error for the Locale object...
Something screwy with your setup, the folllowing program works fine for me.
import java.util.*;
import java.util.Locale;
public class Donors {
public static void main (String [] args) {
for (final String code : Locale.getISOCountries()) {
System.out.println (code);
}
}
}
The fact that it's asking for source code leads me to believe that it's trying to compile or run it in some sort of debugging mode. You shouldn't need the source code for java.util.* to compile, that's just bizarre.
See if my simple test program works in your environment, then try looking for something along those lines (debugging options). Final step: compile your code with the baseline javac (not NetBeans).
UPDATE:
Actually, I have found something. If you are creating GWT applications, I don't think java.util.Locale is available on the client side (only the server side). All of the references on the web to this error message point to GWT and its limitations on the client side which are, after all, converted to Javascript goodies, so cannot be expected to support the entire set of Java libraries.
This page here shows how to do i18n on GWT apps and there's no mention of java.util.Locale except on the server side.
Looks like there might be something fishy in your build environment, as Locale.getISOCountries() should work just fine. Try compiling a small test program manually and see if you get the same error.
Definitely try to boil this down to a minimum, three-line program (or so), compile from the command-line, then put that class into your IDE and see if you still get the error, and if not, then change/add one line at a time until you have the original failing program, looking for what causes the problem. I'm thinking maybe some other import in your code is importing a Locale class? Why in the world would it be looking for source code?
See what happens when you compile this from the command-line:
import java.util.*;
public class LocaleTest {
public static void main(String[] args) {
Locale.getISOCountries();
}
}