Exemplo n.º 1
0
def thresh(event, window):
    if event == '-CAM-THRESH--':
        handle_config.setValue('THRESH SETTINGS', 'CAM_THRESH',
                               handle_config.CAM_THRESH - 5)

    if event == '-CAM-THRESH+-':
        handle_config.setValue('THRESH SETTINGS', 'CAM_THRESH',
                               handle_config.CAM_THRESH + 5)

    window.find_element('-CAM-THRESH-').update(str(handle_config.CAM_THRESH))
Exemplo n.º 2
0
def board(event, window):
    if event == '-WIDTH-70-':  # 70
        handle_config.setValue('BOARD SETTINGS', 'BOARD_WIDTH', -52)
        window.find_element('-WIDTH-70-').Update(button_color=('black',
                                                               'yellow'))

        window.find_element('-WIDTH-96-').Update(
            button_color=sg.theme_button_color())
        window.find_element('-WIDTH-120-').Update(
            button_color=sg.theme_button_color())

    if event == '-WIDTH-96-':
        handle_config.setValue('BOARD SETTINGS', 'BOARD_WIDTH', 0)
        window.find_element('-WIDTH-96-').Update(button_color=('black',
                                                               'yellow'))

        window.find_element('-WIDTH-70-').Update(
            button_color=sg.theme_button_color())
        window.find_element('-WIDTH-120-').Update(
            button_color=sg.theme_button_color())

    if event == '-WIDTH-120-':
        handle_config.setValue('BOARD SETTINGS', 'BOARD_WIDTH', 47)
        window.find_element('-WIDTH-120-').Update(button_color=('black',
                                                                'yellow'))

        window.find_element('-WIDTH-70-').Update(
            button_color=sg.theme_button_color())
        window.find_element('-WIDTH-96-').Update(
            button_color=sg.theme_button_color())

    if event == '-LENGTH--':
        newLength = handle_config.BOARD_LENGTH - 10
        admin_settings.set_board_length(newLength)
        window.find_element('-BOARD-LENGTH-').update(str(newLength))

    if event == '-LENGTH+-':
        newLength = handle_config.BOARD_LENGTH + 10
        admin_settings.set_board_length(newLength)
        window.find_element('-BOARD-LENGTH-').update(str(newLength))
Exemplo n.º 3
0
def calibrate(camera):
    frame = camera.read()
    _, _, \
    side1White, side1A, side1B, side1C, \
    side2White, side2A, side2B, side2C \
        = image_handling.main(frame, True)

    # Update variables
    handle_config.setValue('REJECT SETTINGS', 'SIDE1_PERC', side1White)
    handle_config.setValue('REJECT SETTINGS', 'SIDE1A_PERC', side1A)
    handle_config.setValue('REJECT SETTINGS', 'SIDE1B_PERC', side1B)
    handle_config.setValue('REJECT SETTINGS', 'SIDE1C_PERC', side1C)
    handle_config.setValue('REJECT SETTINGS', 'SIDE2_PERC', side2White)
    handle_config.setValue('REJECT SETTINGS', 'SIDE2A_PERC', side2A)
    handle_config.setValue('REJECT SETTINGS', 'SIDE2B_PERC', side2B)
    handle_config.setValue('REJECT SETTINGS', 'SIDE2C_PERC', side2C)
Exemplo n.º 4
0
    def run(self):
        global THRESHOLD_IMG  # Thresholded image
        global RECTS_ARR  # contains current bounding rectangles
        global PASS_COUNTS, FAIL_COUNTS  # total counts
        global AVG_WIDTHS_TOTAL, AVG_HEIGHTS_TOTAL  # average width/height

        logo_x_offset = 560
        logo_y_offset = 50
        mcs_logo = cv2.imread(handle_config.LOGO_LOCATION)
        mcs_logo = cv2.resize(mcs_logo, (0, 0), fx=1.25, fy=1.25)

        stats_font_size = 1
        if handle_config.LANE_COUNT == 4:
            stats_font_size = 0.8

        while not program_state.STOP_PROGRAM:

            _, FRAME = CAPTURE.read()  # Take each FRAME

            CROPPED = FRAME[
                handle_config.FRAME_HEIGHT_START:handle_config.
                FRAME_HEIGHT_END,
                handle_config.FRAME_WIDTH_START:handle_config.FRAME_WIDTH_END]
            GRAY = cv2.cvtColor(CROPPED,
                                cv2.COLOR_BGR2GRAY)  # Turn image to Grayscale
            _, THRESHOLD_IMG = cv2.threshold(GRAY, handle_config.WHITE_THRESH,
                                             255,
                                             0)  # Run threshold on gray image
            DISPLAY_IMG = CROPPED

            if program_state.THRESH_MODE:
                DISPLAY_IMG = THRESHOLD_IMG

            for lane in range(handle_config.LANE_COUNT):
                if len(RECTS_ARR[lane]) > 0 and len(BOX_ARR[lane]) > 0:
                    color = handle_config.RED
                    current_rect = RECTS_ARR[lane]
                    current_box = BOX_ARR[lane]

                    if current_rect[1][0] > current_rect[1][1]:
                        w = current_rect[1][0]
                        h = current_rect[1][1]
                    else:
                        w = current_rect[1][1]
                        h = current_rect[1][0]

                    calc_dimensions = variables.dimension_calc(lane, w, h)

                    if variables.is_pass(lane, w, h):
                        color = handle_config.GREEN

                    start_pos = min([position[0] for position in current_box])
                    high_pos = min([position[1] for position in current_box])
                    highest_pos = max(
                        [position[1] for position in current_box])
                    low_pos = max([position[1]
                                   for position in current_box]) + 15

                    exiting_box = handle_config.LANE_HEIGHT_START + \
                        handle_config.LANE_HEIGHT - \
                        handle_config.EDGE_GAP

                    if highest_pos > exiting_box:
                        cv2.drawContours(CROPPED, [current_box], 0,
                                         handle_config.ORANGE, 2)
                    else:
                        cv2.drawContours(CROPPED, [current_box], 0, color, 2)
                        cv2.putText(CROPPED, calc_dimensions,
                                    (start_pos, high_pos), handle_config.FONT,
                                    stats_font_size, color, 2)

                    if program_state.CALIBRATE_MODE:
                        pixel_dimensions = '{0}px x {1}px'.format(
                            int(w), int(h))
                        cv2.putText(CROPPED, pixel_dimensions,
                                    (start_pos, low_pos), handle_config.FONT,
                                    stats_font_size, handle_config.RED, 2)

            if program_state.REQUEST_CALIBRATE:
                for lane in range(
                        handle_config.LANE_COUNT):  # loop through lanes
                    if RECTS_ARR[lane]:  # if lane has contour
                        current_rect = RECTS_ARR[lane]
                        if current_rect[1][0] > current_rect[1][1]:
                            w = current_rect[1][0]
                            h = current_rect[1][1]
                        else:
                            w = current_rect[1][1]
                            h = current_rect[1][0]

                        handle_config.PIXEL_WIDTHS[lane] = w
                        handle_config.PIXEL_HEIGHTS[lane] = h

                # Adjust ratios to match calibration
                for index, width in enumerate(handle_config.PIXEL_WIDTHS):
                    handle_config.WIDTH_RATIOS[
                        index] = handle_config.ACTUAL_WIDTH / width
                for index, height in enumerate(handle_config.PIXEL_HEIGHTS):
                    handle_config.HEIGHT_RATIOS[
                        index] = handle_config.ACTUAL_HEIGHT / height

                # Update low highs for calibration
                for index, ratio in enumerate(handle_config.WIDTH_RATIOS):
                    handle_config.LANE_FAIL_WIDTHS_LOW[
                        index] = handle_config.FAIL_WIDTH_LOW / ratio
                for index, ratio in enumerate(handle_config.WIDTH_RATIOS):
                    handle_config.LANE_FAIL_WIDTHS_HIGH[
                        index] = handle_config.FAIL_WIDTH_HIGH / ratio
                for index, ratio in enumerate(handle_config.HEIGHT_RATIOS):
                    handle_config.LANE_FAIL_HEIGHTS_LOW[
                        index] = handle_config.FAIL_HEIGHT_LOW / ratio
                for index, ratio in enumerate(handle_config.HEIGHT_RATIOS):
                    handle_config.LANE_FAIL_HEIGHTS_HIGH[
                        index] = handle_config.FAIL_HEIGHT_HIGH / ratio

                handle_config.setValue('CALIBRATION', 'PIXEL_WIDTHS',
                                       handle_config.PIXEL_WIDTHS)
                handle_config.setValue('CALIBRATION', 'PIXEL_HEIGHTS',
                                       handle_config.PIXEL_HEIGHTS)

                program_state.request_calibration(False)

            # Not Thresh Mode
            not_thresh_statement = (lane
                                    for lane in range(handle_config.LANE_COUNT)
                                    if not program_state.THRESH_MODE
                                    and not program_state.CALIBRATE_MODE)
            for lane in not_thresh_statement:
                AVG_TEXT = '% PASSED: 0'
                AVG_WIDTHS_TEXT = 'AVG LENGTH: ' + str(
                    int(AVG_WIDTHS_TOTAL[lane][0] *
                        handle_config.WIDTH_RATIOS[lane])) + 'mm'
                AVG_HEIGHTS_TEXT = 'AVG THICKNESS: ' + str(
                    int(AVG_HEIGHTS_TOTAL[lane][0] *
                        handle_config.HEIGHT_RATIOS[lane])) + 'mm'
                if PASS_COUNTS[lane] > 0:
                    AVG_TEXT = '% PASSED: ' + str(
                        100 * PASS_COUNTS[lane] /
                        (PASS_COUNTS[lane] + FAIL_COUNTS[lane]))
                cv2.putText(CROPPED, 'LANE ' + str(lane + 1),
                            (handle_config.LANE_WIDTH_START[lane],
                             handle_config.TEXT_Y), handle_config.FONT,
                            stats_font_size, handle_config.RED, 2)
                cv2.putText(CROPPED, 'PASS: '******'FAIL: ' + str(FAIL_COUNTS[lane]),
                            (handle_config.LANE_WIDTH_START[lane],
                             handle_config.TEXT_Y + 60), handle_config.FONT,
                            stats_font_size, handle_config.RED, 2)
                cv2.putText(CROPPED, AVG_TEXT,
                            (handle_config.LANE_WIDTH_START[lane],
                             handle_config.TEXT_Y + 90), handle_config.FONT,
                            stats_font_size, handle_config.RED, 2)
                if AVG_WIDTHS_TOTAL[lane][0] > 0:
                    cv2.putText(CROPPED, AVG_WIDTHS_TEXT,
                                (handle_config.LANE_WIDTH_START[lane],
                                 handle_config.TEXT_Y + 120),
                                handle_config.FONT, stats_font_size,
                                handle_config.RED, 2)
                if AVG_HEIGHTS_TOTAL[lane][0] > 0:
                    cv2.putText(CROPPED, AVG_HEIGHTS_TEXT,
                                (handle_config.LANE_WIDTH_START[lane],
                                 handle_config.TEXT_Y + 150),
                                handle_config.FONT, stats_font_size,
                                handle_config.RED, 2)

            all_lanes_pass = sum(PASS_COUNTS)
            all_lanes_fail = sum(FAIL_COUNTS)
            if all_lanes_pass + all_lanes_fail > 0:
                fail_perc = 100.0 * all_lanes_fail / (all_lanes_pass +
                                                      all_lanes_fail)
                running_total_txt = 'RUNNING TOTAL:- '
                running_total_txt += 'PASSED = ' + str(all_lanes_pass)
                running_total_txt += ' FAILED = ' + str(all_lanes_fail)
                running_total_txt += '    % FAILED = {:.1f}%'.format(fail_perc)

                # get boundary of this text
                textsize = cv2.getTextSize(running_total_txt,
                                           handle_config.FONT, 1, 2)[0]
                # get coords based on boundary
                textX = (CROPPED.shape[1] - textsize[0]) / 2

                textPos = 825
                if handle_config.LANE_COUNT == 3:
                    textPos = 880

                cv2.putText(CROPPED, running_total_txt, (textX, textPos),
                            handle_config.FONT, 1, handle_config.RED, 2)
                cv2.line(CROPPED, (0, textPos - 35), (2000, textPos - 35),
                         handle_config.RED, 2)
                cv2.line(CROPPED, (0, textPos + 15), (2000, textPos + 15),
                         handle_config.RED, 2)

            # Show Lane Boundaries
            cv2.rectangle(CROPPED,
                          (handle_config.LANE_X1, handle_config.LANE_Y1),
                          (handle_config.LANE_X2, handle_config.LANE_Y2),
                          handle_config.YELLOW, 2)
            cv2.rectangle(CROPPED,
                          (handle_config.SPLIT_X1, handle_config.LANE_Y1),
                          (handle_config.SPLIT_X2, handle_config.LANE_Y2),
                          handle_config.YELLOW, 2)
            if handle_config.LANE_COUNT == 4:
                cv2.rectangle(CROPPED,
                              (handle_config.SPLIT_X3, handle_config.LANE_Y1),
                              (handle_config.SPLIT_X4, handle_config.LANE_Y2),
                              handle_config.YELLOW, 2)

            # Lane Traffic Calculations
            red_fail = '111111'
            yellow_fail = '111'

            for lane in range(handle_config.LANE_COUNT):  # loop through lanes
                traffic_colour = handle_config.GREEN
                history = ''.join(str(e) for e in HISTORICAL_FAILS[lane])

                if red_fail in history:
                    traffic_colour = handle_config.RED
                elif yellow_fail in history:
                    traffic_colour = handle_config.YELLOW

                cv2.rectangle(
                    CROPPED,
                    (handle_config.TRAFFIC_X1[lane], handle_config.TRAFFIC_Y1),
                    (handle_config.TRAFFIC_X2[lane], handle_config.TRAFFIC_Y2),
                    traffic_colour, -1)

            # Show MCS Logo
            CROPPED[logo_y_offset:logo_y_offset + mcs_logo.shape[0],
                    logo_x_offset:logo_x_offset + mcs_logo.shape[1]] = mcs_logo

            outputTxt = 'OUTPUT: ' + str(OUTPUT)
            # get boundary of this text
            textsize = cv2.getTextSize(outputTxt, handle_config.FONT, 1, 2)[0]
            # get coords based on boundary
            textX = (CROPPED.shape[1] - textsize[0]) / 2
            # Show current AIO
            cv2.putText(CROPPED, outputTxt, (textX, 435), handle_config.FONT,
                        1, handle_config.RED, 2)

            # Show min/max values
            max_length = 'MAX LENGTH = ' + str(
                int(handle_config.FAIL_WIDTH_HIGH)) + 'mm   '
            min_length = 'MIN LENGTH = ' + str(
                int(handle_config.FAIL_WIDTH_LOW)) + 'mm    '
            max_thickness = 'MAX THICKNESS = ' + str(
                int(handle_config.FAIL_HEIGHT_HIGH)) + 'mm'
            min_thickness = 'MIN THICKNESS = ' + str(
                int(handle_config.FAIL_HEIGHT_LOW)) + 'mm'
            cv2.putText(CROPPED, 'CURRENT REJECT SETTINGS', (240, 950),
                        handle_config.FONT, 1, handle_config.RED, 2)
            cv2.line(CROPPED, (50, 965), (875, 965), handle_config.RED, 2)
            cv2.putText(CROPPED, max_length + max_thickness, (50, 1000),
                        handle_config.FONT, 1, handle_config.RED, 2)
            cv2.putText(CROPPED, min_length + min_thickness, (50, 1050),
                        handle_config.FONT, 1, handle_config.RED, 2)

            window_name = 'LINE VIEW'
            if DISPLAY_IMG != []:
                cv2.namedWindow(window_name, cv2.WND_PROP_FULLSCREEN)
                cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN,
                                      cv2.WINDOW_FULLSCREEN)
                cv2.imshow(window_name, DISPLAY_IMG)

            # Required for loop no need for key read
            k = cv2.waitKey(1) & 0xFF
Exemplo n.º 5
0
def main(window):

    while not program_state.STOP_PROGRAM:
        event, values = window.read()

        # When window is closed
        if event in (sg.WIN_CLOSED, 'Exit'):
            program_state.stop_program()
            break

        if event == '-GRAB-':
            frame = worker_thread.camera.read()
            text_input = values['-FILENAME-IN-']
            cv2.imwrite('images/stored/' + text_input + '.png', frame)

        # admin events
        if event in ('-SETUP-', '-CANCEL-', '-SHUT-DOWN-', '-LIVE-MODE-',
                     '-BARK-MODE-', '-POSITION-MODE-'):
            handle_events.admin(event, window)

        # board position events
        if event in ('-SIDE1-LEFT-', '-SIDE1-RIGHT-', '-SIDE1-UP-',
                     '-SIDE1-DOWN-', '-SIDE2-LEFT-', '-SIDE2-RIGHT-',
                     '-SIDE2-UP-', '-SIDE2-DOWN-'):
            handle_events.position(event)

        # board events
        if event in ('-WIDTH-70-', '-WIDTH-96-', '-WIDTH-120-', '-LENGTH--',
                     '-LENGTH+-'):
            handle_events.board(event, window)

        # thresh events
        if event in ('-CAM-THRESH--', '-CAM-THRESH+-'):
            handle_events.thresh(event, window)

        # When the reset button is pressed
        if event == '-RESET-':
            program_state.clear_results()

            window.find_element('-TOTAL-PASSED-').update(str(0))
            window.find_element('-TOTAL-INSPECTED-').update(str(0))

        # When the start button is pressed
        if event == '-START-':
            window.find_element('-START-').Update(button_color=('black',
                                                                'yellow'))
            program_state.set_run_mode(True)

        # When the start button is pressed
        if event == '-STOP-':
            window.find_element('-START-').Update(
                button_color=sg.theme_button_color())
            program_state.set_run_mode(False)

        # When the increase edge variance value is pressed
        if event == '-EDGE+-':
            handle_config.setValue('REJECT SETTINGS', 'EDGE_VARIANCE',
                                   handle_config.EDGE_VARIANCE + 1)
            edgeStr = str(handle_config.EDGE_VARIANCE) + '%'
            window.find_element('-EDGE-VARIANCE-LEVEL-').update(edgeStr)

        # When the decrease edge variance value is pressed
        if event == '-EDGE--':
            handle_config.setValue('REJECT SETTINGS', 'EDGE_VARIANCE',
                                   handle_config.EDGE_VARIANCE - 1)
            edgeStr = str(handle_config.EDGE_VARIANCE) + '%'
            window.find_element('-EDGE-VARIANCE-LEVEL-').update(edgeStr)

        # When the increase mid size value is pressed
        if event == '-MID-SIZE+-':
            handle_config.setValue('REJECT SETTINGS', 'MID_SIZE',
                                   handle_config.MID_SIZE + 1)
            midSizeStr = str(handle_config.MID_SIZE) + '%'
            window.find_element('-MID-SIZE-').update(midSizeStr)

        # When the decrease mid size value is pressed
        if event == '-MID-SIZE--':
            handle_config.setValue('REJECT SETTINGS', 'MID_SIZE',
                                   handle_config.MID_SIZE - 1)
            midSizeStr = str(handle_config.MID_SIZE) + '%'
            window.find_element('-MID-SIZE-').update(midSizeStr)

        # When the increase reject value is pressed
        if event == '-REJECT+-':
            handle_config.setValue('REJECT SETTINGS', 'REJECT_LEVEL',
                                   handle_config.REJECT_LEVEL + 1)
            rejectStr = str(handle_config.REJECT_LEVEL) + '%'
            window.find_element('-REJECT-LEVEL-').update(rejectStr)

        # When the decrease reject value is pressed
        if event == '-REJECT--':
            handle_config.setValue('REJECT SETTINGS', 'REJECT_LEVEL',
                                   handle_config.REJECT_LEVEL - 1)
            rejectStr = str(handle_config.REJECT_LEVEL) + '%'
            window.find_element('-REJECT-LEVEL-').update(rejectStr)

        # When fault is flagged
        if event == '-FAULT-':
            sg.Popup(  # show popup
                'Fault',
                'Clamps not closed correctly',
                background_color='red',
                font=("Helvetica", 25),
                no_titlebar=True,
                keep_on_top=True)
            program_state.set_run_mode(False)  # stop running
            program_state.set_fault(False)  # stop fault

        # When calibrate button is pressed
        if event == '-CALIBRATE-':
            board_logic.calibrate(worker_thread.camera)

    # if user exits the window, then close the window and exit the GUI func
    window.close()
Exemplo n.º 6
0
    def run(self):
        global THRESHOLD_IMG  # Thresholded image
        global RECTS_ARR  # contains current bounding rectangles
        global PASS_COUNTS, FAIL_COUNTS  # total counts
        global AVG_WIDTHS_TOTAL, AVG_HEIGHTS_TOTAL  # average width/height
        global fpsUI  # fps counter
        fpsUI = FPS().start()
        update_display = False

        while not program_state.STOP_PROGRAM:
            fpsUI.update()
            CROPPED = CAPTURE.read(
            )  # [handle_config.FRAME_HEIGHT_START:handle_config.FRAME_HEIGHT_END, handle_config.FRAME_WIDTH_START:handle_config.FRAME_WIDTH_END]
            GRAY = cv2.cvtColor(CROPPED,
                                cv2.COLOR_BGR2GRAY)  # Turn image to Grayscale
            _, THRESHOLD_IMG = cv2.threshold(GRAY, handle_config.WHITE_THRESH,
                                             255,
                                             0)  # Run threshold on gray image
            DISPLAY_IMG = CROPPED

            if program_state.THRESH_MODE:
                DISPLAY_IMG = THRESHOLD_IMG
            else:
                for lane in range(1, 2):  # handle_config.LANE_COUNT):
                    update_display = False
                    if len(RECTS_ARR[lane]) > 0 and len(BOX_ARR[lane]) > 0:
                        color = handle_config.RED
                        current_rect = RECTS_ARR[lane]
                        current_box = BOX_ARR[lane]

                        if current_rect[1][0] > current_rect[1][1]:
                            w = current_rect[1][0]
                            h = current_rect[1][1]
                        else:
                            w = current_rect[1][1]
                            h = current_rect[1][0]

                        calc_dimensions = variables.dimension_calc(lane, w, h)

                        if variables.is_pass(lane, w, h):
                            color = handle_config.GREEN

                        start_pos = min(
                            [position[0] for position in current_box])
                        high_pos = min(
                            [position[1] for position in current_box])
                        highest_pos = max(
                            [position[1] for position in current_box])
                        low_pos = max(
                            [position[1] for position in current_box]) + 15

                        exiting_box = handle_config.LANE_HEIGHT_START + \
                            handle_config.LANE_HEIGHT - \
                            handle_config.EDGE_GAP

                        if highest_pos > exiting_box:
                            cv2.drawContours(CROPPED, [current_box], 0,
                                             handle_config.ORANGE, 2)
                            pass
                        else:
                            cv2.drawContours(CROPPED, [current_box], 0, color,
                                             2)
                            cv2.putText(CROPPED, calc_dimensions,
                                        (start_pos, high_pos),
                                        handle_config.FONT, 1, color, 2)
                            update_display = True

                        if program_state.CALIBRATE_MODE:
                            pixel_dimensions = '{0}px x {1}px'.format(
                                int(w), int(h))
                            cv2.putText(CROPPED, pixel_dimensions,
                                        (start_pos, low_pos),
                                        handle_config.FONT, 1,
                                        handle_config.RED, 2)

                if program_state.REQUEST_CALIBRATE:
                    for lane in range(
                            handle_config.LANE_COUNT):  # loop through lanes
                        if RECTS_ARR[lane]:  # if lane has contour
                            current_rect = RECTS_ARR[lane]
                            if current_rect[1][0] > current_rect[1][1]:
                                w = current_rect[1][0]
                                h = current_rect[1][1]
                            else:
                                w = current_rect[1][1]
                                h = current_rect[1][0]

                            handle_config.PIXEL_WIDTHS[lane] = w
                            handle_config.PIXEL_HEIGHTS[lane] = h

                    # Adjust ratios to match calibration
                    for index, width in enumerate(handle_config.PIXEL_WIDTHS):
                        handle_config.WIDTH_RATIOS[
                            index] = handle_config.ACTUAL_WIDTH / width
                    for index, height in enumerate(
                            handle_config.PIXEL_HEIGHTS):
                        handle_config.HEIGHT_RATIOS[
                            index] = handle_config.ACTUAL_HEIGHT / height

                    # Update low highs for calibration
                    for index, ratio in enumerate(handle_config.WIDTH_RATIOS):
                        handle_config.LANE_FAIL_WIDTHS_LOW[
                            index] = handle_config.FAIL_WIDTH_LOW / ratio
                    for index, ratio in enumerate(handle_config.WIDTH_RATIOS):
                        handle_config.LANE_FAIL_WIDTHS_HIGH[
                            index] = handle_config.FAIL_WIDTH_HIGH / ratio
                    for index, ratio in enumerate(handle_config.HEIGHT_RATIOS):
                        handle_config.LANE_FAIL_HEIGHTS_LOW[
                            index] = handle_config.FAIL_HEIGHT_LOW / ratio
                    for index, ratio in enumerate(handle_config.HEIGHT_RATIOS):
                        handle_config.LANE_FAIL_HEIGHTS_HIGH[
                            index] = handle_config.FAIL_HEIGHT_HIGH / ratio

                    handle_config.setValue('CALIBRATION', 'PIXEL_WIDTHS',
                                           handle_config.PIXEL_WIDTHS)
                    handle_config.setValue('CALIBRATION', 'PIXEL_HEIGHTS',
                                           handle_config.PIXEL_HEIGHTS)

                    program_state.request_calibration(False)

                # Not Thresh Mode
                not_calib_statement = (
                    lane for lane in range(handle_config.LANE_COUNT)
                    if not program_state.CALIBRATE_MODE)
                for lane in not_calib_statement:
                    AVG_TEXT = '% PASSED: 0'
                    AVG_WIDTHS_TEXT = 'AVG LENGTH: ' + str(
                        int(AVG_WIDTHS_TOTAL[lane][0] *
                            handle_config.WIDTH_RATIOS[lane])) + 'mm'
                    AVG_HEIGHTS_TEXT = 'AVG THICKNESS: ' + str(
                        int(AVG_HEIGHTS_TOTAL[lane][0] *
                            handle_config.HEIGHT_RATIOS[lane])) + 'mm'
                    if PASS_COUNTS[lane] > 0:
                        AVG_TEXT = '% PASSED: ' + str(
                            100 * PASS_COUNTS[lane] /
                            (PASS_COUNTS[lane] + FAIL_COUNTS[lane]))
                    cv2.putText(CROPPED, 'LANE ' + str(lane + 1),
                                (handle_config.LANE_WIDTH_START[lane],
                                 handle_config.TEXT_Y), handle_config.FONT, 1,
                                handle_config.RED, 2)
                    cv2.putText(CROPPED, 'PASS: '******'FAIL: ' + str(FAIL_COUNTS[lane]),
                                (handle_config.LANE_WIDTH_START[lane],
                                 handle_config.TEXT_Y + 60),
                                handle_config.FONT, 1, handle_config.RED, 2)
                    cv2.putText(CROPPED, AVG_TEXT,
                                (handle_config.LANE_WIDTH_START[lane],
                                 handle_config.TEXT_Y + 90),
                                handle_config.FONT, 1, handle_config.RED, 2)
                    if AVG_WIDTHS_TOTAL[lane][0] > 0:
                        cv2.putText(CROPPED, AVG_WIDTHS_TEXT,
                                    (handle_config.LANE_WIDTH_START[lane],
                                     handle_config.TEXT_Y + 120),
                                    handle_config.FONT, 1, handle_config.RED,
                                    2)
                    if AVG_HEIGHTS_TOTAL[lane][0] > 0:
                        cv2.putText(CROPPED, AVG_HEIGHTS_TEXT,
                                    (handle_config.LANE_WIDTH_START[lane],
                                     handle_config.TEXT_Y + 150),
                                    handle_config.FONT, 1, handle_config.RED,
                                    2)

                # Show Lane Boundaries
                cv2.rectangle(CROPPED,
                              (handle_config.LANE_X1, handle_config.LANE_Y1),
                              (handle_config.LANE_X2, handle_config.LANE_Y2),
                              handle_config.YELLOW, 2)
                cv2.rectangle(CROPPED,
                              (handle_config.SPLIT_X1, handle_config.LANE_Y1),
                              (handle_config.SPLIT_X2, handle_config.LANE_Y2),
                              handle_config.YELLOW, 2)
                cv2.rectangle(CROPPED,
                              (handle_config.SPLIT_X3, handle_config.LANE_Y1),
                              (handle_config.SPLIT_X4, handle_config.LANE_Y2),
                              handle_config.YELLOW, 2)

                # Lane Traffic Calculations
                red_fail = '111111'
                yellow_fail = '111'

                # Lane 1 Traffic Light
                lane_1_traffic_colour = handle_config.GREEN
                lane_1_history = ''.join(str(e) for e in HISTORICAL_FAILS[0])
                if red_fail in lane_1_history:
                    lane_1_traffic_colour = handle_config.RED
                elif yellow_fail in lane_1_history:
                    lane_1_traffic_colour = handle_config.YELLOW
                cv2.rectangle(CROPPED, (handle_config.TRAFFIC_LANE_1_X1,
                                        handle_config.TRAFFIC_Y1),
                              (handle_config.TRAFFIC_LANE_1_X2,
                               handle_config.TRAFFIC_Y2),
                              lane_1_traffic_colour, -1)

                # Lane 2 Traffic Light
                lane_2_traffic_colour = handle_config.GREEN
                lane_2_history = ''.join(str(e) for e in HISTORICAL_FAILS[1])
                if red_fail in lane_2_history:
                    lane_2_traffic_colour = handle_config.RED
                elif yellow_fail in lane_2_history:
                    lane_2_traffic_colour = handle_config.YELLOW
                cv2.rectangle(CROPPED, (handle_config.TRAFFIC_LANE_2_X1,
                                        handle_config.TRAFFIC_Y1),
                              (handle_config.TRAFFIC_LANE_2_X2,
                               handle_config.TRAFFIC_Y2),
                              lane_2_traffic_colour, -1)

                # Lane 3 Traffic Light
                lane_3_traffic_colour = handle_config.GREEN
                lane_3_history = ''.join(str(e) for e in HISTORICAL_FAILS[2])
                if red_fail in lane_3_history:
                    lane_3_traffic_colour = handle_config.RED
                elif yellow_fail in lane_3_history:
                    lane_3_traffic_colour = handle_config.YELLOW
                cv2.rectangle(CROPPED, (handle_config.TRAFFIC_LANE_3_X1,
                                        handle_config.TRAFFIC_Y1),
                              (handle_config.TRAFFIC_LANE_3_X2,
                               handle_config.TRAFFIC_Y2),
                              lane_3_traffic_colour, -1)

                # Lane 3 Traffic Light
                lane_4_traffic_colour = handle_config.GREEN
                lane_4_history = ''.join(str(e) for e in HISTORICAL_FAILS[3])
                if red_fail in lane_4_history:
                    lane_4_traffic_colour = handle_config.RED
                elif yellow_fail in lane_4_history:
                    lane_4_traffic_colour = handle_config.YELLOW
                cv2.rectangle(CROPPED, (handle_config.TRAFFIC_LANE_4_X1,
                                        handle_config.TRAFFIC_Y1),
                              (handle_config.TRAFFIC_LANE_4_X2,
                               handle_config.TRAFFIC_Y2),
                              lane_4_traffic_colour, -1)

                # Show Low Cost Automation Banner
                cv2.putText(CROPPED, 'EasiBake Roll Checker', (760, 100),
                            handle_config.FONT, 3, handle_config.RED, 4)
                cv2.putText(CROPPED, 'Low Cost Automation Ltd', (900, 160),
                            handle_config.FONT, 2, handle_config.RED, 3)

                # Show current AIO
                cv2.putText(CROPPED, 'OUTPUT: ' + str(OUTPUT), (950, 890),
                            handle_config.FONT, 1, handle_config.RED, 2)

                # Show min/max values
                max_length = 'MAX LENGTH = ' + str(
                    int(handle_config.FAIL_WIDTH_HIGH)) + 'mm   '
                min_length = 'MIN LENGTH = ' + str(
                    int(handle_config.FAIL_WIDTH_LOW)) + 'mm    '
                max_thickness = 'MAX THICKNESS = ' + str(
                    int(handle_config.FAIL_HEIGHT_HIGH)) + 'mm'
                min_thickness = 'MIN THICKNESS = ' + str(
                    int(handle_config.FAIL_HEIGHT_LOW)) + 'mm'
                cv2.putText(CROPPED, 'CURRENT REJECT SETTINGS', (240, 1800),
                            handle_config.FONT, 1, handle_config.RED, 2)
                cv2.line(CROPPED, (50, 1815), (875, 1815), handle_config.RED,
                         2)
                cv2.putText(CROPPED, max_length + max_thickness, (50, 1850),
                            handle_config.FONT, 1, handle_config.RED, 2)
                cv2.putText(CROPPED, min_length + min_thickness, (50, 1900),
                            handle_config.FONT, 1, handle_config.RED, 2)

            window_name = 'LINE VIEW'
            if DISPLAY_IMG != [] and update_display:
                cv2.namedWindow(window_name, cv2.WND_PROP_FULLSCREEN)
                cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN,
                                      cv2.WINDOW_FULLSCREEN)
                DISPLAY_IMG = cv2.resize(DISPLAY_IMG, (1600, 900),
                                         interpolation=cv2.INTER_AREA)
                cv2.imshow(window_name, DISPLAY_IMG)

            # Required for loop no need for key read
            _ = cv2.waitKey(1) & 0xFF
