mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Fix Matrix::Row() and Matrix::Col() to return proper BGR pixel values for images
This commit is contained in:
parent
118da26a80
commit
765ee8d68b
@ -117,11 +117,15 @@ Matrix::Row(const Arguments& args){
|
|||||||
SETUP_FUNCTION(Matrix)
|
SETUP_FUNCTION(Matrix)
|
||||||
|
|
||||||
int width = self->mat.size().width;
|
int width = self->mat.size().width;
|
||||||
int j = args[0]->IntegerValue();
|
int y = args[0]->IntegerValue();
|
||||||
v8::Local<v8::Array> arr = v8::Array::New(width);
|
v8::Local<v8::Array> arr = v8::Array::New(width * 3);
|
||||||
|
|
||||||
for (int i=0; i<width; i++){
|
for (int x=0; x<width; x++){
|
||||||
arr->Set(i, Number::New(self->mat.at<double>(i, j)));
|
cv::Vec3b pixel = self->mat.at<cv::Vec3b>(y, x);
|
||||||
|
int offset = x * 3;
|
||||||
|
arr->Set(offset , Number::New((double)pixel.val[0]));
|
||||||
|
arr->Set(offset + 1, Number::New((double)pixel.val[1]));
|
||||||
|
arr->Set(offset + 2, Number::New((double)pixel.val[2]));
|
||||||
}
|
}
|
||||||
return scope.Close(arr);
|
return scope.Close(arr);
|
||||||
}
|
}
|
||||||
@ -130,12 +134,16 @@ Handle<Value>
|
|||||||
Matrix::Col(const Arguments& args){
|
Matrix::Col(const Arguments& args){
|
||||||
SETUP_FUNCTION(Matrix)
|
SETUP_FUNCTION(Matrix)
|
||||||
|
|
||||||
int width = self->mat.size().width;
|
int height = self->mat.size().height;
|
||||||
int j = args[0]->IntegerValue();
|
int x = args[0]->IntegerValue();
|
||||||
v8::Local<v8::Array> arr = v8::Array::New(width);
|
v8::Local<v8::Array> arr = v8::Array::New(height * 3);
|
||||||
|
|
||||||
for (int i=0; i<width; i++){
|
for (int y=0; y<height; y++){
|
||||||
arr->Set(i, Number::New(self->mat.at<double>(j, i)));
|
cv::Vec3b pixel = self->mat.at<cv::Vec3b>(y, x);
|
||||||
|
int offset = y * 3;
|
||||||
|
arr->Set(offset , Number::New((double)pixel.val[0]));
|
||||||
|
arr->Set(offset + 1, Number::New((double)pixel.val[1]));
|
||||||
|
arr->Set(offset + 2, Number::New((double)pixel.val[2]));
|
||||||
}
|
}
|
||||||
return scope.Close(arr);
|
return scope.Close(arr);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ OpenCV::ReadImage(const Arguments &args) {
|
|||||||
} else if (args[0]->IsString()) {
|
} else if (args[0]->IsString()) {
|
||||||
|
|
||||||
std::string filename = std::string(*v8::String::AsciiValue(args[0]->ToString()));
|
std::string filename = std::string(*v8::String::AsciiValue(args[0]->ToString()));
|
||||||
mat = cv::imread(filename, -1);
|
mat = cv::imread(filename);
|
||||||
|
|
||||||
} else if (Buffer::HasInstance(args[0])){
|
} else if (Buffer::HasInstance(args[0])){
|
||||||
uint8_t *buf = (uint8_t *) Buffer::Data(args[0]->ToObject());
|
uint8_t *buf = (uint8_t *) Buffer::Data(args[0]->ToObject());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user