def __init__(self):
     self.frame = 0
     self.sequence = None
     self.last_capture = None
     self.sequence_path = None
     self.steering_file_path = None
     self.camera_module = CameraModule()
     self.csv_rows = []
 def __init__(self):
     '''
            shapeNN, patternNN = 인스턴스 생성
            colorDetector = 클래스 인스턴스 생성
      '''
     self.camera = CameraModule()
     self.pattern = Pattern()
     self.shape = Shape()
     self.save_path = '../data'
Ejemplo n.º 3
0
    def __init__(self, display_size, picture_basename, picture_size, pose_time,
                 display_time, trigger_channel, shutdown_channel, lamp_channel,
                 idle_slideshow, slideshow_display_time):
        self.display = GuiModule('Photobooth', display_size)
        self.pictures = PictureList(picture_basename)
        self.camera = CameraModule(picture_size)

        self.pic_size = picture_size
        self.pose_time = pose_time
        self.display_time = display_time

        self.trigger_channel = trigger_channel
        self.shutdown_channel = shutdown_channel
        self.lamp_channel = lamp_channel

        self.idle_slideshow = idle_slideshow
        if self.idle_slideshow:
            self.slideshow_display_time = slideshow_display_time
            self.slideshow = Slideshow(
                display_size, display_time,
                os.path.dirname(os.path.realpath(picture_basename)))

        input_channels = [trigger_channel, shutdown_channel]
        output_channels = [lamp_channel]
        self.gpio = GPIO(self.handle_gpio, input_channels, output_channels)
    def __init__(self, ip, port):

        self.ip = ip
        self.port = int(port)
        print("ip: %s, port: %s" % (self.ip, self.port))

        # Create a TCP/IP socket
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.camera_module = CameraModule()
        self.piggy = Piggy()
        self.piggy.initPiggy()

        # Connect the socket to the port where the server is listening
        server_address = (self.ip, self.port)
        print('+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+')
        print('connecting to address %s at port %s' % server_address)
        print('+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+')
        self.sock.connect(server_address)
        self.start_loop()
class AiClient:
    def __init__(self, ip, port):

        self.ip = ip
        self.port = int(port)
        print("ip: %s, port: %s" % (self.ip, self.port))

        # Create a TCP/IP socket
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.camera_module = CameraModule()
        self.piggy = Piggy()
        self.piggy.initPiggy()

        # Connect the socket to the port where the server is listening
        server_address = (self.ip, self.port)
        print('+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+')
        print('connecting to address %s at port %s' % server_address)
        print('+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+')
        self.sock.connect(server_address)
        self.start_loop()

    def start_loop(self):

        while (True):
            image_data = self.camera_module.capture_image_string()
            response = self.request_data(image_data)
            self.steer_piggy(response)

    def steer_piggy(self, instruction):
        if instruction:
            # Steer the car
            if instruction[0] < 0:
                self.piggy.turnCarLeft(255)
            else:
                self.piggy.turnCarRight(255)
            # Control acceleration
            self.piggy.accelerateCar(int(-(instruction[1]) * 255))

    def request_data(self, message):

        print('sending "%s"' % message)
        self.sock.sendall(message)
        self.sock.sendall("EOM")
        print('all sent')
        response = self.sock.recv(4096)
        print(response)
        if "," in response:
            steering, propagation = response.split(",")
            return steering, propagation
        else:
            print("Could not process response %" % response)
            return None
class Sampler(object):
    STORAGE_ROOT = '/home/pi/'
    CAPTURE_INTERVAL_SECS = 1.0

    def __init__(self):
        self.frame = 0
        self.sequence = None
        self.last_capture = None
        self.sequence_path = None
        self.steering_file_path = None
        self.camera_module = CameraModule()
        self.csv_rows = []

    def start(self):
        self.csv_rows = []
        self.frame = 0
        self.sequence = time.strftime("%Y%m%d%H%M")
        self.sequence_path = os.path.join(self.STORAGE_ROOT, self.sequence)
        if not os.path.exists(self.sequence_path):
            os.makedirs(self.sequence_path)
        self.steering_file_path = os.path.join(self.sequence_path,
                                               'steering.csv')
        self.last_capture = None

    def reject(self):
        shutil.rmtree(self.sequence_path, ignore_errors=True)

    def capture(self, steering, propagation):
        print("capture")
        now = datetime.datetime.now()
        if self.last_capture is not None and (
                now - self.last_capture
        ).total_seconds() < self.CAPTURE_INTERVAL_SECS:
            print("skipping capture")
            return
        self.last_capture = now
        self.frame += 1
        image = self.camera_module.capture()
        filepath = os.path.join(self.sequence_path,
                                "frame_{}.jpeg".format(self.frame))
        print("Saving file {}".format(datetime.datetime.now()))
        image.save(filepath)
        print("Save complete {}".format(datetime.datetime.now()))
        self.csv_rows.append([self.frame, propagation, steering])

    def save_run(self):
        print('saving steering data to csv {}'.format(datetime.datetime.now()))
        with open(self.steering_file_path, 'w') as csvfile:
            writer = csv.writer(csvfile, delimiter=';')
            for csv_row in self.csv_rows:
                writer.writerow(csv_row)
        print("saved steering data {}".format(datetime.datetime.now()))
Ejemplo n.º 7
0
    def __init__(self, display_size, display_rotate, picture_basename,
                 picture_size, pose_time, display_time, trigger_channel,
                 shutdown_channel, lamp_channel, idle_slideshow,
                 slideshow_display_time):
        self.display = GuiModule('Photobooth', display_size)
        if (display_size == (0, 0)):  # Detect actual resolution
            display_size = self.display.get_size()
        self.display_rotate = display_rotate
        if (display_rotate):
            self.display.set_rotate(True)

        self.pictures = PictureList(picture_basename)
        self.camera = CameraModule((picture_size[0] / 2, picture_size[1] / 2),
                                   camera_rotate=camera_rotate)
        self.camera_rotate = camera_rotate

        self.pic_size = picture_size
        self.pose_time = pose_time
        self.display_time = display_time

        self.trigger_channel = trigger_channel
        self.shutdown_channel = shutdown_channel
        self.lamp_channel = lamp_channel

        self.idle_slideshow = idle_slideshow
        if self.idle_slideshow:
            self.slideshow_display_time = slideshow_display_time
            self.slideshow = Slideshow(
                display_size, display_time,
                os.path.dirname(os.path.realpath(picture_basename)))
            if (display_rotate):
                self.slideshow.display.set_rotate(True)

        input_channels = [trigger_channel, shutdown_channel]
        output_channels = [lamp_channel]
        self.gpio = GPIO(self.handle_gpio, input_channels, output_channels)

        self.printer_module = PrinterModule()
        try:
            pygame.mixer.init(buffer=1024)
            self.shutter = pygame.mixer.Sound(shutter_sound)
            self.bip1 = pygame.mixer.Sound(bip1_sound)
            self.bip2 = pygame.mixer.Sound(bip2_sound)
            self.bip2.play()
        except pygame.error:
            self.shutter = None
            pass
Ejemplo n.º 8
0
    def __init__(self, display_size, display_rotate, picture_size, pose_time,
                 display_time, idle_slideshow, slideshow_display_time):
        self.display = GuiModule('Photobooth', display_size)
        if display_size == (0, 0):  # Detect actual resolution
            display_size = self.display.get_size()
        self.display_rotate = display_rotate
        if display_rotate:
            self.display.set_rotate(True)
        # Image basename
        picture_basename = datetime.now().strftime("%Y-%m-%d/pic")
        assembled_picture_basename = datetime.now().strftime(
            "%Y-%m-%d/assembled/pic")

        self.pictures = PictureList(picture_basename)
        self.assembled_pictures = PictureList(assembled_picture_basename)
        self.taking_picture = Lock()
        self.arduino = ArduinoSerial()
        self.camera = CameraModule((picture_size[0] / 2, picture_size[1] / 2),
                                   camera_rotate=camera_rotate)
        self.camera_rotate = camera_rotate

        self.picture_size = picture_size
        self.pose_time = pose_time
        self.display_time = display_time

        self.idle_slideshow = idle_slideshow
        if self.idle_slideshow:
            self.slideshow_display_time = slideshow_display_time
            self.slideshow = Slideshow(display_size,
                                       display_time,
                                       os.path.dirname(
                                           os.path.realpath(picture_basename)),
                                       recursive=False)
            if display_rotate:
                self.slideshow.display.set_rotate(True)

        self.printer_module = PrinterModule()
        try:
            pygame.mixer.init(buffer=1024)
            self.shutter = pygame.mixer.Sound(shutter_sound)
            self.bip1 = pygame.mixer.Sound(bip1_sound)
            self.bip2 = pygame.mixer.Sound(bip2_sound)
            self.bip2.play()
        except pygame.error:
            self.shutter = None
            pass
        self.arduino.start()
