Example #1
0
def main(argv):
  try:
    opts, args = getopt.getopt(argv, "i:d:")
  except getopt.GetoptError:
    usage()
    sys.exit(2)
  INFILE = None
  FORMDATA = None
  for opt, arg in opts:
    if opt == "-h":
      usage()
      sys.exit()
    elif opt == "-i":
      INFILE = arg
    elif opt == "-d":
      FORMDATA = arg
  if not (INFILE or FORMDATA):
    usage()
    sys.exit(2)
  #
  # TODO: First we should read the registration mark data, which will apply to the whole set of forms
  # for a particular survey project. Second, we fix the scanned image. Third, we read the barcode,
  # so we can look up the bubble set information. Last, we check which bubbles have been filled in.
  #
  # Read registration mark data
  rmarks = rm.readform(FORMDATA)
  #
  # Load the image of the filled-out form
  form_img = Image.open(INFILE)
  #
  # Adjust image to fit the prototype
  # TODO: After we try fixing the image once, the registration markers are easier to find.
  # So if we try fixing again, we get closer. This is a little hacky, though. We should make
  # that part of the registration procedure.
  form_img_fixed = rm.fiximage(form_img, rmarks[0], rmarks[1], rmarks[2])
  form_img_fixed = rm.fiximage(form_img_fixed, rmarks[0], rmarks[1], rmarks[2])
  #
  # Read the barcode
  barcodedata = bc.readbarcode(form_img_fixed)
  print("bar code data: %s" % barcodedata)
  #
  # Read form data
  formsets = Bubble.readform(FORMDATA)
  #
  # Check responses to each bubble set
  responses = []
  for bs in formsets.sets:
    responses.append(bs.get_single_answer(form_img_fixed))
  #
  print("Form ID: %s" % formsets.form_id)
  for i in range(len(responses)):
    print("Response #%s: %s" % (i, responses[i]))
Example #2
0
  # Read the barcode
  print 'Reading barcode'
  # Crop out an area around the barcode, to make life easier on the decoder.
  bc_bbox = paperinfo['barcode']['bbox']
  dpi = paperinfo['dpi']
  paper_size = (int(8.5*dpi), int(11.0*dpi))
  crop_buffer = 50
  crop_bbox = (max(bc_bbox[0] - crop_buffer, 0),
               max(bc_bbox[1] - crop_buffer, 0),
               min(bc_bbox[2] + crop_buffer, paper_size[0]),
               min(bc_bbox[3] + crop_buffer, paper_size[1]))
  # We don't need to crop when using the local tool. It will find the barcode
  # effectively.
  #form_id = bc.readbarcode(form_img_fixed.crop(crop_bbox))
  form_id = bc.readbarcode(form_img_fixed)

  # Grab the form data
  formdata_url = '%s/surveys/%s/forms/%s' % (API_BASE, survey_id, form_id)
  print 'Getting form data from %s' % formdata_url
  try:
    data = api_get(formdata_url)
  except APIError, e:
    return 2
  form_data = data['form']
  #
  print 'Processing answers'

  source = {'type' : 'paper',
            'scan' : img_id,
            'form': form_id}
Example #3
0
import json
import subprocess
import glob
import os

rm.DEBUG = True

FORMDATA = "formdata02.json"
INFILE = "form02.tif"
#QRFILE = "qrcodetest01.png"

form = Image.open(INFILE)
#tmp = Image.open(QRFILE)
#form.paste(tmp, (975,50))
barcode.drawbarcode(form, FORMDATA)
data = barcode.readbarcode(form)

print "Decoded data: %s" % data

# #decode = 'java', '-classpath', ':'.join(glob.glob(os.path.dirname(__file__) + '/lib/*.jar')), 'qrdecode'
# decode = 'java', '-classpath', ':'.join(glob.glob('lib/*.jar')), 'qrdecode'
# decode = subprocess.Popen(decode, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
# 
# form.save(decode.stdin, 'PNG')
# decode.stdin.close()
# decode.wait()
# 
# decoded = decode.stdout.read().strip()
# print decoded