mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Changed to non-callback API since all methods are synchronous
This commit is contained in:
parent
0c35976950
commit
024d8e5ee5
@ -38,47 +38,27 @@ NAN_METHOD(Calib3D::FindChessboardCorners)
|
|||||||
|
|
||||||
// Arg 2 would normally be the flags, ignoring this for now and using the default flags
|
// 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
|
// Find the corners
|
||||||
std::vector<cv::Point2f> corners;
|
std::vector<cv::Point2f> corners;
|
||||||
bool found = cv::findChessboardCorners(mat, patternSize, corners);
|
bool found = cv::findChessboardCorners(mat, patternSize, corners);
|
||||||
|
|
||||||
// Make the callback arguments
|
// Make the return value
|
||||||
Local<Value> argv[2];
|
Local<Object> ret = NanNew<Object>();
|
||||||
|
ret->Set(NanNew<String>("found"), NanNew<Boolean>(found));
|
||||||
|
|
||||||
argv[0] = NanNull();
|
Local<Array> cornersArray = Array::New(corners.size());
|
||||||
argv[1] = NanNull(); // This will be replaced by the corners array if corners were found
|
for(unsigned int i = 0; i < corners.size(); i++)
|
||||||
|
|
||||||
// Further processing if we found corners
|
|
||||||
Local<Array> cornersArray;
|
|
||||||
if(found)
|
|
||||||
{
|
{
|
||||||
// Convert the return value to a javascript array
|
Local<Object> point_data = NanNew<Object>();
|
||||||
cornersArray = Array::New(corners.size());
|
point_data->Set(NanNew<String>("x"), NanNew<Number>(corners[i].x));
|
||||||
for(unsigned int i = 0; i < corners.size(); i++)
|
point_data->Set(NanNew<String>("y"), NanNew<Number>(corners[i].y));
|
||||||
{
|
|
||||||
Local<Object> point_data = NanNew<Object>();
|
|
||||||
point_data->Set(NanNew<String>("x"), NanNew<Number>(corners[i].x));
|
|
||||||
point_data->Set(NanNew<String>("y"), NanNew<Number>(corners[i].y));
|
|
||||||
|
|
||||||
cornersArray->Set(Number::New(i), point_data);
|
cornersArray->Set(Number::New(i), point_data);
|
||||||
}
|
|
||||||
|
|
||||||
argv[1] = cornersArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback
|
ret->Set(NanNew<String>("corners"), cornersArray);
|
||||||
TryCatch try_catch;
|
|
||||||
|
|
||||||
cb->Call(NanGetCurrentContext()->Global(), 2, argv);
|
NanReturnValue(ret);
|
||||||
|
|
||||||
if(try_catch.HasCaught()) {
|
|
||||||
FatalException(try_catch);
|
|
||||||
}
|
|
||||||
|
|
||||||
NanReturnUndefined();
|
|
||||||
|
|
||||||
|
|
||||||
} catch (cv::Exception &e) {
|
} catch (cv::Exception &e) {
|
||||||
@ -129,27 +109,11 @@ NAN_METHOD(Calib3D::DrawChessboardCorners)
|
|||||||
// Arg 3, pattern found boolean
|
// Arg 3, pattern found boolean
|
||||||
bool patternWasFound = args[3]->ToBoolean()->Value();
|
bool patternWasFound = args[3]->ToBoolean()->Value();
|
||||||
|
|
||||||
// Final argument is the callback
|
|
||||||
REQ_FUN_ARG(4, cb);
|
|
||||||
|
|
||||||
// Draw the corners
|
// Draw the corners
|
||||||
cv::drawChessboardCorners(mat, patternSize, corners, patternWasFound);
|
cv::drawChessboardCorners(mat, patternSize, corners, patternWasFound);
|
||||||
|
|
||||||
// Make the callback arguments (same image that was passed, now with corners drawn on it)
|
// Return the passed image, now with corners drawn on it
|
||||||
Local<Value> argv[2];
|
NanReturnValue(args[0]);
|
||||||
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();
|
|
||||||
|
|
||||||
} catch (cv::Exception &e) {
|
} catch (cv::Exception &e) {
|
||||||
const char *err_msg = e.what();
|
const char *err_msg = e.what();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user