mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #405 from dxprog/master
loading image by file/buffer now has same behaviour
This commit is contained in:
commit
0374115c72
BIN
examples/files/opencv.png
Executable file
BIN
examples/files/opencv.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 3.5 KiB |
@ -37,14 +37,14 @@ NAN_METHOD(OpenCV::ReadImage) {
|
||||
|
||||
} else if (info[0]->IsString()) {
|
||||
std::string filename = std::string(*Nan::Utf8String(info[0]->ToString()));
|
||||
mat = cv::imread(filename);
|
||||
mat = cv::imread(filename, CV_LOAD_IMAGE_UNCHANGED);
|
||||
|
||||
} else if (Buffer::HasInstance(info[0])) {
|
||||
uint8_t *buf = (uint8_t *) Buffer::Data(info[0]->ToObject());
|
||||
unsigned len = Buffer::Length(info[0]->ToObject());
|
||||
|
||||
cv::Mat *mbuf = new cv::Mat(len, 1, CV_64FC1, buf);
|
||||
mat = cv::imdecode(*mbuf, -1);
|
||||
mat = cv::imdecode(*mbuf, CV_LOAD_IMAGE_UNCHANGED);
|
||||
|
||||
if (mat.empty()) {
|
||||
argv[0] = Nan::Error("Error loading file");
|
||||
|
||||
26
test/unit.js
26
test/unit.js
@ -127,7 +127,7 @@ test(".norm", function(assert){
|
||||
|
||||
var errorL2 = im.norm(im2, cv.Constants.NORM_L2);
|
||||
assert.equal(errorL2, 7295.591339980605);
|
||||
|
||||
|
||||
errorL2 = im.norm(im, cv.Constants.NORM_L2);
|
||||
assert.equal(errorL2, 0);
|
||||
assert.end();
|
||||
@ -205,23 +205,25 @@ test(".bitwiseXor", function(assert){
|
||||
|
||||
|
||||
test("Image read from file", function(assert){
|
||||
cv.readImage("./examples/files/mona.png", function(err, im){
|
||||
cv.readImage("./examples/files/opencv.png", function(err, im){
|
||||
assert.ok(im);
|
||||
assert.equal(im.width(), 500);
|
||||
assert.equal(im.height(), 756)
|
||||
assert.equal(im.empty(), false)
|
||||
assert.end()
|
||||
assert.equal(im.width(), 82);
|
||||
assert.equal(im.height(), 99);
|
||||
assert.equal(im.channels(), 4);
|
||||
assert.equal(im.empty(), false);
|
||||
assert.end();
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
test("read Image from buffer", function(assert){
|
||||
cv.readImage(fs.readFileSync('./examples/files/mona.png'), function(err, im){
|
||||
cv.readImage(fs.readFileSync('./examples/files/opencv.png'), function(err, im){
|
||||
assert.ok(im);
|
||||
assert.equal(im.width(), 500);
|
||||
assert.equal(im.height(), 756)
|
||||
assert.equal(im.empty(), false)
|
||||
assert.end()
|
||||
assert.equal(im.width(), 82);
|
||||
assert.equal(im.height(), 99);
|
||||
assert.equal(im.channels(), 4);
|
||||
assert.equal(im.empty(), false);
|
||||
assert.end();
|
||||
})
|
||||
})
|
||||
|
||||
@ -242,7 +244,7 @@ test("Cascade Classifier", function(assert){
|
||||
|
||||
test("ImageDataStream", function(assert){
|
||||
var s = new cv.ImageDataStream()
|
||||
s.on('load', function(im){
|
||||
s.on('load', function(im){
|
||||
assert.ok(im)
|
||||
assert.equal(im.empty(), false);
|
||||
assert.end()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user