Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/files/opencv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/files/over_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/OpenCV.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
26 changes: 14 additions & 12 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
})
})

Expand All @@ -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()
Expand Down