These days I’ve been experimenting with java (though I’ve always tried to avoid it) due to a client request for a development project.
Java development tools are not entirely ugly as I thought, in fact I found it very productive to develop here, quickly made a desktop application that connected to MySQL to query and save records in a couple of days, But my problem started when trying to run the webcam, I thought that a language like java could have many ways to do this and I was right, but many things are outdated or do not work, for example it seemed logical to use the gstreamer project and the java bridge, but the project is outdated since 2011.
After many tests, I have good results using the library opencv, I know, using opencv to handle a webcam is a very simple operation for all the things that makes this library however was where I could get everything working well I thought it easier to implement that would allow me to operate the same in Windows or mac OSX with just installing opencv on that platform (java is really multiplatform?).
I made a demo code and NetBeans project using pieces of code I found on the Internet and making it work as wanted in a swing frame displaying the video on a JLabel and also lets you shoot video with the push of a button, the code can be downloaded here:
[Info] SwingWebCam.tar.gz [/ info]
To run the code must have opencv installed (available from the official repositories of any linux distribution) and you must load javacv .jar files too to library project path in to Netbeans, don’t worry much about the jar, the code show errors in to Netbeans if you not load the .jar files, this files are needed to you can run the project without errors.
I hope they can help, any doubt please use the comments, otherwise this code is not meant to be more than it is (a demo), so any improvement is welcome but do not think that will be implemented directly in the code.
OF COURSE Java doesn’t suck, that’s why RedHat, IBM, Oracle, and Twitter (to name a few) are investing resources into it. The FUD campaign against Java has been restless, since about 1997… http://ho.io/sunblock Yet, FUD can only fool so many…
See here:
http://www.redhat.com/summit/2012/pdf/2012-DevDay-OpenJDK-Bhole.pdf
And wait until you learn that you DON’T have to code in Java to write Java apps, thanks to JVM languages and Invokedynamic…
http://www.drdobbs.com/jvm/a-long-look-at-jvm-languages/240007765
Jython, JRuby, NetRexx, and many more…
http://en.wikipedia.org/wiki/List_of_JVM_languages
… let you access the power of the JVM and external Java libraries without having to write a single line of Java code. That’s the beauty of Java, it’s NOT ONLY a language, it’s also a Software Platform (JVM) and a level playing field software ecosystem…
Some gems you might not have heard about:
Apache Commons – Reusable Java components
http://commons.apache.org/
One-Jar, the right way to package Java apps 🙂
http://one-jar.sourceforge.net/
Java-Gnome
http://java-gnome.sourceforge.net/
OpenJFX, the future of Java GUIs
http://openjdk.java.net/projects/openjfx/
Thanks for your decision to try Java, despite the FUD! 🙂
FC
Excelente artículo Richzendy, muchas gracias por compartirlo. Justo ahora estaba evaluando apis que me permitieran el manejo de dispositivos de video con Java. También estoy apenas retomando la programación con Java, luego de varios años, y la verdad no ha sido tan malo como pensaba. :-). Buen blog, ya estaré pendiente de nuevos aportes.
Saludos.
HM
Probaste el código? si es así, te funciono todo?
Así es pana, mil gracias. De hecho lo estoy adaptando para hacerlo funcionar en OSX y probando algunas utilidades de JavaCV relacionadas a reconocimiento de caracteres y otras cosillas por ahí. Tu código me ayudo a retomar Java y a conocer JavaCV. Saludos.
oye quise replicar una parte del codigo a un proyecto prpio que es el de toma de video y me sale un erro me podrias ayudar es este Exception in thread “Thread-1” java.lang.NoClassDefFoundError: com/googlecode/javacpp/Pointer
y el ejemplo solo tal cual como está le funciona?
hola esta muy bueno tu codigo y ejemplo.. trato de adaptarlo a un sistema de alta de trabajadores.. pero para guardar la imagen en un gestor de base de datos.. necesito la ruta donde realmente se ha creado la imagen.. ojala puedas contestar
fíjate en el código en la variable a_path del fichero WebCam.java:
String a_path = “WebCamCapture_” + new java.sql.Timestamp(System.currentTimeMillis()) + “.jpg” ;
La variable a_path, contiene la ruta al archivo, físicamente no se guarda en el pc (técnicamente si, pero no accesible directamente), se guarda en el directorio resources de la aplicación.
Puedes manipular la variable y guardar el fichero en base de datos en un campo tipo blob.
pero no me es muy util, estoy guardandolas en bytes, en un campo bytea de postgres..
modificando el codigo pude hacerlo una vez, porque quedo guardada una imagen que tome desde mi aplicaion y su codigo adaptado.. y a esa variable path no le puedo dejar el new java.sql.Timestamp(System.currentTimeMillis()) porq no me la reconoce como una ruta.. gracias!!!
Hola buen dia estoy utilizando esta herramienta pero me genera un error
Exception in thread “Thread-1” java.lang.NoClassDefFoundError: com/googlecode/javacpp/Pointer
agradezco tu colaboración
saludos
Al parecer tiene que ver que no tienes javacv correctamente instalando, puedes chequear este enlace como referencia:
http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/javacv-capture-image-from-webcam.html?showComment=1334645752189#c2497329639007098814
Así lucen mis bibliotecas para el proyecto: http://i.imgur.com/dghEBik.png
Los archivos jar, deberían estar en el zip, pero creo que tienes que cargarlos manualmente además de tener instalado opencv.