我正在检测图像中包含正方形的所有区域。我根据其四个坐标(例如 A、B、C、D)得到包含正方形的检测区域,如下所示:
检测到存在正方形的区域后,我需要创建该区域的直方图。目前,我首先为每个区域创建单独的图像,然后将每个图像发送到 getHistogram(Mat detectedSquare);
以获取直方图。
问题:我的应用程序的计算时间非常非常长,所以我想找到一些方法可以跳过为每个区域创建单独的独立正方形。
我想做的事情:直接为每个区域创建直方图而不为其创建图像。
目前我正在为每个区域创建单独的图像,如下所示,我想摆脱它:
Mat detectedSquare;
detectedSquare.create(rows, cols, CV_8UC3);
Rect regionOfInterest = Rect (min_x,min_y, rows, cols);
detectedSquare= original_Image(regionOfInterest);
getHistogram(Mat detectedSquare);
最佳答案
假设Rect roi
是图像Mat mat
的子区域,你想计算它的直方图,你可以直接这样调用:
getHistgram(Mat(mat(Range(roi.y, roi.y+roi.height)
, Range(roi.x, roi.x+roi.width))));
编辑:正如您在下面评论的那样,您希望使用多线程来加快速度。也许最简单的方法是使用 OpenMP .
vector<Rect> squares(N); // N square regions
#pragma omp parallel for
for (int i=0; i<N; i++)
{
// ... compute histogram for squares[i] ...
}
关于c++ - 将几个 ROI 发送到另一个方法/函数来计算直方图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21705069/