mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #450 from dxprog/master
handles colors with less-/more-than three channels
This commit is contained in:
commit
c0728bacdf
BIN
examples/files/alpha-test.png
Normal file
BIN
examples/files/alpha-test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 815 B |
@ -1606,13 +1606,27 @@ NAN_METHOD(Matrix::HoughCircles) {
|
||||
}
|
||||
|
||||
cv::Scalar setColor(Local<Object> objColor) {
|
||||
Local<Value> valB = objColor->Get(0);
|
||||
Local<Value> valG = objColor->Get(1);
|
||||
Local<Value> valR = objColor->Get(2);
|
||||
int64_t channels[4] = { 0, 0, 0, 0 };
|
||||
|
||||
cv::Scalar color = cv::Scalar(valB->IntegerValue(), valG->IntegerValue(),
|
||||
valR->IntegerValue());
|
||||
return color;
|
||||
// We'll accomodate a channel count up to 4 and fall back to the old
|
||||
// "assume it's always 3" in the default case
|
||||
if (!objColor->HasRealIndexedProperty(1)) {
|
||||
channels[0] = objColor->Get(0)->IntegerValue();
|
||||
} else if (!objColor->HasRealIndexedProperty(2)) {
|
||||
channels[0] = objColor->Get(0)->IntegerValue();
|
||||
channels[1] = objColor->Get(1)->IntegerValue();
|
||||
} else if (!objColor->HasRealIndexedProperty(4)) {
|
||||
channels[0] = objColor->Get(0)->IntegerValue();
|
||||
channels[1] = objColor->Get(1)->IntegerValue();
|
||||
channels[2] = objColor->Get(2)->IntegerValue();
|
||||
channels[3] = objColor->Get(3)->IntegerValue();
|
||||
} else {
|
||||
channels[0] = objColor->Get(0)->IntegerValue();
|
||||
channels[1] = objColor->Get(1)->IntegerValue();
|
||||
channels[2] = objColor->Get(2)->IntegerValue();
|
||||
}
|
||||
|
||||
return cv::Scalar(channels[0], channels[1], channels[2], channels[3]);
|
||||
}
|
||||
|
||||
cv::Point setPoint(Local<Object> objPoint) {
|
||||
|
||||
26
test/unit.js
26
test/unit.js
@ -391,5 +391,31 @@ test('MatchTemplateByMatrix', function(assert) {
|
||||
})
|
||||
});
|
||||
|
||||
test('setColor works will alpha channels', function(assert) {
|
||||
var cv = require('../lib/opencv');
|
||||
var mat = new cv.Matrix(100, 100, cv.Constants.CV_8UC4);
|
||||
|
||||
var SQUARE = [ 50, 50 ];
|
||||
mat.rectangle([ 0, 0 ], SQUARE, [ 0, 187, 255, 255 ], -1);
|
||||
mat.rectangle([ 0, 50 ], SQUARE, [ 0, 187, 124, 200 ], -1);
|
||||
mat.rectangle([ 50, 0 ], SQUARE, [ 241, 161, 0, 128 ], -1);
|
||||
mat.rectangle([ 50, 50 ], SQUARE, [ 20, 83, 246, 70 ], -1);
|
||||
|
||||
cv.readImage('./examples/files/alpha-test.png', function(err, imgMat) {
|
||||
if (!err) {
|
||||
var diff = new cv.Matrix();
|
||||
diff.absDiff(mat, imgMat);
|
||||
// We'll verify that each channel is 0
|
||||
var channels = diff.split();
|
||||
for (var i = 0; i < 4; i++) {
|
||||
assert.equal(channels[i].countNonZero(), 0);
|
||||
}
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
assert.end();
|
||||
});
|
||||
});
|
||||
|
||||
// Test the examples folder.
|
||||
require('./examples')()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user