gpt4 book ai didi

visual-studio-2010 - 如何使用opencv获取视频的第一帧?

转载 作者:行者123 更新时间:2023-12-02 17:53:46 24 4
gpt4 key购买 nike

我必须找到视频的所有帧与该视频的第一帧的互相关...。

double crossCorrelation( IplImage* img1, IplImage* img2 ) {
double corr;
int M = img1->width;
int N = img1->height;

BwImage img_1( img1 );
BwImage img_2( img2 );

CvScalar img1_avg = cvAvg( img1, NULL );
CvScalar img2_avg = cvAvg( img2, NULL );

double sum_img1_img2 = 0;
double sum_img1_2 = 0;
double sum_img2_2 = 0;

for( int m=0; m<M; ++m ) {
for( int n=0; n<N; ++n ) {
sum_img1_img2 = sum_img1_img2 + (img_1[m][n]-img1_avg.val[0])*(img_2[m][n]-img2_avg.val[0]);
sum_img1_2 = sum_img1_2 + (img_1[m][n]-img1_avg.val[0])*(img_1[m][n]-img1_avg.val[0]);
sum_img2_2 = sum_img2_2 + (img_2[m][n]-img2_avg.val[0])*(img_2[m][n]-img2_avg.val[0]);
}
}

corr = sum_img1_img2/sqrt(sum_img1_2*sum_img2_2);
return corr;
}

这是用于找到相关性的代码。对于img1,我需要第1帧,其余帧将在循环中为img 2!

我该怎么办?
请帮忙!

最佳答案

试试这个代码...它的工作..

CvCapture *video = cvCaptureFromFile("C:\\path_to_video.avi");

IplImage *firstFrame = cvQueryFrame(video);//this is the first frame
IplImage *nextFrame;

while(nextFrame!=NULL)
{
nextFrame = cvQueryFrame(video);

if(nextFrame!=NULL)
double CrossCorrValue = crossCorrelation(firstFrame,nextFrame);
}

关于visual-studio-2010 - 如何使用opencv获取视频的第一帧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12230394/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com