class orange_scanning_images():

    def __init__(self):
        self.IMAGE640 = Image("640Background.jpg")
        self.IMAGE1024 = Image("BlackBackground.gif")
        self.IMAGE960 = Image("960x720.jpg")

        self.BACKGROUND_IMAGE = self.IMAGE960

        self.screen = Show_images()
        #self.disp = Display((960, 720))  #((1024, 768))                              # Create a display


    def scanning_start(self):
        img = self.BACKGROUND_IMAGE

        img.dl().setFontSize(70)
        img.dl().text(
            "Orange flap detection",
            (210,img.height/3),
            # (img.width, img.width),
            color=Color.WHITE)
        img.dl().text(
            "Press Enter",
            (340,img.height - 150),
            # (img.width, img.width),
            color=Color.WHITE)

        self.screen.show_till_press_enter(img)


    def reading_from_file_image(self, coord_x, coord_y, flat_ratio, slope_ratio, colour_hue, colour_sat):
        img = self.BACKGROUND_IMAGE

        img.dl().setFontSize(70)
        img.dl().text(
            "Reading calibration data",
            (160,50),
            color=Color.WHITE)

        img.dl().setFontSize(45)
        # img.dl().text("%f" % round(angle_average,2))[0:2]
        # "%04i" % found_object_x
        text_temp = "Flap coordinates: X - %03i, Y - %03i" % (coord_x,coord_y)
        img.dl().text(
            text_temp,
            (120,250),
            color=Color.WHITE)
        text_temp = "W/H ratios: flat - %.2f, slope - %.2f" % (round(flat_ratio,3),round(slope_ratio,3))
        img.dl().text(
            text_temp,
            (120,300),
            color=Color.WHITE)
        text_temp = "Average colour data: Hue - %.1f, Sat - %.1f" % (round(colour_hue,2),round(colour_sat,2))
        img.dl().text(
            text_temp,
            (120,350),
            color=Color.WHITE)

        img.dl().setFontSize(70)
        img.dl().text(
            "Press Enter",
            (340,img.height - 100),
            # (img.width, img.width),
            color=Color.WHITE)

        self.screen.show_till_press_enter(img)


    def no_flaps_found(self, img):
        img.dl().setFontSize(70)
        img.dl().text(
            "Flap was not found",
            (245, 30),
            # (img.width, img.width),
            color=Color.WHITE)

        return self.screen.show_briefly_till_n(img)

    def show_detected_orange_flap(self, img, detected_flap, FlapWHRatio, position, flat_ratio, slope_ratio):

        if position == "Flat":
            text_colour = Color.YELLOW
        else:
            text_colour = Color.RED


        img.dl().rectangle2pts(detected_flap.bottomLeftCorner(),
                               detected_flap.topRightCorner(),
                               text_colour, width = 3)

        img.dl().setFontSize(35)


        # to show the width:
        width_text = "%s" % detected_flap.width()
        width_x = int(detected_flap.bottomLeftCorner()[0] + detected_flap.width()/2 - 15)
        width_y = int(detected_flap.bottomLeftCorner()[1] + 5)
        img.dl().text(
            width_text,
            (width_x,width_y),
            color=text_colour)

        # to show the height:
        height_text = "%s" % detected_flap.height()
        height_x = int(detected_flap.bottomLeftCorner()[0] + detected_flap.width() + 5)
        height_y = int(detected_flap.bottomLeftCorner()[1] - detected_flap.height()/2 - 10)
        img.dl().text(
            height_text,
            (height_x,height_y),
            color=text_colour)


        img.dl().setFontSize(40)
        img.dl().text(
            ("Detected W/H ratio: %.3f" % (FlapWHRatio)),
            (20, 500),
            # (img.width, img.width),
            color=text_colour)
        img.dl().text(
            ("Flat W/H ratio: %.3f" % (flat_ratio)),
            (20, 540),
            # (img.width, img.width),
            color=Color.YELLOW)
        img.dl().text(
            ("Slope W/H ratio: %.3f" % (slope_ratio)),
            (20, 580),
            # (img.width, img.width),
            color=Color.RED)

        img.dl().setFontSize(60)
        img.dl().text(
            ("Flap position is: %s" % position),
            (200, 40),
            color = text_colour)

        return self.screen.show_briefly_till_n(img)
class LED_scanning_images():

    def __init__(self):
        self.IMAGE640 = Image("640Background.jpg")
        self.IMAGE1024 = Image("BlackBackground.gif")
        self.IMAGE960 = Image("960x720.jpg")

        self.BACKGROUND_IMAGE = self.IMAGE960

        self.screen = Show_images()
        #self.disp = Display((960, 720))  #((1024, 768))                              # Create a display


    def scanning_start(self):
        img = self.BACKGROUND_IMAGE

        img.dl().setFontSize(70)
        img.dl().text(
            "LED sequence detection",
            (205,img.height/3),
            # (img.width, img.width),
            color=Color.WHITE)
        img.dl().text(
            "Press Enter",
            (340,img.height - 150),
            # (img.width, img.width),
            color=Color.WHITE)

        self.screen.show_till_press_enter(img)


    def reading_from_file_image(self, m_led_coord_x, m_led_coord_y,
                                dist_led, seq_time, avg_hue, avg_sat):
        img = self.BACKGROUND_IMAGE

        img.dl().setFontSize(70)
        img.dl().text(
            "Reading calibration data",
            (160,50),
            color=Color.WHITE)

        img.dl().setFontSize(45)
        # img.dl().text("%f" % round(angle_average,2))[0:2]
        # "%04i" % found_object_x
        text_temp = "Main LED coordinates: X - %03i, Y - %03i" % (m_led_coord_x,m_led_coord_y)
        img.dl().text(
            text_temp,
            (120,250),
            color=Color.WHITE)
        text_temp = "Average colour data: Hue - %.1f, Sat - %.1f" % (round(avg_hue,2),round(avg_sat,2))
        img.dl().text(
            text_temp,
            (120,300),
            color=Color.WHITE)
        text_temp = "Distance between always on and flashing LED - %.2f" % (round(dist_led,2))
        img.dl().text(
            text_temp,
            (120,350),
            color=Color.WHITE)
        text_temp = "Sequence length - %i" % seq_time
        img.dl().text(
            text_temp,
            (120,400),
            color=Color.WHITE)


        img.dl().setFontSize(70)
        img.dl().text(
            "Press Enter",
            (340,img.height - 100),
            # (img.width, img.width),
            color=Color.WHITE)

        self.screen.show_till_press_enter(img)


    def looking_for_LED(self, img):
        img.dl().setFontSize(70)
        img.dl().text(
            "Looking for always on LED",
            (170, 30),
            # (img.width, img.width),
            color=Color.WHITE)

        return self.screen.show_briefly_till_n(img)

    def sequence_scanning_image_shown(self, img, main_blob,
                                      filtered_img_with_LEDs, crop_width,
                                      time_of_current_state, delta_T,
                                      number_of_blobs):

        img.dl().blit(filtered_img_with_LEDs, ((main_blob.coordinates()[0] - crop_width/2),
                                               main_blob.coordinates()[1] - crop_width/2))

        img.dl().centeredRectangle((main_blob.coordinates()[0],
                            main_blob.coordinates()[1]),(main_blob.width(),main_blob.height()),
                            color = Color.RED, width = 2)

        img.dl().rectangle2pts(
            ((main_blob.coordinates()[0] - crop_width/2), (main_blob.coordinates()[1] + crop_width/2)),
            ((main_blob.coordinates()[0] + crop_width/2), (main_blob.coordinates()[1] - crop_width/2)),
            color = Color.YELLOW, width = 2)


        if number_of_blobs > 1:
            state = "ON"
            previous_state = "OFF"
        else:
            state = "OFF"
            previous_state = "ON"

        img.dl().setFontSize(70)
        img.dl().text(
            ("LED is: %s for: %.1fs" % (state, round(time_of_current_state,1))),
            (240, 30),
            # (img.width, img.width),
            color=Color.WHITE)

        img.dl().setFontSize(50)
        img.dl().text(
            ("Previous state was %s and lasted for: %.2fs" % (previous_state, delta_T)),
            (120,img.height - 80),
            # (img.width, img.width),
            color=Color.WHITE)
        return self.screen.show_briefly_till_n(img)

    def non_valid_scan(self):
        img = self.BACKGROUND_IMAGE

        img.dl().setFontSize(70)
        img.dl().text(
            "Scanning results list:",
            (170,50),
            color=Color.WHITE)

        img.dl().setFontSize(45)

        img.dl().text(
            "Scanning results are not valid:",
            (120,250),
            color=Color.WHITE)
        img.dl().text(
            "Always on LED was not found for ",
            (120,300),
            color=Color.WHITE)
        img.dl().text(
            "more than half of the scan time",
            (120,350),
            color=Color.WHITE)

        img.dl().setFontSize(70)
        img.dl().text(
            "Press Enter",
            (340,img.height - 100),
            # (img.width, img.width),
            color=Color.WHITE)

        self.screen.show_till_press_enter(img)


    def scanning_done_image(self, results_list, average_period):
        img = self.BACKGROUND_IMAGE

        img.dl().setFontSize(70)
        img.dl().text(
            "Scanning results list:",
            (210, 50),
            color=Color.WHITE)

        img.dl().setFontSize(45)

        results_limit = 11
        iterator = range(1,results_limit)
        text_location = 120
        for i in iterator:
            img.dl().text(
            results_list[i],
            (100,text_location),
            color=Color.WHITE)
            text_location = text_location + 50

        img.dl().setFontSize(70)
        img.dl().text(
            ("Average period is: %s" % average_period),
            (210,img.height - 100),
            color=Color.WHITE)

        self.screen.show_till_press_enter(img)
