使用OpenCV比较存储在文件中的两张图片

我的硬盘中包含从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,它们应该就是相似的。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注