Beispiel #1
0
def get_ir_image(cam_handle):
    logger = logging.getLogger(__name__)

    frame = tof.Frame()
    status = cam_handle.requestFrame(frame)
    #logger.debug(status)

    ir_image = np.array(frame.getData(tof.FrameDataType.IR), copy=True)
    return ir_image
Beispiel #2
0
print("system.getAvailableFrameTypes()", status)
print(types)

status = camera1.initialize()
print("camera1.initialize()", status)

camDetails = tof.CameraDetails()
status = camera1.getDetails(camDetails)
print("system.getDetails()", status)
print("camera1 details:", "id:", camDetails.cameraId, "connection:",
      camDetails.connection)

status = camera1.setFrameType(types[0])
print("camera1.setFrameType()", status)

status = camera1.setMode(modes[0])
print("camera1.setMode()", status)

frame = tof.Frame()
status = camera1.requestFrame(frame)
print("camera1.requestFrame()", status)

frameDetails = tof.FrameDetails()
status = frame.getDetails(frameDetails)
print("frame.getDetails()", status)
print("frame details:", "width:", frameDetails.width, "height:",
      frameDetails.height, "type:", frameDetails.type)

image = np.array(frame.getData(tof.FrameDataType.Depth), copy=False)
print(image)
Beispiel #3
0
def run_example(remote):
    cam_ip = ''
    if remote is not None:
        ip = ipaddress.ip_address(remote)
        print('Running script for a camera connected over Ethernet at ip:', ip)
        cam_ip = remote

    system = tof.System()
    status = system.initialize()

    #Specify if you want to load firmware from lf files, or from EEPROM
    from_software = True

    if (from_software):
        #Choose firmware path from here
        firmware_path = "config/BM_Kit/Near/"

        logger.info("Programming firmware from : " + firmware_path)
        cam_handle = device.open_device2(system, cam_ip)
        device.program_firmware2(cam_handle, firmware_path)

        # The following parameters must be specified if firmware is loaded from software
        sw_gain = 1
        sw_offset = 0

    else:
        #Specify which mode to load from EEPROM 'near', 'medium', 'far'
        mode = 'near'

        cameras = []
        if not cam_ip:
            status = system.getCameraList(cameras)
            logger.info("system.getCameraList()" + str(status))
        else:
            status = system.getCameraListAtIp(cameras, cam_ip)
            logger.info("system.getCameraListAtIp()" + str(status))

        cam_handle = cameras[0]

        modes = []
        status = cam_handle.getAvailableModes(modes)
        logger.info("system.getAvailableModes()" + str(status))
        logger.info(str(modes))

        types = []
        status = cam_handle.getAvailableFrameTypes(types)
        logger.info("system.getAvailableFrameTypes()" + str(status))
        logger.info(str(types))

        status = cam_handle.initialize()
        logger.info("cam_handle.initialize()" + str(status))

        status = cam_handle.setFrameType(types[0])
        logger.info("cam_handle.setFrameType()" + str(status))
        logger.info(types[0])

        status = cam_handle.setMode(mode)
        logger.info("cam_handle.setMode()" + str(status))

        frame = tof.Frame()

    logger.info("Device Programmed")

    i = 0

    # Specify frames to capture to output averaged data
    avg_vals = 1
    values_depth = np.zeros(avg_vals)
    values_ir = np.zeros(avg_vals)
    while (True):

        if (from_software):
            # Get depth and ir frames
            depth_image, ir_image = device.get_depth_ir_image(cam_handle)
            # Apply gain and offset
            depth_image = (depth_image * sw_gain) + sw_offset
        else:
            status = cam_handle.requestFrame(frame)
            depth_image = np.array(frame.getData(tof.FrameDataType.Depth),
                                   dtype="uint16",
                                   copy=False)
            ir_image = np.array(frame.getData(tof.FrameDataType.IR),
                                dtype="uint16",
                                copy=False)

        depth_image_size = (int(depth_image.shape[0] / 2),
                            depth_image.shape[1])
        depth_image_2 = np.resize(depth_image, depth_image_size)
        depth_image_2 = cv2.flip(depth_image_2, 1)
        depth_image_2 = np.uint8(depth_image_2)
        color_depth = cv2.applyColorMap(depth_image_2, cv2.COLORMAP_RAINBOW)

        #Draw rectangle at the center of depth image
        cv2.rectangle(color_depth, (315, 235), (325, 245), (0, 0, 0), 2)

        ir_image_2 = np.uint8(255 * (ir_image / 4095))
        ir_image_2.resize((480, 640))
        ir_image_2 = cv2.flip(ir_image_2, 1)
        ir_image_2 = cv2.applyColorMap(ir_image_2, cv2.COLORMAP_BONE)

        #Output images as .png
        cv2.imwrite('ir.png', ir_image_2)
        cv2.imwrite('depth.png', color_depth)

        #Uncomment if running example on 96/Arrow board with HDMI to show stream data on monitor
        #cv2.namedWindow("Depth", cv2.WINDOW_AUTOSIZE)
        #cv2.imshow( "Depth", color_depth)
        #cv2.imshow( "IR", ir_image_2)

        #if cv2.waitKey(1) >= 0:
        #        break

        # values_depth[i] = depth_image[240,320]
        # values_ir[i] = ir_image[240,320]
        # i = i + 1
        # # Generates stats for middle pixel
        # if i == avg_vals:
        # Depth = np.average(values_depth)
        # ir = np.average(values_ir)
        # Std = np.std(values_depth)
        # Noise = (Std/Depth) * 100
        # print('Depth:' + str(Depth))
        # print('STD:' + str(Std))
        # print('N%:' + str(Noise))
        # print('IR:' + str(ir))
        # i = 0

        print(get_TAL_values(cam_handle))