ROI Box via ArUco Marker

이 튜토리얼은 ArUco 마커를 사용하여 ROI 상자의 파라미터를 찾는 방법과 이를 사용하여 빈의 내용을 필터링하는 방법을 보여줍니다. 이 튜토리얼은 Zivid calibration board 의 ArUco 마커를 사용하고 있으며 칼리브레이션 보드가 빈의 오른쪽 하단 모서리에 있다고 가정합니다. 빈 크기도 알고 있는 것으로 가정하고 ROI 상자의 크기를 설정하는 데 사용됩니다. 이렇게 하면 카메라 프레임에서 ROI 파라미터를 자동으로 찾을 수 있습니다.

참고

이 튜토리얼은 데모를 위해 아래 이미지의 장면에 파일 카메라를 사용합니다.

ROI box filtering reduces capture time.

카메라 파일은 Sample Data 에서 다운로드할 수 있습니다.

먼저 ArUco 마커가 있는 포인트 클라우드를 캡처합니다.

소스로 이동

source

const auto fileCamera = std::string(ZIVID_SAMPLE_DATA_DIR) + "/BinWithCalibrationBoard.zfc";

std::cout << "Creating virtual camera using file: " << fileCamera << std::endl;
auto camera = zivid.createFileCamera(fileCamera);

auto settings = Zivid::Settings{ Zivid::Settings::Acquisitions{ Zivid::Settings::Acquisition{} } };

const auto originalFrame = camera.capture(settings);
auto pointCloud = originalFrame.pointCloud();

ArUco 마커 프레임의 원점은 ArUco 마커의 중앙에 있습니다.

체커보드 프레임에 상대적인 ROI 상자 크기 및 오른쪽 하단 모서리.

ArUco 마커 프레임과 ROI 상자 크기를 기준으로 ROI 상자의 오른쪽 하단 모서리 위치를 정의합니다. 그런 다음, 길이와 너비에서 빈 가장자리의 너비를 빼서 빈 벽을 제거합니다.

소스로 이동

source

const float roiBoxLength = 545.F;
const float roiBoxWidth = 345.F;
const float roiBoxHeight = 150.F;
// Coordinates are relative to the ArUco marker origin which lies in the center of the ArUco marker.
// Positive x-axis is "East", y-axis is "South" and z-axis is "Down".
const Zivid::PointXYZ roiBoxLowerRightCornerInArUcoFrame{ 240.F, 30.F, 5.F };
const Zivid::PointXYZ roiBoxUpperRightCornerInArUcoFrame{ roiBoxLowerRightCornerInArUcoFrame.x,
                                                          roiBoxLowerRightCornerInArUcoFrame.y - roiBoxWidth,
                                                          roiBoxLowerRightCornerInArUcoFrame.z };
const Zivid::PointXYZ roiBoxLowerLeftCornerInArUcoFrame{ roiBoxLowerRightCornerInArUcoFrame.x - roiBoxLength,
                                                         roiBoxLowerRightCornerInArUcoFrame.y,
                                                         roiBoxLowerRightCornerInArUcoFrame.z };

ROI 상자의 기본 프레임을 정의하는 세 지점을 설정할 수 있습니다.

소스로 이동

source

const Zivid::PointXYZ pointOInArUcoFrame = roiBoxLowerRightCornerInArUcoFrame;
const Zivid::PointXYZ pointAInArUcoFrame = roiBoxUpperRightCornerInArUcoFrame;
const Zivid::PointXYZ pointBInArUcoFrame = roiBoxLowerLeftCornerInArUcoFrame;

그런 다음 ArUco 마커를 구성합니다.

소스로 이동

source

std::cout << "Configuring ArUco marker" << std::endl;
const auto markerDictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_100);
std::vector<int> markerIds;
std::vector<std::vector<cv::Point2f>> markerCorners;
cv::Ptr<cv::aruco::DetectorParameters> detectorParameters = cv::aruco::DetectorParameters::create();
detectorParameters->cornerRefinementMethod = cv::aruco::CORNER_REFINE_SUBPIX;

OpenCV를 사용하기 때문에 포인트 클라우드의 2D 이미지를 OpenCV 이미지 형식으로 변환해야 합니다.

소스로 이동

source

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

2D 이미지에서 ArUco 마커를 감지합니다.

소스로 이동

source

std::cout << "Detecting ArUco Marker" << std::endl;
cv::aruco::detectMarkers(grayImage, markerDictionary, markerCorners, markerIds, detectorParameters);

그런 다음 ArUco 마커의 포즈를 추정하여 세 지점을 카메라 기준 프레임으로 변환합니다.

소스로 이동

source

std::cout << "Estimating pose of detected ArUco marker" << std::endl;
const auto transformMarkerToCamera = estimateArUcoMarkerPose(pointCloud, markerCorners[0]);
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 },
    transformMarkerToCamera);

힌트

작동 방식을 궁금하다면 Position, Orientation and Coordinate Transformations 에 대해 자세히 알아보세요.

이제 ROI 상자의 크기와 위치를 기반으로 포인트 클라우드를 필터링할 수 있습니다. 첫 번째 범위는 바닥을 포함하도록 작은 음수 값으로 설정되고 두 번째 범위는 상자의 원하는 높이로 설정됩니다.

소스로 이동

source

settings.set(Zivid::Settings::RegionOfInterest{
    Zivid::Settings::RegionOfInterest::Box::Enabled::yes,
    Zivid::Settings::RegionOfInterest::Box::PointO{ roiPointsInCameraFrame[0] },
    Zivid::Settings::RegionOfInterest::Box::PointA{ roiPointsInCameraFrame[1] },
    Zivid::Settings::RegionOfInterest::Box::PointB{ roiPointsInCameraFrame[2] },
    Zivid::Settings::RegionOfInterest::Box::Extents{ -10, roiBoxHeight } });

마지막으로 새로운 캡처를 수행하고 필터링된 포인트 클라우드를 시각화합니다.

소스로 이동

source

const auto roiFrame = camera.capture(settings);

std::cout << "Displaying the ROI-filtered point cloud" << std::endl;
visualizeZividPointCloud(roiFrame);

체커보드가 있는 빈의 ROI 필터링 및 변환 포인트 클라우드

ROI 상자를 기반으로 포인트 클라우드를 필터링하려면 코드 샘플을 실행할 수 있습니다.

Sample: ROIBoxViaArucoMarker.cpp

./ROIBoxViaArucoMarker

자신의 설정에서 이것을 사용하려면 코드 샘플을 수정하십시오.

  1. 파일 카메라를 실제 카메라 및 설정으로 교체하십시오.

  2. 빈의 오른쪽 하단 모서리에 칼리브레이션 보드를 놓습니다.

  3. ROI 상자 크기를 실제 사용하는 빈의 크기로 수정합니다.

  4. 샘플 실행합니다!

이제 ROI 매개변수로 캡처 설정을 저장하고 칼리브레이션 보드를 제거하고 전체 빈의 설정을 사용할 수 있습니다.