我有一个图像平面,可以从相机接收流式视频。我试图将图像放在相机前面,使其充满屏幕。但是,我无法计算相机从图像中获取的距离。
auto camera = this->renderer()->camera();
double *origin = imageData->GetOrigin();
int *extent = imageData->GetExtent();
double *spacing = imageData->GetSpacing();
double viewportHeight = this->renderer()->camera()->viewport()->height();
this->Internal->cameraImagePlaneRepresentation()->setImageData(imageData);
double imageCenterX = origin[0] + 0.5f * (extent[0] + extent[1]) * spacing[0];
double imageCenterY = origin[1] + 0.5f * (extent[2] + extent[3]) * spacing[1];
double imageWidth = (extent[1] - extent[0] + 1.f) * spacing[0];
double imageHeight = (extent[3] - extent[2] + 1.f) * spacing[1];
double viewAngleRadians = degreesToRadians(camera->viewAngle());
double hypotenuse = imageHeight / viewAngleRadians;
double distance = tan(viewAngleRadians * 0.5f) * hypotenuse;
camera->setFocalPoint(vesVector3f(imageCenterX, imageCenterY, 0.f));
camera->setPosition(vesVector3f(imageCenterX, imageCenterY, distance));
我认为距离是正确的,但距离是一个数量级。
答案 0 :(得分:2)
如果你得到正确计算距离的公式,那将非常有帮助。
double viewAngleRadians = degreesToRadians(camera->viewAngle());
double distance = imageHeight / viewAngleRadians;