By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,302 Members | 1,788 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,302 IT Pros & Developers. It's quick & easy.

looking for help about python-sane

P: n/a
I m looking for help about python-sane, The follow sample code try to
grab the image from the webcam through a /dev/video0 on linux, it works
fine for the first 185 times, but it freeze the computer when i ~ 185,
I dont know why?

The computer become very busy when i > 160, very strange?

I m using Ubuntu 5.10 Linux

Thanks
-----------------------code start------------------

#! /usr/bin/python

import sane, time, Image

def grabImage(_webcam):
_webcam.mode='color'
_webcam.start()
img=_webcam.snap()
return img

for i in range(200):
print 'i=', i
sane.init()
webcam = sane.open('v4l:/dev/video0')
grabImage(webcam)
webcam.close()
sane.exit()
time.sleep(1)
----------------------code end-------------------

---------------------output--------------------
i=0
i=1
i=2
.....
i= 182
i= 183
i= 184
i= 185
Traceback (most recent call last):
File "testSane.py", line 17, in ?
grabImage(webcam)
File "testSane.py", line 7, in grabImage
_webcam.start()
File "/usr/lib/python2.4/site-packages/sane.py", line 201, in start
return self.dev.start()
_sane.error: Error during device I/O
Feb 28 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
JW
Every time, or just this run?

Mar 1 '06 #2

P: n/a
JW wrote:
Every time, or just this run?

every time
Mar 1 '06 #3

P: n/a
JW
Sorry, I can't help much with the issue. You are getting a low-level
hardware fault, and
not much information is being propagated up throught the system. It's
not a Python problem, but something with SANE, and the Python wrapper
is just propagating the SANE error to you. I have a few suggestions:

- Use a try block, and see if you can recover:

try:
grabImage(webcam)
except _sane.Error, se:
print se
# but continue

See if all you get is errors, or if it's just a once-in-a-while thing.
Maybe you should sleep longer when you get an error, to give the system
a chance to do something else.

- Try to figure out if SANE is printing any logging message. Check the
kernel log (dmesg), the normal system log, read SANE man pages, etc.
- Read the sane-v4l man page. The one I found on the Internet says it
is Alpha software, which means it is highly experimental, but maybe it
has improved.
- Try a similar task using the native sane tools (sane-find-scanner,
scanimage, etc.). This may generate more useful error messages.
- Post a question to the SANE mailing lists:
http://www.sane-project.org/mailing-lists.html

Once you have a happy SANE setup, then it should be trivial modify the
Python code to do the same thing. Hope this is some help,
JW

Mar 2 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.