Пример #1
0
def save_worker(save_queue, data_queue, process_values, trigger, session_count, gui=None):
    """
    The thread worker used save and analyze the pictures from CameraThread.
        :argument queue: The queue used to store all of the pictures recieved from XimeaController.
        :type queue: Queue.Queue
        :argument process_values: All of the ProcessImage settings in ScarberrySettings.
        :type process_values: dict
        :argument trigger: The ThreadTrigger which contains all of the booleans for thread syncing.
        :type trigger: ThreadTrigger
        :argument session_count: The number of the current instance of the threads
        :type session_count: int
        :keyword gui: Optional interface used to print.
        :type gui: Interface.ScarberryGui
    """
    global abort
    pic_count = 0
    while trigger.get(name='runProcess') and not abort:
        while not save_queue.empty() and not abort:
            pic = save_queue.get()
            Interface.choose_print(gui, 'save', 'pic {} hex: {}'.format(pic_count,pic))
            formated_number = ProcessImage.format_number(pic_count,int(process_values.get("NumberPadding")))
            save_name = process_values.get("BaseName")
            if process_values.get("Count") > 0:
                save_name = '{}.{}'.format(save_name,session_count)
            ProcessImage.save_image(pic,
                                    formated_number,
                                    image_direcoty=process_values.get("ImageDirectory"),
                                    name=save_name,
                                    extention=process_values.get("FileExtension"))
            data_queue.put(pic)
            pic_count += 1
    trigger.set_off('runData')
    Interface.choose_print(gui, 'save', 'SaveImageThread: Finished')
Пример #2
0
def arduino_worker(arduino_values,main_values,trigger,gui=None):
    """
    The thread worker used to start, format, and end communication with the Arduino integral for the operation of ProjectScarberry.
        :argument arduino_values: All of the Arduino settings in ScarberrySettings.
        :type arduino_values: dict
        :argument main_values: All of the Main settings in ScarberrySettings.
        :type main_values: dict
        :argument trigger: The ThreadTrigger which contains all of the booleans for thread syncing.
        :type trigger: ThreadTrigger
        :keyword gui: Optional interface used to print.
        :type gui: Interface.ScarberryGui
    """
    global abort
    wait = True
    controller = ArduinoController.ArduinoController(arduino_values.get("SerialPort"),gui=gui)
    if not abort:
        controller.write_value(arduino_values.get("FrameRate"))
        controller.write_value(arduino_values.get("StrobeCount"))
        controller.write_value(arduino_values.get("DutyCycle"))
    while not trigger.get(name='startArduino') and wait:
        if abort:
            wait = False
    if not abort:
        controller.write_value(1)
        trigger.set_on('startCamera')
        time.sleep(float(main_values.get("RunTime"))+1)
        controller.write_value(4)
        trigger.set_off('startCamera')
    Interface.choose_print(gui, 'arduino', 'ArduinoThread: Finished')
Пример #3
0
def camera_worker(queue,camera_values,arduino_values,trigger,gui=None):
    """
    The thread worker used to start, format, and end communication with the Ximea camera integral for the operation of ProjectScarberry.
        :argument queue: The queue used to store all of the pictures recieved from XimeaController.
        :type queue: Queue.Queue
        :argument camera_values: All of the XimeaController settings in ScarberrySettings.
        :type camera_values: dict
        :argument arduino_values: All of the Arduino settings in ScarberrySettings.
        :type arduino_values: dict
        :argument trigger: The ThreadTrigger which contains all of the booleans for thread syncing.
        :type trigger: ThreadTrigger
        :keyword gui: Optional interface used to print.
        :type gui: Interface.ScarberryGui
    """
    global abort
    camera = XimeaController.XimeaCamera(arduino_values.get("FrameRate"),
                                         gain=camera_values.get("Gain"),
                                         gui=gui)
    wait = True
    trigger.set_on('startArduino')
    while not trigger.get(name='startCamera') and wait:
        if abort:
            wait = False
    if not abort:
        camera.start_acquisition()
        while trigger.get(name='startCamera') and not abort:
            current_image = camera.get_image()
            queue.put(current_image)
        camera.stop_acquisition()
        trigger.set_off('runProcess')
    Interface.choose_print(gui, 'camera', 'CameraThread: Finished')
Пример #4
0
 def get_image(self):
     """
     Prompts the Ximea camera to capture a photo after the next GPI spike.
     """
     try:
         self.camera.get_image(self.image)
         return self.image.get_image_data_numpy()
     except xiapi.Xi_error:
         Interface.choose_print(self.gui, 'camera', 'Xi_error: ERROR 10: Timeout')
         Main.abort_session()
         return None
Пример #5
0
def data_worker(queue, process_values, trigger, session_count, gui=None):
    """
    The thread worker used save and analyze the pictures from CameraThread.
        :argument queue: The queue used to store all of the pictures recieved from XimeaController.
        :type queue: Queue.Queue
        :argument process_values: All of the ProcessImage settings in ScarberrySettings.
        :type process_values: dict
        :argument trigger: The ThreadTrigger which contains all of the booleans for thread syncing.
        :type trigger: ThreadTrigger
        :argument session_count: The number of the current instance of the threads
        :type session_count: int
        :keyword gui: Optional interface used to print.
        :type gui: Interface.ScarberryGui
    """
    global abort
    pic_count = 0
    data_directory = process_values.get("ImageDirectory") + '\\data'
    if not os.path.exists(data_directory):
        os.makedirs(data_directory)
    while trigger.get(name='runData') and not abort:
        while not queue.empty() and not abort:
            pic = queue.get()
            Interface.choose_print(gui, 'data', 'pic {} hex: {}'.format(pic_count, pic))
            formated_number = ProcessImage.format_number(pic_count, int(process_values.get("NumberPadding")))
            save_name = process_values.get("BaseName")
            if process_values.get("Count") > 0:
                save_name = '{}.{}'.format(save_name, session_count)
            data_filename = '{}\\data-{}_{}{}'.format(data_directory,
                                                      save_name,
                                                      formated_number,
                                                      '.txt')
            if process_values.get("SaveDraw"):
                ProcessImage.draw_and_data(pic,
                                           '{}\\data\\data-{}_{}{}'.format(process_values.get("ImageDirectory"),
                                                                           save_name,
                                                                           formated_number,
                                                                           process_values.get("FileExtension")),
                                           data_filename,
                                           process_values.get("BlurValue"),
                                           process_values.get("ThreshLimit"),
                                           draw_rois=process_values.get("DrawROIs"),
                                           draw_centroid=process_values.get("DrawCentroid"),
                                           draw_colours=process_values.get("DrawColour"),
                                           draw_count=process_values.get("DrawCount"))
            else:
                data = ProcessImage.get_data(pic,
                                             process_values.get("BlurValue"),
                                             process_values.get("ThreshLimit"))
                ProcessImage.save_data(data, data_filename)
            pic_count += 1
    Interface.choose_print(gui, 'data', 'DataImageThread: Finished')
Пример #6
0
    def __init__(self,framerate,gain=0,gui=None):
        """
        Initializes an instance of XimeaCamera.
            :argument framerate: Number of pictures taken a second.
            :type framerate: int
            :keyword gain: Brightness modifier of pictures taken.
            type gain: int, float [0 to 6](default 0)
            :keyword gui: Optional interface used to print(default None).
            :type gui: Interface.ScarberryGui
        """
        self.gui = gui
        self.image = xiapi.Image()

        self.camera = xiapi.Camera()
        Interface.choose_print(gui, 'camera', 'Opening camera...')
        try:
            self.camera.open_device()

            exposure = (1000000 / (int(framerate)))
            exposure -= math.pow(10, math.floor(math.log(exposure, 10)) - 1)
            self.camera.set_exposure(int(exposure))

            if gain < 0:
                gain = 0
            if gain > 6:
                gain = 6
            self.camera.set_gain(float(gain))

            self.camera.set_trigger_source('XI_TRG_EDGE_RISING')
            self.camera.set_gpi_mode('XI_GPI_TRIGGER')
            self.camera.set_gpo_selector('XI_GPO_PORT1')
            self.camera.set_gpo_mode('XI_GPO_FRAME_TRIGGER_WAIT')
            self.camera.set_imgdataformat('XI_MONO8')
        except xiapi.Xi_error:
            Interface.choose_print(gui, 'camera', 'Xi_error: ERROR 56: No Devices Found')
            Main.abort_session()
 def write_value(self,value):
     """
     Write a value to the Arduino over Serial.
         :argument value: Value to be written to Arduino
         :type value: string, int, float
         :argument pause: Amount of time spent paused in seconds
         :type pause: int, float
     """
     Interface.choose_print(self.gui, 'arduino', 'Writing "{}"...'.format(value))
     try:
         self.serial.write('{}'.format(value))
         self.serial.readline()
         Interface.choose_print(self.gui, 'arduino', 'Wrote: {}'.format(value))
     except serial.SerialException:
         Interface.choose_print(self.gui,
                                'arduino',
                                'SerialException: WriteFile failed')
         Main.abort_session()
 def __init__(self,com_number,gui=None):
     """
     Initializes an instance of ArduinoController.
         :argument com_number: Port number of the Arduino.
         :type com_number: int
         :keyword gui: Optional interface used to print(default None).
         :type gui: Interface.ScarberryGui
     """
     self.gui = gui
     try:
         self.serial = serial.Serial('COM{}'.format(com_number),115200)
         Interface.choose_print(gui, 'arduino', 'Waiting for COM{}...'.format(com_number))
         print('Waiting for COM{}...'.format(com_number))
         time.sleep(ArduinoController.INITIAL_SLEEP);
         Interface.choose_print(gui, 'arduino', 'Connected to COM{}.'.format(com_number))
         print('Connected to COM{}.'.format(com_number))
     except serial.SerialException:
         Interface.choose_print(self.gui,
                                'arduino',
                                'SerialException: could not open COM{}'.format(com_number))
         Main.abort_session()
Пример #9
0
 def close_camera(self):
     """
     Closes all communication with the Ximea camera.
     """
     Interface.choose_print(self.gui, 'camera','Closing camera...')
     self.camera.close_device()
Пример #10
0
 def stop_acquisition(self):
     """
     Stops aquisition of the Ximea camera.
     """
     Interface.choose_print(self.gui, 'camera','Stopping acquisition...')
     self.camera.stop_acquisition()
Пример #11
0
 def start_acquisition(self):
     """
     Starts acquisition of the Ximea camera.
     """
     Interface.choose_print(self.gui,'camera','Starting data acquisition...')
     self.camera.start_acquisition()