OpenCV 3 with Clojure & Quil
A Quil sketch designed to detect faces with OpenCV 3.3 and LISP!
LightTable - open core.clj
and press Ctrl+Shift+Enter
to evaluate the file.
Emacs - run cider, open core.clj
and press C-c C-k
to evaluate the file.
REPL - run (require 'threevee.core)
.
- find the OpenCV 3.3 jar files with Homebrew
- 3.3 face detection demo code
- original 2.4 face detection demo
- building OpenCV jars (if you don't get them from Homebrew)
- official Clojure OpenCV 2.4 tutorial
- official Clojure OpenCV 3.3 tutorial
- OpenCV + Java face detection & tracking
- official OpenCV 2.4 Java development tutorial
- my old work with Clojure and OpenCV 2.4
- wekinator face tracking, with OpenCV 2.4
You'll have to build and install the OpenCV JAR files for your setup. Installation tested on Archlinux and OS X. The following is a rough summary of "Introduction to OpenCV Development with Clojure."
Note, at time of writing, the latest version was 3.3.0. So, you may need to replace 330
in the instructions below with the current version.
Confirm Java is already installed:
$ java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
Otherwise, install it.
brew update
brew install cmake
brew install python2
brew install ant
If python2 not available, make sure you have Python pointing to Python v2.
To install OpenCV (with Java support) through Homebrew, you need to edit the opencv formula in Homebrew, to add support for Java: brew edit opencv In the text editor that will open, change the line: -DBUILD_opencv_java=OFF in -DBUILD_opencv_java=ON then, after saving the file, you can effectively install OpenCV: brew install --build-from-source opencv
After the installation of OpenCV, the needed jar file and the dylib library will be located at /usr/local/Cellar/opencv/3.x.x/share/OpenCV/java/, e.g., /usr/local/Cellar/opencv/3.3.0_3/share/OpenCV/java/.
NO NEED TO INSTALL IT, WE JUST NEED THE JAR. So, there's no reason to install it.
Create a file named profiles.clj in the ~/.lein directory and copy into it the following content:
{:user {:plugins [[lein-localrepo "0.5.4"]]}}
You may need to change 0.5.4
to the latest version of lein-localrepo
.
mkdir clj-opencv
cd clj-opencv
cp <path>/<to>/opencv/build/bin/opencv-330.jar .
mkdir -p native/macosx/x86_64
cp ../opencv/build/lib/libopencv_java330.dylib native/macosx/x86_64
jar -cMf opencv-native-330.jar native
lein localrepo install opencv-330.jar opencv/opencv 3.3.0
lein localrepo install opencv-native-330.jar opencv/opencv-native 3.3.0
From https://github.com/opencv/opencv Place them in the following locations (if you need them): src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_eye.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_eye_tree_eyeglasses.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_frontalcatface.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_frontalcatface_extended.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_frontalface_alt.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_frontalface_alt_tree.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_frontalface_default.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_fullbody.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_lefteye_2splits.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_licence_plate_rus_16stages.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_lowerbody.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_profileface.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_righteye_2splits.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_russian_plate_number.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_smile.xml src/CASCADE_CLASSIFIERS/OpenCV/haarcascades/haarcascade_upperbody.xml
From https://github.com/opencv/opencv_contrib Place them in the following locations (if you need them): src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_eyepair_big.xml src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_eyepair_small.xml src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_leftear.xml src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_lefteye.xml src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_lefteye_alt.xml src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_mouth.xml src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_nose.xml src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_rightear.xml src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_righteye.xml src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_righteye_alt.xml src/CASCADE_CLASSIFIERS/contrib/haarcascades/haarcascade_mcs_upperbody.xml
Leiningen has an injections
feature (in project.clj
) which loads the native OpenCV libraries. This doesn't work in Boot, because the java.library.path
is not the same. Set this up manually from the command line (doesn't work in the boot.properties
file).
env BOOT_JVM_OPTIONS="$BOOT_JVM_OPTIONS -Djava.library.path=/path/to/native/macosx/x86_64" boot extract-faces
For /path/to/native
, see location of exploded opencv-native-xxx.jar
above.
Copyright © 2017 Pas de Chocolat, LLC
Distributed under the MIT License