C++ 多个图像上的 OpenCV 线性代数?
C++ OpenCV linear algebra on multiple images?
我对C++和OpenCV很陌生,但对Matlab更熟悉。我有一个任务需要移动到C++以加快处理速度。因此,我想就图像处理问题征求您的建议。我在一个文件夹中有 10 张图像,我能够像这样使用 dirent.h 读取它们,并通过在 while 循环中调用frame[count] = rawImage
来提取每一帧:
int count = 0;
std::vector<cv::Mat> frames;
frames.resize(10);
while((_dirent = readdir(directory)) != NULL)
{
std::string fileName = inputDirectory + "\" +std::string(_dirent->d_name);
cv::Mat rawImage = cv::imread(fileName.c_str(),CV_LOAD_IMAGE_GRAYSCALE);
frames[count] = rawImage; // Insert the rawImage to frames (this is original images)
count++;
}
现在我想访问每个帧并进行类似于 Matlab 的计算,以获得另一个矩阵A
,以便A = frames(:,:,1)+2*frames(:,:,2)
.怎么做?
由于frames
是一个std::vector<cv::Mat>
,您应该能够通过以下方式访问每个Mat
:
// suppose you want the nth matrix
cv::Mat frame_n = frames[n];
现在,如果您想进行您在前两个Mat
上所说的计算,那么:
cv::Mat A = frames[0] + 2 * frames[1];
<小时 />示例:
// mat1 = [[1 1 1]
// [2 2 2]
// [3 3 3]]
cv::Mat mat1 = (cv::Mat_<double>(3, 3) << 1, 1, 1, 2, 2, 2, 3, 3, 3);
cv::Mat mat2 = mat1 * 2; // multiplication matrix x scalar
// just to look like your case
std::vector<cv::Mat> frames;
frames.push_back(mat1);
frames.push_back(mat2);
cv::Mat A = frames[0] + 2 * frames[1]; // your calculation works
// A = [[ 5 5 5]
// [10 10 10]
// [15 15 15]]
您始终可以阅读可接受的表达式列表。
相关文章:
- 使用工程空间在软件包中导入的线性代数库EIGEN
- 特征库,简单的线性代数操作,具有稀疏的矩阵,增加了其分配的尺寸
- C++ OpenMP 中线性代数函数的高效并行化
- C++ 多个图像上的 OpenCV 线性代数?
- 带有 TooN 和 ROS 的线性代数
- 线性代数的过载操作员
- 线性代数转换矩阵 - 通过乘以矩阵从点到不同点
- 使用犰狳线性代数包存储矩阵需要多少内存
- 如何设计:矩阵的线性代数例程
- 具有复数的任意精度线性代数c/c++库
- 建议为C++选择一个线性代数库
- C++ eigen3 线性代数库,奇数性能结果
- OpenCV线性SVM未进行训练
- 转换gsl线性代数以用于scalapack或其他并行矩阵库
- 线性代数的CPU指令集
- 结合线性代数库与Boost::Units
- 本征在其线性代数Ax=b中能否使用双精度以上?
- 特征线性代数求解器似乎很慢
- 矩阵/线性代数库的多态包装器-C++,从Eigen开始
- 线性代数-SVD在C/C++中求解harwell-boeing稀疏a.x=b系统