Skip to content

Commit

Permalink
Added flags and paths for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
kiriapurv committed Nov 14, 2014
1 parent f846349 commit 6d56bc7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 14 deletions.
33 changes: 24 additions & 9 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,38 @@
{
"target_name": "camera",
"sources": ["src/native/camera.cpp"],
"include_dirs": [
"/opt/local/include"
],
"link_settings": {
"libraries": ["-lopencv_core", "-lopencv_highgui", "-lopencv_imgproc", "-lopencv_video", "-lopencv_ml"],
"library_dirs": ["/opt/local/lib"]
"libraries": ["-lopencv_core", "-lopencv_highgui", "-lopencv_imgproc", "-lopencv_video", "-lopencv_ml"]
},
"cflags": [
"-g", "-std=c++11", "-Wall"
],
"conditions": [
['OS=="linux"', {
'include_dirs': [
'/usr/include'
],
'link_settings': {
'library_dirs': ['/usr/share/lib']
},
'cflags!': ['-fno-exceptions'],
'cflags_cc!': ['-fno-rtti', '-fno-exceptions']
}],
['OS=="mac"', {
'xcode_settings' : {
'OTHER_CFLAGS' : [
'include_dirs': [
'/opt/local/include'
],
'link_settings': {
'library_dirs': ['/opt/local/lib']
},
'xcode_settings': {
'OTHER_CFLAGS': [
"-mmacosx-version-min=10.7",
"-std=c++11",
"-stdlib=libc++"
],
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'GCC_ENABLE_CPP_RTTI': 'YES'
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'GCC_ENABLE_CPP_RTTI': 'YES'
}
}]
]
Expand Down
49 changes: 44 additions & 5 deletions src/native/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@
#include <fstream>
#include <vector>

#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif

using namespace v8;

//Define functions in scope
std::string* stringValue(Local<Value> value);

int m_brk;
int32_t preview_width, preview_height;
uv_async_t *async;
Expand Down Expand Up @@ -149,6 +159,8 @@ Handle<Value> Open(const Arguments& args) {

//Default Arguments
message->codec = std::string(".jpg");
Local<Value> input = Number::New(0);
std::string* inputString;

//Check if size is passed
if(args.Length() == 2) {
Expand All @@ -166,11 +178,15 @@ Handle<Value> Open(const Arguments& args) {
}
if(params->Has(String::NewSymbol("codec"))) {
Local<String> val = params->Get(String::NewSymbol("codec"))->ToString();
char *buffer = (char*) malloc(sizeof(char) * val->Length());
val->WriteAscii(buffer,0,val->Length());
message->codec = std::string(buffer);
std::free(&buffer);
message->codec = *stringValue(val);
}
if(params->Has(String::NewSymbol("input"))) {
input = params->Get(String::NewSymbol("input"));
if(!input->IsNumber()) {
inputString = stringValue(input);
}
}

}
if(message->window) {
cv::namedWindow("Preview",1);
Expand All @@ -181,7 +197,11 @@ Handle<Value> Open(const Arguments& args) {
message->callBack = Persistent<Function>::New(localFunc);
//Initiate OpenCV WebCam
message->capture = new cv::VideoCapture();
message->capture->open(0);
if(input->IsNumber()) {
message->capture->open((int)input->Int32Value());
} else {
message->capture->open(*inputString);
}
cv::waitKey(10);

uv_work_t* req = new uv_work_t();
Expand All @@ -192,6 +212,12 @@ Handle<Value> Open(const Arguments& args) {
uv_async_init(loop,async,updateAsync);
uv_queue_work(loop, req, CameraOpen,(uv_after_work_cb) CameraClose);

//Free resources
//free #1
if(!input->IsNumber()) {
delete inputString;
}

return scope.Close(String::New("ok"));
}

Expand All @@ -215,4 +241,17 @@ void init(Handle<Object> exports) {
exports->Set(String::NewSymbol("GetPreviewSize"), FunctionTemplate::New(GetPreviewSize)->GetFunction());
}

std::string* stringValue(Local<Value> value) {
if(value->IsString()){
//Alloc #1
char * buffer = (char*) malloc(sizeof(char) * value->ToString()->Length());
value->ToString()->WriteAscii(buffer,0,value->ToString()->Length());
std::string *ret = new std::string(buffer);
free(buffer);
return ret;
} else {
return new std::string("");
}
}

NODE_MODULE(camera, init);

0 comments on commit 6d56bc7

Please sign in to comment.