前提・実現したいこと
下記のようなコンパイルエラーが発生します。
直し方がわかる方ご教授お願いします。
発生している問題・エラーメッセージ
コンパイルエラー C2512 'C2P::C2P': クラス、構造体、共用体に既定のコンストラクターがありません。
該当のソースコード
C++
1#include <iostream> 2#include <fstream> 3#include <vector> 4#include <unordered_map> 5#include <algorithm> 6 7using namespace std; 8using namespace cv; 9 10#define WINDOWWIDTH 5 11#define WINDOWHEIGHT 3 12 13// 14// C2P構造体 15// 16struct C2P 17{ 18 int cx; 19 int cy; 20 int px; 21 int py; 22 23 C2P(int camera_x, int camera_y, int proj_x, int proj_y) 24 { 25 cx = camera_x; 26 cy = camera_y; 27 px = proj_x; 28 py = proj_y; 29 } 30}; 31 32int main() 33{ 34 // 35 // vectorの作成 36 // 37 vector<C2P> c2pList; 38 c2pList.push_back(C2P(3, 5, 0, 0)); 39 c2pList.push_back(C2P(5, 2, 0, 0)); 40 c2pList.push_back(C2P(1, 6, 1, 0)); 41 c2pList.push_back(C2P(4, 2, 2, 0)); 42 c2pList.push_back(C2P(5, 5, 2, 0)); 43 c2pList.push_back(C2P(3, 1, 2, 0)); 44 c2pList.push_back(C2P(7, 5, 3, 0)); 45 c2pList.push_back(C2P(8, 6, 4, 0)); 46 c2pList.push_back(C2P(2, 5, 4, 0)); 47 c2pList.push_back(C2P(6, 4, 1, 1)); 48 c2pList.push_back(C2P(2, 3, 2, 1)); 49 c2pList.push_back(C2P(5, 8, 2, 1)); 50 c2pList.push_back(C2P(2, 3, 3, 1)); 51 c2pList.push_back(C2P(4, 6, 3, 1)); 52 c2pList.push_back(C2P(5, 5, 4, 1)); 53 c2pList.push_back(C2P(1, 3, 4, 1)); 54 c2pList.push_back(C2P(4, 2, 0, 2)); 55 c2pList.push_back(C2P(7, 8, 2, 2)); 56 c2pList.push_back(C2P(4, 7, 2, 2)); 57 c2pList.push_back(C2P(3, 3, 3, 2)); 58 c2pList.push_back(C2P(7, 5, 3, 2)); 59 c2pList.push_back(C2P(4, 4, 4, 2)); 60 c2pList.push_back(C2P(1, 9, 4, 2)); 61 62 63 // 64 // mapの作成 65 // 66 unordered_multimap<int, C2P> c2pMap; 67 unordered_map<int, C2P> c2pMap_new; 68 for (auto elem : c2pList) 69 { 70 c2pMap.insert(make_pair(elem.py * WINDOWWIDTH + elem.px, C2P(elem.cx, elem.cy, elem.px, elem.py))); 71 72 } 73 // 74 // 同じキーを持つ要素の平均を求める 75 // 76 for (int key = 0;key < WINDOWHEIGHT * WINDOWWIDTH;key++) 77 { 78 int cx = 0; 79 int cy = 0; 80 int px = 0; 81 int py = 0; 82 int sum_cx = 0; 83 int sum_cy = 0; 84 auto range = c2pMap.equal_range(key); 85 size_t count = c2pMap.count(key); 86 for (auto iterator = range.first;iterator != range.second;iterator++) 87 { 88 auto target = *iterator; 89 cx = target.second.cx; 90 cy = target.second.cy; 91 px = target.second.px; 92 py = target.second.py; 93 sum_cx += cx; 94 sum_cy += cy; 95 } 96 97 c2pMap.erase(key); 98 99 if (count != 0) 100 { 101 c2pMap_new.insert(make_pair(key, C2P(sum_cx / count, sum_cy / count, px, py))); 102 } 103 104 } 105 106 107 108 for (int key = 0;key < WINDOWHEIGHT * WINDOWWIDTH;key++) 109 { 110 try 111 { 112 cout << "キー:" << key << ',' 113 << "cx:" << c2pMap_new.at(key).cx << ',' 114 << "cy:" << c2pMap_new.at(key).cy << ',' 115 << "px:" << c2pMap_new.at(key).px << ',' 116 << "py:" << c2pMap_new.at(key).py << "\n"; 117 118 } 119 catch (out_of_range&) 120 { 121 continue; 122 } 123 124 } 125 126 127 128 ofstream os("c2p_map.csv"); 129 for (int key = 0;key < WINDOWWIDTH * WINDOWHEIGHT;key++) 130 { 131 try 132 { 133 os << c2pMap_new.at(key).cx 134 <<"," << c2pMap_new.at(key).cy 135 << "," << c2pMap_new.at(key).px 136 << "," << c2pMap_new.at(key).py << endl; 137 } 138 catch (out_of_range&) 139 { 140 continue; 141 } 142 } 143 os.close(); 144 145 146 return 0; 147} 148
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/12/07 21:02