Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial import. Simple API

  • Loading branch information...
commit 2e8998dbfb70c651ebff6c1ca76cafd67efb1133 0 parents
@nikhilm authored
Showing with 119 additions and 0 deletions.
  1. +22 −0 LICENSE
  2. +59 −0 src/face.cc
  3. +8 −0 test.js
  4. +30 −0 wscript
22 LICENSE
@@ -0,0 +1,22 @@
+ Copyright (c) 2010 Nikhil Marathe <nsm.nikhil@gmail.com>
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
59 src/face.cc
@@ -0,0 +1,59 @@
+// Copyright (C) 2010 Nikhil Marathe <nsm.nikhil@gmail.com>
+
+#include <string>
+#include <vector>
+#include <iostream>
+
+#include <node/v8.h>
+#include <node/node.h>
+
+#include <libface/LibFace.h>
+#include <libface/Face.h>
+
+using namespace v8;
+using namespace node;
+
+namespace face {
+
+Handle<Value> Faces( const Arguments &args ) {
+ HandleScope scope;
+
+ std::string filename;
+ if (args.Length() > 0 && args[0]->IsString()) {
+ Local<String> p = args[0]->ToString();
+ String::AsciiValue asc(p);
+ filename = *asc;
+ }
+
+ libface::LibFace detector;
+ std::vector<libface::Face> faces = detector.detectFaces(filename);
+
+ Local<Array> faceArray = Array::New(faces.size());
+ for(int i = 0, l = faces.size(); i < l; i++) {
+ Local<Object> coords = Object::New();
+ coords->Set(String::New("x"), Integer::New(faces[i].getX1()));
+ coords->Set(String::New("y"), Integer::New(faces[i].getY1()));
+ coords->Set(String::New("width"), Integer::New(faces[i].getWidth()));
+ coords->Set(String::New("height"), Integer::New(faces[i].getHeight()));
+
+ faceArray->Set(Integer::New(i), coords);
+ }
+
+ return faceArray;
+}
+
+void Initialize( Handle<Object> target ) {
+ HandleScope scope;
+
+ Local<FunctionTemplate> t = FunctionTemplate::New(Faces);
+
+ target->Set( String::NewSymbol( "faces" ), t->GetFunction() );
+}
+}
+
+extern "C"
+void init( Handle<Object> target ) {
+ HandleScope scope;
+ face::Initialize( target );
+}
+
8 test.js
@@ -0,0 +1,8 @@
+var face = require( "./face" )
+ , sys = require( "sys" )
+
+if( process.argv.length < 3 ) {
+ sys.puts("Usage: node test.js <filename>");
+ process.exit(1);
+}
+sys.debug(sys.inspect(face.faces(process.argv[2])));
30 wscript
@@ -0,0 +1,30 @@
+import Options
+from os import popen, unlink, symlink, getcwd
+from os.path import exists
+import sys
+
+srcdir = "."
+blddir = "build"
+VERSION = "0.0.1"
+
+def set_options(opt):
+ opt.tool_options("compiler_cxx")
+
+def configure(conf):
+ conf.check_tool("compiler_cxx")
+ conf.check_tool("node_addon")
+
+def build(bld):
+ obj = bld.new_task_gen("cxx", "shlib", "node_addon")
+ obj.target = "face"
+ obj.find_sources_in_dirs("src")
+ obj.lib = ["face"]
+
+def shutdown(bld):
+ # HACK to get binding.node out of build directory.
+ # better way to do this?
+ if Options.commands['clean']:
+ if exists('face.node'): unlink('face.node')
+ else:
+ if exists('build/default/face.node') and not exists('face.node'):
+ symlink(getcwd()+'/build/default/face.node', 'face.node')
Please sign in to comment.
Something went wrong with that request. Please try again.