looking for help about python-sane

D

derek

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
 
J

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top