def main():

    init = zcam.PyInitParameters(
        camera_resolution=sl.PyRESOLUTION.PyRESOLUTION_HD720,
        depth_mode=sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE,
        coordinate_units=sl.PyUNIT.PyUNIT_METER,
        coordinate_system=sl.PyCOORDINATE_SYSTEM.
        PyCOORDINATE_SYSTEM_RIGHT_HANDED_Y_UP,
        sdk_verbose=True)
    cam = zcam.PyZEDCamera()
    status = cam.open(init)
    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        exit()

    transform = core.PyTransform()
    tracking_params = zcam.PyTrackingParameters(transform)
    cam.enable_tracking(tracking_params)

    runtime = zcam.PyRuntimeParameters()
    camera_pose = zcam.PyPose()

    viewer = tv.PyTrackingViewer()
    viewer.init()

    py_translation = core.PyTranslation()

    start_zed(cam, runtime, camera_pose, viewer, py_translation)

    viewer.exit()
    glutMainLoop()
Esempio n. 2
0
    def _start(self):
        # Open the camera
        if self.available():
            return True

        # Create a PyInitParameters object and set configuration parameters
        init_params = zcam.PyInitParameters()
        init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720  # Use 2K video mode
        # init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD1080  # Use HD1080 video mode
        # init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720
        # init_params.camera_fps = 10  # 30 is default
        # init_params.enable_right_side_measure = True
        init_params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_QUALITY
        init_params.coordinate_units = sl.PyUNIT.PyUNIT_MILLIMETER
        init_params.depth_minimum_distance = 300  # 300mm, 30cm

        err = self.zed.open(init_params)
        if err != tp.PyERROR_CODE.PySUCCESS:
            print("We failed to open the ZED camera, exit!")
            # exit(1)
            return False

        time.sleep(4)

        self._set_default_camera_settings()
        self.camera_settings_value = self.getParameters()

        K1, K2 = self.get_camera_parameters()
        K1 = np.array(K1).astype(np.float32).reshape(3, 3)
        K2 = np.array(K2).astype(np.float32).reshape(3, 3)
        self.cameraCalibration = CameraCalibration(leftK=K1, rightK=K2)

        return True
Esempio n. 3
0
def initZed(fps):
    # Create a PyZEDCamera object
    zed = zcam.PyZEDCamera()
    # Create a PyInitParameters object and set configuration parameters
    init_params = zcam.PyInitParameters()
    init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD1080  # Use HD1080 video mode
    init_params.camera_fps = fps  # Set fps at 30

    # Use a right-handed Y-up coordinate system
    init_params.coordinate_system = sl.PyCOORDINATE_SYSTEM.PyCOORDINATE_SYSTEM_RIGHT_HANDED_Y_UP
    init_params.coordinate_units = sl.PyUNIT.PyUNIT_METER  # Set units in meters

    # Open the camera
    err = zed.open(init_params)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Enable positional tracking with default parameters
    py_transform = core.PyTransform(
    )  # First create a PyTransform object for PyTrackingParameters object
    tracking_parameters = zcam.PyTrackingParameters(init_pos=py_transform)
    err = zed.enable_tracking(tracking_parameters)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    image = core.PyMat()
    zed_pose = zcam.PyPose()
    return zed, image, zed_pose
def main():
    print("Running...")
    init = zcam.PyInitParameters()
    cam = zcam.PyZEDCamera()
    if not cam.is_opened():
        print("Opening ZED Camera...")
    status = cam.open(init)
    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        exit()

    runtime = zcam.PyRuntimeParameters()
    mat = core.PyMat()

    print_camera_information(cam)
    print_help()

    key = ''
    while key != 113:  # for 'q' key
        err = cam.grab(runtime)
        if err == tp.PyERROR_CODE.PySUCCESS:
            cam.retrieve_image(mat, sl.PyVIEW.PyVIEW_LEFT)
            cv2.imshow("ZED", mat.get_data())
            key = cv2.waitKey(5)
            settings(key, cam, runtime, mat)
        else:
            key = cv2.waitKey(5)
    cv2.destroyAllWindows()

    cam.close()
    print("\nFINISH")
def main():
    # Create a PyZEDCamera object
    zed = zcam.PyZEDCamera()

    # Create a PyInitParameters object and set configuration parameters
    init_params = zcam.PyInitParameters()
    init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720  # Use HD720 video mode (default fps: 60)
    # Use a right-handed Y-up coordinate system
    init_params.coordinate_system = sl.PyCOORDINATE_SYSTEM.PyCOORDINATE_SYSTEM_RIGHT_HANDED_Y_UP
    init_params.coordinate_units = sl.PyUNIT.PyUNIT_METER  # Set units in meters

    # Open the camera
    err = zed.open(init_params)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Enable positional tracking with default parameters.
    # Positional tracking needs to be enabled before using spatial mapping
    py_transform = core.PyTransform()
    tracking_parameters = zcam.PyTrackingParameters(init_pos=py_transform)
    err = zed.enable_tracking(tracking_parameters)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Enable spatial mapping
    mapping_parameters = zcam.PySpatialMappingParameters()
    err = zed.enable_spatial_mapping(mapping_parameters)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Grab data during 500 frames
    i = 0
    py_mesh = mesh.PyMesh()  # Create a PyMesh object

    while i < 500:
        # For each new grab, mesh data is updated
        if zed.grab(zcam.PyRuntimeParameters()) == tp.PyERROR_CODE.PySUCCESS:
            # In the background, spatial mapping will use newly retrieved images, depth and pose to update the mesh
            mapping_state = zed.get_spatial_mapping_state()

            print("\rImages captured: {0} / 500 || {1}".format(
                i, mapping_state))

            i = i + 1

    print("\n")

    # Extract, filter and save the mesh in an obj file
    print("Extracting Mesh...\n")
    zed.extract_whole_mesh(py_mesh)
    print("Filtering Mesh...\n")
    py_mesh.filter(mesh.PyMeshFilterParameters()
                   )  # Filter the mesh (remove unnecessary vertices and faces)
    print("Saving Mesh...\n")
    py_mesh.save("mesh.obj")

    # Disable tracking and mapping and close the camera
    zed.disable_spatial_mapping()
    zed.disable_tracking()
    zed.close()
Esempio n. 6
0
    def init_zed(self):
        # Create a PyZEDCamera object
        zed = zcam.PyZEDCamera()

        # Create a PyInitParameters object and set configuration parameters
        init_params = zcam.PyInitParameters()
        init_params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_QUALITY  # Use PERFORMANCE depth mode
        init_params.coordinate_units = sl.PyUNIT.PyUNIT_METER  # Use milliliter units (for depth measurements)
        init_params.camera_fps = 30
        init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD1080
        init_params.depth_minimum_distance = 0.3
        init_params.coordinate_system = sl.PyCOORDINATE_SYSTEM.PyCOORDINATE_SYSTEM_IMAGE

        # Open the camera
        err = zed.open(init_params)
        if err != tp.PyERROR_CODE.PySUCCESS:
            exit(1)

        # Create and set PyRuntimeParameters after opening the camera
        self.runtime_parameters = zcam.PyRuntimeParameters()
        self.runtime_parameters.sensing_mode = sl.PySENSING_MODE.PySENSING_MODE_FILL  # Use STANDARD sensing mode

        image = core.PyMat()
        depth = core.PyMat()
        point_cloud = core.PyMat()

        return zed, image, depth, point_cloud
Esempio n. 7
0
def main():
    print("Running...")
    init = zcam.PyInitParameters()
    init.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE
    init.coordinate_units = sl.PyUNIT.PyUNIT_CENTIMETER

    cam = zcam.PyZEDCamera()
    if not cam.is_opened():
        print("Opening ZED Camera...")
    status = cam.open(init)
    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        print('error opening camera!! abort abort')
        exit()

    runtime = zcam.PyRuntimeParameters()
    mat = core.PyMat()

    print_camera_information(cam)

    key = ''
    while key != 113:  # for 'q' key
        err = cam.grab(runtime)
        if err == tp.PyERROR_CODE.PySUCCESS:
            cam.retrieve_image(mat, sl.PyVIEW.PyVIEW_DEPTH)

            cv2.imshow("ZED", mat.get_data())
            key = cv2.waitKey(5)
            # settings(key, cam, runtime, mat)
        else:
            key = cv2.waitKey(5)
    cv2.destroyAllWindows()

    cam.close()
    print("\nFINISH")
Esempio n. 8
0
    def __init__(self, model_path):
        print('[INFO] Capture: Setting up camera.')
        # Create a PyZEDCamera object
        self.zed = zcam.PyZEDCamera()

        # Create a PyInitParameters object and set configuration parameters
        init_params = zcam.PyInitParameters()
        init_params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE  # Use PERFORMANCE depth mode
        init_params.coordinate_units = sl.PyUNIT.PyUNIT_MILLIMETER  # Use milliliter units (for depth measurements)

        # Open the camera
        err = self.zed.open(init_params)
        if err != tp.PyERROR_CODE.PySUCCESS:
            exit(1)

        # Create and set PyRuntimeParameters after opening the camera
        self.runtime_parameters = zcam.PyRuntimeParameters()
        self.runtime_parameters.sensing_mode = sl.PySENSING_MODE.PySENSING_MODE_STANDARD  # Use STANDARD sensing mode

        i = 0  #counter
        self.image = core.PyMat()
        print('[INFO] Capture: Camera setup complete.')
        print('[INFO] Capture: Setting up model...')

        # load model once
        self.model = load_model(model_path)  #TODO hard code model
        print('[INFO] Capture: Model loaded successfully.')
Esempio n. 9
0
def main():
    # Create a PyZEDCamera object
    zed = zcam.PyZEDCamera()

    # Create a PyInitParameters object and set configuration parameters
    init_params = zcam.PyInitParameters()
    init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD1080  # Use HD1080 video mode
    init_params.camera_fps = 30  # Set fps at 30

    # Open the camera
    err = zed.open(init_params)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Capture 50 frames and stop
    i = 0
    image = core.PyMat()
    while i < 50:
        # Grab an image, a PyRuntimeParameters object must be given to grab()
        if zed.grab(zcam.PyRuntimeParameters()) == tp.PyERROR_CODE.PySUCCESS:
            # A new image is available if grab() returns PySUCCESS
            zed.retrieve_image(image, sl.PyVIEW.PyVIEW_LEFT)
            timestamp = zed.get_timestamp(sl.PyTIME_REFERENCE.PyTIME_REFERENCE_CURRENT)  # Get the timestamp at the time the image was captured
            print("Image resolution: {0} x {1} || Image timestamp: {2}\n".format(image.get_width(), image.get_height(),
                  timestamp))
            i = i + 1

    # Close the camera
    zed.close()
Esempio n. 10
0
    def __init__(self, inputQueue, outputQueue, visualize):
        self.inputQueue = inputQueue
        self.outputQueue = outputQueue
        #self.outputQueueImages = outputQueueImages
        self.visualize = visualize
        self.xlist = []
        self.ylist = []
        if (self.visualize):
            plt.figure(1)
        init = zcam.PyInitParameters(
            camera_resolution=sl.PyRESOLUTION.PyRESOLUTION_VGA,
            depth_mode=sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE,
            coordinate_units=sl.PyUNIT.PyUNIT_METER,
            coordinate_system=sl.PyCOORDINATE_SYSTEM.
            PyCOORDINATE_SYSTEM_RIGHT_HANDED_Y_UP,
            sdk_verbose=False)
        cam = zcam.PyZEDCamera()
        self.image = core.PyMat()
        status = cam.open(init)
        if status != tp.PyERROR_CODE.PySUCCESS:
            print(repr(status))
            exit()

        transform = core.PyTransform()
        tracking_params = zcam.PyTrackingParameters(transform)
        cam.enable_tracking(tracking_params)

        runtime = zcam.PyRuntimeParameters()
        camera_pose = zcam.PyPose()

        py_translation = core.PyTranslation()
        print("Starting ZEDPositioning")
        self.start_zed(cam, runtime, camera_pose, py_translation)
Esempio n. 11
0
def distance():
    # Create a PyZEDCamera object
    zed = zcam.PyZEDCamera()

    # Create a PyInitParameters object and set configuration parameters
    init_params = zcam.PyInitParameters()
    init_params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE  # Use PERFORMANCE depth mode
    init_params.coordinate_units = sl.PyUNIT.PyUNIT_MILLIMETER  # Use milliliter units (for depth measurements)

    # Open the camera
    err = zed.open(init_params)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Create and set PyRuntimeParameters after opening the camera
    runtime_parameters = zcam.PyRuntimeParameters()
    runtime_parameters.sensing_mode = sl.PySENSING_MODE.PySENSING_MODE_STANDARD  # Use STANDARD sensing mode
    # runtime_parameters.sensing_mode = sl.PySENSING_MODE.PySENSING_MODE_LAST # Use STANDARD sensing mode

    # Capture 50 images and depth, then stop
    i = 0
    image = core.PyMat()
    depth = core.PyMat()
    point_cloud = core.PyMat()

    while i < 500:
        # A new image is available if grab() returns PySUCCESS
        if zed.grab(runtime_parameters) == tp.PyERROR_CODE.PySUCCESS:
            # Retrieve left image
            zed.retrieve_image(image, sl.PyVIEW.PyVIEW_LEFT)
            # Retrieve depth map. Depth is aligned on the left image
            zed.retrieve_measure(depth, sl.PyMEASURE.PyMEASURE_DEPTH)
            # Retrieve colored point cloud. Point cloud is aligned on the left image.
            zed.retrieve_measure(point_cloud, sl.PyMEASURE.PyMEASURE_XYZRGBA)

            # Get and print distance value in mm at the center of the image
            # We measure the distance camera - object using Euclidean distance
            x = round(image.get_width() / 2)
            y = round(image.get_height() / 2)
            err, point_cloud_value = point_cloud.get_value(x, y)
            distance = math.sqrt(point_cloud_value[0] * point_cloud_value[0] +
                                 point_cloud_value[1] * point_cloud_value[1] +
                                 point_cloud_value[2] * point_cloud_value[2])

            if not np.isnan(distance) and not np.isinf(distance):
                distance = round(distance)
                print("Distance to Camera at ({0}, {1}): {2} mm\n".format(
                    x, y, distance))
                # Increment the loop
                i = i + 1
            else:
                print(
                    "Can't estimate distance at this position, move the camera\n"
                )
            sys.stdout.flush()

    # Close the camera

    zed.close()
Esempio n. 12
0
def detect_video(yolo):

    zed = zcam.PyZEDCamera()

    # Create a PyInitParameters object and set configuration parameters
    init_params = zcam.PyInitParameters()
    init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720
    init_params.camera_fps = 60

    init_params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE  # Use PERFORMANCE depth mode
    init_params.coordinate_units = sl.PyUNIT.PyUNIT_MILLIMETER  # Use milliliter units (for depth measurements)

    # Open the camera
    err = zed.open(init_params)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    frame = core.PyMat()

    # Create and set PyRuntimeParameters after opening the camera
    runtime_parameters = zcam.PyRuntimeParameters()
    runtime_parameters.sensing_mode = sl.PySENSING_MODE.PySENSING_MODE_STANDARD  # Use STANDARD sensing mode

    accum_time = 0
    curr_fps = 0
    fps = "FPS: ??"
    prev_time = timer()

    while True:
        if zed.grab(runtime_parameters) == tp.PyERROR_CODE.PySUCCESS:

            # A new image is available if grab() returns PySUCCESS
            zed.retrieve_image(frame, sl.PyVIEW.PyVIEW_LEFT)
            image = Image.fromarray(frame.get_data())

            image, voc_detections = detect_img(yolo, image.copy(), video=True)

            result = np.asarray(image)
            curr_time = timer()
            exec_time = curr_time - prev_time
            prev_time = curr_time
            accum_time = accum_time + exec_time
            curr_fps = curr_fps + 1
            if accum_time > 1:
                accum_time = accum_time - 1
                fps = "FPS: " + str(curr_fps)
                curr_fps = 0
            cv2.putText(result,
                        text=fps,
                        org=(3, 15),
                        fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                        fontScale=0.50,
                        color=(255, 0, 0),
                        thickness=2)
            cv2.namedWindow("result", cv2.WINDOW_NORMAL)
            cv2.imshow("result", result)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
Esempio n. 13
0
def main():
    print("Running...")
    init = zcam.PyInitParameters()
    init.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_QUALITY
    init.coordinate_units = sl.PyUNIT.PyUNIT_CENTIMETER

    cam = zcam.PyZEDCamera()
    if not cam.is_opened():
        print("Opening ZED Camera...")
    status = cam.open(init)
    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        print('error opening camera!! abort abort')
        exit()

    runtime = zcam.PyRuntimeParameters()
    mat = core.PyMat()
    thresholdMat = core.PyMat()
    print_camera_information(cam)
    '''
    python OpenCV Code
        
    img = cv.imread('gradient.png',0)
    ret,thresh1 = cv.threshold(img,127,255,cv.THRESH_BINARY)
    ret,thresh2 = cv.threshold(img,127,255,cv.THRESH_BINARY_INV)
    ret,thresh3 = cv.threshold(img,127,255,cv.THRESH_TRUNC)
    ret,thresh4 = cv.threshold(img,127,255,cv.THRESH_TOZERO)
    ret,thresh5 = cv.threshold(img,127,255,cv.THRESH_TOZERO_INV)
    titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
    images = [img, thresh1, thresh2, thresh3, thresh4, thresh5]
    '''
    '''
    # need gray image for near / far 
    grayImage.allocate(kinect.width, kinect.height);
	grayThreshNear.allocate(kinect.width, kinect.height);
	grayThreshFar.allocate(kinect.width, kinect.height);
	'''

    key = ''
    while key != 113:  # for 'q' key
        err = cam.grab(runtime)
        if err == tp.PyERROR_CODE.PySUCCESS:
            cam.retrieve_image(mat, sl.PyVIEW.PyVIEW_DEPTH)

            thresholdMat = cv2.threshold(mat.get_data(), 128, 255,
                                         cv2.THRESH_BINARY)
            cv2.imshow("ZED", thresholdMat)
            key = cv2.waitKey(5)

            # settings(key, cam, runtime, mat)
        else:
            key = cv2.waitKey(5)
    cv2.destroyAllWindows()

    cam.close()
    print("\nFINISH")
def main():
    # Create a PyZEDCamera object
    zed = zcam.PyZEDCamera()

    # Create a PyInitParameters object and set configuration parameters
    init_params = zcam.PyInitParameters()
    init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720  # Use HD720 video mode (default fps: 60)
    # Use a right-handed Y-up coordinate system
    init_params.coordinate_system = sl.PyCOORDINATE_SYSTEM.PyCOORDINATE_SYSTEM_RIGHT_HANDED_Y_UP
    init_params.coordinate_units = sl.PyUNIT.PyUNIT_METER  # Set units in meters

    # Open the camera
    err = zed.open(init_params)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Enable positional tracking with default parameters
    py_transform = core.PyTransform(
    )  # First create a PyTransform object for PyTrackingParameters object
    tracking_parameters = zcam.PyTrackingParameters(init_pos=py_transform)
    err = zed.enable_tracking(tracking_parameters)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Track the camera position during 1000 frames
    i = 0
    zed_pose = zcam.PyPose()
    runtime_parameters = zcam.PyRuntimeParameters()

    while i < 1000:
        if zed.grab(runtime_parameters) == tp.PyERROR_CODE.PySUCCESS:
            # Get the pose of the left eye of the camera with reference to the world frame
            zed.get_position(zed_pose,
                             sl.PyREFERENCE_FRAME.PyREFERENCE_FRAME_WORLD)

            # Display the translation and timestamp
            py_translation = core.PyTranslation()
            tx = round(zed_pose.get_translation(py_translation).get()[0], 3)
            ty = round(zed_pose.get_translation(py_translation).get()[1], 3)
            tz = round(zed_pose.get_translation(py_translation).get()[2], 3)
            print("Translation: Tx: {0}, Ty: {1}, Tz {2}, Timestamp: {3}\n".
                  format(tx, ty, tz, zed_pose.timestamp))

            # Display the orientation quaternion
            py_orientation = core.PyOrientation()
            ox = round(zed_pose.get_orientation(py_orientation).get()[0], 3)
            oy = round(zed_pose.get_orientation(py_orientation).get()[1], 3)
            oz = round(zed_pose.get_orientation(py_orientation).get()[2], 3)
            ow = round(zed_pose.get_orientation(py_orientation).get()[3], 3)
            print("Orientation: Ox: {0}, Oy: {1}, Oz {2}, Ow: {3}\n".format(
                ox, oy, oz, ow))

            i = i + 1

    # Close the camera
    zed.close()
Esempio n. 15
0
def initCam():
    #myCam = cv2.VideoCapture(0) # Other camera than ZED
    myCam = zcam.PyZEDCamera()  # only for ZED camera
    if not myCam.is_opened():
        print("Opening ZED Camera...")
    init = zcam.PyInitParameters()
    status = myCam.open(init)
    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        exit()
    return myCam
Esempio n. 16
0
def ZED_live():
    zed = zcam.PyZEDCamera()
    # Create a PyInitParameters object and set configuration parameters
    init_params = zcam.PyInitParameters()
    init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720
    init_params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE   # Use HD720 video mode (default fps: 60)
    # Use a right-handed Y-up coordinate system
    #init_params.coordinate_system = sl.PyCOORDINATE_SYSTEM.PyCOORDINATE_SYSTEM_RIGHT_HANDED_Y_UP
    init_params.coordinate_units = sl.PyUNIT.PyUNIT_MILLIMETER  # Set units in meters
    err = zed.open(init_params)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)
    return zed, zcam.PyRuntimeParameters()
def main():
    init = zcam.PyInitParameters()
    cam  = zcam.PyZEDCamera()
    if cam.is_opened():
        pass
    else:
        print("Opening ZED Camera...")

    init.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD1080
    status = cam.open(init)
    cam.set_camera_settings(sl.PyCAMERA_SETTINGS.PyCAMERA_SETTINGS_AUTO_WHITEBALANCE, 1, False)
    if status == tp.PyERROR_CODE.PySUCCESS:
        pass
    else:
        print(repr(status))
        exit()

    runtime = zcam.PyRuntimeParameters()
    mat = core.PyMat()

    # make save directory of images
    cwd      = os.getcwd()
    dir_name = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    dir_path = cwd + "/" + dir_name

    if os.path.exists(dir_path):
        pass
    else:
        os.makedirs(dir_path)

    key = ''
    count = 0
    while key != 113:
        err = cam.grab(runtime)
        if err == tp.PyERROR_CODE.PySUCCESS:
            cam.retrieve_image(mat, sl.PyVIEW.PyVIEW_LEFT)
            
            img = mat.get_data()
            cv2.imshow("ZED", img)

            file_name = ("image_{0:08d}.jpg".format(count))
            cv2.imwrite(dir_path + "/" + file_name, img)
            count = count + 1
                        
            key = cv2.waitKey(10)
        else:
            key = cv2.waitKey(10)
    cv2.destroyAllWindows()

    cam.close()
    print("\nFINISH")
Esempio n. 18
0
def default_init_params():
    params = zcam.PyInitParameters()  # creates a place to store params
    params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720
    params.camera_fps = 60
    # options are HD2K (15fps), HD1080 (max 30fps), HD720 (max 60fps), WVGA (max 100fps)
    params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE
    # options are NONE, PERFORMANCE, MEDIUM, QUALITY, ULTRA
    params.depth_stabilization = True
    params.depth_minimum_distance = 7
    # less than 10, lower numbers increase grab() time
    params.coordinate_system = sl.PyCOORDINATE_SYSTEM.PyCOORDINATE_SYSTEM_RIGHT_HANDED_Z_UP
    params.coordinate_units = sl.PyUNIT.PyUNIT_FOOT
    # options are MILLIMETER, CENTIMETER, METER, INCH, FOOT
    return params
Esempio n. 19
0
def main():

    if len(sys.argv) != 2:
        print("Please specify path to .svo file.")
        exit()

    filepath = sys.argv[1]
    print("Reading SVO file: {0}".format(filepath))

    init = zcam.PyInitParameters(svo_input_filename=filepath,
                                 svo_real_time_mode=False)
    cam = zcam.PyZEDCamera()
    status = cam.open(init)
    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        exit()

    runtime = zcam.PyRuntimeParameters()
    mat = core.PyMat()

    #if a directory doesn't already exist, create one
    save_dir = "".join(filepath.split('.')[:-1])
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
    img_num = 0

    key = ''
    #print("  Save the current image:     s")
    #print("  Quit the video reading:     q\n")
    while key != 113:  # for 'q' key
        img_path = save_dir + "/{:04d}.png".format(img_num)
        err = cam.grab(runtime)
        if err == tp.PyERROR_CODE.PySUCCESS:
            cam.retrieve_image(mat)
            cv2.imwrite(img_path, mat.get_data())
            #cv2.imshow("ZED", mat.get_data())
            key = cv2.waitKey(1)
            saving_image(key, mat)
        else:
            #key = cv2.waitKey(1)
            key = 113

    cv2.destroyAllWindows()

    #print_camera_information(cam)
    #saving_depth(cam)
    #saving_point_cloud(cam)

    cam.close()
    print("\nFINISH")
Esempio n. 20
0
def main():
    print("Running...")
    init = zcam.PyInitParameters()
    init.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720
    init.camera_linux_id = 0
    init.camera_fps = 30  # The framerate is lowered to avoid any USB3 bandwidth issues
    cam = zcam.PyZEDCamera()
    if not cam.is_opened():
        print("Opening ZED Camera 1...")
    status = cam.open(init)
    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        exit()

    init.camera_linux_id = 1  # selection of the ZED ID
    cam2 = zcam.PyZEDCamera()
    if not cam2.is_opened():
        print("Opening ZED Camera 2...")
    status = cam2.open(init)
    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        exit()

    runtime = zcam.PyRuntimeParameters()
    mat = core.PyMat()
    mat2 = core.PyMat()

    print_camera_information(cam)
    print_camera_information(cam2)

    key = ''
    while key != 113:  # for 'q' key
        # The computation could also be done in a thread, one for each camera
        err = cam.grab(runtime)
        if err == tp.PyERROR_CODE.PySUCCESS:
            cam.retrieve_image(mat, sl.PyVIEW.PyVIEW_LEFT)
            cv2.imshow("ZED 1", mat.get_data())

        err = cam2.grab(runtime)
        if err == tp.PyERROR_CODE.PySUCCESS:
            cam2.retrieve_image(mat2, sl.PyVIEW.PyVIEW_LEFT)
            cv2.imshow("ZED 2", mat2.get_data())

        key = cv2.waitKey(5)
    cv2.destroyAllWindows()

    cam.close()
    print("\nFINISH")
def main():

    if len(sys.argv) != 2:
        print("Please specify path to .svo file.")
        exit()

    filepath = sys.argv[1]
    print("Reading SVO file: {0}".format(filepath))

    cam = zcam.PyZEDCamera()
    init = zcam.PyInitParameters(svo_input_filename=filepath)
    status = cam.open(init)
    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        exit()

    runtime = zcam.PyRuntimeParameters()
    spatial = zcam.PySpatialMappingParameters()
    transform = core.PyTransform()
    tracking = zcam.PyTrackingParameters(transform)

    cam.enable_tracking(tracking)
    cam.enable_spatial_mapping(spatial)

    pymesh = mesh.PyMesh()
    print("Processing...")
    for i in range(200):
        cam.grab(runtime)
        cam.request_mesh_async()

    cam.extract_whole_mesh(pymesh)
    cam.disable_tracking()
    cam.disable_spatial_mapping()

    filter_params = mesh.PyMeshFilterParameters()
    filter_params.set(mesh.PyFILTER.PyFILTER_HIGH)
    print("Filtering params : {0}.".format(pymesh.filter(filter_params)))

    apply_texture = pymesh.apply_texture(
        mesh.PyMESH_TEXTURE_FORMAT.PyMESH_TEXTURE_RGBA)
    print("Applying texture : {0}.".format(apply_texture))
    print_mesh_information(pymesh, apply_texture)

    save_filter(filter_params)
    save_mesh(pymesh)
    cam.close()
    print("\nFINISH")
Esempio n. 22
0
def capture_thread_func(svo_filepath=None):
    global image_np_global, depth_np_global, exit_signal, new_data

    zed = zcam.PyZEDCamera()

    # Create a PyInitParameters object and set configuration parameters
    init_params = zcam.PyInitParameters()
    init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720  # Use HD1080 video mode
    init_params.camera_fps = 30  # Set fps at 30
    init_params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE
    init_params.coordinate_units = sl.PyUNIT.PyUNIT_METER
    init_params.svo_real_time_mode = False
    if svo_filepath is not None:
        init_params.svo_input_filename = svo_filepath

    # Open the camera
    err = zed.open(init_params)
    print(err)
    while err != tp.PyERROR_CODE.PySUCCESS:
        err = zed.open(init_params)
        print(err)
        sleep(1)

    image_mat = core.PyMat()
    depth_mat = core.PyMat()
    runtime_parameters = zcam.PyRuntimeParameters()

    while not exit_signal:
        if zed.grab(runtime_parameters) == tp.PyERROR_CODE.PySUCCESS:
            zed.retrieve_image(image_mat,
                               sl.PyVIEW.PyVIEW_LEFT,
                               width=width,
                               height=height)
            zed.retrieve_measure(depth_mat,
                                 sl.PyMEASURE.PyMEASURE_XYZRGBA,
                                 width=width,
                                 height=height)
            lock.acquire()
            image_np_global = load_image_into_numpy_array(image_mat)
            depth_np_global = load_depth_into_numpy_array(depth_mat)
            new_data = True
            lock.release()

        sleep(0.01)

    zed.close()
Esempio n. 23
0
def main():

    # sys.argv[1] = '/home/ogai1234/Desktop/la.svo'
    # if len(sys.argv) != 2:
    # 	print("Please specify path to .svo file.")
    # 	exit()

    # filepath = sys.argv[1]
    # global n
    # n = 1
    #change this name WHICH is in desktop
    filename = ['3318']

    for i in range(len(filename)):
        print("Reading SVO file: {0}".format(filename[i]))

        os.mkdir('/home/ogai1234/Desktop/' + filename[i])

        init = zcam.PyInitParameters(svo_input_filename=(filename[i] + '.svo'),
                                     svo_real_time_mode=False)
        cam = zcam.PyZEDCamera()
        status = cam.open(init)
        if status != tp.PyERROR_CODE.PySUCCESS:
            print(repr(status))
            exit()

        runtime = zcam.PyRuntimeParameters()
        mat = core.PyMat()
        m = '2018_' + filename[i] + '_'
        j = 0
        key = ''
        while status:
            if cam.grab(runtime) == tp.PyERROR_CODE.PySUCCESS:
                cam.retrieve_image(mat)
                cv2.imshow("ZED", mat.get_data())
                if j % 10 == 0:
                    filepath = '/home/ogai1234/Desktop/' + str(
                        filename[i]) + '/' + m + str(int(math.floor(
                            j / 10))) + '.jpg'
                    img = mat.write(filepath)
                key = cv2.waitKey(1)
                # print('11111111111111111111')
                # n = n +1
                j = j + 1
        cam.close()
        print("\nFINISH")
Esempio n. 24
0
def ZED_SVO():
    zed = zcam.PyZEDCamera()
    # Create a PyInitParameters object and set configuration parameters
    #init_params = zcam.PyInitParameters()
    filepath = sys.argv[1]
    init_params = zcam.PyInitParameters(svo_input_filename=filepath,svo_real_time_mode=False)
    init_params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE  # Use PERFORMANCE depth mode
    init_params.coordinate_units = sl.PyUNIT.PyUNIT_MILLIMETER  # Use milliliter units (for depth measurements)

    # Open the camera
    err = zed.open(init_params)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Create and set PyRuntimeParameters after opening the camera
    runtime_parameters = zcam.PyRuntimeParameters()
    runtime_parameters.sensing_mode = sl.PySENSING_MODE.PySENSING_MODE_STANDARD  # Use STANDARD sensing mode
    return zed, runtime_parameters
def main():
    # Create a PyZEDCamera object
    zed = zcam.PyZEDCamera()

    # Create a PyInitParameters object and set configuration parameters
    init_params = zcam.PyInitParameters()
    init_params.sdk_verbose = False

    # Open the camera
    err = zed.open(init_params)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Get camera information (ZED serial number)
    zed_serial = zed.get_camera_information().serial_number
    print("Hello! This is my serial number: {0}".format(zed_serial))

    # Close the camera
    zed.close()
Esempio n. 26
0
    def __init__(self, resolution='720', depth_mode='ultra', depth=True, color=True):
        self.depth = depth
        self.color = color
        self.init = zcam.PyInitParameters()

        resolutions = {'720': sl.PyRESOLUTION.PyRESOLUTION_HD720,
                       '1080':sl.PyRESOLUTION.PyRESOLUTION_HD1080,
                       '2K'  :sl.PyRESOLUTION.PyRESOLUTION_HD2K}

        depthModes = {'perf': sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE,
                      'med': sl.PyDEPTH_MODE.PyDEPTH_MODE_MEDIUM,
                      'qual': sl.PyDEPTH_MODE.PyDEPTH_MODE_QUALITY,
                      'ultra': sl.PyDEPTH_MODE.PyDEPTH_MODE_ULTRA,}

        self.init.camera_resolution = resolutions[resolution]
        self.init.depth_mode = depthModes[depth_mode]
        self.cam = zcam.PyZEDCamera()
        self.inQ, self.outQ = Queue(maxsize=1), Queue(maxsize=1)
        return
Esempio n. 27
0
def main():
    if len(sys.argv) != 2:
        print("Please specify path to .svo file.")
        exit()

    filepath = sys.argv[1]
    print("Reading SVO file: {0}".format(filepath))

    init = zcam.PyInitParameters(svo_input_filename=filepath, camera_image_flip=False, svo_real_time_mode=False)

    cam = zcam.PyZEDCamera()
    status = cam.open(init)
    zed_cuda_ctx=PyCudaContext()

    zed_cuda_ctx.pop_ctx()
    predictor = predict.Prediction()
    zed_cuda_ctx.push_ctx()

    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        exit()

    fourcc = cv2.VideoWriter_fourcc(*'mp4v')  # Be sure to use lower case
    out = cv2.VideoWriter('output.mp4', fourcc, 10.0, (1920, 1080))

    runtime = zcam.PyRuntimeParameters()
    mat = core.PyMat()
    while True:  # for 'q' key
        err = cam.grab(runtime)
        if err == tp.PyERROR_CODE.PySUCCESS:
            cam.retrieve_image(mat)
            npimg = mat.get_data().astype(np.float32)[:,:,:3]
            zed_cuda_ctx.pop_ctx()
            prediction = predictor.infer(npimg, overlay=True)
            zed_cuda_ctx.push_ctx()
            out_image = cv2.cvtColor(np.array(prediction), cv2.COLOR_RGB2BGR)
            cv2.imshow('Perception', out_image)
            out.write(out_image)
            key = cv2.waitKey(1)
    cv2.destroyAllWindows()
    out.release()
    cam.close()
    print("\nFINISH")
Esempio n. 28
0
def init_zed():
    global zed
    global runtime_parameters

    zed = zcam.PyZEDCamera()

    init_params = zcam.PyInitParameters()
    init_params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE
    init_params.coordinate_units = sl.PyUNIT.PyUNIT_MILLIMETER

    err = zed.open(init_params)
    if err == tp.PyERROR_CODE.PySUCCESS:
        print("ZED Opened")
        pass
    else:
        print("init_zed failed!! ERROR_CODE:%d" % err)
        exit(1)

    runtime_parameters = zcam.PyRuntimeParameters()
    runtime_parameters.sensing_mode = sl.PySENSING_MODE.PySENSING_MODE_STANDARD
def main():
    print("\n\n\n############################################################")
    print("Welcome to the Artificial Intelligence Lecture 2: Perception")
    print("############################################################ \n")

    print("\n **** Codeexample 2: Image Capturing  *** \n")


    print("\n1. Opening the camera by creating and Camera Object and initializing the camera:")
    # Create a PyZEDCamera object
    zed = zcam.PyZEDCamera()

    # Create a PyInitParameters object and set configuration parameters
    init_params = zcam.PyInitParameters()
    init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD1080  # Use HD1080 video mode: VGA,HD720,HD1080,HD2k
    init_params.camera_fps = 30  # Set fps at 30: 15,30, 60,100

    # Open the camera
    err = zed.open(init_params)
    if err != tp.PyERROR_CODE.PySUCCESS:
        exit(1)

    # Capture 5 frames and stop
    i = 0
    image = core.PyMat()
    runtime_parameters = zcam.PyRuntimeParameters()
    while i < 1:
        # Grab an image, a PyRuntimeParameters object must be given to grab()
        if zed.grab(runtime_parameters) == tp.PyERROR_CODE.PySUCCESS:
            # A new image is available if grab() returns PySUCCESS
            zed.retrieve_image(image, sl.PyVIEW.PyVIEW_LEFT)
            timestamp = zed.get_timestamp(sl.PyTIME_REFERENCE.PyTIME_REFERENCE_CURRENT)  # Get the timestamp at the time the image was captured
            print("Image resolution: {0} x {1} || Image timestamp: {2}\n".format(image.get_width(), image.get_height(),
                  timestamp))
            cv2.imwrite('Pictures/Image_1.png',image.get_data())

            i = i + 1


    # Close the camera
    zed.close()
Esempio n. 30
0
def main():

    if len(sys.argv) != 2:
        print("Please specify path to .svo file.")
        exit()

    filepath = sys.argv[1]
    print("Reading SVO file: {0}".format(filepath))

    init = zcam.PyInitParameters(svo_input_filename=filepath)
    cam = zcam.PyZEDCamera()
    status = cam.open(init)
    if status != tp.PyERROR_CODE.PySUCCESS:
        print(repr(status))
        exit()

    runtime = zcam.PyRuntimeParameters()
    mat = core.PyMat()

    key = ''
    print("  Save the current image:     s")
    print("  Quit the video reading:     q\n")
    while key != 113:  # for 'q' key
        err = cam.grab(runtime)
        if err == tp.PyERROR_CODE.PySUCCESS:
            cam.retrieve_image(mat)
            cv2.imshow("ZED", mat.get_data())
            key = cv2.waitKey(1)
            saving_image(key, mat)
        else:
            key = cv2.waitKey(1)
    cv2.destroyAllWindows()

    print_camera_information(cam)
    saving_depth(cam)
    saving_point_cloud(cam)

    cam.close()
    print("\nFINISH")