示例#3
0
class LED_scanning_images():
    def __init__(self):
        self.IMAGE640 = Image("640Background.jpg")
        self.IMAGE1024 = Image("BlackBackground.gif")
        self.IMAGE960 = Image("960x720.jpg")

        self.BACKGROUND_IMAGE = self.IMAGE960

        self.screen = Show_images()
        #self.disp = Display((960, 720))  #((1024, 768))                              # Create a display

    def scanning_start(self):
        img = self.BACKGROUND_IMAGE

        img.dl().setFontSize(70)
        img.dl().text(
            "LED sequence detection",
            (205, img.height / 3),
            # (img.width, img.width),
            color=Color.WHITE)
        img.dl().text(
            "Press Enter",
            (340, img.height - 150),
            # (img.width, img.width),
            color=Color.WHITE)

        self.screen.show_till_press_enter(img)

    def reading_from_file_image(self, m_led_coord_x, m_led_coord_y, dist_led,
                                seq_time, avg_hue, avg_sat):
        img = self.BACKGROUND_IMAGE

        img.dl().setFontSize(70)
        img.dl().text("Reading calibration data", (160, 50), color=Color.WHITE)

        img.dl().setFontSize(45)
        # img.dl().text("%f" % round(angle_average,2))[0:2]
        # "%04i" % found_object_x
        text_temp = "Main LED coordinates: X - %03i, Y - %03i" % (
            m_led_coord_x, m_led_coord_y)
        img.dl().text(text_temp, (120, 250), color=Color.WHITE)
        text_temp = "Average colour data: Hue - %.1f, Sat - %.1f" % (round(
            avg_hue, 2), round(avg_sat, 2))
        img.dl().text(text_temp, (120, 300), color=Color.WHITE)
        text_temp = "Distance between always on and flashing LED - %.2f" % (
            round(dist_led, 2))
        img.dl().text(text_temp, (120, 350), color=Color.WHITE)
        text_temp = "Sequence length - %i" % seq_time
        img.dl().text(text_temp, (120, 400), color=Color.WHITE)

        img.dl().setFontSize(70)
        img.dl().text(
            "Press Enter",
            (340, img.height - 100),
            # (img.width, img.width),
            color=Color.WHITE)

        self.screen.show_till_press_enter(img)

    def looking_for_LED(self, img):
        img.dl().setFontSize(70)
        img.dl().text(
            "Looking for always on LED",
            (170, 30),
            # (img.width, img.width),
            color=Color.WHITE)

        return self.screen.show_briefly_till_n(img)

    def sequence_scanning_image_shown(self, img, main_blob,
                                      filtered_img_with_LEDs, crop_width,
                                      time_of_current_state, delta_T,
                                      number_of_blobs):

        img.dl().blit(filtered_img_with_LEDs,
                      ((main_blob.coordinates()[0] - crop_width / 2),
                       main_blob.coordinates()[1] - crop_width / 2))

        img.dl().centeredRectangle(
            (main_blob.coordinates()[0], main_blob.coordinates()[1]),
            (main_blob.width(), main_blob.height()),
            color=Color.RED,
            width=2)

        img.dl().rectangle2pts(((main_blob.coordinates()[0] - crop_width / 2),
                                (main_blob.coordinates()[1] + crop_width / 2)),
                               ((main_blob.coordinates()[0] + crop_width / 2),
                                (main_blob.coordinates()[1] - crop_width / 2)),
                               color=Color.YELLOW,
                               width=2)

        if number_of_blobs > 1:
            state = "ON"
            previous_state = "OFF"
        else:
            state = "OFF"
            previous_state = "ON"

        img.dl().setFontSize(70)
        img.dl().text(
            ("LED is: %s for: %.1fs" %
             (state, round(time_of_current_state, 1))),
            (240, 30),
            # (img.width, img.width),
            color=Color.WHITE)

        img.dl().setFontSize(50)
        img.dl().text(
            ("Previous state was %s and lasted for: %.2fs" %
             (previous_state, delta_T)),
            (120, img.height - 80),
            # (img.width, img.width),
            color=Color.WHITE)
        return self.screen.show_briefly_till_n(img)

    def non_valid_scan(self):
        img = self.BACKGROUND_IMAGE

        img.dl().setFontSize(70)
        img.dl().text("Scanning results list:", (170, 50), color=Color.WHITE)

        img.dl().setFontSize(45)

        img.dl().text("Scanning results are not valid:", (120, 250),
                      color=Color.WHITE)
        img.dl().text("Always on LED was not found for ", (120, 300),
                      color=Color.WHITE)
        img.dl().text("more than half of the scan time", (120, 350),
                      color=Color.WHITE)

        img.dl().setFontSize(70)
        img.dl().text(
            "Press Enter",
            (340, img.height - 100),
            # (img.width, img.width),
            color=Color.WHITE)

        self.screen.show_till_press_enter(img)

    def scanning_done_image(self, results_list, average_period):
        img = self.BACKGROUND_IMAGE

        img.dl().setFontSize(70)
        img.dl().text("Scanning results list:", (210, 50), color=Color.WHITE)

        img.dl().setFontSize(45)

        results_limit = 11
        iterator = range(1, results_limit)
        text_location = 120
        for i in iterator:
            img.dl().text(results_list[i], (100, text_location),
                          color=Color.WHITE)
            text_location = text_location + 50

        img.dl().setFontSize(70)
        img.dl().text(("Average period is: %s" % average_period),
                      (210, img.height - 100),
                      color=Color.WHITE)

        self.screen.show_till_press_enter(img)