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

Corrupted image file #29

Closed
xseignard opened this issue Apr 6, 2013 · 27 comments
Closed

Corrupted image file #29

xseignard opened this issue Apr 6, 2013 · 27 comments

Comments

@xseignard
Copy link

Hello, I installed this lib on my raspberry pi with :

  • node : 0.8.22
  • libgphoto2-2 and libgphoto2-2-dev : 2.4.14

And tried to take a shot with my eos 550d as presented in the exemple.

camera.takePicture({download: true}, function(er, data) {
    fs.writeFile("picture.jpg", data, function(err) {
        if (err) {
            console.log(err);
        } else {
            console.log("The file was saved!");
        }
    });
});

But the picture.jpg is always corrupted when I try to open it. With the following error: Not a JPEG file: starts with 0x00 0x00

Any idea?

Regards,

Xavier

@lwille
Copy link
Owner

lwille commented Apr 6, 2013

Hi xavier,

you can tell gphoto2 to directly download the picture to a file by passing in {download: true, targetPath: './test.jpg'}.
You should also inspect the error passed by takePicture.

I don't have my test setup at hand so I can only try to give you some hints - I assume taking pictures using the gphoto2 commandline is working fine?

@xseignard
Copy link
Author

gphoto2 is working fine, and the error is undefined so it seems to be working.

@lwille
Copy link
Owner

lwille commented Apr 6, 2013

I'm always setting the 'binary' flag on the writeFile, did you try this already?

        fs.writeFile("series_"+i+".jpg", data, "binary", function(er){})

edit: the docs say it's set using {encoding: 'binary'} now ..

@xseignard
Copy link
Author

I tried with setting the encoding, and I have the same issue.

@xseignard
Copy link
Author

