Skip to content

Commit

Permalink
Merge pull request #251 from zivid/2023-12-19-update-cpp-samples
Browse files Browse the repository at this point in the history
Samples: Add loading projector image with Zivid API
  • Loading branch information
SatjaSivcev authored Dec 20, 2023
2 parents c79807f + 79460ab commit f0352c9
Showing 1 changed file with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ namespace
}


std::string getProjectorImageFileForGivenCamera(const Zivid::Camera &camera)
{
const auto model = camera.info().model().value();
switch(model)
{
case Zivid::CameraInfo::Model::ValueType::zividTwo:
// intentional fallthrough
case Zivid::CameraInfo::Model::ValueType::zividTwoL100:
return std::string(ZIVID_SAMPLE_DATA_DIR) + "/ZividLogoZivid2ProjectorResolution.png";
case Zivid::CameraInfo::Model::ValueType::zivid2PlusM130:
// intentional fallthrough
case Zivid::CameraInfo::Model::ValueType::zivid2PlusM60:
// intentional fallthrough
case Zivid::CameraInfo::Model::ValueType::zivid2PlusL110:
return std::string(ZIVID_SAMPLE_DATA_DIR) + "/ZividLogoZivid2PlusProjectorResolution.png";
case Zivid::CameraInfo::Model::ValueType::zividOnePlusSmall:
// intentional fallthrough
case Zivid::CameraInfo::Model::ValueType::zividOnePlusMedium:
// intentional fallthrough
case Zivid::CameraInfo::Model::ValueType::zividOnePlusLarge:
throw std::invalid_argument("Projecting images is not supported for Zivid One+ cameras");
}
throw std::invalid_argument("Invalid camera model");
}

} // namespace

int main()
Expand All @@ -51,7 +76,7 @@ int main()
auto camera = zivid.connectCamera();

std::string imageFile = std::string(ZIVID_SAMPLE_DATA_DIR) + "/ZividLogo.png";
std::cout << "Reading 2D image from file: " << imageFile << std::endl;
std::cout << "Reading 2D image (of arbitrary resolution) from file: " << imageFile << std::endl;
const auto inputImage = cv::imread(imageFile, cv::IMREAD_UNCHANGED);

std::cout << "input image size: " << inputImage.size() << std::endl;
Expand Down Expand Up @@ -90,6 +115,22 @@ int main()

} // projectedImageHandle now goes out of scope, thereby stopping the projection

std::string projectorImageFileForGivenCamera = getProjectorImageFileForGivenCamera(camera);

std::cout << "Reading 2D image (of resolution matching the Zivid camera projector resolution) from file: "
<< projectorImageFileForGivenCamera << std::endl;
const auto projectorImageForGivenCamera = Zivid::Image<Zivid::ColorBGRA>(projectorImageFileForGivenCamera);

{ // A Local Scope to handle the projected image lifetime

auto projectedImageHandle =
Zivid::Experimental::Projection::showImage(camera, projectorImageForGivenCamera);

std::cout << "Press enter to stop projecting..." << std::endl;
std::cin.get();

} // projectedImageHandle now goes out of scope, thereby stopping the projection

std::cout << "Done" << std::endl;
}
catch(const std::exception &e)
Expand Down

0 comments on commit f0352c9

Please # to comment.