mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Added drawChessboardCorners
This commit is contained in:
parent
e35698ac16
commit
088b44bdeb
@ -8,6 +8,7 @@ void Calib3D::Init(Handle<Object> target)
|
||||
NanAssignPersistent(inner, obj);
|
||||
|
||||
NODE_SET_METHOD(obj, "findChessboardCorners", FindChessboardCorners);
|
||||
NODE_SET_METHOD(obj, "drawChessboardCorners", DrawChessboardCorners);
|
||||
|
||||
target->Set(NanNew("calib3d"), obj);
|
||||
}
|
||||
@ -86,3 +87,72 @@ NAN_METHOD(Calib3D::FindChessboardCorners)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// cv::drawChessboardCorners
|
||||
NAN_METHOD(Calib3D::DrawChessboardCorners)
|
||||
{
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0 is the image
|
||||
Matrix* m = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat mat = m->mat;
|
||||
|
||||
// Arg 1 is the pattern size
|
||||
cv::Size patternSize;
|
||||
if (args[1]->IsArray()) {
|
||||
Local<Object> v8sz = args[1]->ToObject();
|
||||
|
||||
patternSize = cv::Size(v8sz->Get(0)->IntegerValue(), v8sz->Get(1)->IntegerValue());
|
||||
} else {
|
||||
JSTHROW_TYPE("Must pass pattern size");
|
||||
}
|
||||
|
||||
// Arg 2 is the corners array
|
||||
std::vector<cv::Point2f> corners;
|
||||
if(args[2]->IsArray()) {
|
||||
Local<Array> cornersArray = Local<Array>::Cast(args[2]);
|
||||
|
||||
for(unsigned int i = 0; i < cornersArray->Length(); i++)
|
||||
{
|
||||
Local<Object> pt = cornersArray->Get(i)->ToObject();
|
||||
corners.push_back(cv::Point2f(pt->Get(NanNew<String>("x"))->ToNumber()->Value(),
|
||||
pt->Get(NanNew<String>("y"))->ToNumber()->Value()));
|
||||
}
|
||||
} else {
|
||||
JSTHROW_TYPE("Must pass corners array");
|
||||
}
|
||||
|
||||
// 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<Value> 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();
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ public:
|
||||
static void Init(Handle<Object> target);
|
||||
|
||||
static NAN_METHOD(FindChessboardCorners);
|
||||
|
||||
static NAN_METHOD(DrawChessboardCorners);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user