Commit ef890c67 authored by Zhiping Jiang (蒋志平)'s avatar Zhiping Jiang (蒋志平) 💬

Merge commit '13e4ea4f'

* commit '13e4ea4f':
  update screenCamerainfo---transform between screen pixel and camera point
parents d23e7222 13e4ea4f
......@@ -168,3 +168,120 @@ double ScreenCameraInfo::cameraSymmetricYFov() {
cv::Size2i symmetricFrameSize = cameraSymmetricFrameSize();
return cve::rad2deg(2.0 * atan2(symmetricFrameSize.height / 2.0, cameraMatrix(1, 1)));
}
cv::Matx33d ScreenCameraInfo::transformationFromScreenToCamera() {
return cv::Matx33d(-1, 0, 0, 0, -1, 0, 0, 0, 1);
}
double ScreenCameraInfo::currentDisplayRatio() {
float currentDisplayMaxLength = frontCameraResolution.width > frontCameraResolution.height ? frontCameraResolution.width : frontCameraResolution.height;
float physicalDisplayMaxLength = screenPhysicalResolution.width > screenPhysicalResolution.height ? screenPhysicalResolution.width : screenPhysicalResolution.height;
return 1.f * currentDisplayMaxLength / physicalDisplayMaxLength;
}
double ScreenCameraInfo::currentDisplayPPI() {
double currentDisplayRatio = ScreenCameraInfo::currentDisplayRatio();
return screenPhysicalPPI * currentDisplayRatio;
}
cv::Point2d ScreenCameraInfo::frontCameraPixelInCurrentResolution() {
double currentDisplayRatio = ScreenCameraInfo::currentDisplayRatio();
return equavalentPixelPointForFrontCamera*currentDisplayRatio;
}
cv::Matx44d ScreenCameraInfo::transformFromFrontCameraFrameToSceneModelCenteredOnScreenCenter() {
cv::Vec2d screenCenterPixel = cv::Vec2d(frontCameraResolution.width, frontCameraResolution.height)*0.5;
cv::Vec3d screenCenterInCameraFrame = frontCameraPointFromPixel(screenCenterPixel);
return cve::matx::joinRotationMatAndTranslationVec(cv::Matx33d::eye(), screenCenterInCameraFrame)*cve::matx::joinRotationMatAndTranslationVec(cve::matx::rotationMatrixFromEulerAngles(0.0, 0.0, -CV_PI), cv::Vec3d(0, 0, 0));
}
double ScreenCameraInfo::screenRotationForOrientation(UIDeviceOrientation orientation) {
double radianValue = 0;
switch (orientation) {
case UIDeviceOrientationPortrait:
radianValue = 0;
break;
case UIDeviceOrientationLandscapeLeft:
radianValue = CV_PI / 2.0;
break;
case UIDeviceOrientationLandscapeRight:
radianValue = -CV_PI / 2.0;
break;
case UIDeviceOrientationPortraitUpsideDown:
radianValue = CV_PI;
break;
default:
radianValue = 0;
break;
}
return radianValue;
}
cv::Vec2d ScreenCameraInfo::screenCoordinateCenterInUIDeviceOrientation(UIDeviceOrientation orientation) {
cv::Vec2d resultVector;
switch (orientation) {
case UIDeviceOrientationPortrait:
resultVector = cv::Vec2d(0, 0);
break;
case UIDeviceOrientationLandscapeLeft:
resultVector = cv::Vec2d(screenPhysicalResolution.width, 0);
break;
case UIDeviceOrientationLandscapeRight:
resultVector = cv::Vec2d(screenPhysicalResolution.width, 0);
break;
case UIDeviceOrientationPortraitUpsideDown:
resultVector = cv::Vec2d(screenPhysicalResolution.width, screenPhysicalResolution.height);
break;
default:
resultVector = cv::Vec2d(0, 0);
}
return resultVector*currentDisplayRatio();
}
cv::Vec2d ScreenCameraInfo::transformPixel(cv::Vec2d pointA, UIDeviceOrientation deviceOrientationA, UIDeviceOrientation deviceOrientationB) {
cv::Vec2d zeroPointForA = screenCoordinateCenterInUIDeviceOrientation(deviceOrientationA);
cv::Vec2d zerosPointForB = screenCoordinateCenterInUIDeviceOrientation(deviceOrientationB);
double screenAngleForA = screenRotationForOrientation(deviceOrientationA);
double screenAngleForB = screenRotationForOrientation(deviceOrientationB);
// first transform to standard portaint.
cv::Vec2d pointInPortaint = cve::matx::transformVectorWithTransformMat(cve::matx::rotationMatrixFromEulerAngles(0.0,0.0,-screenAngleForA), pointA)+zeroPointForA;
pointInPortaint = pointInPortaint- zerosPointForB;
cv::Vec2d pointInB = cve::matx::transformVectorWithTransformMat(cve::matx::rotationMatrixFromEulerAngles(0.0, 0.0, screenAngleForB), pointInPortaint);
return pointInB;
}
cv::Vec3d ScreenCameraInfo::frontCameraPointFromPixel(cv::Vec2d pixel, UIDeviceOrientation deviceOrientation) {
// first obtain the inver rotation angle.
double inverseRotationRadian = screenRotationForOrientation(deviceOrientation);
// obtain the Zero (in the given device orientation)'s position in standard portait coordinate system.
cv::Vec2d coordinateZeroInPortraitScreen = screenCoordinateCenterInUIDeviceOrientation(deviceOrientation);
// then obtain the given pixel's cooridnate in portait view.
cv::Vec2d pixelCoordinateInPortraitScreen = cve::matx::transformVectorWithTransformMat(cve::matx::rotationMatrixFromEulerAngles(0.0, 0.0, inverseRotationRadian), pixel)+ coordinateZeroInPortraitScreen;
// the pixel distance to the camera
pixelCoordinateInPortraitScreen = pixelCoordinateInPortraitScreen- cv::Vec2d(frontCameraPixelInCurrentResolution());
// rotate the pixel_to_camera into portait view
cv::Vec2d pixelInPortraitCameraFrame = cve::matx::transformVectorWithTransformMat(transformationFromScreenToCamera(), pixelCoordinateInPortraitScreen);
// then rotate to the current camera orientation,
// note that the rotation angle is inversed.
cv::Vec2d pixelInCameraFrame = cve::matx::transformVectorWithTransformMat(cve::matx::rotationMatrixFromEulerAngles(0.0, 0.0, inverseRotationRadian), pixelInPortraitCameraFrame);
// transformed into milimeter.
pixelInCameraFrame = pixelInCameraFrame/currentDisplayPPI();
pixelInCameraFrame =pixelInCameraFrame*INCH_TO_MM;
return cve::vec::changeDimension<3>(pixelInCameraFrame,0.0);
}
cv::Vec3d ScreenCameraInfo::frontCameraPointFromPixel(cv::Vec2d pixel) {
UIDeviceOrientation currentOrientation = UIDeviceOrientationPortrait;
return frontCameraPointFromPixel(pixel,currentOrientation);
}
cv::Vec2d ScreenCameraInfo::pixelFromFrontCameraPoint(cv::Vec3d point, UIDeviceOrientation deviceOrientation) {
cv::Vec2d frontCameraPixel2D = cve::vec::changeDimension<2>(point);
frontCameraPixel2D = frontCameraPixel2D*(MM_TO_INCH * currentDisplayPPI());
frontCameraPixel2D = cve::matx::transformVectorWithTransformMat(transformationFromScreenToCamera().t(), frontCameraPixel2D);
double inverseRotationRadian = -screenRotationForOrientation(deviceOrientation);
// convert to portrait camera view
cv::Vec2d pixelInPortraitFrontCamera = cve::matx::transformVectorWithTransformMat(cve::matx::rotationMatrixFromEulerAngles(0.0, 0.0, inverseRotationRadian), frontCameraPixel2D);
cv::Vec2d pointInPortraitScreen = cv::Vec2d(frontCameraPixelInCurrentResolution())+ pixelInPortraitFrontCamera;
// get screen pixel in portrait view
cv::Vec2d pointInTargetOrientation = transformPixel(pointInPortraitScreen, UIDeviceOrientationPortrait, deviceOrientation);
return pointInTargetOrientation;
}
cv::Vec2d ScreenCameraInfo::pixelFromFrontCameraPoint(cv::Vec3d point) {
UIDeviceOrientation currentOrientation = UIDeviceOrientationPortrait;
return pixelFromFrontCameraPoint(point,currentOrientation);
}
cv::Vec3d ScreenCameraInfo::sceneModelScreenCenterFramePointFromFrontCamearPoint(cv::Vec3d point) {
return cve::matx::transformVectorWithTransformMat(transformFromFrontCameraFrameToSceneModelCenteredOnScreenCenter(), point);
}
\ No newline at end of file
......@@ -11,6 +11,12 @@
#include <stdio.h>
#include <opencv2/opencv.hpp>
#ifndef INCH_TO_MM
#define INCH_TO_MM 25.4
#endif
#ifndef MM_TO_INCH
#define MM_TO_INCH 1.0/25.4
#endif
typedef enum {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottom
......@@ -48,6 +54,21 @@ public:
static std::string currentDeviceCode();
static ScreenCameraInfo & getCurrentDiviceInfo();
cv::Matx33d transformationFromScreenToCamera();
double currentDisplayRatio();
double currentDisplayPPI();
cv::Point2d frontCameraPixelInCurrentResolution();
cv::Matx44d transformFromFrontCameraFrameToSceneModelCenteredOnScreenCenter();
double screenRotationForOrientation(UIDeviceOrientation orientation);
cv::Vec2d screenCoordinateCenterInUIDeviceOrientation(UIDeviceOrientation orientation);
cv::Vec2d transformPixel(cv::Vec2d pointA, UIDeviceOrientation deviceOrientationA, UIDeviceOrientation deviceOrientationB);
cv::Vec3d frontCameraPointFromPixel(cv::Vec2d pixel, UIDeviceOrientation deviceOrientation);
cv::Vec3d frontCameraPointFromPixel(cv::Vec2d pixel);
cv::Vec2d pixelFromFrontCameraPoint(cv::Vec3d point, UIDeviceOrientation deviceOrientation);
cv::Vec2d pixelFromFrontCameraPoint(cv::Vec3d point);
cv::Vec3d sceneModelScreenCenterFramePointFromFrontCamearPoint(cv::Vec3d point);
private:
ScreenCameraInfo();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment