Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't load tiff image from readImage(buffer) #653

Open
fiefdx opened this issue Mar 29, 2019 · 0 comments
Open

Can't load tiff image from readImage(buffer) #653

fiefdx opened this issue Mar 29, 2019 · 0 comments
Labels

Comments

@fiefdx
Copy link

fiefdx commented Mar 29, 2019

Describe the bug

const fs = require('fs');
const path = require('path');

const cv = require("opencv");

const sourcePath = "./test.tiff";
const targetPath = "./test.jpg";

console.log("before image resize");

let content = fs.readFileSync(sourcePath);
console.log(`content type: ${content instanceof Buffer}`);

cv.readImage(content, function(err, mat) {
	mat.resize(640, 360);
	// mat.save(targetPath);
	let buf = mat.toBuffer({ext: ".jpg", jpegQuality: 100});
	var targetFile = fs.openSync(targetPath, "w");
        fs.writeFileSync(targetFile, buf, {encoding: 'binary', flag: 'w'});
        fs.closeSync(targetFile);
	console.log("convert image");
});

console.log("after image resize");

breeze@breeze-desktop:~/Work/uber-test/xviz/examples/data-server$ nodejs ./opencv-tiff2jpeg.js 
before image resize
content type: true
OpenCV Error: Unspecified error (failed to write image data to temporary file) in imdecode_, file /home/breeze/Work/data/vehicle_data/impl-ros-kinetic/script/tmp/opencv-3.3.0/modules/imgcodecs/src/loadsave.cpp, line 657
/home/breeze/Work/uber-test/xviz/examples/data-server/opencv-tiff2jpeg.js:15
	mat.resize(640, 360);
	    ^

TypeError: Cannot read property 'resize' of null
    at /home/breeze/Work/uber-test/xviz/examples/data-server/opencv-tiff2jpeg.js:15:6
    at Object.<anonymous> (/home/breeze/Work/uber-test/xviz/examples/data-server/opencv-tiff2jpeg.js:14:4)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

OS / Libraries

  • Ubuntu 16.04
@fiefdx fiefdx added the bug label Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant