基于关键点组合两个贴图的值
Combine values of two maps based on keys
这是最后的手段。。
所以我有两张地图。
typedef std::map <string, vector<float> > Dict;
typedef std::map <string, string> Dict1;
第一张地图的内容如下所示:Dict={A:-3.1,2.1,1.1};{B:-4.5,5.6,7.2}…
来自第二个映射的字符串与来自第一个映射的键相同。Dict1={A:B};。。。
我需要创建这样的东西:
Dict2 = {-3.1, 2.1, 1.1: -4.5, 5.6, 7.2}...
或者两个将它们放在两个向量中,但有可能重建Dict1的结构。从技术上讲,这些是一些点的坐标。
实际上,我走了第二条路线,试图创建两个向量,然后进行匹配,但显然我犯了一些错误。。这是我所拥有的:
typedef std::map <string, vector<float> > Dict;
typedef std::map <string, string> Dict1;
typedef std::vector<float> V1;
V1 v1;
V1 v2;
Dict d;
Dict d1;
//Here is the code, I know, oh well...
for( map<string, vector<float> >::iterator iter0 = d.begin(); iter0 != d.end(); ++iter0 ) {
for( map<string, string >::iterator iter1 = d1.begin(); iter1 != d1.end(); ++iter1 ) {
vector <float> tempVal0 = (*iter0).second;
string tempKey0 = (*iter0).first;
string tempVal1 = (*iter1).second;
string tempKey1 = (*iter1).first;
size_t comp1 = tempKey0.compare(tempKey1);
if(comp1 == 0 ){
for (unsigned i = 2; i < tempVal0.size(); i++) {
v1.push_back(tempVal0[i-2]);
v1.push_back(tempVal0[i-1]);
v1.push_back(tempVal0[i]);
for( map<string, vector<float> >::iterator iter00 = d.begin(); iter00 != d.end(); ++iter00 ) {
for( map<string, string >::iterator iter11 = d1.begin(); iter11 != d1.end(); ++iter11 ) {
vector <float> tempVal00 = (*iter00).second;
string tempKey00 = (*iter00).first;
string tempVal11 = (*iter11).second;
string tempKey11 = (*iter11).first;
size_t comp2 = tempVal1.compare(tempKey00);
if (comp2 == 0){
for (unsigned i = 2; i < tempVal00.size(); i++) {
v2.push_back(tempVal00[i-2]);
v2.push_back(tempVal00[i-1]);
v2.push_back(tempVal00[i]);
}
}
}
}
}
}
}
}
我错过了什么??
std::map<string, vector<float>> d;
std::map<string, string> d1;
std::map<vector<float>, vector<float>> d2;
// Fill the maps here
for(std::map<string, string>::iterator i = d1.begin(); i != d1.end(); i++) {
d2[d[i->first]] = d[i->second];
}
这是一个相当琐碎的操作,具有C++标准库的基本工作知识。我不完全确定你打算如何比较浮点向量。默认情况下,C++没有用于浮点向量的比较器。
相关文章:
- 如何在C++中从两个单独的for循环中添加两个数组
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- 如何返回一个类的两个对象相加的结果
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 两个字符串在 c++ 中不相等
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 两个文件使用彼此的功能-如何解决
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 如何确保在使用基于布尔值的两个方法之一调用方法时避免分支预测错误
- 停止cmake target_link_libraries将插件中静态库的两个对象文件链接到静态库本身
- 将fold表达式与std::一起用于两个元组
- 如何在C++中比较两个char数组
- 给定两个偶数,求出它们之间所有偶数的平方和
- 比较两个大小不等的映射c++
- C++需要帮助从用户那里获得一个整数,并确保它在另外两个整数之间
- 如何在for循环中包含两个索引值的测试条件
- 如何在OpenCV中比较两个组关键点
- 基于关键点组合两个贴图的值