Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial import. Simple API

  • Loading branch information...
commit 2e8998dbfb70c651ebff6c1ca76cafd67efb1133 0 parents
Nikhil Marathe authored

Showing 4 changed files with 119 additions and 0 deletions. Show diff stats Hide diff stats

  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 @@
  1 + Copyright (c) 2010 Nikhil Marathe <nsm.nikhil@gmail.com>
  2 +
  3 + Permission is hereby granted, free of charge, to any person
  4 + obtaining a copy of this software and associated documentation
  5 + files (the "Software"), to deal in the Software without
  6 + restriction, including without limitation the rights to use,
  7 + copy, modify, merge, publish, distribute, sublicense, and/or sell
  8 + copies of the Software, and to permit persons to whom the
  9 + Software is furnished to do so, subject to the following
  10 + conditions:
  11 +
  12 + The above copyright notice and this permission notice shall be
  13 + included in all copies or substantial portions of the Software.
  14 +
  15 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16 + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  17 + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18 + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19 + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20 + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21 + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22 + OTHER DEALINGS IN THE SOFTWARE.
59 src/face.cc
... ... @@ -0,0 +1,59 @@
  1 +// Copyright (C) 2010 Nikhil Marathe <nsm.nikhil@gmail.com>
  2 +
  3 +#include <string>
  4 +#include <vector>
  5 +#include <iostream>
  6 +
  7 +#include <node/v8.h>
  8 +#include <node/node.h>
  9 +
  10 +#include <libface/LibFace.h>
  11 +#include <libface/Face.h>
  12 +
  13 +using namespace v8;
  14 +using namespace node;
  15 +
  16 +namespace face {
  17 +
  18 +Handle<Value> Faces( const Arguments &args ) {
  19 + HandleScope scope;
  20 +
  21 + std::string filename;
  22 + if (args.Length() > 0 && args[0]->IsString()) {
  23 + Local<String> p = args[0]->ToString();
  24 + String::AsciiValue asc(p);
  25 + filename = *asc;
  26 + }
  27 +
  28 + libface::LibFace detector;
  29 + std::vector<libface::Face> faces = detector.detectFaces(filename);
  30 +
  31 + Local<Array> faceArray = Array::New(faces.size());
  32 + for(int i = 0, l = faces.size(); i < l; i++) {
  33 + Local<Object> coords = Object::New();
  34 + coords->Set(String::New("x"), Integer::New(faces[i].getX1()));
  35 + coords->Set(String::New("y"), Integer::New(faces[i].getY1()));
  36 + coords->Set(String::New("width"), Integer::New(faces[i].getWidth()));
  37 + coords->Set(String::New("height"), Integer::New(faces[i].getHeight()));
  38 +
  39 + faceArray->Set(Integer::New(i), coords);
  40 + }
  41 +
  42 + return faceArray;
  43 +}
  44 +
  45 +void Initialize( Handle<Object> target ) {
  46 + HandleScope scope;
  47 +
  48 + Local<FunctionTemplate> t = FunctionTemplate::New(Faces);
  49 +
  50 + target->Set( String::NewSymbol( "faces" ), t->GetFunction() );
  51 +}
  52 +}
  53 +
  54 +extern "C"
  55 +void init( Handle<Object> target ) {
  56 + HandleScope scope;
  57 + face::Initialize( target );
  58 +}
  59 +
8 test.js
... ... @@ -0,0 +1,8 @@
  1 +var face = require( "./face" )
  2 + , sys = require( "sys" )
  3 +
  4 +if( process.argv.length < 3 ) {
  5 + sys.puts("Usage: node test.js <filename>");
  6 + process.exit(1);
  7 +}
  8 +sys.debug(sys.inspect(face.faces(process.argv[2])));
30 wscript
... ... @@ -0,0 +1,30 @@
  1 +import Options
  2 +from os import popen, unlink, symlink, getcwd
  3 +from os.path import exists
  4 +import sys
  5 +
  6 +srcdir = "."
  7 +blddir = "build"
  8 +VERSION = "0.0.1"
  9 +
  10 +def set_options(opt):
  11 + opt.tool_options("compiler_cxx")
  12 +
  13 +def configure(conf):
  14 + conf.check_tool("compiler_cxx")
  15 + conf.check_tool("node_addon")
  16 +
  17 +def build(bld):
  18 + obj = bld.new_task_gen("cxx", "shlib", "node_addon")
  19 + obj.target = "face"
  20 + obj.find_sources_in_dirs("src")
  21 + obj.lib = ["face"]
  22 +
  23 +def shutdown(bld):
  24 + # HACK to get binding.node out of build directory.
  25 + # better way to do this?
  26 + if Options.commands['clean']:
  27 + if exists('face.node'): unlink('face.node')
  28 + else:
  29 + if exists('build/default/face.node') and not exists('face.node'):
  30 + symlink(getcwd()+'/build/default/face.node', 'face.node')

0 comments on commit 2e8998d

Please sign in to comment.
Something went wrong with that request. Please try again.