Permalink
Browse files

Check if image is valid.

Use openCV primitives to attempt load once so we know
its an image. libface segfaults on a non image.
  • Loading branch information...
1 parent b681d8d commit 0412bd90875017004810c055698006ad2d25b418 @nikhilm committed Dec 14, 2010
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/face.cc
View
@@ -7,6 +7,7 @@
#include <v8.h>
#include <node.h>
+#include <opencv2/opencv.hpp>
#include <libface/LibFace.h>
#include <libface/Face.h>
@@ -25,6 +26,11 @@ Handle<Value> Faces( const Arguments &args ) {
filename = *asc;
}
+ IplImage *img = cvLoadImage(filename.c_str());
+ if( !img ) {
+ return String::New( cvErrorStr( cvGetErrStatus() ) );
+ }
+
libface::LibFace detector;
std::vector<libface::Face> faces = detector.detectFaces(filename);
@@ -39,7 +45,7 @@ Handle<Value> Faces( const Arguments &args ) {
faceArray->Set(Integer::New(i), coords);
}
- return faceArray;
+ return scope.Close(faceArray);
}
void Initialize( Handle<Object> target ) {

0 comments on commit 0412bd9

Please sign in to comment.