Unwrap Image to height map

you could write a .ply file from the unwrapped image (make a pointcloud) and throw that at blender / meshlab.

void ply2(const Mat &m, const Mat &col) {
	cout << m.size << " " << m.type() << " " << m.channels() << endl;
	string ply_header = format("ply\nformat ascii 1.0\nelement vertex %d\nproperty float x\nproperty float y\nproperty float z\nproperty uchar red\nproperty uchar green\nproperty uchar blue\nend_header", m.total());
	ofstream of("sinus2.ply");
	of << ply_header << endl;
	for (int r=0; r<m.rows; r++) {
		for (int c=0; c<m.cols; c++) {
            Vec3b pix = col.at<Vec3b>(r,c);
			of << format("%5.4f %5.4f %5.4f %d %d %d\n", float(c),float(r),m.at<float>(r,c), pix[0], pix[1], pix[2]);
		}
	}
	of.close();
}

// load this seperately, so we can use color info
Mat color = imread("phase1.png");

Mat depthMap;
unwrappedPhaseMap.convertTo(depthMap, CV_32F, 1.0/16); // scaling magic, adjust to your needs
 
ply2(depthMap, color);

struct

2 Likes