在OpenCV中使用ROI? [英] Using ROI in OpenCV?

查看:89
本文介绍了在OpenCV中使用ROI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ROI只能用矩形实现.但是,我有一个要设置为ROI的轮廓.有没有人知道我将如何使用轮廓作为ROI而不是矩形?

ROI can only be implemented with an rectangle. I however have a contour that I want to set as an ROI. Does anyone have an idea of how I would go about using a contour as an ROI rather than a rectangle?

否则,如果不可能的话,我如何仅将动作聚焦在特定轮廓的像素中?

Otherwise if not possible, how could I focus my actions only in pixels in a specific contour?

谢谢

PS:对不起所有这些OpenCV问题.真的很困惑:$

PS: Sorry for all these OpenCV questions. Just really confused :$

推荐答案

OpenCV仅支持矩形ROI.

OpenCV supports only rectangular ROIs.

但是,要对特定像素进行一些处理,可以使用一些辅助功能.

However, to make some processing for specific pixels, you can use some helper functions.

其中之一是pointPolygonTest(),它告诉您给定的像素不属于多边形.

One of them is pointPolygonTest(), which tells you a given pixel belongs on not to a polygon.

因此您可以编写类似

for(i=0;i<height;i++)
{
      for(j=0;j<width;j++)
      {
          if(pointPolygonTest(Point(i,j),myPolygon))
          {
                 // do some processing
          }
      }
}

也请检查此样本 http://opencv.itseez.com /doc/tutorials/imgproc/shapedescriptors/point_polygon_test/point_polygon_test.html#point-polygon-test

另一个(更快)的选项是@ andeas-haferburg推荐的一个.通过在新的灰度图像中绘制多边形来制作蒙版:

Another (faster) option is the one sugested by @andeas-haferburg. Make a mask by painting your polygon in a new grayscale image:

drawPoly() 

(因此背景为0,多边形为255),则可以传递其他功能,也可以自己使用它:

(So that background is 0, and the polygon is 255), Then you can pass to some other functions, or use it by yourself:

for(i=0;i<height;i++)
{
      for(j=0;j<width;j++)
      {
          if(mask[j+w*i]))
          {
                 // do some processing
          }
      }
}

上面的示例只是伪代码,您必须使其工作.

The example above is just pseudo code, you have to make it work.

这篇关于在OpenCV中使用ROI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