有关春的诗句
三字俗语梦见抱孩子图像相似度计算之直⽅图⽅法OpenCV实现
英文词汇
操作步骤:
1. 载⼊图像(灰度图或者彩⾊图),并使其⼤⼩⼀致;
黄瓜炒胡萝卜2. 若为彩⾊图,增进⾏颜⾊空间变换,从RGB转换到HSV,若为灰度图则⽆需变换;
3. 若为灰度图,直接计算其直⽅图,并进⾏直⽅图归⼀化;
我好想你英文4. 若为彩⾊图,则计算其彩⾊直⽅图,并进⾏彩⾊直⽅图归⼀化;
5. 使⽤相似度公式,如相关系数、卡⽅、相交或巴⽒距离,计算出相似度值。
string strSrcImageName = "src.jpg"; cv::Mat matSrc, matSrc1, matSrc2; matSrc = cv::imread(strSrcImageName, CV_LOAD_IMAGE_UNCHANGED); cv:: resize(matSrc, matSrc1, cv::Size(357, 419), 0, 0, cv::INTER_NEAREST); cv::resize(matSrc, matSrc2, cv::Size(2177, 3233), 0, 0, cv::INTER_LANCZOS4) ; cv::Mat matDst1, matDst2; cv::Size sizeImage = cv::Size(500, 500); cv::resize(matSrc1, matDst1, sizeImage, 0, 0, cv::INTER_CUBIC); //cv::flip(matDst 1, matDst1, 1); cv::resize(matSrc2, matDst2, sizeImage, 0, 0, cv::INTER_CUBIC); if (matSrc.channels() == 1) { int hist司马懿夫人>蜂蜜的用途
Size = 256; float range[] = {0, 256 }; const float* histRange = {range}; bool uniform = true; bool accumulate = fal; cv::Mat hist1, hist2; cv::calcHist(&matDst1, 1, 0, cv::Mat(), hist1, 1, & histSize, &histRange, uniform, accumulate); cv::normalize(hist1, hist1, 0, 1, cv::NORM_MINMAX, -1, cv::Mat()); cv::calcHist(&matDst2, 1, 0, cv::Mat(), h ist2, 1, &histSize, &histRange, uniform, accumulate); cv::normalize(hist2, hist2, 0, 1, cv::NORM_MINMAX, -1, cv::Mat()); double dSimilarity = cv::compa reHist(hist1, hist2, CV_COMP_CORREL);//,CV_COMP_CHISQR,CV_COMP_INTERSECT,CV_COMP_BHATTACHARYYA cout<<"similarity = "<<dSimila rity<<endl; } el { cv::cvtColor(matDst1, matDst1, cv::COLOR_BGR2HSV); cv::cvtColor(matDst2, matDst2, cv::COLOR_BGR2HSV); int h_bins = 50, s _bins = 60; int histSize[] = {h_bins, s_bins}; float h_ranges[] = {0, 180}; float s_ranges[] = {0, 256}; const float* ranges[] = {h_ranges, s_ranges}; int ch annels[] = {0, 1}; cv::MatND hist1, hist2; cv::calcHist(&matDst1, 1, channels, cv::Mat(), hist1, 2, histSize, ranges, true, fal); cv::normalize(hist1, hist1, 0, 1, cv::NORM_MINMAX, -1, cv::Mat()); cv::calcHist(&matDst2, 1, channels, cv::Mat(), hist2, 2, histSize, ranges, true, fal); cv::normalize(hist2, hist2, 0, 1, cv::NORM_MINMAX, -1, cv::Mat()); double dSimilarity = cv::compareHist(hist1, hist2, CV_COMP_CORREL); cout<<"similarity = "<<dSimilarity<<en dl; }