mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #158 from salmanulhaq/issue-147
Added nchannel check. Fixes issue #147
This commit is contained in:
commit
38a672d499
@ -9,6 +9,8 @@ cv.readImage("./mona.png", function(err, im) {
|
||||
img_hsv.convertHSVscale();
|
||||
img_gray.convertGrayscale();
|
||||
|
||||
console.log(img_gray.pixel(100,100));
|
||||
|
||||
im.save("/tmp/nor.png");
|
||||
img_hsv.save("/tmp/hsv.png");
|
||||
img_gray.save("/tmp/gray.png");
|
||||
|
||||
@ -212,19 +212,32 @@ Matrix::Pixel(const Arguments& args){
|
||||
|
||||
Local<Object> objColor = args[2]->ToObject();
|
||||
|
||||
self->mat.at<cv::Vec3b>(y, x)[0] = (uchar) objColor->Get(0)->IntegerValue();
|
||||
self->mat.at<cv::Vec3b>(y, x)[1] = (uchar) objColor->Get(1)->IntegerValue();
|
||||
self->mat.at<cv::Vec3b>(y, x)[2] = (uchar) objColor->Get(2)->IntegerValue();
|
||||
if(self->mat.channels() == 3){
|
||||
self->mat.at<cv::Vec3b>(y, x)[0] = (uchar) objColor->Get(0)->IntegerValue();
|
||||
self->mat.at<cv::Vec3b>(y, x)[1] = (uchar) objColor->Get(1)->IntegerValue();
|
||||
self->mat.at<cv::Vec3b>(y, x)[2] = (uchar) objColor->Get(2)->IntegerValue();
|
||||
}
|
||||
else if(self->mat.channels() == 1)
|
||||
self->mat.at<uchar>(y,x) = (uchar) objColor->Get(0)->IntegerValue();
|
||||
|
||||
return scope.Close(args[2]->ToObject());
|
||||
}else{
|
||||
cv::Vec3b intensity = self->mat.at<cv::Vec3b>(y, x);
|
||||
|
||||
v8::Local<v8::Array> arr = v8::Array::New(3);
|
||||
arr->Set(0, Number::New( intensity[0] ));
|
||||
arr->Set(1, Number::New( intensity[1] ));
|
||||
arr->Set(2, Number::New( intensity[2] ));
|
||||
return scope.Close(arr);
|
||||
if(self->mat.channels() == 3){
|
||||
cv::Vec3b intensity = self->mat.at<cv::Vec3b>(y, x);
|
||||
|
||||
v8::Local<v8::Array> arr = v8::Array::New(3);
|
||||
arr->Set(0, Number::New( intensity[0] ));
|
||||
arr->Set(1, Number::New( intensity[1] ));
|
||||
arr->Set(2, Number::New( intensity[2] ));
|
||||
return scope.Close(arr);
|
||||
}
|
||||
else if(self->mat.channels() == 1){
|
||||
|
||||
uchar intensity = self->mat.at<uchar>(y, x);
|
||||
return scope.Close(Number::New(intensity));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return scope.Close(Undefined());
|
||||
@ -305,7 +318,6 @@ Matrix::Clone(const Arguments& args){
|
||||
return scope.Close(im_h);
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Row(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user