SDK 0.6 Fix the Cube at a certain distance from the user


Hi, everyone
I am using the last SDK 0.6 and trying to put the box at a fixed distance from the camera as well in your Scanner App. I referred to a post here to change it but it didn’t work for 0.6 when I changed the line like @jim_selikoff mentioned in his post: [quote=“jim_selikoff, post:8, topic:5065”]
You could try translating the final camera pose calculated by STCameraPoseInitializer in enterScanningState, e.g.:

_slamState.tracker.initialCameraPose = GLKMatrix4Translate(_slamState.cameraPoseInitializer.cameraPose, 0.0, 0.0, 0.05);

Here’s a video showing the results:

The box disappears after I press Scan and won’t scan anything. I want my cube to behave like it does in this video:
Except I do not want the cube to constantly try to find a plane and I want it to put at a fixed distance in z-direction like for example 1 meter from the camera.
Thank you in advance.

How does 'Detect Inner Pixels' work?
Set vertical position of scan volume


This topic has come up from time to time, and I’m certain that many devs have solved it individually. This time around I wanted to offer a step by step example of how to accomplish fixed cube placement.

Here are the basic steps:

  1. In setupSLAM, use STCameraPoseInitializerStrategyGravityAlignedAtOrigin when initializing STCameraPoseInitializer

  2. In setupMapper, set the kSTMapperVolumeHasSupportPlaneKey mapper option to @NO

  3. Since STCameraPoseInitializerStrategyGravityAlignedAtOrigin doesn’t require depth information we can pass nil as the depthFrame parameter in updateCameraPoseWithGravity:

    bool success = [_slamState.cameraPoseInitializer updateCameraPoseWithGravity:_lastGravity depthFrame:nil error:nil];

  4. Also while in ScannerStateCubePlacement state, we can tell the cube renderer there is no support plane since our strategy is not looking for one:

[_display.cubeRenderer setCubeHasSupportPlane:NO];

  1. For this example I added a GLKMatrix4 to struct SlamData with a fixed z-offset of 1 meter:
    GLKMatrix4 cubePose = GLKMatrix4Translate(GLKMatrix4Identity, 0.0, 0.0, -1.0);

  2. In renderSceneForDepthFrame while in ScannerStateCubePlacement add an offset to center the cube:

    float xOffset = _slamState.cameraPoseInitializer.volumeSizeInMeters.x / 2.0;
    float yOffset = _slamState.cameraPoseInitializer.volumeSizeInMeters.y / 2.0;

    _slamState.cubePose = GLKMatrix4Translate(cameraViewpoint, xOffset, yOffset, -1.0);

_slamState.cubePose will now be used instead of cameraViewpoint to render the cube outline and highlighted depth.

  1. Finally, in enterScanningState initialize the tracker’s camera pose using the offset cube, with some tweaks to account for the color-to-depth camera rigid body transform:

    GLKMatrix4 colorCameraPoseInSensorCoordinateSpace;
    [_sensorController colorCameraPoseInSensorCoordinateFrame:colorCameraPoseInSensorCoordinateSpace.m];

    bool invertible;
    GLKMatrix4 colorCameraInversePose = GLKMatrix4Invert (colorCameraPoseInSensorCoordinateSpace, &invertible);

    _slamState.cubePose = GLKMatrix4Multiply(_slamState.cubePose, colorCameraInversePose);

    _slamState.tracker.initialCameraPose = _slamState.cubePose;

Those are the basic steps! Here’s a link to a set of diff patches to the stock 0.6 SDK Scanner sample with the modifications outlined above:

Thanks @tuna.ozerdem for re-introducing this topic, and for your help testing the tweak!


How to scan rotating object or person?
Cube Size set with predefined sizes
How can I prevent the Bounding Box from jumping around?
Cube Size set with predefined sizes
Initial cube position
Room setup for 3D scanning where the object is hanging
Problem at eye level on scan face in high resolution
Need to scan foot palm with rectangular size cube and cube distance of 30cm from scanner.
Scanning without support plane
What properties I can Set or Change to change scanner box frame?
Center cube placement bounding box with gravityAlignedAtOrigin STCameraPoseInitializerStrategy?

Thank for this step by step.

However now If I scan an object which is on a table, in addition to the object, the scanners scans the table (support) whereas before it took only the object.
Is there a way to make it happen again ?



You can tweak _slamState.tracker.initialCameraPose before scanning begins as shown here:



Thank for your reply.
However I cannot access to your link. I have his message : “Sorry, you don’t have access to that topic!”

Volume Box Offset Into Support Plane

Here it is:

bool invertible;
GLKMatrix4 cubePose = GLKMatrix4Invert (_slamState.cameraPoseInitializer.cameraPose, &invertible);
cubePose = GLKMatrix4Translate(cubePose, 0, yOffset, 0);
GLKMatrix4 cameraPose = GLKMatrix4Invert (cubePose, &invertible);

_slamState.tracker.initialCameraPose = cameraPose;


Jim this tweak has to be done instead of :

bool invertible;
GLKMatrix4 colorCameraInversePose = GLKMatrix4Invert (colorCameraPoseInSensorCoordinateSpace, &invertible);

_slamState.cubePose = GLKMatrix4Multiply(_slamState.cubePose, colorCameraInversePose);

_slamState.tracker.initialCameraPose = _slamState.cubePose; 

Right ? Because I’m doing that but when I touch the scan button, the cube moved suddenly almost out of the screen…




The offset tweak I posted a few days ago assumed tabletop pose initializer strategy. For the fixed cube case, try inserting this just before bool invertible:

float yOffset = -0.01;
colorCameraPoseInSensorCoordinateSpace = GLKMatrix4Translate(colorCameraPoseInSensorCoordinateSpace, 0, yOffset, 0);



Would these changes also work in the more recent Scanner apps (Swift 4 etc.)?

For example I don’t see how to access “colorCameraPoseInSensorCoordinateSpace” from the enterScanningState method?

Any help appreciated :slight_smile: