繁体   English   中英

多个图像上的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) 怎么做?

由于framesstd::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]]

您始终可以阅读可接受的表达式列表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM