如何根据距离指定图像大小

时间:2014-07-28 16:46:59

标签: ios objective-c image-processing augmented-reality core-motion

我根据预定义(例如)距离和图像宽度&分配图像大小。高度。我引用了这些链接:link1 link2

height_of_frame = ((obj_distance) * measured_object_height_in_mm / 1000.0))/focal;

width_of_frame = ((obj_distance) * measured_object_width_in_mm / 1000.0))/focal;

int imagesize_height = ((152.4)*1990/1000)/0.33;

int imagesize_width = ((152.4)*3500/1000)/0.33;

距离cm = 152.4且ipadMini相机焦距为3.3mm = 0.33cm

但是,如果我这样做,它会缩小图像尺寸,不会接近或接近。

基于宽高比的图像尺寸:

CGFloat widthRatio = self.view.frame.size.width / enteredRoomSize.width;
 CGFloat heightRatio = self.view.frame.size.height / enteredRoomSize.height;

  CGSize imageSize = CGSizeMake(350 * widthRatio, 199 * widthRatio);

 mmageView=[[UIImageView alloc]init];

 CGRect frame = mmageView.frame; frame.size = imageSize; mmageView.frame = frame;

1 个答案:

答案 0 :(得分:0)

这是基础数学。公式是:

object_distance = (focal * real_object_height)/object_height;

因此你应该:

height_of_frame = (focal * measured_object_height_in_mm / 1000.0))/obj_distance;

width_of_frame = (focal  * measured_object_width_in_mm / 1000.0))/obj_distance;

此外,height_of_framefocal具有相同的单位(通常为像素),obj_distance应以米为单位,而不是以厘米为单位。