diff --git a/src/Calib3D.cc b/src/Calib3D.cc index f8a1fcc..3519470 100644 --- a/src/Calib3D.cc +++ b/src/Calib3D.cc @@ -38,47 +38,27 @@ NAN_METHOD(Calib3D::FindChessboardCorners) // Arg 2 would normally be the flags, ignoring this for now and using the default flags - // Final argument is the callback function - REQ_FUN_ARG(2, cb); - // Find the corners std::vector corners; bool found = cv::findChessboardCorners(mat, patternSize, corners); - // Make the callback arguments - Local argv[2]; + // Make the return value + Local ret = NanNew(); + ret->Set(NanNew("found"), NanNew(found)); - argv[0] = NanNull(); - argv[1] = NanNull(); // This will be replaced by the corners array if corners were found - - // Further processing if we found corners - Local cornersArray; - if(found) + Local cornersArray = Array::New(corners.size()); + for(unsigned int i = 0; i < corners.size(); i++) { - // Convert the return value to a javascript array - cornersArray = Array::New(corners.size()); - for(unsigned int i = 0; i < corners.size(); i++) - { - Local point_data = NanNew(); - point_data->Set(NanNew("x"), NanNew(corners[i].x)); - point_data->Set(NanNew("y"), NanNew(corners[i].y)); + Local point_data = NanNew(); + point_data->Set(NanNew("x"), NanNew(corners[i].x)); + point_data->Set(NanNew("y"), NanNew(corners[i].y)); - cornersArray->Set(Number::New(i), point_data); - } - - argv[1] = cornersArray; + cornersArray->Set(Number::New(i), point_data); } - // Callback - TryCatch try_catch; + ret->Set(NanNew("corners"), cornersArray); - cb->Call(NanGetCurrentContext()->Global(), 2, argv); - - if(try_catch.HasCaught()) { - FatalException(try_catch); - } - - NanReturnUndefined(); + NanReturnValue(ret); } catch (cv::Exception &e) { @@ -129,27 +109,11 @@ NAN_METHOD(Calib3D::DrawChessboardCorners) // Arg 3, pattern found boolean bool patternWasFound = args[3]->ToBoolean()->Value(); - // Final argument is the callback - REQ_FUN_ARG(4, cb); - // Draw the corners cv::drawChessboardCorners(mat, patternSize, corners, patternWasFound); - // Make the callback arguments (same image that was passed, now with corners drawn on it) - Local argv[2]; - argv[0] = NanNull(); - argv[1] = args[0]; - - // Callback - TryCatch try_catch; - - cb->Call(NanGetCurrentContext()->Global(), 2, argv); - - if(try_catch.HasCaught()) { - FatalException(try_catch); - } - - NanReturnUndefined(); + // Return the passed image, now with corners drawn on it + NanReturnValue(args[0]); } catch (cv::Exception &e) { const char *err_msg = e.what();