For the last couple of weeks I was trying to find a way to get images through my webcam using Java since I need to use the Real Time Java Specification (RTSJ) for a project at the University, My first option was the Java Media Framework (JMF) but after I tried it and not being able to detect any webcam that I had and founding that Sun hasn't work in it for 6 years, then I decided to look for other options, the first thing that came to my mind was the Java Native Interface (JNI) and V4L2, but after the frustration of understanding how to get an image out of my camera by using V4L2 I decided to search for OpenCV under Linux... and it was a brilliant idea, since I found that there were some Java binding already made, you can read more about them here and you will need to download the following files and i recomend you to use the sample files to test it.
I got the OpenCV library from the Ubuntu repository, but if you want to compile the last version of the library here are some instructions.
Then for some reason that I really don't understand you will need Processing, I downloaded both the compiled version and the source code.
Now you will need to copy the following files in the same folder:
- core.jar
You will find this file in processing compiled version in the following path processing-1.0.3/lib - processing directory
It contains some source code from processing, I got it from the following path processing/core/src, rember this is in the source package. - OpenCV.jar libOpenCV.libjni libOpenCV.so
You will find it in the following path OpenCV/library, remember this must go in the output directory where the JAR file is generated. - hypermedia directory
It contains some source code that you will need, path OpenCV/source/java
!!! required library not found : no OpenCV in java.library.path Verify that the java.library.path property is correctly set and 'libcxcore.so', 'libcv.so', 'libcvaux.so', 'libml.so', and 'libhighgui.so' are placed (or linked) in one of your system shared libraries folder
Exception in thread "main" java.lang.UnsatisfiedLinkError: hypermedia.video.OpenCV.capture(III)V at hypermedia.video.OpenCV.capture(Native Method)
Then I tried to run it as follows java -Djava.library.path=/usr/lib -jar myfile.jar but it didn't work, so I went to the NetBeansProjects directory and look for the output JAR file, which usualy is located in the dist project subdirecory, there I created simbolic links to all the libraries that I needed, for example ln -s /usr/lib/libcxcore.so libcxcore.so, I cross my fingers run the above command with the terminal and IT WORKED!!!
NOTE: The next thing to do in order to be able to run the project from Netbeans is to copy the symbolic links and libOpenCV.so and libOpenCV.jnilib to the jre/lib/i386.
23 comments:
Hello,
Any idea for using OpenCV under windows??
I get this error:
UnsatisfiedLinkError: hypermedia.video.OpenCV.capture(III)V
Thx!
Sergi
Well, I have not tried under Windows, but did you put the OpenCV.dll in the same directory than the JAR file or in Windows directory?, I'm not sure if you also need the OpenCV.libjni.
Where do you have the OpenCV library?
MAN ! CONGRATULATIONS !
YOU'RE A GENIUS !
I DON;T KNOW LINUX but i hope I'll learn.
anyway - it worked - i copied that *.dll in the respective folder and I have myself a capture !! and that's all i really wanted!
i still have something that's bothering eclipse :
The haar classifier cascade file 'haarcascade_frontalface_alt.xml' can not be found in folders, you must specify the full path instead.
Good to know that you found this blog helpful, about Eclipse I can not help you, my main IDE for Java is NetBeans.
i got rid of the buzz with haarcascade_.... by copying that xml in the projects folder and it's all working at full power
Man that helps a good thing, i've a projekt to develop a code under linux/java/openCV who allows me to motiontrack a person in a static surrounding.
this is a good start. Cross your fingers for me :-D
Greets
Henrik from Germany
You're a genius! Do you have any idea how to get the OpenCV 1.20 library for Java? I'm stuck with the one I got from http://ubaa.net/shared/processing/opencv/download/opencv_01.zip
It only allows me to use OpenCV 1.00 and I'm sure 1.20 is so much faster! Please help me :)
Hi the files in opencv_01.zip is not the OpenCV library they are just the bindings to the library... I don't know if the bindings are going to work with the 1.2 version, however the source code of the bindings come inside the opencv_01.zip file, so in the worst case you can modify and compile it to work with the opencv 1.2 version.
To dowload the OpenGL 1.2 library for Linux you can go to http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/
I've tried your solution but I received this:
!!! required library not found : /usr/lib/libOpenCV.so: /usr/lib/libOpenCV.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)
I'm on ubuntu64, any idea?
Sorry for the late answer, I really don't work with ubuntu64 or any linux 64 edition, but probably this has to do with the fact that the JNI was compiled to work with the OpenCV 32bits version and not with the 64bits version, then you have to get the 32bits version... at least it's what the message says:
wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)
Tnx for your reply, I've tried to recomplile JNI and also .so file, but I miss some files.
I've compiled on ubuntu64 with:
javah -jni hypermedia.video.OpenCV
and
g++ -shared OpenCV.cpp -o libOpenCV.so -I/usr/include/opencv/ -I/usr/lib/jvm/java-1.6.0-openjdk/include/ -lcv -lhighgui -fPIC
and now copy libOpenCv.so in /usr/lib.
It works| :)
Well Leonox , i tried OpenCv 1.0 on Windows Vista , and on Netbeans 6.7.1 , jdk 1.6.0.16 .... I did all the steps and copied my .dlls in system32 folder as well.
When i compile it, it doesnot give any error, and my webcam which is A4Tech pks 635k , also gives a blue turn-on light .... but ...
i get a black display and no image capture ...
i did searched other forums as well, one of which said if you upgrade it to 1.1 it should remove the bug of black screen and it should give some image capturing .... Unfortunately i did try that ... and still no image capture ....
Uff ... congrats , after everything i switched to ubuntu 9.04 with jdk 1.6.0.17 and Netbeans 6.8 ........ and i got the image capture .... :D I am thinking of linux for a while now :DDDDDD
Black Screen Problem!!!
Hi all, im using the java wrapper for openCV under windows. I have successfully installed openCV v1.0 (i tested the newest versions and they dont work properly), i have set the variable system Path properly pointing to the "bin" directory of my openCV installation software, i have also pasted the openCV.dll into the bin directory, i have placed properly the "hypermedia" and "processing" folders to the appropriate locations, i have attached all the appropriate jar files needed by openCV, i have tested all these in XP and Vista..
Despite all these steps i did, all the examples provided by the openCV for the java version (face detection, BlobDetection, Aplets, etc) work properly without linking or runtime exceptions BUT I HAVE BLACK SCREEN TO ALL OF THEM!!!
What should i do more???
Even the face detection works, i see the bounding box tracking the movement of my head but i dont have image, just blank background colour.
Any suggestions? Please Help..
Black Screen Problem!!!
Hi all, im using the java wrapper for openCV under windows. I have successfully installed openCV v1.0 (i tested the newest versions and they dont work properly), i have set the variable system Path properly pointing to the "bin" directory of my openCV installation software, i have also pasted the openCV.dll into the bin directory, i have placed properly the "hypermedia" and "processing" folders to the appropriate locations, i have attached all the appropriate jar files needed by openCV, i have tested all these in XP and Vista..
Despite all these steps i did, all the examples provided by the openCV for the java version (face detection, BlobDetection, Aplets, etc) work properly without linking or runtime exceptions BUT I HAVE BLACK SCREEN TO ALL OF THEM!!!
What should i do more???
Even the face detection works, i see the bounding box tracking the movement of my head but i dont have image, just blank background colour.
Any suggestions? Please Help..
hola, no se si posteando en español me puedas responder.. o si lo tenga que hacer en ingles, por lo pronto lo haré en español!!! jejejeje.
mi pregunta es la siguiente, esta librería sirve para comparar rostros en una bd, o sea, quiero hacer una aplicación para reconocimiento facial, eh estado revisando la librería opencv para ver si tiene una captura de imagen guardando las características de un rostro, no lo eh encontrado, luego el método para encontrar las similitudes tampoco, tu que ya utilizaste la librería, no se si hayas usado esto... de cualquier forma cualquier comentario sera de mucha ayuda!! gracias
Hola, instalé OpenCV en Ubuntu 10.04, compilé los ejemplos en C y funciona. Cuando trato de hacer andar Processing con la librería de OpenCV me sale el siguente error.
!!! required library not found : /home/marcos/Proyectos/processing-1.1/libraries/OpenCV/library/libOpenCV.so: libcxcore.so.1: no se puede abrír el archivo de objeto compartido: No existe el fichero ó directorio
Verify that the java.library.path property is correctly set and 'libcxcore.so', 'libcv.so', 'libcvaux.so', 'libml.so', and 'libhighgui.so' are placed (or linked) in one of your system shared libraries folder
Busqué por todo internet pero no logro encontrar una solución. Si me podes dar una mano te lo agradecería. Desde ya muchas gracias y felicitaciones por tu blog
Hai all,
i followed ur producer but i getting this error. .
""
!!! required library not found : no OpenCV in java.library.path
Verify that the java.library.path property is correctly set and the '\path\to\OpenCV\bin' exists in your system PATH
Exception in thread "main" java.lang.UnsatisfiedLinkError: capture
at hypermedia.video.OpenCV.capture(Native Method)
at hypermedia.video.OpenCV.capture(OpenCV.java:945)
at FaceDetection.(FaceDetection.java:54)
at FaceDetection.main(FaceDetection.java:130)
""
i am using java ,processing ,opencv on windows in netbeans. .
can any body help me in this issue?? pls...
wat is the steps at need to be followed for netbeans/eclipes ??
. .
This is so useful and so awesome!
but I keep running into the same problem you mentioned and I can't seem to get around it...
!!! required library not found : no OpenCV in java.library.path
Verify that the java.library.path property is correctly set and 'libcxcore.so', 'libcv.so', 'libcvaux.so', 'libml.so', and 'libhighgui.so' are placed (or linked) in one of your system shared libraries folder
Where are those files located?
I don't have a "dist" folder and when I searched for the files on my computer I got nothing.
I have tried to run it in both Eclipse and NetBeans. I am using Linux and a logitech camera, so I think everything should work...apart for these lost files.
If you could get back to me, I would really appreciate it. I have been trying to set up a camera on Linux with OpenCV for a while and it is integral to my own research project.
Thanks for all your help.
~Caitlyn
Thanks for solution, i worked with jmf, and it not worked for me.
Publicar un comentario