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 Dec 15, 2023
1 parent d316c74 commit a181a94
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 177 deletions.
115 changes: 58 additions & 57 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ int main(int argc, char **argv)
std::cout << "Press r to centre and zoom the viewer so that the entire cloud is visible" << std::endl;
std::cout << "Press q to me exit the viewer application" << std::endl;
while(!viewer.wasStopped())
{}
{
}
if(saveStitched)
{
std::cerr << "Saving " << stitchedPointCloud.points.size()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ int main(int argc, char **argv)
std::cout << "Press r to centre and zoom the viewer so that the entire cloud is visible" << std::endl;
std::cout << "Press q to me exit the viewer application" << std::endl;
while(!viewer.wasStopped())
{}
{
}
if(saveStitched)
{
std::cerr << "Saving " << stitchedPointCloud.points.size()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace
return points;
}


std::vector<Zivid::PointXYZ> transformGridToCalibrationBoard(
const std::vector<cv::Matx41f> &grid,
const Zivid::Matrix4x4 &transformCameraToCheckerboard)
Expand All @@ -49,6 +50,7 @@ namespace
return pointsInCameraFrame;
}


void drawFilledCircles(
cv::Mat image,
const std::vector<Zivid::PointXY> &positions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace
return projectorImage;
}


void projecting(Zivid::Camera &camera, const Zivid::Image<Zivid::ColorBGRA> &projectorImageFunctionScope)
{
auto projectedImageHandle = Zivid::Experimental::Projection::showImage(camera, projectorImageFunctionScope);
Expand All @@ -52,6 +53,7 @@ int main()
const auto redColor = Zivid::ColorBGRA(0, 0, 255, 255);

auto projectorImage = createProjectorImage(projectorResolution, redColor);

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

std::cout << "Press enter to stop projecting using the \".stop()\" function." << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace
return projectorImage;
}


} // namespace

int main()
Expand Down
2 changes: 2 additions & 0 deletions source/Applications/PointCloudTutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ complete list of output data formats and how to copy them from the GPU.
| `Zivid::Array2D<Zivid::PointXYZColorRGBA>` | `PointCloud::copyData<PointXYZColorRGBA>()` | 16 bytes | 37 MB |
| `Zivid::Array2D<Zivid::PointXYZColorBGRA>` | `PointCloud::copyPointsXYZColorsBGRA()` or `PointCloud::copyData<PointXYZColorBGRA>()` | 16 bytes | 37 MB |
| `Zivid::Image<Zivid::ColorRGBA>` | `PointCloud::copyImageRGBA()` | 4 bytes | 9 MB |
| `Zivid::Image<Zivid::ColorBGRA>` | `PointCloud::copyImageBGRA()` | 4 bytes | 9 MB |
| `Zivid::Image<Zivid::ColorsRGB>` | `PointCloud::copyImagesRGB()` | 4 bytes | 9 MB |

Here is an example of how to copy data.

Expand Down
122 changes: 79 additions & 43 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(ZividCppSamples)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/3rd-party)
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/3rd-party
)
include(CompilerOptions)

set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL "MinSizeRel;Release;")
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO "RelWithDebInfo;Release;")

set(ZIVID_VERSION 2.10.0)

option(USE_EIGEN3 "Enable samples which depend on Eigen 3" ON)
option(USE_OPENCV "Enable samples which depend on OpenCV" ON)
option(USE_PCL "Enable samples which depend on Point Cloud Library (PCL)" ON)
option(USE_ARUCO
"Enable samples which depend on ArUco (OpenCV with extra modules)" OFF)
option(USE_ARUCO "Enable samples which depend on ArUco (OpenCV with extra modules)" OFF)
option(USE_HALCON "Enable samples which depend on Halcon" OFF)

set(SAMPLES
Expand All @@ -36,14 +41,15 @@ set(SAMPLES
Camera/InfoUtilOther/CaptureWithDiagnostics
Camera/InfoUtilOther/GetCameraIntrinsics
Camera/InfoUtilOther/FirmwareUpdater
Camera/InfoUtilOther/PrintVersionInfo
Camera/InfoUtilOther/CameraInfo
Camera/InfoUtilOther/SettingsInfo
Camera/InfoUtilOther/FrameInfo
Camera/InfoUtilOther/ZividBenchmark
Camera/InfoUtilOther/Warmup
Camera/Maintenance/VerifyCameraInField
Camera/Maintenance/VerifyCameraInFieldFromZDF
Camera/Maintenance/CorrectCameraInField
Camera/Maintenance/ResetCameraInField
Applications/Basic/Visualization/CaptureFromFileCameraVis3D
Applications/Basic/Visualization/CaptureVis3D
Applications/Basic/Visualization/ReadPCLVis3D
Expand All @@ -70,18 +76,24 @@ set(SAMPLES
Applications/Advanced/ROIBoxViaCheckerboard
Applications/Advanced/GammaCorrection
Applications/Advanced/ProjectAndFindMarker
Applications/Advanced/ReprojectPoints)
Applications/Advanced/ReprojectPoints
)

set(Eigen3_DEPENDING UtilizeHandEyeCalibration PoseConversions
ROIBoxViaArucoMarker ROIBoxViaCheckerboard)
set(Eigen3_DEPENDING
UtilizeHandEyeCalibration
PoseConversions
ROIBoxViaArucoMarker
ROIBoxViaCheckerboard
)
set(PCL_DEPENDING
Capture2DAnd3D
MaskPointCloud
ReadPCLVis3D
CaptureWritePCLVis3D
CaptureHDRVisNormals
StitchByTransformation
StitchByTransformationFromZDF)
StitchByTransformationFromZDF
)
set(OpenCV_DEPENDING
Capture2DAnd3D
CaptureUndistort2D
Expand All @@ -94,7 +106,8 @@ set(OpenCV_DEPENDING
GammaCorrection
ProjectAndFindMarker
ReprojectPoints
ReadAndProjectImage)
ReadAndProjectImage
)
set(Visualization_DEPENDING
CaptureVis3D
CaptureLiveVis3D
Expand All @@ -104,7 +117,8 @@ set(Visualization_DEPENDING
CaptureUndistort2D
CreateDepthMap
ROIBoxViaArucoMarker
ROIBoxViaCheckerboard)
ROIBoxViaCheckerboard
)
set(Clipp_DEPENDING
CameraUserData
MultiCameraCalibrationFromZDF
Expand All @@ -114,17 +128,25 @@ set(Clipp_DEPENDING
Capture2DAnd3D
ZividBenchmark
CaptureFromFileCamera
CaptureFromFileCameraVis3D)
CaptureFromFileCameraVis3D
)
set(Thread_DEPENDING
Capture2DAnd3D MultiCameraCaptureSequentially MultiCameraCaptureInParallel
MultiCameraCaptureSequentiallyWithInterleavedProcessing ZividBenchmark)
set(ArUco_DEPENDING TransformPointCloudViaArucoMarker ROIBoxViaArucoMarker)
set(Halcon_DEPENDING CaptureHalconViaGenICam CaptureHalconViaZivid)
Capture2DAnd3D
MultiCameraCaptureSequentially
MultiCameraCaptureInParallel
MultiCameraCaptureSequentiallyWithInterleavedProcessing
ZividBenchmark
)
set(ArUco_DEPENDING
TransformPointCloudViaArucoMarker
ROIBoxViaArucoMarker
)
set(Halcon_DEPENDING
CaptureHalconViaGenICam
CaptureHalconViaZivid
)

find_package(
Zivid ${ZIVID_VERSION}
COMPONENTS Core
REQUIRED)
find_package(Zivid ${ZIVID_VERSION} COMPONENTS Core REQUIRED)
find_package(Threads REQUIRED)

macro(disable_samples DEPENDENCY_NAME)
Expand All @@ -143,13 +165,13 @@ if(USE_EIGEN3)
if(NOT DEFINED EIGEN3_INCLUDE_DIR)
message(
FATAL_ERROR
"Please point EIGEN3_INCLUDE_DIR to the root directory of your Eigen3 installation (the folder containing Eigen/Core, Eigen/Dense etc.), or disable the Eigen samples (-DUSE_EIGEN3=OFF)."
"Please point EIGEN3_INCLUDE_DIR to the root directory of your Eigen3 installation (the folder containing Eigen/Core, Eigen/Dense etc.), or disable the Eigen samples (-DUSE_EIGEN3=OFF)."
)
else()
if(NOT IS_DIRECTORY "${EIGEN3_INCLUDE_DIR}/Eigen")
message(
FATAL_ERROR
"EIGEN3_INCLUDE_DIR was set to ${EIGEN3_INCLUDE_DIR}, which is not a valid Eigen 3 directory. Please correct this, or disable the Eigen samples (-DUSE_EIGEN3=OFF)."
"EIGEN3_INCLUDE_DIR was set to ${EIGEN3_INCLUDE_DIR}, which is not a valid Eigen 3 directory. Please correct this, or disable the Eigen samples (-DUSE_EIGEN3=OFF)."
)
endif()
endif()
Expand All @@ -162,21 +184,31 @@ if(USE_PCL)
if(NOT PCL_FOUND)
message(
FATAL_ERROR
"Point Cloud Library (PCL) not found. Please point PCL_DIR to the directory of your PCL installation (containing the file PCLConfig.cmake), or disable the PCL samples with -DUSE_PCL=OFF."
"Point Cloud Library (PCL) not found. Please point PCL_DIR to the directory of your PCL installation (containing the file PCLConfig.cmake), or disable the PCL samples with -DUSE_PCL=OFF."
)
endif()
else()
disable_samples("PCL")
endif()

if(USE_OPENCV)
set(OPENCV_COMMON_MODULES core highgui calib3d)
set(OPENCV_COMMON_MODULES
core
highgui
calib3d
)
if(USE_ARUCO)
find_package(OpenCV 4.1.0 COMPONENTS ${OPENCV_COMMON_MODULES} aruco)
find_package(
OpenCV
4.1.0
COMPONENTS
${OPENCV_COMMON_MODULES}
aruco
)
if(NOT OpenCV_FOUND)
message(
FATAL_ERROR
"OpenCV not found. Please point OpenCV_DIR to the directory of your OpenCV installation (containing the file OpenCVConfig.cmake). If you don't have OpenCV with extra modules (OpenCV_Contrib), disable the ArUco samples with -DUSE_ARUCO=OFF."
"OpenCV not found. Please point OpenCV_DIR to the directory of your OpenCV installation (containing the file OpenCVConfig.cmake). If you don't have OpenCV with extra modules (OpenCV_Contrib), disable the ArUco samples with -DUSE_ARUCO=OFF."
)
endif()
else()
Expand All @@ -185,7 +217,7 @@ if(USE_OPENCV)
if(NOT OpenCV_FOUND)
message(
FATAL_ERROR
"OpenCV not found. Please point OpenCV_DIR to the directory of your OpenCV installation (containing the file OpenCVConfig.cmake), or disable the OpenCV samples with -DUSE_OPENCV=OFF."
"OpenCV not found. Please point OpenCV_DIR to the directory of your OpenCV installation (containing the file OpenCVConfig.cmake), or disable the OpenCV samples with -DUSE_OPENCV=OFF."
)
endif()
endif()
Expand All @@ -195,7 +227,10 @@ endif()

if(USE_HALCON)
if(DEFINED ENV{HALCONROOT} AND NOT $ENV{HALCONROOT} STREQUAL "")
message("Using HALCONROOT " $ENV{HALCONROOT})
message(
"Using HALCONROOT "
$ENV{HALCONROOT}
)
string(REGEX REPLACE "\\\\" "/" HALCONROOT $ENV{HALCONROOT})
endif()
find_package(Halcon REQUIRED)
Expand Down Expand Up @@ -226,46 +261,47 @@ foreach(SAMPLE ${SAMPLES})

target_link_libraries(${SAMPLE_NAME} Zivid::Core)

target_compile_definitions(
${SAMPLE_NAME} PRIVATE ZIVID_SAMPLE_DATA_DIR="${ZIVID_SAMPLE_DATA_DIR}")
target_compile_definitions(${SAMPLE_NAME} PRIVATE ZIVID_SAMPLE_DATA_DIR="${ZIVID_SAMPLE_DATA_DIR}")

if(${SAMPLE_NAME} IN_LIST Visualization_DEPENDING)
target_link_libraries(${SAMPLE_NAME} Zivid::Visualization)
endif()

if(${SAMPLE_NAME} IN_LIST Eigen3_DEPENDING)
target_include_directories(${SAMPLE_NAME} SYSTEM
PRIVATE ${EIGEN3_INCLUDE_DIR})
target_include_directories(${SAMPLE_NAME} SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR})
endif()

if(${SAMPLE_NAME} IN_LIST PCL_DEPENDING)
target_link_libraries(${SAMPLE_NAME} ${PCL_LIBRARIES})
target_include_directories(${SAMPLE_NAME} SYSTEM
PRIVATE ${PCL_INCLUDE_DIRS})
target_include_directories(${SAMPLE_NAME} SYSTEM PRIVATE ${PCL_INCLUDE_DIRS})
endif()

if(${SAMPLE_NAME} IN_LIST OpenCV_DEPENDING)
target_link_libraries(${SAMPLE_NAME} ${OpenCV_LIBS})
endif()

if(${SAMPLE_NAME} IN_LIST Clipp_DEPENDING)
target_include_directories(
${SAMPLE_NAME} SYSTEM
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/3rd-party/clipp/include)
target_include_directories(${SAMPLE_NAME} SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/3rd-party/clipp/include)
endif()

if(${SAMPLE_NAME} IN_LIST Thread_DEPENDING)
target_link_libraries(${SAMPLE_NAME} Threads::Threads)
endif()

