OpenCV:将 Mat 转换为 UChar4
OpenCV: Convert Mat into UChar4
我刚刚完成了Udacity 并行编程第 2 阶段课程,现在我正在使用 OpenCV 将我所学到的知识应用到一个基本应用程序中,该应用程序将高斯模糊应用于通过网络摄像头的持续图像流。
我正在将帧加载到一个Mat
对象中,在我的循环中我想调用一个方法gaussian_cpu
,唯一的问题是它需要将 uchar4 传递给输入和输出参数。如何将Mat
对象转换为uchar4
?
// Keep processing frames - Do CPU First
while(cpu_frames > 0)
{
cout << cpu_frames << "n";
camera >> frameIn;
gaussian_cpu(frameIn, frameOut, numRows(), numCols(), h_filter__, 9);
imshow("Source", frameIn);
imshow("Dest", frameOut);
// 2ms delay to prevent system from being interrupted whilst drawing the new frame
waitKey(2);
cpu_frames--;
}
我的方法签名如下所示:
void gaussian_cpu(
const uchar4* const rgbaImage, // input image from the camera
uchar4* const outputImage, // The image we are writing back for display
size_t numRows, size_t numCols, // Width and Height of the input image (rows/cols)
const float* const filter, // The value of sigma
const int filterWidth // The size of the stencil (3x3) 9
)
我需要使用 uchar4,这样我就可以拆分通道,进行卷积,然后重新组合通道以返回输出图像。 有什么办法可以做到这一点吗?
opencv 通常使用 bgr,3 通道垫,但基本:
Mat bgra;
cvtColor( frameIn, bgra, CV_BGR2BGRA );
将生成一个(未使用的(第 4 个通道。 现在你可能必须为你分配 mem 输出图像:
Mat frameOut( bgra.size(), bgra.type() );
然后你可以把它们输入到你的gaussian_cpu((:
int filterWidth=5;
float *filter = ... // your job, not mine ;)
gaussian_cpu( (uchar4*)(bgra.data), (uchar4*)(frameOut.data), bgra.rows, bgra.cols, filter, filterWidth );
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中使用nlohmann从类到json的转换
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 复制列表初始化的隐式转换的等级是多少
- 正在将指针转换为范围
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 是否可以从int转换为enum类类型
- openCL:如何将 uint4 转换为 uchar4
- OpenCV:将 Mat 转换为 UChar4