Fix Get / Set - closes #15

This commit is contained in:
Peter Braden 2012-10-15 13:09:37 -07:00
parent 7468d0e5fe
commit 03e444071c
2 changed files with 21 additions and 6 deletions

View File

@ -129,9 +129,9 @@ Matrix::DblGet(cv::Mat mat, int i, int j){
switch(mat.type()){ switch(mat.type()){
case CV_32FC3: case CV_32FC3:
pix = mat.at<cv::Vec3b>(i, j); pix = mat.at<cv::Vec3b>(i, j);
pint &= (uchar) pix.val[2]; pint |= (uchar) pix.val[2];
pint &= ((uchar) pix.val[1]) << 8; pint |= ((uchar) pix.val[1]) << 8;
pint &= ((uchar) pix.val[0]) << 16; pint |= ((uchar) pix.val[0]) << 16;
val = (double) pint; val = (double) pint;
break; break;
@ -166,6 +166,7 @@ Matrix::Set(const Arguments& args){
int i = args[0]->IntegerValue(); int i = args[0]->IntegerValue();
int j = args[1]->IntegerValue(); int j = args[1]->IntegerValue();
double val = args[2]->NumberValue(); double val = args[2]->NumberValue();
int vint = 0;
if(args.Length() == 4) { if(args.Length() == 4) {
self->mat.at<cv::Vec3b>(i,j)[args[3]->NumberValue()] = val; self->mat.at<cv::Vec3b>(i,j)[args[3]->NumberValue()] = val;
@ -174,10 +175,16 @@ Matrix::Set(const Arguments& args){
switch(self->mat.type()){ switch(self->mat.type()){
case CV_32FC3: case CV_32FC3:
self->mat.at<cv::Vec3b>(i,j)[0] = static_cast<unsigned int> (val + 0.5) >> 16; vint = static_cast<unsigned int>(val + 0.5);
self->mat.at<cv::Vec3b>(i,j)[1] = static_cast<unsigned int> (val + 0.5) >> 8; self->mat.at<cv::Vec3b>(i,j)[0] = (uchar) (vint >> 16) & 0xff;
self->mat.at<cv::Vec3b>(i,j)[2] = static_cast<unsigned int> (val + 0.5); self->mat.at<cv::Vec3b>(i,j)[1] = (uchar) (vint >> 8) & 0xff;
self->mat.at<cv::Vec3b>(i,j)[2] = (uchar) (vint) & 0xff;
//printf("!!!i %x, %x, %x", (vint >> 16) & 0xff, (vint >> 8) & 0xff, (vint) & 0xff);
break; break;
default:
self->mat.at<double>(i,j) = val;
} }

View File

@ -72,6 +72,14 @@ vows.describe('Smoke Tests OpenCV').addBatch({
assert.ok(new cv.Matrix); assert.ok(new cv.Matrix);
assert.ok(new cv.Matrix(1,2)); assert.ok(new cv.Matrix(1,2));
} }
, "set/row" : function(cv){
var mat = new cv.Matrix(1, 2);
mat.set(0,0,3)
mat.set(0,1,5000)
assert.deepEqual(mat.row(0), [3,5000]);
}
, "get/set" : function(cv){ , "get/set" : function(cv){
var mat = new cv.Matrix(1,2); var mat = new cv.Matrix(1,2);
assert.equal(mat.set(0,0,3), undefined); assert.equal(mat.set(0,0,3), undefined);