Ejemplo n.º 9
0
    def __init__(self, display_size, picture_basename, picture_size, pose_time, display_time,
                 trigger_channel, shutdown_channel, lamp_channel):
        self.display      = GuiModule('Photobooth', display_size)
        self.pictures     = PictureList(picture_basename)
        self.camera       = CameraModule(picture_size)

        self.pic_size     = picture_size
        self.pose_time    = pose_time
        self.display_time = display_time

        self.trigger_channel  = trigger_channel
        self.shutdown_channel = shutdown_channel
        self.lamp_channel     = lamp_channel

        input_channels    = [ trigger_channel, shutdown_channel ]
        output_channels   = [ lamp_channel ]
        self.gpio         = GPIO(self.handle_gpio, input_channels, output_channels)
class Classification:
    def __init__(self):
        '''
               shapeNN, patternNN = 인스턴스 생성
               colorDetector = 클래스 인스턴스 생성
         '''
        self.camera = CameraModule()
        self.pattern = Pattern()
        self.shape = Shape()
        self.save_path = '../data'

    def execute(self):
        '''각 프로세스에서 리턴값을 큐에 담아야 넘겨받을 수 있음'''
        colorQ = Queue()
        patternQ = Queue()
        shapeQ = Queue()
        # 사진 촬영
        data_pattern, data_shape = self.camera.capture()
        '''각각 프로세스로 만들어서 병렬 처리하게 만들었어 조금이라도 시간을 단축시켜보고자...'''
        # args=('./capture_img/image.jpg')
        color_process = Process(target=color.execute,
                                args=(self.save_path + '/image.jpg', colorQ))
        pattern_process = Process(target=self.pattern.image_predict,
                                  args=(data_pattern, patternQ))
        shape_process = Process(target=self.shape.image_predict,
                                args=(data_shape, shapeQ))
        '''프로세스 시작'''
        color_process.start()
        # 카메라모듈에서 전처리된 사진으로 각각 예측하여 스트링 반환.
        pattern_process.start()
        shape_process.start()
        '''프로세스 끝나면 각 큐에서 결과값 추출하기'''
        color_process.join()
        color_string = colorQ.get()

        pattern_process.join()
        pattern = patternQ.get()

        shape_process.join()
        shape = shapeQ.get()

        return color_string, pattern, shape
Ejemplo n.º 11
0
    def __init__(self, display_size, picture_basename, picture_size, pose_time,
                 display_time, SWITCH, SHUTDOWN, POSE_LED, ON_LED,
                 idle_slideshow, slideshow_display_time):
        self.display = GuiModule('Photobooth', display_size)
        self.pictures = PictureList(picture_basename)
        self.camera = CameraModule(picture_size)

        self.pic_size = picture_size
        self.pose_time = pose_time
        self.display_time = display_time

        #  self.SWITCH       = SWITCH
        #  self.SHUTDOWN     = SHUTDWON
        #  self.POSE_LED     = POSE_LED
        #  self.ON_LED       = ON_LED

        self.idle_slideshow = idle_slideshow
        if self.idle_slideshow:
            self.slideshow_display_time = slideshow_display_time
            self.slideshow = Slideshow(
                display_size, display_time,
                os.path.dirname(os.path.realpath(picture_basename)))
