Skip to content

Commit

Permalink
Check if image is valid.
Browse files Browse the repository at this point in the history
Use openCV primitives to attempt load once so we know
its an image. libface segfaults on a non image.
  • Loading branch information
nikhilm committed Dec 14, 2010
1 parent b681d8d commit 0412bd9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/face.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <v8.h>
#include <node.h>

#include <opencv2/opencv.hpp>
#include <libface/LibFace.h>
#include <libface/Face.h>

Expand All @@ -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);

Expand All @@ -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 ) {
Expand Down

0 comments on commit 0412bd9

Please sign in to comment.