数组到OpenCV矩阵
Array to OpenCV matrix
我有一个数组double dc[][]
,并希望将其转换为IplImage* image
并进一步转换为视频帧。我要做的就是给我一个视频,我提取出一些特征,然后用提取出来的特征制作一个新的视频。我的方法是将视频分成几帧从每一帧中提取特征然后像这样进行更新在每一帧的迭代中,我得到一个新的dc
double dc[48][44];
for(int i=0;i<48;i++)
{
for(int j=0;j<44;j++)
{
dc[i][j]=max1[i][j]/(1+max2[i][j]);
}
}
现在我需要保存这个dc以便我可以重建视频。谁来帮我一下。提前感谢
如果您同意使用Mat
,那么您可以为现有的用户分配的内存创建Mat
。其中一个Mat
构造函数的签名是:
Mat::Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP)
,其中参数为:
rows: the memory height,
cols: the width,
type: one of the OpenCV data types (e.g. CV_8UC3),
data: pointer to your data,
step: (optional) stride of your data
我建议你看一下这里的Mat
文档
int main()
{
//allocate and initialize your user-allocated memory
const int nrows = 10;
const int ncols = 10;
double data[nrows][ncols];
int vals = 0;
for (int i = 0; i < nrows; i++)
{
for (int j = 0; j < ncols; j++)
{
data[i][j] = vals++;
}
}
//make the Mat from the data (with default stride)
cv::Mat cv_data(nrows, ncols, CV_64FC1, data);
//print the Mat to see for yourself
std::cout << cv_data << std::endl;
}
您可以通过OpenCV VideoWriter类将Mat保存到视频文件中。你只需要创建一个VideoWriter,打开一个视频文件,然后写你的帧(就像Mat一样)。你可以在这里看到一个使用VideoWriter的例子
下面是使用VideoWriter类的一个简短示例:
//fill-in a name for your video
const std::string filename = "...";
const double FPS = 30;
VideoWriter outputVideo;
//opens the output video file using an MPEG-1 codec, 30 frames per second, of size height x width and in color
outputVideo.open(filename, CV_FOURCC('P','I','M,'1'), FPS, Size(height, width));
Mat frame;
//do things with the frame
// ...
//writes the frame out to the video file
outputVideo.write(frame);
VideoWriter最棘手的部分是打开文件,因为你有很多选项。您可以在这里看到不同编解码器的名称
相关文章:
- OpenCV C++.快速计算混淆矩阵
- 在 OpenCV C++ 中估计基本矩阵之前对相应点进行归一化的正确方法是什么?
- 如何在C++或OpenCV子矩阵中的2D子向量上使用OpenACC?
- 使用 mat.at<uchar>(i,j) 的 opencv C++中的矩阵赋值错误
- OpenCV矩阵奇怪的加法,乘法与浮点数和8位值
- 在C++中使用OpenCV矩阵中的特征将图像旋转90度
- OpenCV 向量 x 矩阵互相关
- 从 16UC3 到 8UC3 的高性能 OpenCV 矩阵转换
- OpenCV的卡尔曼滤波器过渡矩阵如何处理时间(如t和t^2)进行运动预测?
- 使用opencv在GPU上调整图像大小会产生空的输出矩阵
- Opencv中使用c++的矩阵乘法
- 将元素从opencv矩阵复制到特征矩阵
- 在opencv中创建4x4垫矩阵时出错
- OpenCV 简单 2D 矩阵乘法失败
- 如何在OpenCV中将4维矩阵转换为NHWC格式
- 在 openCV 矩阵中查找列最大值的索引和值
- 当我在Xcode上访问矩阵(openCV垫子)的位置时,为什么我会得到未定义的行为(exc_bad_access(代码=
- Boost thread_group 返回空矩阵 (openCV)
- 变换四元数相机旋转矩阵- OpenCV
- 单通道垫作为矩阵Opencv