mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #294 from jainanshul/matrix_scalar
Create a matrix using the provided scalar
This commit is contained in:
commit
97b896331c
@ -108,8 +108,9 @@ Matrix::Init(Handle<Object> target) {
|
|||||||
|
|
||||||
NAN_METHOD(Matrix::New) {
|
NAN_METHOD(Matrix::New) {
|
||||||
NanScope();
|
NanScope();
|
||||||
if (args.This()->InternalFieldCount() == 0)
|
if (args.This()->InternalFieldCount() == 0) {
|
||||||
NanThrowTypeError("Cannot instantiate without new");
|
NanThrowTypeError("Cannot instantiate without new");
|
||||||
|
}
|
||||||
|
|
||||||
Matrix *mat;
|
Matrix *mat;
|
||||||
|
|
||||||
@ -119,6 +120,10 @@ NAN_METHOD(Matrix::New) {
|
|||||||
mat = new Matrix(args[0]->IntegerValue(), args[1]->IntegerValue());
|
mat = new Matrix(args[0]->IntegerValue(), args[1]->IntegerValue());
|
||||||
} else if (args.Length() == 3 && args[0]->IsInt32() && args[1]->IsInt32() && args[2]->IsInt32()) {
|
} else if (args.Length() == 3 && args[0]->IsInt32() && args[1]->IsInt32() && args[2]->IsInt32()) {
|
||||||
mat = new Matrix(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue());
|
mat = new Matrix(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue());
|
||||||
|
} else if (args.Length() == 4 && args[0]->IsInt32() && args[1]->IsInt32() &&
|
||||||
|
args[2]->IsInt32() && args[3]->IsArray()) {
|
||||||
|
mat = new Matrix(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||||
|
args[2]->IntegerValue(), args[3]->ToObject());
|
||||||
} else { // if (args.Length() == 5) {
|
} else { // if (args.Length() == 5) {
|
||||||
Matrix *other = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
Matrix *other = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||||
int x = args[1]->IntegerValue();
|
int x = args[1]->IntegerValue();
|
||||||
@ -150,6 +155,22 @@ Matrix::Matrix(cv::Mat m, cv::Rect roi): ObjectWrap() {
|
|||||||
mat = cv::Mat(m, roi);
|
mat = cv::Mat(m, roi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix::Matrix(int rows, int cols, int type, Local<Object> scalarObj) {
|
||||||
|
mat = cv::Mat(rows, cols, type);
|
||||||
|
if (mat.channels() == 3) {
|
||||||
|
mat.setTo(cv::Scalar(scalarObj->Get(0)->IntegerValue(),
|
||||||
|
scalarObj->Get(1)->IntegerValue(),
|
||||||
|
scalarObj->Get(2)->IntegerValue()));
|
||||||
|
} else if (mat.channels() == 2) {
|
||||||
|
mat.setTo(cv::Scalar(scalarObj->Get(0)->IntegerValue(),
|
||||||
|
scalarObj->Get(1)->IntegerValue()));
|
||||||
|
} else if (mat.channels() == 1) {
|
||||||
|
mat.setTo(cv::Scalar(scalarObj->Get(0)->IntegerValue()));
|
||||||
|
} else {
|
||||||
|
NanThrowError("Only 1-3 channels are supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NAN_METHOD(Matrix::Empty){
|
NAN_METHOD(Matrix::Empty){
|
||||||
|
|||||||
@ -11,6 +11,7 @@ class Matrix: public node::ObjectWrap {
|
|||||||
Matrix(cv::Mat other, cv::Rect roi);
|
Matrix(cv::Mat other, cv::Rect roi);
|
||||||
Matrix(int rows, int cols);
|
Matrix(int rows, int cols);
|
||||||
Matrix(int rows, int cols, int type);
|
Matrix(int rows, int cols, int type);
|
||||||
|
Matrix(int rows, int cols, int type, Local<Object> scalarObj);
|
||||||
|
|
||||||
static double DblGet(cv::Mat mat, int i, int j);
|
static double DblGet(cv::Mat mat, int i, int j);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user