c++ - How do I get the region of interest in 3 channels when capturing images with computer vision?
问题描述
I am learning about computer vision. I get ROI in mono channel like this.(cf. I calculate sample average pixel color.)
std::string path = "C:\\image\\Lenna.png";
cv::Mat mImage = cv::imread(path);
cv::Mat mImage_mono;
cv::cvtColor(mImage, mImage_mono, CV_RGB2GRAY);
int width = mImage_mono.cols;
int height = mImage_mono.rows;
unsigend char * PImage = mImage_mono.data
const int kernel_size = 100;
const int kernel_size_half = 100/2;
int sum
int avg
sum = 0;
for (int row = height / 2 - kernel_size_half; row < height / 2 + kernel_size_half; row++) {
for (int col = width / 2 - kernel_size_half; col < width / 2 + kernel_size_half; col++)
{
int index = row * width + col;
sum+= pImage[index];
}
}
avg = sum / (kernel_size * kernel_size);
I want to get ROI in 3 channels(R,G,B) like mono channels(I want using 'for' code) and I want something like face detection only in ROI. In 3 channels, I have to take into account about array. I know that array takes data ordering (B, G, R). So I think I have to multiply 3 at width and height and i do that but do not work correctly. how I can get ROI in multi channels not using fuction "cv::cvSetImageROI"?
解决方案
你想通过颜色通道分割图像并获得每个通道的ROI吗?
cv::Rect r(0, 0, roi_width, roi_height);
cv::Mat bgr[3];
cv::Mat b_roi;
cv::split(image, bgr);
b_roi = bgr[0](r); // get the ROI of blue channel
希望这可以帮助
推荐阅读
- django - 如何测试/模拟断开的数据库连接
- r - 仅在使用 R Markdown 的投影仪暂停后显示脚注
- python - 如何在没有 OpenCV 的情况下使用 Python 将 Rodrigues 向量转换为旋转矩阵
- javascript - javascript中的倒数计时器,只有天、小时、分钟-摆脱秒
- javascript - 带有 Tampermonkey 的警报用户名
- mysql - SQL - 我如何计算每天的活跃订阅者
- azure - Azure DataFactory 中流水线的条件执行
- html - 如何在一行中将 3 个 div 等间距与浏览器的等间距
- sql-server - 如何在 SQL Server 的日期范围内使用 Stacked CTE 或日历表
- python - 为什么 Django 的 pk_range 方法不起作用?