增强现实

发布于 2024-12-03 06:33:03 字数 966 浏览 1 评论 0原文

我想在相机的图像上绘制该地点的引脚和信息。 请任何人帮助我.. 我已经在应用程序委托中完成了编码 代码是:-

overlay = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; overlay.opaque = NO; overlay.backgroundColor=[UIColor clearColor]; 
    [window addSubview:overlay]; 
#define CAMERA_TRANSFORM 1.24299 
    UIImagePickerController *uip;
    @try {
        uip = [[[UIImagePickerController alloc] init] autorelease];
        uip.sourceType = UIImagePickerControllerSourceTypeCamera; uip.showsCameraControls = NO;
        uip.toolbarHidden = YES; 
        uip.navigationBarHidden = YES; 
        uip.wantsFullScreenLayout = YES;
        uip.cameraViewTransform = CGAffineTransformScale(uip.cameraViewTransform, CAMERA_TRANSFORM, CAMERA_TRANSFORM); 
    } 
    @catch (NSException * e) 
    { [uip release]; 
        uip = nil;
    }
    @finally
    { if(uip) {
        [overlay addSubview:[uip view]]; [overlay release]; }
    }

它显示相机。不是我想检测该位置并将图钉放在该位置上,以显示该位置的信息。

i want to draw the pin and information of the place on the image of the camera..
Please any one help me..
i had done the coding in the app delegate
The code is :-

overlay = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; overlay.opaque = NO; overlay.backgroundColor=[UIColor clearColor]; 
    [window addSubview:overlay]; 
#define CAMERA_TRANSFORM 1.24299 
    UIImagePickerController *uip;
    @try {
        uip = [[[UIImagePickerController alloc] init] autorelease];
        uip.sourceType = UIImagePickerControllerSourceTypeCamera; uip.showsCameraControls = NO;
        uip.toolbarHidden = YES; 
        uip.navigationBarHidden = YES; 
        uip.wantsFullScreenLayout = YES;
        uip.cameraViewTransform = CGAffineTransformScale(uip.cameraViewTransform, CAMERA_TRANSFORM, CAMERA_TRANSFORM); 
    } 
    @catch (NSException * e) 
    { [uip release]; 
        uip = nil;
    }
    @finally
    { if(uip) {
        [overlay addSubview:[uip view]]; [overlay release]; }
    }

it shows the camera.Not i want to detect the place and put the pin on that place which shows the information of that place.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぺ禁宫浮华殁 2024-12-10 06:33:03

这里有一个更简单的方法来检测相机的存在:

BOOL isCameraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];

恐怕 99% 的工作仍然在前面。大致您需要以下内容:

  1. 获取用户的地理位置。
  2. 获取您想要显示的兴趣点 (POI) 的地理位置。您可能需要使用第三方库,例如 Foursquare、Google 地图或类似的库。
  3. 使用两点之间的直角三角形 h^2=c^2+c^2 计算用户和 POI 之间的距离。

    请注意,球面几何中的距离是使用半正矢公式计算的,但如果我们假设笛卡尔坐标,则精度损失对于小距离来说是无关的,因此我们将这样做。

  4. 假设东为 0°,获取用户到 POI 的角度,即 atan dy/dx(y=纬度,x=经度)。 dy 当然是用户的纬度和 POI 之间的差值。
  5. 从罗盘获取方位并计算用户方位与 POI 角度之间的差值。
  6. 对象在屏幕上的位置取决于方位和设备方向。如果用户正在精确地查看 POI,请在屏幕中间为 POI 绘制标签。如果存在与精确角度的偏移,请乘以 offset *(以像素为单位的宽度/水平视野) 以获得表示该点的标签的以像素为单位的偏移。对垂直偏移执行相同的操作。
    • 如果 X 轴上存在旋转 (参见此处的轴),应用垂直偏移。
    • 如果 Y 轴发生旋转,罗盘的方位将会更新。
    • 如果在 Z 轴上有旋转,如果物体靠近,则以相反的角度旋转物体。
  7. 根据距离(最小值和最大值)缩放标签。

要定位标签,您可能需要使用 3D 引擎或将它们围绕设备旋转一圈(x=x+r*cos、y=y+r*sin)并使用广告牌效果。

如果这听起来工作量太大,请集中精力使用偏移*像素宽度/水平视野来实现对方位变化的响应。水平视野是相机的可视角度。对于人类来说是 180°,对于 iPhone 3 来说是 37.5°,那么对于 iPhone 4 来说是 45° 吗?宽度为 320,因此如果您与目标的距离为 10°,则必须将其水平移动到距中心 320*10/37.5 像素的位置。

如果罗盘的读数有太多噪音,请添加低通滤波器。

Here is a more straightforward recipe to detect the presence of a camera:

BOOL isCameraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];

99% of the job is still ahead I'm afraid. Roughly you need the following:

  1. Get the geographical location for the user.
  2. Get the geographical location for the point of interest (POI) you want to show. You may need to use a 3rd party library like Foursquare, Google maps, or something like that.
  3. Calculate the distance between the user and a POI using a right triangle between both points h^2=c^2+c^2.

    Note that the distance in spherical geometry is calculated with the haversine formula, but the loss of precision is irrelevant for small distances if we assume cartesian coordinates, so we will just do that.

  4. Assuming that east is 0º, get the angle from the user to the POI, which is atan dy/dx (y=latitude, x=longitude). dy is of course, the difference between the latitudes from the user and the POI.
  5. Get the bearing from the compass and calculate the difference between the user bearing and the angle to the POI.
  6. The position on screen of the object depends on the bearing and the device orientation. If the user is looking exactly at the POI, paint a label for the POI in the middle of the screen. If there is an offset from the exact angle, multiply offset * (width in pixels / horizontal field vision) to get the offset in pixels for the label representing the point. Do the same for the vertical offset.
    • If there is a rotation on the axis X (see the axis here), apply a vertical offset.
    • If there is a rotation on the axis Y, there will be an update in bearing from the compass.
    • If there is a rotation on the axis Z, if the object is near rotate the object in the opposite angle.
  7. Scale the label according to the distance, with a minimum and a maximum.

To position the labels you may want to use a 3D engine or rotate them in a circle around your device (x=x+r*cos, y=y+r*sin) and use a billboard effect.

If that sounds like too much work, concentrate on implementing just the response to changes in bearing using offset * width in pixels / horizontal field vision. Horizontal field vision is the visible angle for the camera. It is 180º for humans, 37.5 for iPhone 3, and hmm was it 45º for iPhone 4? Width is 320, so if you are looking 10º away from your target, you have to move it horizontally 320*10/37.5 pixels away from the center.

If the readings from the compass have too much noise, add a low pass filter.

一念一轮回 2024-12-10 06:33:03

请访问

https://github.com/zac/iphonearkit

这是可用的最好的 ObjectiveC 代码。

Please go through

https://github.com/zac/iphonearkit.

It's the best objectiveC code available.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文