Log in or register to post comments

how to obtain the location of the viewpoint.

March 18, 2012 - 8:43pm #1

First of all, please forgive my poor English.
I want to know how to obtain the location of the viewpoint.
In xcode, I know that 3d objects modelViewMatrix.
Can I calculate the location of the point of view?

Re: how to obtain the location of the viewpoint.

April 13, 2012 - 3:44am #5

Got it - I forgot to scale between camera pixel coordinates and screen pixel coordinates (on iPhone the scale is 1), so the two helper functions should be:

- (CGPoint) projectCoord:(CGPoint)coord inView:(const QCAR::CameraCalibration&)cameraCalibration andPose:(QCAR::Matrix34F)pose withOffset:(CGPoint)offset andScale:(CGFloat)scale
    CGPoint converted;
    QCAR::Vec3F vec(coord.x,coord.y,0);
    QCAR::Vec2F sc = QCAR::Tool::projectPoint(cameraCalibration, pose, vec);
    converted.x = sc.data[0]*scale - offset.x;
    converted.y = sc.data[1]*scale - offset.y;
    return converted;

- (void) calcScreenCoordsOf:(CGSize)target inView:(CGFloat *)matrix inPose:(QCAR::Matrix34F)pose
    // 0,0 is at centre of target so extremities are at w/2,h/2
    CGFloat w = target.width/2;
    CGFloat h = target.height/2;
    // need to account for the orientation on view size
    CGFloat viewWidth = self.frame.size.height; // Portrait
    CGFloat viewHeight = self.frame.size.width; // Portrait    
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if (UIInterfaceOrientationIsLandscape(orientation))
        viewWidth = self.frame.size.width;
        viewHeight = self.frame.size.height;        
    // calculate any mismatch of screen to video size
    QCAR::CameraDevice& cameraDevice = QCAR::CameraDevice::getInstance();
    const QCAR::CameraCalibration& cameraCalibration = cameraDevice.getCameraCalibration();
    QCAR::VideoMode videoMode = cameraDevice.getVideoMode(QCAR::CameraDevice::MODE_DEFAULT);
    CGFloat scale = viewWidth/videoMode.mWidth;
    if (videoMode.mHeight * scale < viewHeight)
        scale = viewHeight/videoMode.mHeight;
    CGFloat scaledWidth = videoMode.mWidth * scale;
    CGFloat scaledHeight = videoMode.mHeight * scale;
    CGPoint margin = {(scaledWidth - viewWidth)/2, (scaledHeight - viewHeight)/2};
    // now project the 4 corners of the target
    ImageTargetsAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    delegate.s0 = [self projectCoord:CGPointMake(-w,h) inView:cameraCalibration andPose:pose withOffset:margin andScale:scale];
    delegate.s1 = [self projectCoord:CGPointMake(-w,-h) inView:cameraCalibration andPose:pose withOffset:margin andScale:scale];
    delegate.s2 = [self projectCoord:CGPointMake(w,-h) inView:cameraCalibration andPose:pose withOffset:margin andScale:scale];
    delegate.s3 = [self projectCoord:CGPointMake(w,h) inView:cameraCalibration andPose:pose withOffset:margin andScale:scale];

I'll update the examples. Thanks for raising this. :-)

Re: how to obtain the location of the viewpoint.

April 12, 2012 - 2:46am #4

Just to let you know I am looking into this... I just need to find some more time to get further into it.

Re: how to obtain the location of the viewpoint.

April 8, 2012 - 6:34pm #3

Thank you very much, this is what I want.
This Demo of the IPhone on a normal run, but in the IPad, the four coordinates can not be perfect tracking.
When I move the camera, the distance of four View(s0 ~ s3) traveled is always larger than the actual moving distance of the camera.
I am looking for a long time, but did not find out where the problem,Can you help me find it?

Re: how to obtain the location of the viewpoint.

March 19, 2012 - 4:45am #2

Hi huanxsd,

Take a look at [B" />http://ar.qualcomm.at/node/2000738> and [B" />projectCoord[/B" /> in Playing Video Over the Image

Log in or register to post comments