This is a webcam viewing program. It is written in Java using JavaFX and using the OpenCV library to get webcam images and do image processing on them.
- JRE 1.8 (Java SE 8 or higher)
- OpenCV Java Library 3.3 (3.0 or higher) See OpenCV 3.3 for instructions.
- Download the source code.
- In VideoTest/VideoCommon run:
ant jar
- In VideoTest/VideoTest run:
ant jar
- In VideoTest/VideoTest run:
java -jar VideoTest.jar
NOTE: Currently the code is written to run against OpenCV 3.0 or higher and will not work with OpenCV 2.4 which is the default in most Linux Distros.
Camera Resolution: 800.0 x 600.0 select: Bad file descriptor Capture stopped Missed frame count = 6 VIDIOC_DQBUF: Bad file descriptor select: Bad file descriptor VIDIOC_DQBUF: Bad file descriptor OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/imgproc/src/color.cpp, line 3737 Exception in thread "Camera-Consumer-1" CvException [org.opencv.core.CvException: cv::Exception: /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/imgproc/src/color.cpp:3737: error: (-215) scn == 3 || scn == 4 in function cvtColor ] at org.opencv.imgproc.Imgproc.cvtColor_1(Native Method) at org.opencv.imgproc.Imgproc.cvtColor(Imgproc.java:4598) at videotest.CameraConsumer.run(CameraConsumer.java:77) at java.lang.Thread.run(Thread.java:748)
Modification of procedures from OpenCV Java Webpage.
cd opencv
mkdir build
cd build
ccmake ..
Configure the settings shown in the next section.
make -j8
sudo make install
cd /usr/local/share/OpenCV/java
sudo execstack -c libopencv_java330.so
BUILD_SHARED_LIBS=OFF
WITH_JPEG=OFF
When the project is built, both opencv-330.jar and libopencv_java330.so must be available to load. The program loads the .so with System.loadLibrary("bla.so") or System.load("/path/to/bla.so") The build process does not move the .so file to the correct location and putting the .so in the jar is only possible if you write some code to extract it before loading it.
- bug filed here
- In OpenCV 3.3 reading from the camera results in continuous messages like these being printed out: Corrupt JPEG data: 2 extraneous bytes before marker 0xd3 Corrupt JPEG data: 1 extraneous bytes before marker 0xd3 Corrupt JPEG data: 1 extraneous bytes before marker 0xd5 Corrupt JPEG data: 2 extraneous bytes before marker 0xd7 Corrupt JPEG data: 1 extraneous bytes before marker 0xd7 Corrupt JPEG data: 1 extraneous bytes before marker 0xd5 Corrupt JPEG data: 1 extraneous bytes before marker 0xd5 Corrupt JPEG data: 2 extraneous bytes before marker 0xd1 Corrupt JPEG data: 2 extraneous bytes before marker 0xd2 Corrupt JPEG data: 1 extraneous bytes before marker 0xd5
--> Fixed by compiling OpenCv with WITH_JPEG=OFF
setting.
--> Fixed by pull request 9479
Scanning dependencies of target opencv_dnn In file included from /home/pjsanfil/Projects/opencv-3.3.0/modules/imgcodecs/src/grfmts.hpp:53:0, from /home/pjsanfil/Projects/opencv-3.3.0/modules/imgcodecs/src/loadsave.cpp:47: /home/pjsanfil/Projects/opencv-3.3.0/modules/imgcodecs/src/grfmt_exr.hpp:52:31: fatal error: ImfChromaticities.h: No such file or directory compilation terminated.
OpenJDK 64-Bit Server VM warning: You have loaded library /home/pjsanfil/Projects/VideoTest/libs/libopencv_java330.so which might have disabled stack guard. The VM will try to fix the stack guard now. It's highly recommended that you fix the library with 'execstack -c ', or link it with '-z noexecstack'.
--> Fixed by adding execstack build step to Building OpenCV instructions.
Core.NATIVE_LIBRARY_NAME appears to resolve to "opencv_java330" when the name should be "libopencv_java330.so"
System.setProperty() to set the java.library.path to search for libopencv_java330.so does not seem to work.
http://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.html