Last active
June 19, 2016 09:19
-
-
Save tkymx/78712d7301510be8e96d729cfc3d6d82 to your computer and use it in GitHub Desktop.
キネクトから取得されたデプス情報を格納する テキストベースでちょっと重い
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Depth | |
{ | |
int m_w, m_h; | |
std::vector<std::vector<double>> depth; | |
public: | |
bool load_depth(std::string name) | |
{ | |
//delete | |
if (!depth.empty()) | |
{ | |
for (auto v : depth)v.clear(); | |
depth.clear(); | |
} | |
//new | |
std::ifstream ifs(name); | |
if (!ifs.is_open()) | |
return false; | |
ifs >> m_h >> m_w; | |
depth.resize(m_h); | |
for (int i = 0; i < m_h; i++) | |
{ | |
depth[i].resize(m_w); | |
for (int j = 0; j < m_w; j++) | |
{ | |
int a; | |
ifs >> a; | |
depth[i][j] = a; | |
} | |
} | |
ifs.close(); | |
return true; | |
} | |
bool write_depth(std::string name) | |
{ | |
std::ofstream ofs(name); | |
if (!ofs.is_open()) | |
return false; | |
ofs << m_h << " "<< m_w << " "; | |
for (int i = 0; i < m_h; i++) | |
{ | |
for (int j = 0; j < m_w; j++) | |
{ | |
ofs << depth[i][j] << " "; | |
} | |
ofs << std::endl; | |
} | |
} | |
bool write_region_point_to_pts(std::string name, int x, int y, int w, int h , cv::Mat *img=NULL) | |
{ | |
std::ofstream ofs(name); | |
if (ofs.is_open()) | |
{ | |
ofs << "version: 1" << std::endl; | |
ofs << "n_points: " << w*h << std::endl; | |
ofs << "{" << std::endl; | |
bool isThrough = false; | |
for (int i = 0; i < h; i++) | |
{ | |
for (int j = 0; j < w; j++) | |
{ | |
int iny = y + j; | |
int inx = x + j; | |
double yy = y + i; | |
double xx = x + j; | |
double z = get_depth(xx, yy); | |
toMeter(xx, yy, z); | |
if (xx!=0 && yy!=0 && z!=0 && z < 1400) | |
{ | |
ofs << xx/1000 << " " | |
<< yy / 1000 << " " | |
<< z / 1000; | |
if (img != NULL) | |
{ | |
ofs << " " | |
<< (int)img->at<cv::Vec3b>(iny, inx)[0] << " " | |
<< (int)img->at<cv::Vec3b>(iny, inx)[1] << " " | |
<< (int)img->at<cv::Vec3b>(iny, inx)[2]; | |
} | |
ofs << std::endl; | |
isThrough = true; | |
} | |
} | |
} | |
if (!isThrough) | |
MessageBox(NULL, "nothing outputed", "caution", MB_OK); | |
ofs << "}" << std::endl; | |
ofs.close(); | |
return true; | |
} | |
return false; | |
} | |
bool is_in() | |
{ | |
if (depth.empty())return false; | |
return true; | |
} | |
double get_depth(int x, int y) | |
{ | |
if (x < 1)return 0; | |
if (y < 1)return 0; | |
if (x >= m_w - 1)return 0; | |
if (y >= m_h - 1)return 0; | |
double z = depth[y][x]; | |
return z; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment