示例#1
0
    def _scan_file_image(self):
        """Load and process (scan for barcodes) an image from file
        """
        filepath = str(QtGui.QFileDialog.getOpenFileName(self, "Open file"))
        if filepath:
            cv_image = Image.from_file(filepath)
            gray_image = cv_image.to_grayscale()

            # Scan the image for barcodes
            plate_type = self._config.plate_type.value()
            barcode_size = self._config.barcode_size.value()
            SlotScanner.DEBUG = self._config.slot_images.value()
            SlotScanner.DEBUG_DIR = self._config.slot_image_directory.value()

            if plate_type == "None":
                scanner = OpenScanner(barcode_size)
            else:
                scanner = GeometryScanner(plate_type, barcode_size)

            scan_result = scanner.scan_next_frame(gray_image, is_single_image=True)
            plate = scan_result.plate()

            # If the scan was successful, store the results
            if plate is not None:
                self.recordTable.add_record(plate, cv_image)
            else:
                error = "There was a problem scanning the image:\n{}".format(scan_result.error())
                QtGui.QMessageBox.warning(self, "Scanning Error", error)
示例#2
0
    def _scan_file_image(self):
        """Load and process (scan for barcodes) an image from file
        """
        filepath = str(QtGui.QFileDialog.getOpenFileName(self, 'Open file'))
        if filepath:
            cv_image = Image.from_file(filepath)
            gray_image = cv_image.to_grayscale()

            # Scan the image for barcodes
            plate_type = self._config.plate_type.value()
            barcode_size = self._config.barcode_size.value()
            SlotScanner.DEBUG = self._config.slot_images.value()
            SlotScanner.DEBUG_DIR = self._config.slot_image_directory.value()

            if plate_type == "None":
                scanner = OpenScanner(barcode_size)
            else:
                scanner = GeometryScanner(plate_type, barcode_size)

            scan_result = scanner.scan_next_frame(gray_image, is_single_image=True)
            plate = scan_result.plate()

            # If the scan was successful, store the results
            if plate is not None:
                self.recordTable.add_record(plate, cv_image)
            else:
                error = "There was a problem scanning the image:\n{}".format(scan_result.error())
                QtGui.QMessageBox.warning(self, "Scanning Error", error)
def run_scans(img_file, expected_codes):
    filepath = os.path.join(TEST_IMG_DIR, img_file)
    cv_image = Image.from_file(filepath)
    gray_image = cv_image.to_grayscale()
    results = GeometryScanner("Unipuck",
                              [14]).scan_next_frame(gray_image,
                                                    is_single_image=True)
    plate = results.plate()
    store_scan(img_file, plate, cv_image)

    correctly_read_count = 0
    slots = [plate.slot(i) for i in range(16)]
    num_found = len([s for s in slots if s.state() == s.VALID])
    #barcodes_for_debug = [s.barcode_data() for s in slots]
    assert num_found == len(expected_codes)

    for expected_code in expected_codes:
        expected_code_text = expected_code[0]
        slot = expected_code[1]

        barcode_read = plate.slot(slot).barcode_data()
        #print(barcode_read, expected_code_text)
        if barcode_read == expected_code_text:
            correctly_read_count += 1

    assert correctly_read_count == len(expected_codes)
def run_scans(img_file, expected_codes):
    filepath = os.path.join(TEST_IMG_DIR, img_file)
    print(img_file)
    cv_image = Image.from_file(filepath)
    gray_image = cv_image.to_grayscale()
    results = GeometryScanner("Unipuck", [14]).scan_next_frame(gray_image, is_single_image=True)
    plate = results.plate()
    if plate != None:
        for expected_code in expected_codes:
            expected_code_text = expected_code[0] #text
            slot_number = expected_code[1] #number
            slot = plate.slot(slot_number)
            read_code_text = slot.barcode_data()
            #print(slot_number, read_code_text, expected_code_text)
            if slot.state() == slot.VALID:
                assert read_code_text == expected_code_text
示例#5
0
def run_tests():

    # Run all of the test cases
    total = 0
    correct = 0
    found = 0
    start = time.clock()
    for case in TEST_CASES:
        file = case[0]
        expected_codes = case[1]
        total += len(expected_codes)

        filename = TEST_IMG_DIR + file
        cv_image = Image.from_file(filename)
        gray_image = cv_image.to_grayscale()
        results = GeometryScanner("Unipuck",
                                  14).scan_next_frame(gray_image,
                                                      is_single_image=True)
        plate = results.plate()
        store_scan(plate, cv_image)

        pass_count = 0
        slots = [plate.slot(i) for i in range(16)]
        num_found = len([s for s in slots if s.state() == s.VALID])
        for expected_code in expected_codes:
            text = expected_code[0]
            slot = expected_code[1]

            data = plate.slot(slot).barcode_data()
            if data == text:
                pass_count += 1

        result = "pass" if pass_count == len(expected_codes) else "FAIL"
        print("{0} - {1}  -  {2}/{3} matches ({4} found)".format(
            file, result, pass_count, len(expected_codes), num_found))

        correct += pass_count
        found += num_found

    end = time.clock()
    print("Summary | {0} secs | {1} correct | {2} found | {3} total".format(
        end - start, correct, found, total))
示例#6
0
def run_tests():

    # Run all of the test cases
    total = 0
    correct = 0
    found = 0
    start = time.clock()
    for case in TEST_CASES:
        file = case[0]
        expected_codes = case[1]
        total += len(expected_codes)

        filename = TEST_IMG_DIR + file
        cv_image = Image.from_file(filename)
        gray_image = cv_image.to_grayscale()
        results = GeometryScanner("Unipuck", 14).scan_next_frame(gray_image, is_single_image=True)
        plate = results.plate()
        store_scan(plate, cv_image)

        pass_count = 0
        slots = [plate.slot(i) for i in range(16)]
        num_found = len([s for s in slots if s.state() == s.VALID])
        for expected_code in expected_codes:
            text = expected_code[0]
            slot = expected_code[1]

            data = plate.slot(slot).barcode_data()
            if data == text:
                pass_count += 1

        result = "pass" if pass_count == len(expected_codes) else "FAIL"
        print("{0} - {1}  -  {2}/{3} matches ({4} found)".format(file, result, pass_count, len(expected_codes), num_found))

        correct += pass_count
        found += num_found

    end = time.clock()
    print("Summary | {0} secs | {1} correct | {2} found | {3} total".format(end-start, correct,found,total))
 def get_holder_image(self):
     image = Image.from_file(self.holder_image_path)
     return image
 def get_image(self):
     image = Image.from_file(self.image_path)
     return image
示例#9
0
""" This file gives an illustrated demonstration of process involved in
locating a datamatrix in an image. This isn't to be used as a test as it
re-implements some parts of the locator algorithm

"""
import cv2

from dls_util.image import Image, Color
from dls_util.shape import Point
from dls_barcode.datamatrix.locate.locate_contour import ContourLocator as CL


# Load the image file
folder = "./demo-resources/"
file = folder + "dm.png"
image_original = Image.from_file(file)

# Convert to a grayscale image
image_mono = image_original.to_grayscale()

# Perform adaptive threshold
block_size = 35
C = 16
image_threshold = CL._do_threshold(image_mono, block_size, C)

# Perform morphological close
close_size = 2
image_morphed = CL._do_close_morph(image_threshold, close_size)

# Find a bunch of contours in the image.
contours = CL._get_contours(image_morphed)
示例#10
0
 def image(self):
     image = Image.from_file(self.image_path)
     return image