Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenCV-Mat的向量数组_C++_Opencv - Fatal编程技术网

C++ OpenCV-Mat的向量数组

C++ OpenCV-Mat的向量数组,c++,opencv,C++,Opencv,我已经创建了矢量的矢量来存储cv::Mat(framecollection)。我的计划是将视频的每一帧分割成N*N个块并存储。但在这里,当我运行代码时,它只在framecollection的每个位置存储最后一帧。我不知道代码有什么问题 int nframes=(int)capture.get(CV_CAP_PROP_FRAME_COUNT); int frame_row=capture.get(CV_CAP_PROP_FRAME_HEIGHT); int frame_cols=capture.g

我已经创建了矢量的矢量来存储cv::Mat(framecollection)。我的计划是将视频的每一帧分割成N*N个块并存储。但在这里,当我运行代码时,它只在framecollection的每个位置存储最后一帧。我不知道代码有什么问题

int nframes=(int)capture.get(CV_CAP_PROP_FRAME_COUNT);
int frame_row=capture.get(CV_CAP_PROP_FRAME_HEIGHT);
int frame_cols=capture.get(CV_CAP_PROP_FRAME_WIDTH);
int X=ceil(frame_row/(double)N);//rows
int Y=ceil(frame_cols/(double)N);//cols 
std::vector<std::vector<Mat> > framecollection(nframes, std::vector<Mat> (X*Y));
//std::array< std::vector<Mat>, nframes > framecollection;
int f=0;
for( ; ; )
{
    capture >> frame;

    if(frame.empty())
        break;

    vector<Mat> blocks;
    for (int r = 0; r < frame_row; r += N)
    {
        for (int c = 0; c < frame_cols; c += N)
        {
            Mat tile = frame(Range(r, min(r + N, frame_row)),Range(c, min(c + N, frame_cols)));
            blocks.push_back(tile);
        }
    }
    framecollection[f]=blocks;
    f++;

}
intnframes=(int)capture.get(CV\u CAP\u PROP\u FRAME\u COUNT);
int frame\u row=capture.get(CV\u CAP\u PROP\u frame\u HEIGHT);
int frame\u cols=capture.get(CV\u CAP\u PROP\u frame\u WIDTH);
int X=单元(帧/行/(双)N)//排
int Y=ceil(帧列/(双)N)//科尔斯
std::vector帧集合(nframes,std::vector(X*Y));
//std::arrayframecollection;
int f=0;
对于(;;)
{
捕获>>帧;
if(frame.empty())
打破
向量块;
对于(int r=0;r

//framecollection在每个位置只提供最后一帧

尝试
块。向后推(tile.clone())
VideoCapture
重用存储帧的
Mat
Mat
的工作原理有点像一个共享指针(您可能应该花更多的时间阅读文档)——它只在必要或明确请求时进行复制/重新分配。在您的情况下,您只是对单个底层共享映像进行了额外的查看。感谢sturkmen和Dan Mašek的回复,我理解我的错误。尝试
blocks.push_back(tile.clone())
VideoCapture
重用存储帧的
Mat
Mat
的工作原理有点像一个共享指针(您可能应该花更多的时间阅读文档)——它只在必要或明确请求时进行复制/重新分配。在你的例子中,你只是对单一的底层共享映像进行了额外的查看。感谢sturkmen和Dan Mašek的回复,我理解我的错误。