Ejemplo n.º 12
0
def main():

    ### Initialisation ###
    Logger.info(__name__, "Initialising.... ")
    pygame.init()
    gameDisplay = pygame.display.set_mode((disp_w, disp_h), pygame.FULLSCREEN)
    pygame.mouse.set_visible(False)
    pygame.display.set_caption('Photobooth')
    clock = pygame.time.Clock()

    pictures = PictureList(cfg, picture_basename)

    #pkill -USR1 python
    signal.signal(signal.SIGUSR1, sig_green_handler)
    #pkill -USR2 python
    signal.signal(signal.SIGUSR2, sig_red_handler)

    camera = CameraModule(image_size)
    printer = PrinterModule(cfg)

    intro_ani = IntroAnimation(cfg, gameDisplay, disp_w, disp_h, fps, gpio,
                               pictures)
    capture = Capture(cfg, gameDisplay, disp_w, disp_h, 15, gpio, camera)
    process = Process(cfg, gameDisplay, disp_w, disp_h, fps, gpio, pictures)
    upload = Upload(cfg, gameDisplay, disp_w, disp_h, fps, gpio)
    prin = Prin(cfg, gameDisplay, disp_w, disp_h, fps, gpio, printer)

    #Clean entire tmp_directory
    for f in os.listdir(cfg.get("tmp_dir")):
        f_pth = os.path.join(cfg.get("tmp_dir"), f)
        try:
            if os.path.isfile(f_pth):
                os.unlink(f_pth)
        except:
            pass

    Logger.success(__name__, "Initialisation Complete! ")
    state = "INTRO_S"
    retake = False
    while not state == "END":

        event_list = pygame.event.get()

        if reset_combo(event_list):
            Logger.warning(__name__, "Restarting...")
            intro_ani.stop()
            capture.stop()
            process.stop()
            upload.stop()
            os.execv(sys.executable, ['python'] + sys.argv)

        ### INTRO ANIMATION STATES ###
        if state == "INTRO_S":
            retake = False
            final_photos = {}
            final_link = ""
            final_uploaded = False
            final_printed = False

            intro_ani.start()
            pygame.display.update()
            state = "INTRO"

        if state == "INTRO":
            for event in event_list:
                if event.type == pygame.QUIT:
                    state = "END"
                elif green_press(event):
                    state = "CAPTURE_S"

            intro_ani.next()
            pygame.display.update()

        ### CAPTURE STATES ###
        if state == "CAPTURE_S":
            capture.start(retake)
            pygame.display.update()
            state = "CAPTURE"

        if state == "CAPTURE":
            for event in event_list:
                if event.type == pygame.QUIT:
                    state = "END"

            capture.next()
            pygame.display.update()

            if capture.is_done():
                capture.reset()
                photo_set = capture.cap_path
                photo_set_thumbs = capture.cap_thumbs
                state = "PROCESS_S"

        ### PROCESS STATES ###
        if state == "PROCESS_S":
            process.start(photo_set, photo_set_thumbs)
            pygame.display.update()
            state = "PROCESS"

        if state == "PROCESS":
            for event in event_list:
                if event.type == pygame.QUIT:
                    state = "END"
                elif process.is_done():
                    if green_press(event):
                        final_photos = process.get_result()
                        process.reset()

                        if cfg.get("upload__enabled"):
                            state = "UPLOAD_S"
                        elif cfg.get("printer__enabled"):
                            final_link = cfg.get("event_url")
                            state = "PRINT_S"
                        else:
                            state = "DONE"

                    elif red_press(event):  #Retake
                        process.reset()
                        retake = True
                        state = "CAPTURE_S"
            process.next()
            pygame.display.update()

        ### PRINTER UPLOAD STATES ###
        if state == "UPLOAD_S":
            #Update Photo Upload/ Printer Enable Switch State
            # TODO

            upload.start(final_photos)
            pygame.display.update()
            state = "UPLOAD"

        if state == "UPLOAD":
            for event in event_list:
                if event.type == pygame.QUIT:
                    state = "END"
                elif upload.is_done():
                    final_link = upload.upload_link
                    #TODO upload success
                    if green_press(event):
                        upload.reset()
                        final_uploaded = True

                        if cfg.get("printer__enabled"):
                            state = "PRINT_S"
                        else:
                            state = "DONE"

            upload.next()
            pygame.display.update()

        ### PRINTER UPLOAD STATES ###
        if state == "PRINT_S":
            #Update Photo Upload/ Printer Enable Switch State
            # TODO

            prin.start(final_photos, final_link)
            pygame.display.update()
            state = "PRINT"

        if state == "PRINT":
            for event in event_list:
                if event.type == pygame.QUIT:
                    state = "END"

            if prin.is_done():
                #TODO Get print success value
                prin.reset()
                state = "DONE"
                final_printed = True

            prin.next()
            pygame.display.update()

        if state == "DONE":
            pictures.log_add(final_photos['primary'], final_link,
                             final_uploaded, final_printed)
            state = "INTRO_S"

        if "CAPTURE" in state:
            clock.tick(15)
        else:
            clock.tick(fps)

    pygame.quit()
    quit()