def create_devices_with_tries():
    """
    This function waits for the user to connect a device before raising
    an exception
    """

    tries = 0
    tries_max = 6
    sleep_time_secs = 10
    while tries < tries_max:  # Waits for devices
        devices = system.create_device()
        if not devices:
            print(
                f'Try {tries+1} of {tries_max}: waiting for {sleep_time_secs} '
                f'secs for a device to be connected!')
            for sec_count in range(sleep_time_secs):
                time.sleep(1)
                print(f'{sec_count + 1 } seconds passed ',
                      '.' * sec_count,
                      end='\r')
            tries += 1
        else:
            print(f'Created {len(devices)} device(s)')
            return devices
    else:
        raise Exception(f'No device found! Please connect a device and run '
                        f'the example again.')
Пример #2
0
def example_entry_point():

    # Discover devices --------------------------------------------------------

    print('Discover devices on network')
    device_infos1 = system.device_infos
    if not device_infos1:
        raise BaseException('No device is found!')
    device_info1 = device_infos1[0]
    print('Device1 info: ')
    pprint(device_info1, indent=4)

    # Create new IP -----------------------------------------------------------

    print('Current IP = ', device_info1['ip'])
    new_ip = add_one_to_ip(device_info1['ip'])
    device_info1_new = {
        'mac': device_info1['mac'],
        'ip': new_ip,
        'subnetmask': device_info1['subnetmask'],
        'defaultgateway': device_info1['defaultgateway']
    }
    print('New IP     = ', device_info1_new['ip'])
    # Force IP ----------------------------------------------------------------

    # Note: The force_ip function can also take a list of device infos to
    # force new IP addesses for multiple devices.
    print('New IP is being forced')
    system.force_ip(device_info1_new)
    print('New IP was forced successfully')

    # Discover devices --------------------------------------------------------

    print('Discover devices on network --------------------------------------')
    device_infos2 = system.device_infos
    if not device_infos2:
        raise BaseException('No device is found!')
    device_info2 = device_infos2[0]
    print('Device2 info: ')
    pprint(device_info2, indent=4)

    if device_info2 != device_info1_new:
        #raise Exception('device_info did not update')
        pass

    # create device with new ip
    system.create_device(device_info1_new)
def example_entry_point():

    # Get connected devices ---------------------------------------------------

    # create_device function with no arguments would create a list of
    # device objects from all connected devices
    devices = system.create_device()
    if not len(devices):
        raise Exception(f'No device found!\n'
                        f'Please connect a device and run the example again.')
    print(f'Created {len(devices)} device(s)')

    device = devices[0]
    print(f'Device used in the example:\n\t{device}')

    # just to have a viewable image
    print('Setting \'Width\' and \'Height\' Nodes value to their '
          'max values')
    device.nodemap['Width'].value = device.nodemap['Width'].max
    device.nodemap['Height'].value = device.nodemap['Height'].max

    with device.start_stream(1):
        print('Stream started')

        buffer = device.get_buffer()
        print(f'Image buffer received')

        # create an image writer
        # The writer, optionally, can take width, height, and bits per pixel
        # of the image(s) it would save. if these arguments are not passed
        # at run time, the first buffer passed to the Writer.save()
        # function will configure the writer to the arguments buffer's width,
        # height, and bits per pixel
        writer = Writer()
        # default name for the image is 'image_<count>.jpg' where count
        # is a pre-defined tag that gets updated every time a buffer image
        # is saved. More custom tags can be added using
        # Writer.register_tag() function
        writer.save(buffer)
        print(f'Image saved {writer.saved_images[-1]}')

        device.requeue_buffer(buffer)
        print(f'Image buffer requeued')

    # device.stop_stream() is automatically called at the end of the
    # context manger scope

    # clean up ----------------------------------------------------------------

    # This function call with no arguments will destroy all of the
    # created devices. Having this call here is optional, if it is not
    # here it will be called automatically when the system module is unloading.
    system.destroy_device()
    print('Destroyed all created devices')
def example_entry_point():

    # create devices
    print('Creating devices')
    devices = system.create_device()
    try:
        device = devices[0]
    except IndexError as ie:
        print('No device found!')
        raise ie
    print(f'Device used in the example:\n\t{device}')

    # get nodes
    nodes = device.nodemap.get_node(['Width', 'Height', 'PixelFormat'])

    # nodes
    nodes['Width'].value = nodes['Width'].max

    print('Setting Height to its maximum value')
    height = nodes['Height']
    height.value = height.max

    # set pixel format to mono8, most cameras should support it
    #print('Setting Pixel Format to Mono8')
    #nodes['PixelFormat'].value = 'Mono8'
    print('Setting Pixel Format to Mono16')
    nodes['PixelFormat'].value = 'Mono16'

    # grab and save an image buffer
    print('Starting stream')
    with device.start_stream(1):
        print('Grabbing an image buffer')
        image = device.get_buffer()  # optional args

        print(f' Width X Height = {image.width} x {image.height}')

        print('Converting image buffer to a numpy array')
        nparray = np.asarray(image.data,
                             dtype=np.uint8).view(np.uint16).reshape(
                                 (image.height, image.width))
        print(nparray)

        nparray.tofile('image_mono16.raw')

        #im = img.fromarray(nparray)
        #im.save('test.raw')

        device.requeue_buffer(image)
def example_entry_point():

    # create devices
    print('Creating devices')
    devices = system.create_device()
    try:
        device = devices[0]
    except IndexError as ie:
        print('No device found!')
        raise ie
    print(f'Device used in the example:\n\t{device}')

    # get nodes
    nodes = device.nodemap.get_node(['Width', 'Height', 'PixelFormat'])

    # nodes
    nodes['Width'].value = nodes['Width'].max

    print('Setting Height to its maximum value')
    height = nodes['Height']
    height.value = height.max

    # set pixel format to mono8, most cameras should support it
    print('Setting Pixel Format to Mono8')
    nodes['PixelFormat'].value = 'Mono8'
    device.nodemap.get_node('TestPattern').value = 'Pattern0'

    # grab and save an image buffer
    print('Starting stream')
    with device.start_stream(1):
        print('Grabbing an image buffer')
        image = device.get_buffer()  # optional args

        print(f' Width X Height = {image.width} x {image.height}')

        print('Converting image buffer to a numpy array')
        bytes_per_pixel = image.bits_per_pixel / 8
        nparray = np.asarray(image.data, dtype=np.uint8)
        nparray.reshape((image.height, image.width, bytes_per_pixel))

        image_name = 'mono8_image_saved_as_mono8.raw'
        nparray.tofile(image_name)

        print(f' Saved image path is: {os.getcwd()}\\{image_name}')
        device.requeue_buffer(image)
Пример #6
0
 def create_devices_with_tries(self, device_info):
     tries = 0
     tries_max = 1
     sleep_time_secs = 10
     while tries < tries_max:  # Wait for device for 60 seconds
         devices = system.create_device(device_info)
         if not devices:
             print(
                 f'Try {tries+1} of {tries_max}: waiting for {sleep_time_secs} '
                 f'secs for a device to be connected!')
             for sec_count in range(sleep_time_secs):
                 time.sleep(1)
                 print(f'{sec_count + 1 } seconds passed ',
                       '.' * sec_count,
                       end='\r')
             tries += 1
         else:
             print(f'Created {len(devices)} device(s)')
             return devices
     else:
         raise Exception('No device found! Please connect a device and run '
                         'the example again.')
Пример #7
0
    def start(self):
        # Get connected devices ---------------------------------------------------
        devices = system.create_device()
        print(f'Created {len(devices)} device(s)')
        try:
            self.device = devices[0]
        except:
            print('No device found!')
            exit()
        print(f'Device used in the example:\n\t{self.device}')

        # Get nodes ---------------------------------------------------------------
        nodes = self.device.nodemap.get_node(
            ['Width', 'Height', 'PixelFormat'])
        self.height, self.width = nodes['Height'].value, nodes['Width'].value

        print('Depth image size: %d x %d' % (self.height, self.width))

        nodes['PixelFormat'].value = self.args.pixel_format
        print('-------------------------------------------Starting stream')
        self.device.start_stream(1)
        print('---------------------->>>>>>>>>> Sensor initialized ....')
        self.get_sensor_specs()
Пример #8
0
def example_entry_point():

    # create devices
    print('Creating devices')
    devices = system.create_device()
    try:
        device = devices[0]
    except IndexError as ie:
        print('No device found!')
        raise ie
    print(f'Device used in the example:\n\t{device}')

    # get nodes
    nodes = device.nodemap.get_node(['Width', 'Height', 'PixelFormat'])

    # nodes
    nodes['Width'].value = nodes['Width'].max

    print('Setting Height to its maximum value')
    height = nodes['Height']
    height.value = height.max

    # set pixel format to mono8, most cameras should support it
    print('Setting Pixel Format to Mono8')
    nodes['PixelFormat'].value = 'Mono8'

    # grab and save an image buffer
    print('Starting stream')
    with device.start_stream(1):
        image = device.get_buffer()  # optional args

        print(f' Width X Height = {image.width} x {image.height}')

        print('Press Enter to convert image using np.asarray and image.data')
        input()
        print(
            'Converting image buffer to a numpy array using np.asarray and image.data...'
        )
        start1 = time.perf_counter()
        nparray = np.asarray(image.data, dtype=np.uint8).reshape(
            (image.height, image.width))
        end1 = time.perf_counter()
        delta1 = end1 - start1
        print(f'...took {delta1:.6f} sec')

        print(nparray)

        print('Saving image...')
        im = img.fromarray(nparray)
        im.save('test1.png')
        print('Saved test1.png')

        print()
        print(
            'Press Enter to convert image using np.ctypeslib.as_array and image image.pdata'
        )
        input()
        print(
            'Converting image buffer with np.ctypeslib.as_array and image image.pdata...'
        )

        start2 = time.perf_counter()
        nparray2 = np.ctypeslib.as_array(
            image.pdata,
            shape=(image.height, image.width, int(
                image.bits_per_pixel / 8))).reshape(image.height, image.width)
        end2 = time.perf_counter()
        delta2 = end2 - start2
        print(f'...took {delta2:.6f} sec')

        print(nparray2)

        print('Saving image...')
        im2 = img.fromarray(nparray2)
        im.save('test2.png')
        print('Saved test2.png')

        device.requeue_buffer(image)