if(${SAMPLE_NAME} IN_LIST Halcon_DEPENDING)
target_link_libraries(${SAMPLE_NAME} ${HALCON_LIBS} ${HDEVENGINE_LIBS})
target_link_libraries(
${SAMPLE_NAME}
${HALCON_LIBS}
${HDEVENGINE_LIBS}
)
target_include_directories(
${SAMPLE_NAME} PUBLIC ${HALCON_INC_DIRS} ${HDEVENGINE_INC_DIRS}
include)
${SAMPLE_NAME}
PUBLIC
${HALCON_INC_DIRS}
${HDEVENGINE_INC_DIRS}
include
)
endif()

endforeach()

target_compile_definitions(ZividBenchmark
PRIVATE OS_NAME=\"${CMAKE_SYSTEM_NAME}\")
target_compile_definitions(ZividBenchmark PRIVATE OS_NAME=\"${CMAKE_SYSTEM_NAME}\")
27 changes: 15 additions & 12 deletions source/Camera/Advanced/Capture2DAnd3D/Capture2DAnd3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Capture 2D and then 3D using various capture strategies, optimizing for both 2D quality and 2D acquisition speed.
*/

#include <Zivid/Experimental/Calibration.h>
#include <Zivid/Zivid.h>

#include <clipp.h>
Expand All @@ -17,21 +18,22 @@ Capture 2D and then 3D using various capture strategies, optimizing for both 2D

namespace
{
cv::Mat mapBGR(const Zivid::Settings::Sampling::Pixel &pixelsToSample, const cv::Mat &fullResolutionBGR)
cv::Mat mapBGR(const Zivid::Experimental::PixelMapping &pixelMapping, const cv::Mat &fullResolutionBGR)
{
std::cout << "Pixels to sample: " << pixelsToSample << std::endl;
const int subsampleDivider =
(pixelsToSample.value() == Zivid::Settings::Sampling::Pixel::ValueType::all) ? 1 : 2;
int offset = (pixelsToSample.value() == Zivid::Settings::Sampling::Pixel::ValueType::blueSubsample2x2) ? 0 : 1;
cv::Mat
mappedBGR(fullResolutionBGR.rows / subsampleDivider, fullResolutionBGR.cols / subsampleDivider, CV_8UC3);
std::cout << "Pixel mapping: " << pixelMapping << std::endl;
cv::Mat mappedBGR(
fullResolutionBGR.rows / pixelMapping.rowStride(),
fullResolutionBGR.cols / pixelMapping.colStride(),
CV_8UC3);
std::cout << "Mapped width: " << mappedBGR.cols << ", height: " << mappedBGR.rows << std::endl;
for(size_t row = 0; row < static_cast<size_t>(fullResolutionBGR.rows - offset); row += subsampleDivider)
for(size_t row = 0; row < static_cast<size_t>(fullResolutionBGR.rows - pixelMapping.rowOffset());
row += pixelMapping.rowStride())
{
for(size_t col = 0; col < static_cast<size_t>(fullResolutionBGR.cols - offset); col += subsampleDivider)
for(size_t col = 0; col < static_cast<size_t>(fullResolutionBGR.cols - pixelMapping.colOffset());
col += pixelMapping.colStride())
{
mappedBGR.at<cv::Vec3b>(row / subsampleDivider, col / subsampleDivider) =
fullResolutionBGR.at<cv::Vec3b>(row + offset, col + offset);
mappedBGR.at<cv::Vec3b>(row / pixelMapping.rowStride(), col / pixelMapping.colStride()) =
fullResolutionBGR.at<cv::Vec3b>(row + pixelMapping.rowOffset(), col + pixelMapping.colOffset());
}
}
return mappedBGR;
Expand Down Expand Up @@ -214,9 +216,10 @@ int main(int argc, char **argv)
const_cast<void *>(static_cast<const void *>(image.data())));
cv::Mat fullResolutionBGR;
cv::cvtColor(fullResolutionBGRA, fullResolutionBGR, cv::COLOR_BGRA2BGR);
const auto pixelMapping = Zivid::Experimental::Calibration::pixelMapping(camera, settings);
const auto mappedBGR = (pixelsToSample.value() == Zivid::Settings::Sampling::Pixel::ValueType::all)
? fullResolutionBGR
: mapBGR(pixelsToSample, fullResolutionBGR);
: mapBGR(pixelMapping, fullResolutionBGR);
if(pixelsToSample.value() == Zivid::Settings::Sampling::Pixel::ValueType::all)
{
displayBGR({ fullResolutionBGR }, { "Full resolution 2D" });
Expand Down
Loading

0 comments on commit a181a94

Please sign in to comment.