So I finally succeded to install libgphoto2-2.5 (with that script: https://github.com/gonzalo/gphoto2-updater).

I then cloned this repo, checked out the feature/libgphoto2-2.5.x branch, did npm install and then sudo npm link.

In my project I did a npm link gphoto2 and tried this snippet:

var fs = require('fs'),
    GPhoto = require('gphoto2'),
    gphoto = new GPhoto.GPhoto2();

// List cameras / assign list item to variable to use below options
gphoto.list(function(list) {
    if(list.length === 0) return;
    var camera = list[0];
    console.log('Found', camera.model);

    // Take picture with camera object obtained from list()
    camera.takePicture({download:true}, function(err, data) {
        fs.writeFile('pic.jpg', data, {encoding: 'binary'}, function(err) {
            console.log(err);   
        });
    });
});

err is null and the jpg file is corrupted.

Any idea?

Env: node 0.10.2, libgphoto2-2.5. And gphoto2 works well.
I'm using a EOS550D.

Regards

@xseignard
Copy link
Author

I tried with the 2.5.1.1 of libgphoto (from this script : https://github.com/Deckchair/gphoto2-updater)

Here is the output of gphoto2 --version:

This version of gphoto2 is using the following software versions and options:
gphoto2         2.5.1          gcc, popt(m), exif, no cdk, no aa, no jpeg, no readline
libgphoto2      2.5.1.1        all camlibs, gcc, ltdl, EXIF
libgphoto2_port 0.10.0         gcc, ltdl, USB, serial without locking

Same corrupted image.

@xseignard
Copy link
Author

I tried the same on my workstation (ubuntu12.04, x64):

  • Install libgphoto 2.5.1.1 from this script : https://github.com/Deckchair/gphoto2-updater
  • Clone this repo, check out the feature/libgphoto2-2.5.x branch
  • Then npm install and sudo npm link
  • In my project I did a npm link gphoto2

Then i have this snippet:

var fs = require('fs'),
    GPhoto = require('gphoto2'),
    gphoto = new GPhoto.GPhoto2();

// List cameras / assign list item to variable to use below options
gphoto.list(function(list) {
    if(list.length === 0) return;
    var camera = list[0];
    console.log('Found', camera.model);

    // Take picture with camera object obtained from list()
    camera.takePicture({download:true}, function(err, data) {
    console.log(err);         
    fs.writeFile('pic.jpg', data, {encoding: 'binary'}, function(err) {
            console.log(err);   
        });
    });
});

And when I run it, the err param of the callback of takePicture returns a weird -110.

When I run the following shell command : gphoto2 --capture-image-and-download everything is fine.

I never succeeded to make this package work. I'm running out of options here. Any idea on why this doesn't work?

@lwille
Copy link
Owner

lwille commented Apr 17, 2013

This is really strange. Did you actually run the tests in feature/libgphoto2-2.5.x?

Looks like I have to get an Ubuntu machine :-/

@marvin
Copy link

marvin commented Apr 17, 2013

the tests worked on ubuntu and debian for me.

On 17 April 2013 11:09, Leonhardt Wille notifications@github.com wrote:

This is really strange. Did you actually run the tests in
feature/libgphoto2-2.5.x?

Looks like I have to get an Ubuntu machine :-/


Reply to this email directly or view it on GitHubhttps://github.com//issues/29#issuecomment-16494958
.

@lwille
Copy link
Owner

lwille commented Apr 20, 2013

Just closed #30. @xseignard, did you try executing your tests with sudo? It shouldn't be necessary, but I think we should try to rule out the most basic things that could be different on your system ..

NPM release will come soon, I'd like to have some more time to figure out these errors.

@xseignard
Copy link
Author

Hi there, I finally got my camera back.
On my ubuntu12.04 (amd64)machine:

  • I pulled the latest changes : git co master && git pull
  • Installed the deps: npm install
  • Then launched the tests : npm test (tried with sudo npm test with the same result)

I recieve a segmentation fault.

I also tried with the npm link method as described above, and I still have the -110 error code.

I should give a try on the Pi and let you know.

@xseignard
Copy link
Author

So I tried on the Pi, it's a complete mess.
I now have an error related to python, and the parser module... when I try to do a npm install after a fresh clone.

> gphoto2@0.1.2 preinstall /home/pi/projects/node-gphoto2
> (pkg-config libgphoto2 || dpkg -s libgphoto2-2-dev || (echo 'ERROR: libgphoto2 seems not to be installed.' 1>&2; exit 1)) && node-gyp rebuild

Traceback (most recent call last):
  File "/home/pi/node/node-v0.10.2-linux-arm-pi/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp", line 15, in <module>
    import gyp
  File "/home/pi/node/node-v0.10.2-linux-arm-pi/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 8, in <module>
    import gyp.input
  File "/home/pi/node/node-v0.10.2-linux-arm-pi/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 5, in <module>
    from compiler.ast import Const
  File "/usr/lib/python2.7/compiler/__init__.py", line 29, in <module>
    from compiler.transformer import parse, parseFile
  File "/usr/lib/python2.7/compiler/transformer.py", line 29, in <module>
    import parser
ImportError: No module named parser
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/home/pi/node/node-v0.10.2-linux-arm-pi/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:415:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:757:12)
gyp ERR! System Linux 3.6.11+
gyp ERR! command "node" "/home/pi/node/node-v0.10.2-linux-arm-pi/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/pi/projects/node-gphoto2
gyp ERR! node -v v0.10.2
gyp ERR! node-gyp -v v0.9.3
gyp ERR! not ok 
npm ERR! gphoto2@0.1.2 preinstall: `(pkg-config libgphoto2 || dpkg -s libgphoto2-2-dev || (echo 'ERROR: libgphoto2 seems not to be installed.' 1>&2; exit 1)) && node-gyp rebuild`
npm ERR! `sh "-c" "(pkg-config libgphoto2 || dpkg -s libgphoto2-2-dev || (echo 'ERROR: libgphoto2 seems not to be installed.' 1>&2; exit 1)) && node-gyp rebuild"` failed with 1
npm ERR! 
npm ERR! Failed at the gphoto2@0.1.2 preinstall script.
npm ERR! This is most likely a problem with the gphoto2 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     (pkg-config libgphoto2 || dpkg -s libgphoto2-2-dev || (echo 'ERROR: libgphoto2 seems not to be installed.' 1>&2; exit 1)) && node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls gphoto2
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.6.11+
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install"
npm ERR! cwd /home/pi/projects/node-gphoto2
npm ERR! node -v v0.10.2
npm ERR! npm -v 1.2.15
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/pi/projects/node-gphoto2/npm-debug.log
npm ERR! not ok code 0

@xseignard
Copy link
Author

So, i restarted from a fresh install of raspbian:

and the tests fails, you can find the output here https://gist.github.com/xseignard/5477705

gphoto2 --capture-image-and-download works, and my test snippet do not (the returned data is a buffer full of zeros), err is undefined and error is null

var fs = require('fs'),
    GPhoto = require('gphoto2'),
    gphoto = new GPhoto.GPhoto2();

// List cameras / assign list item to variable to use below options
gphoto.list(function(list) {
    if(list.length === 0) return;
    var camera = list[0];
    console.log('Found', camera.model);

    // Take picture with camera object obtained from list()
    camera.takePicture({download:true}, function(err, data) {
        console.log(data);         
        console.log(err);
        fs.writeFile('pic.jpg', data, {encoding: 'binary'}, function(error) {
            console.log(error);   
        });
    });
});

I give up.

@80leaves
Copy link

copy that, I get the same behaviour on a raspberry

gphoto2 2.5.0 gcc, popt(m), exif, no cdk, no aa, no jpeg, no readline
libgphoto2 2.5.0 all camlibs, gcc, ltdl, EXIF
libgphoto2_port 0.10.0 gcc, ltdl, USB, serial without locking

and node v0.10.3

found camera: { model: '###',
  port: 'usb:001,004',
  _gphoto2_ref_obj_: {} }
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...>
undefined
null

@xseignard
Copy link
Author

Hi!
This lib, and node.js, is a perfect fit for Raspberry Pi, can I help in any way?

@lwille
Copy link
Owner

lwille commented Apr 29, 2013

I started setting up a fresh Raspbian installation, but didn't have the time to run further tests.
Regarding the Python build errors, have you tried installing any other native module that involves node-gyp?

@xseignard
Copy link
Author

Yes, i tried with mongodb and it was OK. I didn't encountered the problem
after a fresh install. Regards

@a0n
Copy link

a0n commented Jul 29, 2013

i am experiencing the exact same problem!
i am wondering if it has something todo with the fact that in the config.gypi there is a line:
"python": "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python"

that is obviously wrong!

@lwille
Copy link
Owner

lwille commented Jul 29, 2013

The config.gypi is not contained in this module - I guess there's something wrong with your python setup. I installed python via homebrew - although I must admit that I don't do any XCode development, so I don't know wether it could break other stuff. And no, it should only affect the build process performed by gyp, but not the compiled binaries.

I still have no clue why it doesn't work on some systems, please always send all available data (OS version, camera model, libgphoto2 version) with your reports.

@zn4ke
Copy link

zn4ke commented Oct 21, 2013

Im having problems with corrupt image files as well
Im using node (v0.10.20) with gphoto2 (2.5.2) on raspberry with raspbian (wheezy)

camera.takePicture({download:true}, function(err, data){
   fs.writeFile("public/images/sampleImg.jpg", data, {encoding: 'binary'}, function(err){
      console.log(err);
   });
}

this produces no errors but a corrupt .jpg file with a resonable file size. the data buffer seems to contain only zeroes.
the files produced via the cli or with childprocess.exec("gphoto2 --capture-image-and-download") are good.

camera.takePicture({download:true, targetPath: './test.jpg'}, function(err){
   console.log(err);
}

produces error: 22 and no file is saved to the files system

has anyone found a solution to this?

edit: accidentially i shot with the lens cap on. fs.writeFile(...) does produce a valid file (smaller size and all pixels obviously allmost black but non-zero). With targetPath set, error 22 is returned as before.

//with lenscap
error: undefined
<Buffer ff d8 ff e1 2e c0 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 0c 00 0f 01 02 00 06 00 00 00 9e 00 00 00 10 01 02 00 0d 00 00 00 a4 00 00 00 12 01 03 00 01 ...>
data-length: 126991
GET /shoot 200 726ms - 11b
null

//without lenscap
error: undefined
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...>
data-length: 766201
GET /shoot 200 728ms - 11b
null


@luky83
Copy link

luky83 commented Dec 12, 2013

I premise that my camera (Canon EOS 20D) has experimental support in normal mode with libgphoto2. Anyway I can successfully run ''gphoto --capture-image-and-download" but I'm experiencing this bug so I report my setup and build process.

Debian GNU/Linux 7.2 (wheezy) with kernel 3.2.0-4-686-pae (fresh install)

  • installed libpopt-dev 1.16-7

    sudo apt-get install libpopt-dev
    
  • downloaded and compiled libtool-2.4.2

  • downloaded and compiled libgphoto2-2.5.2

  • downloaded and compiled gphoto2-2.5.2

  • created symbolic links:

    sudo ln -s /usr/local/lib/libgphoto2.so.6 /usr/lib/libgphoto2.so.6
    sudo ln -s /usr/local/lib/libgphoto2.so /usr/lib/libgphoto2.so
    sudo ln -s /usr/local/lib/libgphoto2_port.so.10 /usr/lib/libgphoto2_port.so.10
    
  • created permission for usb camera

    su
    /usr/local/lib/libgphoto2/print-camera-list udev-rules version 0.98 group plugdev mode 0660 > /etc/udev/rules.d/90-libgphoto2.rules
    
  • tested gphoto2

    gphoto2 --capture-image-and-download
    
  • downloaded and compiled node.js-v0.10.22

  • installed clang 1:3.0-6.2

    sudo apt-get install clang
    
  • installed dipendencies

    npm install gphoto2
    

I also report the output of node installation of gphoto2:

luca@dellbian:~/Scaricati/xmirror2$ npm install gphoto2
npm http GET https://registry.npmjs.org/gphoto2
npm http 304 https://registry.npmjs.org/gphoto2

> gphoto2@0.1.3 preinstall /home/luca/Scaricati/xmirror2/node_modules/gphoto2
> (pkg-config libgphoto2 || dpkg -s libgphoto2-2-dev || (echo 'ERROR: libgphoto2 seems not to be installed.' 1>&2; exit 1)) && node-gyp rebuild

make: Entering directory `/home/luca/Scaricati/xmirror2/node_modules/gphoto2/build'
  CXX(target) Release/obj.target/gphoto2/src/autodetect.o
  CXX(target) Release/obj.target/gphoto2/src/binding.o
  CXX(target) Release/obj.target/gphoto2/src/camera.o
  CXX(target) Release/obj.target/gphoto2/src/camera_helpers.o
  CXX(target) Release/obj.target/gphoto2/src/gphoto.o
  SOLINK_MODULE(target) Release/obj.target/gphoto2.node
  SOLINK_MODULE(target) Release/obj.target/gphoto2.node: Finished
  COPY Release/gphoto2.node
make: Leaving directory `/home/luca/Scaricati/xmirror2/node_modules/gphoto2/build'
gphoto2@0.1.3 node_modules/gphoto2
luca@dellbian:~/Scaricati/xmirror2$ 

@lpinca
Copy link
Contributor

lpinca commented Dec 15, 2013

@zn4ke this is wrong:

camera.takePicture({download:true, targetPath: './test.jpg'}, function(err){
   console.log(err);
}

targetPath should be a template of this form whateverXXXXXX. This because node-gphoto2 uses mkstemp internally.

@luky83
Copy link

luky83 commented Dec 16, 2013

@lpinca
I tried your code, this time the file is not filled with zeros but I still can't open it (Not a JPEG file: starts with 0x75 0x6e)

@luky83
Copy link

luky83 commented Dec 16, 2013

When I take a shot with gphoto2 command line I can see the led on my camera flashing two times. It's doing a quick blink just before shooting the picture, afterwards it keeps blinking while the file is being downloaded.

When I take a shot within nodejs it's doing only the quick blink just before shooting. It seems like it doesn't read any data from the camera after taking the picture

@luky83
Copy link

luky83 commented Dec 16, 2013

There should be a problem with mkstemp with my setup. If I call

// Download a picture from camera
  camera.downloadPicture({
      cameraPath:'/DCIM/231CANON/IMG_3125.JPG',
      targetPath:'/tmp/foo.XXXXX'
    }, function(er, tmpname){
      fs.rename(tmpname, './picture.jpg');
  });

I get this error:
fs.js:14278: Uncaught TypeError: old path must be a string
So I replace tmpname with tmpname+""

// Download a picture from camera
  camera.downloadPicture({
      cameraPath:'/DCIM/231CANON/IMG_3125.JPG',
      targetPath:'/tmp/foo.XXXXX'
    }, function(er, tmpname){
      fs.rename(tmpname+"", './picture.jpg');
  });

but (apart from a missing callback error) if I console.log(tmpname) I always get undefined instead of the temp path.
Also, I cant see any file in my /tmp folder

@lpinca
Copy link
Contributor

lpinca commented Dec 16, 2013

@luky83 make sure you have write permission on the tmp folder.
Also try this snippet which is probably the easiest:

camera.takePicture({
  targetPath: __dirname + '/foo.XXXXXX'
}, function(err, path) {
  if (err) return console.log(err);
  console.log('picture saved in ' + path);
});

@lwille lwille closed this as completed in 94035ec Dec 17, 2013
lwille pushed a commit that referenced this issue Dec 17, 2013
@lwille
Copy link
Owner

lwille commented Dec 17, 2013

Thanks for your fix and help, @lpinca 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants