opencv 计算两幅图像相似度(欧氏距离,余弦距离)

功能:利用HOG特征比较两幅图像的相似度

opencv PAI:

CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride,
                  Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1,
                  int _histogramNormType=HOGDescriptor::L2Hys,
                  double _L2HysThreshold=0.2, bool _gammaCorrection=false,
                  int _nlevels=HOGDescriptor::DEFAULT_NLEVELS, bool _signedGradient=false)
#include
#include
#include "string"
#include "algorithm"
#include"opencv2/opencv.hpp"

void GetHOGHistogram(cv::Mat img,std::vector&descriptors)//取得图像img的HOG特征向量
{
    cv::HOGDescriptor *hog=new cv::HOGDescriptor(cvSize(64,128),cvSize(32,32),cvSize(8,8),cvSize(16,16),9);
    hog->compute(img,descriptors,cv::Size(8,8), cv::Size(0,0));
}
int main()
{
    std::string imgDir01 = "/home/.../images/personTestImage/2021-05-14_15-21-06.jpg";
    std::string imgDir02 = "/home/.../images/personTestImage/2021-05-14_15-21-09.jpg";

    cv::Mat src01 = cv::imread(imgDir01, 0);
    std::cout<<"src01.size(x,y):"< hogDesc01(0);
    std::vector hogDesc02(0);
    GetHOGHistogram(src01, hogDesc01);
    GetHOGHistogram(src02, hogDesc02);
    std::cout<

素材:

opencv 计算两幅图像相似度(欧氏距离,余弦距离)_第1张图片opencv 计算两幅图像相似度(欧氏距离,余弦距离)_第2张图片

运行结果:

opencv 计算两幅图像相似度(欧氏距离,余弦距离)_第3张图片

参考:

https://blog.csdn.net/yixinuestc/article/details/104689902 代码参考该博客

https://blog.csdn.net/v_july_v/article/details/8203674/ 该博客提到了巴氏距离以及各种距离以及KD树的知识点

https://www.cnblogs.com/likui360/p/11972495.html 该博客列举了欧式距离,曼哈顿距离,余弦距离以及杰拉德等距离

 

 

 

你可能感兴趣的:(C++,OpenCV,API,图像处理,opencv,计算机视觉)