Пример #1
0
    def decode(self, data):
        """Fill buffer with a raw binary data

        Each byte already must represent one pixel

        Parameters::

            data : image binary data
        """

        buffer = api.begin(self._obj, self._width, self._height)

        converters.raw(buffer, data)

        api.end(self._obj)

        for i in range(api.count(self._obj)):

            # Extract first code
            api.extract(self._obj, i, self._code)
            try:
                api.decode(self._code, self._data)
            except api.exceptions.DecodeException:
                continue

            yield Code(
                tuple([(corner.x, corner.y) for corner in self._code.corners]),
                self._code.size,
                self._data.version,
                self._data.ecc_level,
                self._data.data_type,
                ctypes.string_at(self._data.payload, self._data.payload_len),
            )
Пример #2
0
    def decode(self, data):
        """Fill buffer with a raw binary data

        Each byte already must represent one pixel

        Parameters::

            data : image binary data
        """

        buffer = api.begin(self._obj, self._width, self._height)

        converters.raw(buffer, data)

        api.end(self._obj)

        for i in range(api.count(self._obj)):

            # Extract first code
            api.extract(self._obj, i, self._code)
            try:
                api.decode(self._code, self._data)
            except api.exceptions.DecodeException:
                continue

            yield Code(
                tuple([(corner.x, corner.y) for corner in self._code.corners]),
                self._code.size,
                self._data.version,
                self._data.ecc_level,
                self._data.data_type,
                ctypes.string_at(self._data.payload, self._data.payload_len),
            )
Пример #3
0
def decode(image):
    """Recognize image and return generator with all the available QR codes

    Currently supports only PIL Image object as an parameter
    """

    # TODO: `image` type check

    # Convert to grayscale mode
    if image.mode not in ('1', 'L'):
        image = image.convert('L')

    width, height = image.size
    pixels = image.load()

    obj = api.new()
    api.resize(obj, width, height)
    buffer = api.begin(obj, width, height)

    # Fill buffer with a image pixels. One cell, one pixel.
    for idx, pixel in enumerate(converters.pil(image)):
        buffer[idx] = pixel

    # Finish codes identification
    api.end(obj)

    code = api.structures.Code()
    data = api.structures.Data()

    for i in range(api.count(obj)):

        # Extract first code
        api.extract(obj, i, code)
        api.decode(code, data)

        yield Code(
            tuple([(corner.x, corner.y) for corner in code.corners]),
            code.size,
            data.version,
            data.ecc_level,
            data.data_type,
            ctypes.string_at(data.payload, data.payload_len),
        )

    api.destroy(obj)
Пример #4
0
def decode(image):
    """Recognize image and return generator with all the available QR codes

    Currently supports only PIL Image object as an parameter
    """

    # TODO: `image` type check

    # Convert to grayscale mode
    if image.mode not in ('1', 'L'):
        image = image.convert('L')

    width, height = image.size
    pixels = image.load()

    obj = api.new()
    api.resize(obj, width, height)
    buffer = api.begin(obj, width, height)

    # Fill buffer with a image pixels. One cell, one pixel.
    for idx, pixel in enumerate(converters.pil(image)):
        buffer[idx] = pixel

    # Finish codes identification
    api.end(obj)

    code = api.structures.Code()
    data = api.structures.Data()

    for i in range(api.count(obj)):

        # Extract first code
        api.extract(obj, i, code)
        api.decode(code, data)

        yield Code(
            tuple([(corner.x, corner.y) for corner in code.corners]),
            code.size,
            data.version,
            data.ecc_level,
            data.data_type,
            ctypes.string_at(data.payload, data.payload_len),
        )

    api.destroy(obj)
Пример #5
0
    parser.add_option(
        "-r",
        "--recheck",
        action="store_true",
        dest="recheck",
        default=False,
        help="recheck all data stored in db and fix the missing ones.")
    parser.add_option("-d",
                      "--out-dir",
                      dest="outdir",
                      default="./downloads",
                      help="the downloads directory")
    (options, args) = parser.parse_args()

    print(options, options.update)

    if options.recheck:
        #TODO: cleanup database
        pass

    if options.update:
        api = api.Api()
        api.begin()

    outpath = options.outdir

    retriever.startVideoTask(outpath)

    retriever.startSlicesTaskV2(outpath)

    pass