how to write this properly -- gives an windows error

This is the place for queries that don't fit in any of the other categories.

how to write this properly -- gives an windows error

Postby pynub » Sun Sep 15, 2013 9:14 pm

hi all

I have this problem often, I'm just trying to get my head around how python does these variables:

I have this code:

Code: Select all
# obtain image data
pil = Image.open(argv[1]).convert('L')
width, height = pil.size
raw = pil.tostring()


(from the zbar api page - http://sourceforge.net/apps/mediawiki/z ... ng_the_API )

I wanted to supply a smaller area of the image, so I wanted to crop the image area. I found this
Code: Select all

# obtain image data
pil = Image.open(argv[1]).convert('L')
width, height = pil.size
cropped = pil.crop((0,250,width,height-1000))
raw = cropped.tostring()




This should crop a 250 pixel high by the image width, starting 1000 pixels down. (the image is 1608x2250 pixels)

Doesn't work though. Have what I done make sense ?
pynub
 
Posts: 6
Joined: Sun Sep 15, 2013 9:04 pm

Re: how to write this properly -- gives an windows error

Postby stranac » Mon Sep 16, 2013 3:01 pm

When posting code examples, it would be nice if we could run the code without modification.
Also, if there are dependencies(like the image), attach those too.

And finally, what does "Doesn't work" mean?
Post the full traceback you're getting.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1093
Joined: Thu Feb 07, 2013 3:42 pm

Re: how to write this properly -- gives an windows error

Postby pynub » Tue Sep 17, 2013 11:18 am

I'm using the zbar lib to try and read barcodes -- unless anyone has a better way to read a code39 barcode or a patch code as in the data files below.

I have hosted the files here / here

run the script with 'barcode.py 0069.tif'

I can read the page with the first code barcode.py

When I made the edits above to make it try to read only a smaller section of the image using the crop command it does not work. By does not work I mean I get a windows error box 'python has stopped working' with this text
Code: Select all
Problem signature:
  Problem Event Name:   APPCRASH
  Application Name:   python.exe
  Application Version:   0.0.0.0
  Application Timestamp:   5193f37d
  Fault Module Name:   libzbar-0.dll
  Fault Module Version:   0.2.0.0
  Fault Module Timestamp:   4ae71251
  Exception Code:   c0000005
  Exception Offset:   0000971c
  OS Version:   6.1.7601.2.1.0.256.48
  Locale ID:   2057
  Additional Information 1:   0a9e
  Additional Information 2:   0a9e372d3b4ad19135b953a78882e789
  Additional Information 3:   0a9e
  Additional Information 4:   0a9e372d3b4ad19135b953a78882e789

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt
pynub
 
Posts: 6
Joined: Sun Sep 15, 2013 9:04 pm

Re: how to write this properly -- gives an windows error

Postby pynub » Wed Sep 18, 2013 10:12 am

So I got this working, and this speeds up the process nicely as it no longer has to scan the entire image for a barcode.

I need to only check if the page size is within limits, and also validate for only PATCHT as a returned barcode.

Code: Select all
#!/usr/bin/python
from sys import argv
import zbar
import Image

if len(argv) < 2: exit(1)

# create a reader
scanner = zbar.ImageScanner()

# configure the reader
scanner.parse_config('enable')

# obtain image data
pil = Image.open(argv[1]).convert('L')
width, height = pil.size
print pil.size
cropped = pil.crop((446,1000,1246,1400))
width, height = cropped.size
print cropped.size
raw = cropped.tostring()


# wrap image data
image = zbar.Image(width, height, 'Y800', raw)

# scan the image for barcodes
scanner.scan(image)

# extract results
for symbol in image:
    # do something useful with results
    print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data

# clean up
del(image)
pynub
 
Posts: 6
Joined: Sun Sep 15, 2013 9:04 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 1 guest