Completes Impl of ProjectCameraPoints in 2d and 3d session
Converts the structs and calls the corresponding
core_lib functions
Bug: 157498737
Tests: mm -j
Change-Id: I5b632a405a2636528133c4cd648f1ce2ed435dbe
diff --git a/surround_view/service-impl/SurroundView2dSession.cpp b/surround_view/service-impl/SurroundView2dSession.cpp
index 2ecbe7b..1f7bf3b 100644
--- a/surround_view/service-impl/SurroundView2dSession.cpp
+++ b/surround_view/service-impl/SurroundView2dSession.cpp
@@ -373,48 +373,54 @@
return {};
}
-Return<void> SurroundView2dSession::projectCameraPoints(
- const hidl_vec<Point2dInt>& points2dCamera,
- const hidl_string& cameraId,
- projectCameraPoints_cb _hidl_cb) {
+Return<void> SurroundView2dSession::projectCameraPoints(const hidl_vec<Point2dInt>& points2dCamera,
+ const hidl_string& cameraId,
+ projectCameraPoints_cb _hidl_cb) {
LOG(DEBUG) << __FUNCTION__;
- scoped_lock <mutex> lock(mAccessLock);
-
+ std::vector<Point2dFloat> outPoints;
bool cameraIdFound = false;
+ int cameraIndex = 0;
+ // Note: mEvsCameraIds must be in the order front, right, rear, left.
for (auto& evsCameraId : mEvsCameraIds) {
- if (cameraId == evsCameraId) {
- cameraIdFound = true;
- LOG(INFO) << "Camera id found.";
- break;
- }
+ if (cameraId == evsCameraId) {
+ cameraIdFound = true;
+ LOG(DEBUG) << "Camera id found for projection: " << cameraId;
+ break;
+ }
+ cameraIndex++;
}
if (!cameraIdFound) {
- LOG(ERROR) << "Camera id not found.";
- _hidl_cb({});
+ LOG(ERROR) << "Camera id not found for projection: " << cameraId;
+ _hidl_cb(outPoints);
return {};
}
- hidl_vec<Point2dFloat> outPoints;
- outPoints.resize(points2dCamera.size());
-
int width = mConfig.width;
int height = mHeight;
- for (int i=0; i<points2dCamera.size(); i++) {
- // Assuming all the points in the image frame can be projected into 2d
- // Surround View space. Otherwise cannot.
- if (points2dCamera[i].x < 0 || points2dCamera[i].x > width-1 ||
- points2dCamera[i].y < 0 || points2dCamera[i].y > height-1) {
- LOG(WARNING) << __FUNCTION__
- << ": gets invalid 2d camera points. Ignored";
- outPoints[i].isValid = false;
- outPoints[i].x = 10000;
- outPoints[i].y = 10000;
- } else {
- outPoints[i].isValid = true;
- outPoints[i].x = 0;
- outPoints[i].y = 0;
+ for (const auto& cameraPoint : points2dCamera) {
+ Point2dFloat outPoint = {false, 0.0, 0.0};
+ // Check of the camear point is within the camera resolution bounds.
+ if (cameraPoint.x < 0 || cameraPoint.x > width - 1 || cameraPoint.y < 0 ||
+ cameraPoint.y > height - 1) {
+ LOG(WARNING) << "Camera point (" << cameraPoint.x << ", " << cameraPoint.y
+ << ") is out of camera resolution bounds.";
+ outPoint.isValid = false;
+ outPoints.push_back(outPoint);
+ continue;
}
+
+ // Project points using mSurroundView function.
+ const Coordinate2dInteger camPoint(cameraPoint.x, cameraPoint.y);
+ Coordinate2dFloat projPoint2d(0.0, 0.0);
+
+ outPoint.isValid =
+ mSurroundView->GetProjectionPointFromRawCameraToSurroundView2d(camPoint,
+ cameraIndex,
+ &projPoint2d);
+ outPoint.x = projPoint2d.x;
+ outPoint.y = projPoint2d.y;
+ outPoints.push_back(outPoint);
}
_hidl_cb(outPoints);
@@ -744,4 +750,3 @@
} // namespace automotive
} // namespace hardware
} // namespace android
-
diff --git a/surround_view/service-impl/SurroundView3dSession.cpp b/surround_view/service-impl/SurroundView3dSession.cpp
index 1acce89..a2ae436 100644
--- a/surround_view/service-impl/SurroundView3dSession.cpp
+++ b/surround_view/service-impl/SurroundView3dSession.cpp
@@ -494,35 +494,52 @@
}
Return<void> SurroundView3dSession::projectCameraPointsTo3dSurface(
- const hidl_vec<Point2dInt>& cameraPoints,
- const hidl_string& cameraId,
- projectCameraPointsTo3dSurface_cb _hidl_cb) {
-
- vector<Point3dFloat> points3d;
+ const hidl_vec<Point2dInt>& cameraPoints, const hidl_string& cameraId,
+ projectCameraPointsTo3dSurface_cb _hidl_cb) {
+ LOG(DEBUG) << __FUNCTION__;
bool cameraIdFound = false;
+ int cameraIndex = 0;
+ std::vector<Point3dFloat> points3d;
+
+ // Note: mEvsCameraIds must be in the order front, right, rear, left.
for (auto& evsCameraId : mEvsCameraIds) {
- if (cameraId == evsCameraId) {
- cameraIdFound = true;
- LOG(INFO) << "Camera id found.";
- break;
- }
+ if (cameraId == evsCameraId) {
+ cameraIdFound = true;
+ LOG(DEBUG) << "Camera id found for projection: " << cameraId;
+ break;
+ }
+ cameraIndex++;
}
if (!cameraIdFound) {
- LOG(ERROR) << "Camera id not found.";
+ LOG(ERROR) << "Camera id not found for projection: " << cameraId;
_hidl_cb(points3d);
return {};
}
for (const auto& cameraPoint : cameraPoints) {
- Point3dFloat point3d;
- point3d.isValid = (cameraPoint.x >= 0
- && cameraPoint.x < mConfig.width
- && cameraPoint.y >= 0
- && cameraPoint.y < mConfig.height);
+ Point3dFloat point3d = {false, 0.0, 0.0, 0.0};
+
+ // Verify if camera point is within the camera resolution bounds.
+ point3d.isValid = (cameraPoint.x >= 0 && cameraPoint.x < mConfig.width &&
+ cameraPoint.y >= 0 && cameraPoint.y < mConfig.height);
if (!point3d.isValid) {
- LOG(WARNING) << "Camera point out of bounds.";
+ LOG(WARNING) << "Camera point (" << cameraPoint.x << ", " << cameraPoint.y
+ << ") is out of camera resolution bounds.";
+ points3d.push_back(point3d);
+ continue;
}
+
+ // Project points using mSurroundView function.
+ const Coordinate2dInteger camCoord(cameraPoint.x, cameraPoint.y);
+ Coordinate3dFloat projPoint3d(0.0, 0.0, 0.0);
+ point3d.isValid =
+ mSurroundView->GetProjectionPointFromRawCameraToSurroundView3d(camCoord,
+ cameraIndex,
+ &projPoint3d);
+ point3d.x = projPoint3d.x;
+ point3d.y = projPoint3d.y;
+ point3d.z = projPoint3d.z;
points3d.push_back(point3d);
}
_hidl_cb(points3d);
@@ -874,4 +891,3 @@
} // namespace automotive
} // namespace hardware
} // namespace android
-