Skip to content

Commit

Permalink
Merge pull request peterbraden#2 from jhurliman/master
Browse files Browse the repository at this point in the history
Fix Matrix::Row() and Matrix::Col() to return proper BGR pixel values for images
  • Loading branch information
peterbraden committed May 5, 2012
2 parents 118da26 + 765ee8d commit c13aa6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/Matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,15 @@ Matrix::Row(const Arguments& args){
SETUP_FUNCTION(Matrix)

int width = self->mat.size().width;
int j = args[0]->IntegerValue();
v8::Local<v8::Array> arr = v8::Array::New(width);

for (int i=0; i<width; i++){
arr->Set(i, Number::New(self->mat.at<double>(i, j)));
int y = args[0]->IntegerValue();
v8::Local<v8::Array> arr = v8::Array::New(width * 3);

for (int x=0; x<width; x++){
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);
}
Expand All @@ -130,12 +134,16 @@ Handle<Value>
Matrix::Col(const Arguments& args){
SETUP_FUNCTION(Matrix)

int width = self->mat.size().width;
int j = args[0]->IntegerValue();
v8::Local<v8::Array> arr = v8::Array::New(width);
int height = self->mat.size().height;
int x = args[0]->IntegerValue();
v8::Local<v8::Array> arr = v8::Array::New(height * 3);

for (int i=0; i<width; i++){
arr->Set(i, Number::New(self->mat.at<double>(j, i)));
for (int y=0; y<height; y++){
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenCV.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ OpenCV::ReadImage(const Arguments &args) {
} else if (args[0]->IsString()) {

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])){
uint8_t *buf = (uint8_t *) Buffer::Data(args[0]->ToObject());
Expand Down

0 comments on commit c13aa6a

Please sign in to comment.