def set_side1_box_lr(value):
    if (handle_config.SIDE1_LEFT + value) > 0:
        handle_config.setValue('BOARD SETTINGS', 'SIDE1_LEFT', handle_config.SIDE1_LEFT + value)
def set_board_length(value):
    handle_config.setValue('BOARD SETTINGS', 'BOARD_LENGTH', value)
def set_side2_box_ud(value):
    if (handle_config.SIDE2_TOP + value) > 0:
        handle_config.setValue('BOARD SETTINGS', 'SIDE2_TOP', handle_config.SIDE2_TOP + value)
Exemplo n.º 10
0
    def change_config_value(self, variable, value, text):
        if variable == 'WHITE_THRESH':
            handle_config.WHITE_THRESH += value
            handle_config.setValue('THRESHOLD', 'WHITE_THRESH',
                                   handle_config.WHITE_THRESH)
            self.root.settings_win.threshold_text.set(
                handle_config.WHITE_THRESH)
        elif variable == 'FAIL_WIDTH_LOW':
            handle_config.FAIL_WIDTH_LOW += value
            handle_config.setValue('THRESHOLD', 'FAIL_WIDTH_LOW',
                                   handle_config.FAIL_WIDTH_LOW)

            for index, _ in enumerate(handle_config.LANE_FAIL_WIDTHS_LOW):
                handle_config.LANE_FAIL_WIDTHS_LOW[index] = \
                    handle_config.FAIL_WIDTH_LOW / handle_config.WIDTH_RATIOS[index]
            handle_config.setValue('THRESHOLD', 'LANE_FAIL_WIDTHS_LOW',
                                   handle_config.LANE_FAIL_WIDTHS_LOW)

            self.root.settings_win.min_length_text.set(
                handle_config.FAIL_WIDTH_LOW)
        elif variable == 'FAIL_WIDTH_HIGH':
            handle_config.FAIL_WIDTH_HIGH += value
            handle_config.setValue('THRESHOLD', 'FAIL_WIDTH_HIGH',
                                   handle_config.FAIL_WIDTH_HIGH)

            for index, _ in enumerate(handle_config.LANE_FAIL_WIDTHS_HIGH):
                handle_config.LANE_FAIL_WIDTHS_HIGH[index] = \
                    handle_config.FAIL_WIDTH_HIGH / handle_config.WIDTH_RATIOS[index]
            handle_config.setValue('THRESHOLD', 'LANE_FAIL_WIDTHS_HIGH',
                                   handle_config.LANE_FAIL_WIDTHS_HIGH)

            self.root.settings_win.max_length_text.set(
                handle_config.FAIL_WIDTH_HIGH)
        elif variable == 'FAIL_HEIGHT_LOW':
            handle_config.FAIL_HEIGHT_LOW += value
            handle_config.setValue('THRESHOLD', 'FAIL_HEIGHT_LOW',
                                   handle_config.FAIL_HEIGHT_LOW)

            for index, _ in enumerate(handle_config.LANE_FAIL_HEIGHTS_LOW):
                handle_config.LANE_FAIL_HEIGHTS_LOW[index] = \
                    handle_config.FAIL_HEIGHT_LOW / handle_config.HEIGHT_RATIOS[index]
            handle_config.setValue('THRESHOLD', 'LANE_FAIL_HEIGHTS_LOW',
                                   handle_config.LANE_FAIL_HEIGHTS_LOW)

            self.root.settings_win.min_thickness_text.set(
                handle_config.FAIL_HEIGHT_LOW)
        elif variable == 'FAIL_HEIGHT_HIGH':
            handle_config.FAIL_HEIGHT_HIGH += value
            handle_config.setValue('THRESHOLD', 'FAIL_HEIGHT_HIGH',
                                   handle_config.FAIL_HEIGHT_HIGH)

            for index, _ in enumerate(handle_config.LANE_FAIL_HEIGHTS_HIGH):
                handle_config.LANE_FAIL_HEIGHTS_HIGH[index] = \
                    handle_config.FAIL_HEIGHT_HIGH / handle_config.HEIGHT_RATIOS[index]
            handle_config.setValue('THRESHOLD', 'LANE_FAIL_HEIGHTS_HIGH',
                                   handle_config.LANE_FAIL_HEIGHTS_HIGH)

            self.root.settings_win.max_thickness_text.set(
                handle_config.FAIL_HEIGHT_HIGH)