add compare

This commit is contained in:
Pierre Colle 2017-09-05 17:36:48 +02:00
parent 8a9c02a5e4
commit 416fbd100e
2 changed files with 33 additions and 0 deletions

View File

@ -101,6 +101,13 @@ void Constants::Init(Local<Object> target) {
CONST_INT(CV_DIST_MASK_5);
CONST_INT(CV_DIST_MASK_PRECISE);
CONST_ENUM(CMP_EQ)
CONST_ENUM(CMP_GT)
CONST_ENUM(CMP_GE)
CONST_ENUM(CMP_LT)
CONST_ENUM(CMP_LE)
CONST_ENUM(CMP_NE)
target->Set(Nan::New("TERM_CRITERIA_EPS").ToLocalChecked(), Nan::New<Integer>((int)cv::TermCriteria::EPS));
target->Set(Nan::New("TERM_CRITERIA_COUNT").ToLocalChecked(), Nan::New<Integer>((int)cv::TermCriteria::COUNT));

View File

@ -116,6 +116,7 @@ void Matrix::Init(Local<Object> target) {
Nan::SetPrototypeMethod(ctor, "reshape", Reshape);
Nan::SetPrototypeMethod(ctor, "release", Release);
Nan::SetPrototypeMethod(ctor, "subtract", Subtract);
Nan::SetPrototypeMethod(ctor, "compare", Compare);
target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction());
};
@ -2835,3 +2836,28 @@ NAN_METHOD(Matrix::Subtract) {
return;
}
NAN_METHOD(Matrix::Compare) {
SETUP_FUNCTION(Matrix)
if (info.Length() < 2) {
Nan::ThrowTypeError("Invalid number of arguments");
}
Matrix *other = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
int cmpop = info[1]->IntegerValue();
int width = self->mat.size().width;
int height = self->mat.size().height;
cv::Mat res = cv::Mat(width, height, CV_8UC1);
cv::compare(self->mat, other->mat, res, cmpop);
Local<Object> out = Nan::NewInstance(Nan::GetFunction(Nan::New(Matrix::constructor)).ToLocalChecked()).ToLocalChecked();
Matrix *m_out = Nan::ObjectWrap::Unwrap<Matrix>(out);
m_out->mat = res;
info.GetReturnValue().Set(out);
return;
}