根据一个男生的照片,从已有的女生图片中匹配到和男生最般配的女生,这要怎么用c++实现呀!求帮助😨
你这里的最般配指什么?特征?还是相似度?得用到opencv,我这里给一个案例
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void matchFeatures(Mat& descriptors1, Mat& descriptors2, vector<DMatch>& matches) {
// 特征匹配器
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce");
// 根据特征描述符进行匹配
matcher->match(descriptors1, descriptors2, matches);
}
double computeSimilarityScore(vector<DMatch>& matches) {
double score = 0.0;
for (size_t i = 0; i < matches.size(); i++) {
score += matches[i].distance;
}
return score;
}
int findBestMatch(Mat& descriptors1, vector<Mat>& descriptors2List) {
int bestMatchIndex = -1;
double bestScore = numeric_limits<double>::max();
for (size_t i = 0; i < descriptors2List.size(); i++) {
vector<DMatch> matches;
matchFeatures(descriptors1, descriptors2List[i], matches);
double score = computeSimilarityScore(matches);
if (score < bestScore) {
bestScore = score;
bestMatchIndex = i;
}
}
return bestMatchIndex;
}
int main() {
Mat maleImage = imread("male.jpg", IMREAD_GRAYSCALE);
Mat femaleImage1 = imread("female1.jpg", IMREAD_GRAYSCALE);
Mat femaleImage2 = imread("female2.jpg", IMREAD_GRAYSCALE);
// 提取特征描述符
Ptr<FeatureDetector> detector = ORB::create();
Ptr<DescriptorExtractor> extractor = ORB::create();
vector<KeyPoint> maleKeypoints, femaleKeypoints1, femaleKeypoints2;
Mat maleDescriptors, femaleDescriptors1, femaleDescriptors2;
detector->detectAndCompute(maleImage, Mat(), maleKeypoints, maleDescriptors);
detector->detectAndCompute(femaleImage1, Mat(), femaleKeypoints1, femaleDescriptors1);
detector->detectAndCompute(femaleImage2, Mat(), femaleKeypoints2, femaleDescriptors2);
// 构建女生的特征描述符列表
vector<Mat> femaleDescriptorsList = { femaleDescriptors1, femaleDescriptors2 };
int bestMatchIndex = findBestMatch(maleDescriptors, femaleDescriptorsList);
if (bestMatchIndex >= 0) {
cout << "The best match is female" << bestMatchIndex + 1 << endl;
} else {
cout << "No match found" << endl;
}
return 0;
}
夫妻相
答案:时间足够长后,男女比例依然1:1
假设有n个家庭
n/2的家庭第一胎就生出男孩,所以只有1个孩子。
有n/4的家庭先生1女孩,再生1男孩,有2个孩子。
有n/8的家庭线生2女孩,再生1男孩,有3个孩子。
孩子总数为:
n/2+(n/4)x2+(n/8)x3 +(n/16)x4… = 2xn
每个家庭都会有一个男孩,所以2n的孩子中,男孩数为n,所以女孩数也为n。
所以比列依然为1:1
一般来说,可以把人的相貌分为一些类型,比如说女生的短发、流海、马尾、长发,脸型的圆脸、瓜子、梨子,体型的消瘦、丰腴等等,你可以用有监督学习或者无监督学习先对照片聚类或者分类,然后你可以让异性首先在几个随机抽取的图片里选择ta喜欢的类型,然后将对应的类型再给他匹配。要考虑某些类型的供给平衡问题,比如说美女很多男生都喜欢,所以说还要给每个人进行一个供给需求度的打分,优先将需求度高的两者先匹配起来。
在真实的商业系统里,门道就更多了,有时候要考虑的是刺激更多用户使用,那么还得故意造成一些失配,以便吊住一些用户的胃口。