如何使用 OpenCV 比较存储在文件中的两个图像

how to compare two images stored in a file using opencv

本文关键字:图像 两个 OpenCV 何使用 比较 存储 文件      更新时间:2023-10-16

我的硬盘包含从2分钟视频中提取的3380帧。

  1. 我想对相似的帧进行分组,并且从每个组中将一个/两个帧作为代表整个帧组的组的标题。

  2. 我也尝试使用直方图比较,但直方图仅提供图形表示,

我正在做视频摘要

这是我的代码:

#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main(int argc, char** argv)
{
    // Read a video file from file
    CvCapture* capture = cvCaptureFromAVI("C:\Users\Pavilion\Documents\Visual Studio 2013\Projects\video\optical illusions.avi");
    int loop = 0;
    IplImage* frame = NULL;
    Mat matframe;
    Mat img_hsv, img_rgb;
    char fname[20];
    do
    {
        // capture frames from video
        frame = cvQueryFrame(capture);
        matframe = cv::cvarrToMat(frame);
        // create a window to show frames
        cvNamedWindow("video_frame", CV_WINDOW_AUTOSIZE);
        // Display images in a window
        cvShowImage("video_frame", frame);
        sprintf(fname, "C:\Users\Pavilion\Documents\Visual Studio 2013\Projects\video\video\frames\frame%d.jpg", loop);
        // write images to a folder
        imwrite(fname, matframe);
        // Convert RGB to HSV
        cvtColor(img_rgb, img_hsv, CV_RGB2HSV);
        loop++;
        cvWaitKey(10);
    } while (frame != NULL);
    return 0;
    /*
    // read and process frames from file
    char name[50];
    int i = 0;
    Mat output_image;
    while (1){
    sprintf(name, "frame%d.jpg", i);
    //Load the image
    Mat input_image = imread(name, 1);
    if (!input_image.data) break;
    //Image RGB to Grayscale
    cvtColor(input_image, output_image, CV_RGB2GRAY);
    //Applying Gaussian
    GaussianBlur(output_image, output_image, Size(21.0, 21.0), 50.0);
    //applying adaptive threshold
    adaptiveThreshold(output_image, output_image, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV, 111, -20);
    sprintf(name, "frame%d-bin.jpg", i);
    //save the image
    imwrite(name, output_image);
    i++;

    }
    */
}

有人可以帮助我吗,我是OpenCV的新手。

您可以使用特征检测对相似图像进行分组。如果你从frame1frame2那里得到足够的matches,它们应该是相似的。