c++ - 将几个 ROI 发送到另一个方法/函数来计算直方图?

标签 c++ opencv image-processing histogram

我正在检测图像中包含正方形的所有区域。我根据其四个坐标(例如 A、B、C、D)得到包含正方形的检测区域,如下所示:

image

检测到存在正方形的区域后,我需要创建该区域的直方图。目前,我首先为每个区域创建单独的图像,然后将每个图像发送到 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/

相关文章:

C++/CImg 不一致的结果

c++ - 是否有允许模拟 std::ifstream 和其他 I/O 库的模拟框架?

android - 从 ANDROID 设备实时流式传输视频到 OPENCV

c++ - 将 cv::Mat 转换为 IplImage*

algorithm - 视频变化检测

image - 每个颜色 channel 的位数是什么意思?

c++ - 虚函数中的默认参数

c++ - 在 Code::Blocks 中构建一个 wxWidgets 程序

opencv - 食品包装上的错误检测 - 使用 Opencv

python - 使用 OpenCV 和 Python 将拼图图像拼接在一起