Esempio n. 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]))
Esempio n. 2
0
def main(argv):
  try:
    opts, args = getopt.getopt(argv, "i:d:o:")
  except getopt.GetoptError:
    usage()
    sys.exit(2)
  SKELETON = None
  FORMDATA = None
  OUTFILE = None
  for opt, arg in opts:
    if opt == "-h":
      usage()
      sys.exit()
    elif opt == "-i":
      SKELETON = arg
    elif opt == "-d":
      FORMDATA = arg
    elif opt == "-o":
      OUTFILE = arg
  if not (SKELETON or FORMDATA or OUTFILE):
    usage()
    sys.exit(2)
  # Read the JSON string for the form data from the file
  formdatafile = file(FORMDATA, "r")
  # Load the form data
  formdata = json.load(formdatafile)
  formdatafile.close()
  #
  # Create bubble objects from the form data
  formsets = Bubble.readform(FORMDATA)
  #
  # Load the skeletal form
  form_img = Image.open(SKELETON)
  #
  # Draw the bubbles
  for bs in formsets.sets:
    bs.draw(form_img)
  #
  # Draw the registration markers according to the data
  rmarks = rm.readform(FORMDATA)
  for mark in rmarks:
    mark.draw(form_img)
  #
  # Draw the barcode
  bc.drawbarcode(form_img, FORMDATA)
  #
  # Save the form
  form_img.save(OUTFILE, "TIFF")
Esempio n. 3
0
from PIL import Image
import formbot.bubble as Bubble
import formbot.regmark as rm
import json

rm.DEBUG = True

FORMDATA = "formdata02.json"
INFILE = "form02_filled04.jpg"

# Read form data
formsets = Bubble.readform(FORMDATA)
#
# Read registration mark data
rmarks = rm.readform(FORMDATA)
#
# Load the image of the filled-out form
form_img = Image.open(INFILE)


##########
# Preprocess the image
##########
(w,h) = form_img.size
if w > h:
  form_img = form_img.transpose(Image.ROTATE_270)
  (w,h) = form_img.size
if h*(17.0/22.0) < w:
  # Pad the height
  hnew = int(w*(22.0/17.0))
  wnew = w