【问题标题】:Nao Robot: How to use the ALImage ROINao 机器人:如何使用 ALImage ROI
【发布时间】:2014-02-05 22:13:29
【问题描述】:

我想做的事:

将 Nao Robot 相机图像的 ROI 转换为 OpenCV::Mat 格式。稍后我将使用这个 OpenCV::Mat

情况:

Nao SDK 以ALImage 的格式提供图像。可以convert the ALImage to OpenCV::Mat format,但我不需要所有的图像,只需要一个小的 ROI。尽管 ALImage 提供了自己的ROI,但使用它的方法并不是很有帮助:

int        getNumOfROIs () const 
const ROI* getROI (int index) const
void       addROI (const ROI &rect)
void       cleanROIs ()
void       setEnableROIs (bool enable)
bool       isROIEnabled () const 

问题:

如何使用这些 ROI?

【问题讨论】:

    标签: c++ opencv nao-robot


    【解决方案1】:

    假设您已经有了 ROI 的坐标,您可以像 this 一样裁剪 cv::Mat

    // your source image
    cv::Mat image(imagesource); 
    
    // a rectangle with your ROI coordinates
    cv::Rect myROI(10, 10, 100, 100);
    
    // a "reference" to the image data within the rectangle
    cv::Mat croppedImage = image(myROI);
    

    请注意,这不会复制图像数据。 imagecroppedImage 都共享相同的底层原始数据(详细示例可以在 opencv documentation 中找到)。完成大源图像后,您可以执行 image.release()croppedImage = croppedImage.clone(); 来释放所有不必要的数据(在您的 ROI 之外)。

    编辑:

    我还没有与AL::ALImage::ROI 合作,但the definition in alimage/alimage.h 看起来对cv::Rect 很熟悉。因此,您可能可以执行以下操作:

    // let's pretend you already got your image ...
    AL::ALImage yourImage;
    // ... and a ROI ...
    AL::ALImage::ROI yourROI;
    // ... as well as a Mat header with the dimensions and type of yourImage
    cv::Mat header;
    
    // then you can convert the ROI, ...
    cv::Rect cvROI(yourROI.x, yourROI.y, yourROI.w, yourROI.h);
    // ... wrap ALImage to a Mat (which should not copy anything) ...
    header.data = yourImage.getData();
    // ... and then proceed with the steps mentioned above to crop your Mat
    cv::Mat cropped = header(cvROI);
    header.release();
    cropped = cropped.clone();
    
    // ... 
    // your image processing using cropped
    // ...
    

    我希望这会有所帮助。

    【讨论】:

    • 我不是在问如何使用 OpenCV ROI,我是在问如何使用 ALImage ROI。请仔细阅读所有问题。
    • @Manuel 那么请更具体地说明您拥有什么以及您真正想要什么,因为“使用 ALImage ROI”非常抽象。
    猜你喜欢
    • 2022-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多