I'm试图将像素数据转换为OpenCV Mat对象
I'm trying to convert pixel data to an OpenCV Mat object
我有原始像素数据,我想通过opencv-cvShowImage()函数输出。
我有以下代码:
#include <opencv2/highgui/highgui.hpp>
// pdata is the raw pixel data as 3 uchars per pixel
static char bitmap[640*480*3];
memcpy(bitmap,pdata,640*480*3);
cv::Mat mat(480,640,CV_8UC3,bitmap);
std::cout << mat.flags << ", "
<< mat.dims << ", "
<< mat.rows << ", "
<< mat.cols << std::endl;
cvShowImage("result",&mat);
哪个输出:
1124024336, 2, 480, 640
到控制台,但无法使用cvShowImage()输出图像。相反,抛出一个异常,并显示消息:
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat
我怀疑问题出在我创建垫子对象的方式上,但我很难找到关于我应该如何做到这一点的更具体的信息。
我认为CV_8UC3的描述不足以呈现数据数组。难道它不必知道数据是RGB还是YUY2等等吗。?我该如何设置?
尝试cv::imshow("result", mat)
,而不是混合使用旧的C和新的C++API。我认为将Mat
转换为CvArr*
是问题的根源。
所以,像这样的东西:
#include <opencv2/highgui/highgui.hpp>
// pdata is the raw pixel data as 3 uchars per pixel
static char bitmap[640*480*3];
memcpy(bitmap,pdata,640*480*3);
cv::Mat mat(480,640,CV_8UC3,bitmap);
std::cout << mat.flags << ", "
<< mat.dims << ", "
<< mat.rows << ", "
<< mat.cols << std::endl;
cv::imshow("result", mat);
相关文章:
- 防止主数据类型C++的隐式转换
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 如何在C++中将十六进制字符串转换为文本数据
- 将复杂的非基元C++数据类型转换为 Erlang/Elixir 格式,以使用 NIF 导出方法
- 从'size_t'转换为"常量双倍",可能会丢失数据
- 将传入的网络"char*"数据转换为"uint8_t"并返回的安全方法是什么?
- Static_cast转换为错误的数据类型,但结果仍然正确?
- 使用带有链表的堆栈数据结构将中缀转换为后缀
- PyTorch C++将数据转换为张量失败
- 使用从文件(stod、strtod、atof)中提取的数据C++从字符串转换为双精度.csv
- 虚拟成员函数的定义是否强制在同一转换单元中动态初始化静态数据成员?
- 如何使用 dart:ffi 将 Uint8List 转换为 C 等效数据类型
- 如何索引转换后的用户数据值?
- 使用 OpenCV 和 Android NDK 转换数据格式
- 如何转换数据结构以在 c++ 中转换字符*
- C++读取文件并转换数据
- 在C++中为C库强制转换数据类型
- 在C++中,关于位移和强制转换数据类型
- 最有效的方式转换数据帧到矩阵,反之亦然