如何将帧复制到帧

时间:2012-07-11 22:00:19

标签: c opencv

如何将一帧中的变量转换为另一帧,这是一种不是内存管理问题的副本

例如:

iplimage *frame = NULL;
iplimage *Temp_frame = NULL;

while(1) {
frame = cvQueryFrame( capture );

if( !frame ) break;

    Temp_frame=cvcloneimage(frame);

    cvreleaseImage(&Temp_frame);

    cvreleaseImage(&frame);
}

错误:

打开cv.exe时0x75b39673处的未处理异常:Microsoft C ++异常:cv ::内存位置0x0015f250处的异常..

请帮忙。

1 个答案:

答案 0 :(得分:1)

iplimage *frame = NULL;
iplimage *Temp_frame = NULL;

while(1) 
{
    frame = cvQueryFrame(capture);    
    if (!frame) 
        break;

    if (!Temp_frame) // creates Temp_frame only once
        Temp_frame = cvCreateImage(cvGetSize(frame), frame->depth, frame->nChannels);    

    cvCopy(frame , Temp_frame, NULL);

    // DO NOT RELEASE the return of cvQueryFrame()!
    // I believe that's what crashing your application.
    //cvreleaseImage(&frame);
}

// Since the size of "frame" won't change, there's no need to to create/release 
// Temp_frame on every iteration of the loop. So we release it at the end:
cvReleaseImage(&Temp_frame);