Ejemplo n.º 1
0
    def get_page_rotation(self):
        # Returns page rotation or "None" if it cannot be retrieved

        # Figure out wether the page is rotated by looking for a barcode first
        # at the bottom right, then at the top left.
        # Note that we do not care about the value of the barcode, we are happy
        # to simply know that it exists.

        paper_width = self.obj.sheet.survey.defs.paper_width
        paper_height = self.obj.sheet.survey.defs.paper_height

        # Search for the barcode in the lower right corner.
        # Note that we cannot find another barcode this way, because the one in the
        # center of the page is not complete
        code = \
            read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                         paper_width / 2,
                         paper_height - defs.corner_mark_bottom - defs.code128_vpad - defs.code128_height - 5,
                         paper_width / 2,
                         defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

        if code is None:
            # Well, that failed, so try to search the upper left corner instead
            code = \
                read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                             0, 0,
                             paper_width / 2,
                             defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

            if code is not None:
                return True
            else:
                return None
        else:
            return False
Ejemplo n.º 2
0
    def get_page_rotation(self):
        # Returns page rotation or "None" if it cannot be retrieved

        # Figure out wether the page is rotated by looking for a barcode first
        # at the bottom right, then at the top left.
        # Note that we do not care about the value of the barcode, we are happy
        # to simply know that it exists.

        paper_width = self.obj.sheet.survey.defs.paper_width
        paper_height = self.obj.sheet.survey.defs.paper_height

        # Search for the barcode in the lower right corner.
        # Note that we cannot find another barcode this way, because the one in the
        # center of the page is not complete
        code = \
            read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                         paper_width / 2,
                         paper_height - defs.corner_mark_bottom - defs.code128_vpad - defs.code128_height - 5,
                         paper_width / 2,
                         defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

        if code is None:
            # Well, that failed, so try to search the upper left corner instead
            code = \
                read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                             0, 0,
                             paper_width / 2,
                             defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

            if code is not None:
                return True
            else:
                return None
        else:
            return False
Ejemplo n.º 3
0
 def find_bottom_center_barcode(self):
   return read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                  self.paper_width() * 0.375,
                  self.paper_height() * 0.75,
                  self.paper_width() * 0.25,
                  self.paper_height() * 0.25,
                  "QRCODE")
Ejemplo n.º 4
0
    def recognize(self):
        img = self.obj.sheet.get_page_image(self.obj.page_number)

        if img is None or img.recognize.matrix is None:
            self.obj.sheet.valid = 0
            return

        x = self.obj.x
        y = self.obj.y
        width = self.obj.width
        height = self.obj.height

        surface = img.surface.surface
        matrix = img.recognize.matrix

        res = read_barcode(surface, matrix,
                           x, y, width, height,
                           "QRCODE")

        # This is maybe a bit odd, but we accept empty string as a valid
        # content (if there was a barcode which was just the empty string).
        if res is not None:
            self.obj.data.state = True
            self.obj.data.text = res
        else:
            self.obj.data.state = False
            self.obj.data.text = None
Ejemplo n.º 5
0
    def recognize(self):
        img = self.obj.sheet.get_page_image(self.obj.page_number)

        if img is None or img.recognize.matrix is None:
            self.obj.sheet.valid = 0
            return

        x = self.obj.x
        y = self.obj.y
        width = self.obj.width
        height = self.obj.height

        surface = img.surface.surface
        matrix = img.recognize.matrix

        res = read_barcode(surface, matrix, x, y, width, height, "QRCODE")

        # This is maybe a bit odd, but we accept empty string as a valid
        # content (if there was a barcode which was just the empty string).
        if res is not None:
            self.obj.data.state = True
            self.obj.data.text = res
        else:
            self.obj.data.state = False
            self.obj.data.text = None
Ejemplo n.º 6
0
 def find_bottom_center_barcode(self):
   return read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                  self.paper_width() * 0.375,
                  self.paper_height() * 0.75,
                  self.paper_width() * 0.25,
                  self.paper_height() * 0.25,
                  "QRCODE")
Ejemplo n.º 7
0
    def get_global_id(self):
        # Returns the global ID or "None" if it cannot be retrieved

        # In this function assume that the rotation is correct already.
        paper_width = self.obj.sheet.survey.defs.paper_width
        paper_height = self.obj.sheet.survey.defs.paper_height

        # Search for the barcode in the bottom center of the page
        code = \
            read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                         paper_width / 4,
                         paper_height - defs.corner_mark_bottom - defs.code128_vpad - defs.code128_height - 5,
                         paper_width / 2,
                         defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

        # Simply return the code, it may be alphanumeric, we don't care here
        return code
Ejemplo n.º 8
0
    def get_global_id(self):
        # Returns the global ID or "None" if it cannot be retrieved

        # In this function assume that the rotation is correct already.
        paper_width = self.obj.sheet.survey.defs.paper_width
        paper_height = self.obj.sheet.survey.defs.paper_height

        # Search for the barcode in the bottom center of the page
        code = \
            read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                         paper_width / 4,
                         paper_height - defs.corner_mark_bottom - defs.code128_vpad - defs.code128_height - 5,
                         paper_width / 2,
                         defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5, "*")

        # Simply return the code, it may be alphanumeric, we don't care here
        return code
Ejemplo n.º 9
0
def get_questionnaire_id(image):
    # Returns the questionnaire ID or "None" if it cannot be retrieved

    # In this function assume that the rotation is correct already.
    paper_width = image.obj.sheet.survey.defs.paper_width
    paper_height = image.obj.sheet.survey.defs.paper_height

    # Search for the barcode on the bottom left of the page
    code = \
        read_barcode(image.obj.surface.surface, image.obj.matrix.mm_to_px(),
                     0,
                     paper_height - defs.corner_mark_bottom - defs.code128_vpad - defs.code128_height - 5,
                     paper_width / 2,
                     defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

    # Simply return the code, it may be alphanumeric, we don't care here
    # XXX: Is that assumption sane?
    return code
Ejemplo n.º 10
0
    def get_questionnaire_id(self):
        # Returns the questionnaire ID or "None" if it cannot be retrieved

        # In this function assume that the rotation is correct already.
        paper_width = self.obj.sheet.survey.defs.paper_width
        paper_height = self.obj.sheet.survey.defs.paper_height

        # Search for the barcode on the bottom left of the page
        code = \
            read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                         0,
                         paper_height - defs.corner_mark_bottom - defs.code128_vpad - defs.code128_height - 5,
                         paper_width / 2,
                         defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

        # Simply return the code, it may be alphanumeric, we don't care here
        # XXX: Is that assumption sane?
        return code
Ejemplo n.º 11
0
    def get_survey_id(self):
        # Returns the survey ID or "None" if it cannot be retrieved

        # In this function assume that the rotation is correct already.
        paper_width = self.obj.sheet.survey.defs.paper_width
        paper_height = self.obj.sheet.survey.defs.paper_height

        # Search for the barcode in the lower left corner.
        code = \
            read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                         paper_width / 2,
                         paper_height - defs.corner_mark_bottom - defs.code128_vpad - defs.code128_height - 5,
                         paper_width / 2,
                         defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

        if code is None or not code.isdigit() or len(code) <= 4:
            return None

        return int(code[:-4])
Ejemplo n.º 12
0
    def get_survey_id(self):
        # Returns the survey ID or "None" if it cannot be retrieved

        # In this function assume that the rotation is correct already.
        paper_width = self.obj.sheet.survey.defs.paper_width
        paper_height = self.obj.sheet.survey.defs.paper_height

        # Search for the barcode in the lower left corner.
        code = \
            read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                         paper_width / 2,
                         paper_height - defs.corner_mark_bottom - defs.code128_vpad - defs.code128_height - 5,
                         paper_width / 2,
                         defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

        if code is None or not code.isdigit() or len(code) <= 4:
            return None

        return int(code[:-4])
Ejemplo n.º 13
0
    def get_barcode_id(self):
        # Returns the questionnaire ID or "None" if it cannot be retrieved

        # In this function assume that the rotation is correct already.
        paper_width = self.obj.sheet.survey.defs.paper_width
        paper_height = self.obj.sheet.survey.defs.paper_height
        print('GET BARCODE ID PROCESS')
        # Search for the barcode on the top right of the page
        code = \
            read_barcode(self.obj.surface.surface, self.obj.recognize.matrix,
                        12,
                        22,
                        187,
                        70, "*")

        # Simply return the code, it may be alphanumeric, we don't care here
        # XXX: Is that assumption sane?
        print ('GET BARCODE ID DONE : '+str(code))
        return code
Ejemplo n.º 14
0
    def get_page_number(self):
        # Returns page number or "None" if it cannot be retrieved

        # In this function assume that the rotation is correct already.
        paper_width = self.obj.sheet.survey.defs.paper_width
        paper_height = self.obj.sheet.survey.defs.paper_height

        # Search for the barcode in the lower right corner.
        code = \
            read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                         paper_width / 2,
                         paper_height - defs.corner_mark_bottom - defs.code128_vpad - defs.code128_height - 5,
                         paper_width / 2,
                         defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

        # The code needs to be entirely numeric and at least 4 characters for the page
        if code is None or(not code.isdigit() and len(code) < 4):
            return None

        # The page number is in the lower four digits, simply extract it and convert
        # to integer
        return int(code[-4:])
Ejemplo n.º 15
0
    def get_page_number(self):
        # Returns page number or "None" if it cannot be retrieved

        # In this function assume that the rotation is correct already.
        paper_width = self.obj.sheet.survey.defs.paper_width
        paper_height = self.obj.sheet.survey.defs.paper_height

        # Search for the barcode in the lower right corner.
        code = \
            read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                         paper_width / 2,
                         paper_height - defs.corner_mark_bottom - defs.code128_vpad - defs.code128_height - 5,
                         paper_width / 2,
                         defs.corner_mark_bottom + defs.code128_vpad + defs.code128_height + 5)

        # The code needs to be entirely numeric and at least 4 characters for the page
        if code is None or(not code.isdigit() and len(code) < 4):
            return None

        # The page number is in the lower four digits, simply extract it and convert
        # to integer
        return int(code[-4:])
Ejemplo n.º 16
0
 def find_top_left_barcode(self):
   return read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                  0, 0,
                  self.paper_width() * 0.25,
                  self.paper_height() * 0.25,
                  "QRCODE")
Ejemplo n.º 17
0
 def find_top_left_barcode(self):
   return read_barcode(self.obj.surface.surface, self.obj.matrix.mm_to_px(),
                  0, 0,
                  self.paper_width() * 0.25,
                  self.paper_height() * 0.25,
                  "QRCODE")