我正在尝试将视频与视频中已经存在的图像(.jpg 格式)(.avi 格式)进行比较。我正在尝试在 Visual C++ 中完成这项任务。当比较两个静态图像时,它会给出正确的结果,但是当将图像与视频进行比较时,在视频中未检测到该图像。我正在使用以下代码来完成上述任务:
// project1.1.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/legacy/legacy.hpp"
#include <stdio.h>
#include <iostream>
IplImage* image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;
CvSize size;
int w0, h0,i;
int threshold1, threshold2;
int l,level = 4;
int sthreshold1, sthreshold2;
int l_comp;
int block_size = 1000;
float parameter;
double threshold;
double rezult, min_rezult;
int filter = CV_GAUSSIAN_5x5;
CvConnectedComp *cur_comp, min_comp;
CvSeq *comp;
CvMemStorage *storage;
CvPoint pt1, pt2;
static void ON_SEGMENT(int a)
{
(void)a;
cvPyrSegmentation(image0, image1, storage, &comp,
level, threshold1+1, threshold2+1);
cvShowImage("Segmentation", image1);
}
using namespace std;
int main( int argc, char** argv )
{
char* filename;
CvCapture *capture = cvCaptureFromAVI("fractogene.avi");
if(!capture)
{
printf("!!! cvCaptureFromAVI failed (file not found?)\n");
while(1);
return -1;
}
int fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
cvNamedWindow("display_video", CV_WINDOW_AUTOSIZE);
IplImage* frame = NULL;
IplImage* frame1 = NULL;
char key = 0;
filename = argc == 2 ? argv[1] : (char*)"loadedimage.bmp";
if( (image[0] = cvLoadImage( filename, 1)) == 0 )
{
printf("Cannot load fileimage - %s\n", filename);
return -1;
}
frame1=image[0];
cvNamedWindow("Source", 0);
cvShowImage("Source", frame1);
while (key != 'q')
{
frame = cvQueryFrame(capture);
if (frame==frame1)
printf("frames matched\n");
else
printf("frames not matched\n");
if (!frame)
{
printf("!!! cvQueryFrame failed: no frame\n");
break;
}
cvShowImage("display_video", frame);
key = cvWaitKey(1000 / fps);
}
cvReleaseCapture(&capture);
cvWaitKey(0);
return 0;
}
我的项目即将到期。如果可能,请提供帮助。期待您的回复。