Created
November 16, 2012 14:47
-
-
Save nikhil9/4087860 to your computer and use it in GitHub Desktop.
Code for Face Detection in Javacv using haar classifier.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.googlecode.javacv.cpp.opencv_core.IplImage; | |
import static com.googlecode.javacv.cpp.opencv_core.*; | |
import static com.googlecode.javacv.cpp.opencv_highgui.*; | |
import static com.googlecode.javacv.cpp.opencv_objdetect.*; | |
public class FaceDetection{ | |
public static final String XML_FILE = | |
"resources/haarcascade_frontalface_default.xml"; | |
public static void main(String[] args){ | |
IplImage img = cvLoadImage("resources/lena.jpg"); | |
detect(img); | |
} | |
public static void detect(IplImage src){ | |
CvHaarClassifierCascade cascade = new | |
CvHaarClassifierCascade(cvLoad(XML_FILE)); | |
CvMemStorage storage = CvMemStorage.create(); | |
CvSeq sign = cvHaarDetectObjects( | |
src, | |
cascade, | |
storage, | |
1.5, | |
3, | |
CV_HAAR_DO_CANNY_PRUNING); | |
cvClearMemStorage(storage); | |
int total_Faces = sign.total(); | |
for(int i = 0; i < total_Faces; i++){ | |
CvRect r = new CvRect(cvGetSeqElem(sign, i)); | |
cvRectangle ( | |
src, | |
cvPoint(r.x(), r.y()), | |
cvPoint(r.width() + r.x(), r.height() + r.y()), | |
CvScalar.RED, | |
2, | |
CV_AA, | |
0); | |
} | |
cvShowImage("Result", src); | |
cvWaitKey(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dear Nikhil,
Thanks for sharing.
I am getting the following excetpion while executing the code downloaded from your repository on GitHub (https://github.com/nikhil9/FaceDetection)
OpenJDK 64-Bit Server VM warning: You have loaded library /usr/local/lib/libopencv_core.so.3.0.0 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'.
Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/javacpp5998446228712/libjniopencv_core.so: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1851)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1062)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:418)
at com.googlecode.javacpp.Loader.load(Loader.java:368)
at com.googlecode.javacpp.Loader.load(Loader.java:315)
at com.googlecode.javacv.cpp.opencv_core.(opencv_core.java:131)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at com.googlecode.javacpp.Loader.load(Loader.java:334)
at com.googlecode.javacv.cpp.opencv_imgproc.(opencv_imgproc.java:96)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at com.googlecode.javacpp.Loader.load(Loader.java:334)
at com.googlecode.javacv.cpp.opencv_highgui.(opencv_highgui.java:85)
at FaceDetection.main(FaceDetection.java:15)
From where can I download the shared library?
Which version of javac are you using?
Regards,