如何访问加载的映像的各个 R/G/B 组件(较新的 C++ API)
How to access the individual R/G/B components of a loaded in image (newer C++ API)
我见过类似的问题,但答案是针对旧的C API。
我有一个加载了cv::Mat img = cv::imread("C:/some_image.jpg");
的彩色图像 通常,我使用 img.at<float>(row, col)
访问灰度图像中的元素,但这显然只会返回浮点数。 如何为每个像素位置的每个分量 R、G、B 获取一个值(也许是浮点数?整数?)?
一种方法就像你一样,但三个通道将存储在三维向量中,而不是一个通道浮点数。
cv::Mat img = ...;
cv::Vec3f pixel = img.at<cv::Vec3f>(row, col);
// pixel contains [red, green, blue] values
你可以这样做:
img_channel_=image.channels();
img_rows_=image.rows;
img_cols_=image.cols;
if (image.isContinuous() && fg_img_.isContinuous() && moving_img_.isContinuous() && abandon_img_.isContinuous()) {
img_cols_ *=img_rows_;
img_rows_=1;
}
img_cols_*=img_channel_;
for (int i=0; i<img_rows_; ++i) {
const int iindex=i*img_cols_;
const uchar *piex=image.ptr<uchar>(i);//three channel
for (int j=0,truej=0; j<img_cols_; j+=img_channel_, ++truej) {
piex[0]=pixe[1]+piex[2];//B=G+R
}
}
相关文章:
- 如何将 txt 文件中的行分隔为组件C++
- 使用不同的CRT将新的C++代码与旧的(二进制)组件隔离开来的最佳方法是什么
- 到连接组件算法的问题(递归)
- 两个 COM 组件中 ENUM 的重复条目
- 为什么 gcc 会产生这种奇怪的组件与叮当声?
- 使用 bfs 解决连接组件问题时得到错误的答案
- 如何在ECS框架中更新组件数据和通知系统
- 如何从ECS中的模板方法获取组件?
- 使用蓝牙组件将数据从Android手机传输到串行设备时出现问题
- 组件上的虚幻引擎可蓝图UFUNCTION会导致构建错误
- 在C++中访问蓝图类组件的正确方法是什么?
- 有关纯 ECS(实体组件系统)和更新系统的问题
- 提高基于组件的游戏引擎的效率
- 从组件的 std::type_index 获取派生最多的类型
- 我们可以将阈值应用于色彩空间模型的单个组件(如 RGB 和 LAB)吗?
- 如何通过 UActor组件获取演员列表?
- 在Visual Studio 2017中使用c ++组件构建python解决方案时出现问题
- 如何访问基类向量中的子类变量?(对于实体组件系统)
- 根据组件 1、2(和 3)对空间 (2D/3D) 向量进行排序
- 从 WinRT C++组件访问 COM 对象