Skip to content

Commit

Permalink
Samples: Automatic updates to public repository
Browse files Browse the repository at this point in the history
Remember to do the following:
    1. Ensure that modified/deleted/new files are correct
    2. Make this commit message relevant for the changes
    3. Force push
    4. Delete branch after PR is merged

If this commit is an update from one SDK version to another,
make sure to create a release tag for previous version.
  • Loading branch information
csu-bot-zivid committed Sep 13, 2024
1 parent ae8df0f commit e452c71
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int main()
std::string fileName;
size_t imageCoordinateX = 0;
size_t imageCoordinateY = 0;
Zivid::Matrix4x4 transformBaseToCamera;
Zivid::Matrix4x4 baseToCameraTransform;

bool loopContinue = true;
while(loopContinue)
Expand All @@ -148,7 +148,7 @@ int main()

std::cout << "Reading camera pose in robot base reference frame (result of eye-to-hand calibration"
<< std::endl;
transformBaseToCamera.load(std::string(ZIVID_SAMPLE_DATA_DIR) + eyeToHandTransformFile);
baseToCameraTransform.load(std::string(ZIVID_SAMPLE_DATA_DIR) + eyeToHandTransformFile);

loopContinue = false;
break;
Expand All @@ -168,16 +168,16 @@ int main()
std::cout
<< "Reading camera pose in end-effector reference frame (result of eye-in-hand calibration)"
<< std::endl;
Zivid::Matrix4x4 transformEndEffectorToCamera(
Zivid::Matrix4x4 endEffectorToCameraTransform(
std::string(ZIVID_SAMPLE_DATA_DIR) + eyeInHandTransformFile);

std::cout << "Reading end-effector pose in robot base reference frame" << std::endl;
Zivid::Matrix4x4 transformBaseToEndEffector(
Zivid::Matrix4x4 baseToEndEffectorTransform(
std::string(ZIVID_SAMPLE_DATA_DIR) + robotTransformFile);

std::cout << "Computing camera pose in robot base reference frame" << std::endl;
transformBaseToCamera = eigenToZivid(
zividToEigen(transformBaseToEndEffector) * zividToEigen(transformEndEffectorToCamera));
baseToCameraTransform = eigenToZivid(
zividToEigen(baseToEndEffectorTransform) * zividToEigen(endEffectorToCameraTransform));

loopContinue = false;
break;
Expand Down Expand Up @@ -216,10 +216,10 @@ int main()
<< pointInCameraFrame.y() << " " << pointInCameraFrame.z() << std::endl;

// Converting to Eigen matrix for easier computation
const Eigen::Affine3f transformBaseToCameraEigen = zividToEigen(transformBaseToCamera);
const Eigen::Affine3f baseToCameraTransformEigen = zividToEigen(baseToCameraTransform);

std::cout << "Transforming (picking) point from camera to robot base reference frame" << std::endl;
const Eigen::Vector4f pointInBaseFrame = transformBaseToCameraEigen * pointInCameraFrame;
const Eigen::Vector4f pointInBaseFrame = baseToCameraTransformEigen * pointInCameraFrame;

std::cout << "Point coordinates in robot base reference frame: " << pointInBaseFrame.x() << " "
<< pointInBaseFrame.y() << " " << pointInBaseFrame.z() << std::endl;
Expand All @@ -231,7 +231,7 @@ int main()
{
std::cout << "Transforming point cloud" << std::endl;

pointCloud.transform(transformBaseToCamera);
pointCloud.transform(baseToCameraTransform);

const auto saveFile = "ZividGemTransformed.zdf";
std::cout << "Saving point cloud to file: " << saveFile << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ int main()
}

std::cout << "Estimating pose of detected ArUco marker" << std::endl;
const auto transformCameraToMarker = detectionResult.detectedMarkers()[0].pose().toMatrix();
const auto cameraToMarkerTransform = detectionResult.detectedMarkers()[0].pose().toMatrix();

std::cout << "Transforming the ROI base frame points to the camera frame" << std::endl;
const auto roiPointsInCameraFrame = transformPoints(
std::vector<Zivid::PointXYZ>{ pointOInArUcoFrame, pointAInArUcoFrame, pointBInArUcoFrame },
transformCameraToMarker);
cameraToMarkerTransform);

std::cout << "Setting the ROI" << std::endl;
settings.set(Zivid::Settings::RegionOfInterest{
Expand Down
15 changes: 8 additions & 7 deletions source/Applications/Advanced/ReprojectPoints/ReprojectPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ namespace
}


std::vector<Zivid::PointXYZ> transformGridToCalibrationBoard(
std::vector<Zivid::PointXYZ> transformGridToCameraFrame(
const std::vector<cv::Matx41f> &grid,
const Zivid::Matrix4x4 &transformCameraToCheckerboard)
const Zivid::Matrix4x4 &cameraToCheckerboardTransform)
{
std::vector<Zivid::PointXYZ> pointsInCameraFrame;
const auto transformationMatrix = cv::Matx44f{ transformCameraToCheckerboard.data() };
const auto transformationMatrix = cv::Matx44f{ cameraToCheckerboardTransform.data() };
for(const auto &point : grid)
{
const auto transformedPoint = transformationMatrix * point;
Expand Down Expand Up @@ -87,15 +87,16 @@ int main()
}

std::cout << "Estimating checkerboard pose" << std::endl;
const auto transformCameraToCheckerboard = detectionResult.pose().toMatrix();
std::cout << transformCameraToCheckerboard << std::endl;
const auto cameraToCheckerboardTransform = detectionResult.pose().toMatrix();
std::cout << cameraToCheckerboardTransform << std::endl;

std::cout << "Creating a grid of 7 x 6 points (3D) with 30 mm spacing to match checkerboard corners"
<< std::endl;
const auto grid = checkerboardGrid();
const auto gridInCheckerboardFrame = checkerboardGrid();

std::cout << "Transforming the grid to the camera frame" << std::endl;
const auto pointsInCameraFrame = transformGridToCalibrationBoard(grid, transformCameraToCheckerboard);
const auto pointsInCameraFrame =
transformGridToCameraFrame(gridInCheckerboardFrame, cameraToCheckerboardTransform);

std::cout << "Getting projector pixels (2D) corresponding to points (3D) in the camera frame" << std::endl;
const auto projectorPixels = Zivid::Projection::pixelsFrom3DPoints(camera, pointsInCameraFrame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ int main()
auto frame = Zivid::Frame(dataFile);
auto pointCloud = frame.pointCloud();

const auto transformMillimetersToMeters =
const auto millimetersToMetersTransform =
Zivid::Matrix4x4{ { 0.001F, 0, 0, 0 }, { 0, 0.001F, 0, 0 }, { 0, 0, 0.001F, 0 }, { 0, 0, 0, 1 } };

std::cout << "Transforming point cloud from mm to m" << std::endl;
pointCloud.transform(transformMillimetersToMeters);
pointCloud.transform(millimetersToMetersTransform);

const auto transformedFile = "FrameInMeters.zdf";
std::cout << "Saving transformed point cloud to file: " << transformedFile << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ int main()
std::cout << "ArUco marker pose in camera frame:" << std::endl;
std::cout << transformCameraToMarker << std::endl;
std::cout << "Camera pose in ArUco marker frame:" << std::endl;
const auto transformMarkerToCamera = transformCameraToMarker.inverse();
std::cout << transformMarkerToCamera << std::endl;
const auto markerToCameraTransform = transformCameraToMarker.inverse();
std::cout << markerToCameraTransform << std::endl;

const auto transformFile = "ArUcoMarkerToCameraTransform.yaml";
std::cout << "Saving a YAML file with Inverted ArUco marker pose to file: " << transformFile << std::endl;
transformMarkerToCamera.save(transformFile);
markerToCameraTransform.save(transformFile);

std::cout << "Transforming point cloud from camera frame to ArUco marker frame" << std::endl;
pointCloud.transform(transformMarkerToCamera);
pointCloud.transform(markerToCameraTransform);

const auto arucoMarkerTransformedFile = "CalibrationBoardInArucoMarkerOrigin.zdf";
std::cout << "Saving transformed point cloud to file: " << arucoMarkerTransformedFile << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,24 @@ int main()

std::cout << "Detecting and estimating pose of the Zivid checkerboard in the camera frame" << std::endl;
const auto detectionResult = Zivid::Calibration::detectCalibrationBoard(frame);
const auto transformCameraToCheckerboard = detectionResult.pose().toMatrix();
std::cout << transformCameraToCheckerboard << std::endl;
const auto cameraToCheckerboardTransform = detectionResult.pose().toMatrix();
std::cout << cameraToCheckerboardTransform << std::endl;
std::cout << "Camera pose in checkerboard frame:" << std::endl;
const auto transformCheckerboardToCamera = transformCameraToCheckerboard.inverse();
std::cout << transformCheckerboardToCamera << std::endl;
const auto checkerboardToCameraTransform = cameraToCheckerboardTransform.inverse();
std::cout << checkerboardToCameraTransform << std::endl;

const auto transformFile = "CheckerboardToCameraTransform.yaml";
std::cout << "Saving a YAML file with Inverted checkerboard pose to file: " << transformFile << std::endl;
transformCheckerboardToCamera.save(transformFile);
checkerboardToCameraTransform.save(transformFile);

std::cout << "Transforming point cloud from camera frame to Checkerboard frame" << std::endl;
pointCloud.transform(transformCheckerboardToCamera);
pointCloud.transform(checkerboardToCameraTransform);

std::cout << "Converting to OpenCV image format" << std::endl;
const auto bgraImage = pointCloudToColorBGRA(pointCloud);

std::cout << "Visualizing checkerboard with coordinate system" << std::endl;
drawCoordinateSystem(frame, transformCameraToCheckerboard, bgraImage);
drawCoordinateSystem(frame, cameraToCheckerboardTransform, bgraImage);
displayBGRA(bgraImage, "Checkerboard transformation frame");

const auto checkerboardTransformedFile = "CalibrationBoardInCheckerboardOrigin.zdf";
Expand Down
2 changes: 1 addition & 1 deletion source/Applications/PointCloudTutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ m](https://support.zivid.com/latest//academy/applications/transform/transform-mi
source](https://github.com/zivid/zivid-cpp-samples/tree/master//source/Applications/Advanced/HandEyeCalibration/UtilizeHandEyeCalibration/UtilizeHandEyeCalibration.cpp#L234))

``` sourceCode cpp
pointCloud.transform(transformBaseToCamera);
pointCloud.transform(baseToCameraTransform);
```

## Downsample
Expand Down

0 comments on commit e452c71

Please sign in to comment.