Skip to content

Commit

Permalink
Simplified MeshUtils::extractTexture a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikhuber committed Jul 25, 2014
1 parent 4fa9702 commit f7dbce4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
Expand Up @@ -144,9 +144,10 @@ int main(int argc, char *argv[])
Logger appLogger = Loggers->getLogger("generateMultipieSigset");
appLogger.debug("Verbose level for console output: " + logging::logLevelToString(logLevel));

path outputSigset(R"(C:\Users\Patrik\Documents\GitHub\experiments\MultiPIE\probe_pm60_45_30_15.sig.txt)");
path outputSigset(R"(C:\Users\Patrik\Documents\GitHub\experiments\MultiPIE\probe_m30.sig.txt)");

path multipieRoot(R"(Z:\datasets\still01\multiPIE\data\)");
//path multipieRoot(R"(Z:\datasets\still01\multiPIE\data\)");
path multipieRoot(R"(K:\still01\multiPIE\data\)");
// MULTIPIE_ROOT_DIR/session0x/multiview/subjId/exprNum/camera/subj_session_expr_cam_imgNum.png
// Example: MULTIPIE_ROOT_DIR / 001 / 01 / 01_0 / 001_01_01_010_00.png
string session("session"); // add 01, 02, 03 or 04
Expand All @@ -156,8 +157,8 @@ int main(int argc, char *argv[])
vector<string> sessions{ "01" };
vector<string> recordingIds{ "01" }; // Not unique. E.g. in session01, id02 is smile, while in session02, id02 is surprise... So: Only enter 1 session + multiple recording Ids, OR, multiple sessions and 1 recording Id.

vector<string> cameras{ "09_0", "20_0", "08_0", "19_0", "13_0", "04_1", "14_0", "05_0" }; // probes - +-60, 45, 30, 15 yaw angle
//vector<string> cameras{ "14_0" }; // -15 yaw
//vector<string> cameras{ "09_0", "20_0", "08_0", "19_0", "13_0", "04_1", "14_0", "05_0" }; // probes - +-60, 45, 30, 15 yaw angle
vector<string> cameras{ "13_0" }; //
//vector<string> cameras{ "05_1" }; // gallery - frontal
vector<string> lighting{ "07" }; // probes
//vector<string> lighting{ "07" }; // gallery
Expand Down
8 changes: 4 additions & 4 deletions fitter/share/configs/default.cfg
@@ -1,10 +1,10 @@
morphableModel
{
;filename C:\\Users\\Patrik\\Documents\\GitHub\\bsl_model_first\\SurreyLowResGuosheng\\NON3448\\ShpVtxModelBin_NON3448.scm ; Filename to a 3D Morphable Model
filename C:\\Users\\Patrik\\Desktop\\einordnen\\Github\\3DMM_Guosheng_Newest_All_2014\\ShpVtxModelBin.scm
filename C:\\Users\\Patrik\\Documents\\GitHub\\bsl_model_first\\SurreyLowResGuosheng\\NON3448\\ShpVtxModelBin_NON3448.scm ; Filename to a 3D Morphable Model
;filename C:\\Users\\Patrik\\Desktop\\einordnen\\Github\\3DMM_Guosheng_Newest_All_2014\\ShpVtxModelBin.scm
vertexMapping C:\\Users\\Patrik\\Documents\\GitHub\\featurePoints_SurreyScm.txt ; A file that provides mappings from landmark names to vertex id's. Optional, only for scm models.
;isomap "C:\\Users\\Patrik\\Documents\\Github\\bsl_model_first\\SurreyLowResGuosheng\\NON3448\\isomap.txt" ; A file that provides texture mapping coordinates for each vertex. Optional, only for scm models.
isomap "C:\\Users\\Patrik\\Desktop\\einordnen\\Github\\3DMM_Guosheng_Newest_All_2014\\IsoMnF_Ar2.txt"
isomap "C:\\Users\\Patrik\\Documents\\Github\\bsl_model_first\\SurreyLowResGuosheng\\NON3448\\isomap.txt" ; A file that provides texture mapping coordinates for each vertex. Optional, only for scm models.
;isomap "C:\\Users\\Patrik\\Desktop\\einordnen\\Github\\3DMM_Guosheng_Newest_All_2014\\IsoMnF_Ar2.txt"
;filename C:\\Users\\Patrik\\Cloud\\PhD\\MorphModel\\ShpVtxModelBin.scm
;vertexMapping C:\\Users\\Patrik\\Documents\\GitHub\\featurePoints_SurreyScm.txt
;filename C:/Users/Patrik/Documents/USB_ALL/GitHub/bsl_model_first/bfm_statismo/bfm2009_face05.h5
Expand Down
4 changes: 2 additions & 2 deletions frDbTool/frDbTool.cpp
Expand Up @@ -123,7 +123,7 @@ int main(int argc, char *argv[])
return 1;
}

string databaseFilename = "C:\\Users\\Patrik\\Documents\\Github\\frdb.sqlite";
string databaseFilename = "C:\\Users\\Patrik\\Documents\\Github\\experiments\\frdb.sqlite";

bool doCreate = false;
// create the database
Expand Down Expand Up @@ -232,7 +232,7 @@ int main(int argc, char *argv[])
cout << query.lastError().text().toStdString() << endl;
}

path sigsetToImport(R"(C:\Users\Patrik\Documents\GitHub\experiments\MultiPIE\probe_m30.sig.txt)");
path sigsetToImport(R"(C:\Users\Patrik\Documents\GitHub\experiments\MultiPIE\lists\gallery_frontal.sig.txt)");
auto sigset = facerecognition::utils::readSigset(sigsetToImport);
for (auto&& record : sigset) {
string database = "MultiPIE";
Expand Down
28 changes: 16 additions & 12 deletions libRender/src/render/MeshUtils.cpp
Expand Up @@ -6,6 +6,7 @@
*/

#include "render/MeshUtils.hpp"
#include "render/utils.hpp"

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
Expand Down Expand Up @@ -272,38 +273,41 @@ bool MeshUtils::isPointInTriangle(cv::Point2f point, cv::Point2f triV0, cv::Poin
// image: where to extract the texture from
// note: framebuffer should have size of the image (ok not necessarily. What about mobile?) (well it should, to get optimal quality (and everywhere the same quality)?)
// note: mvpMatrix: Atm working with a 4x4 (full) affine. But anything would work, just take care with the w-division.
// Regarding the depth-buffer: We could also pass an instance of a Renderer here. Depending on how "stateful" the renderer is, this might make more sense.
cv::Mat MeshUtils::extractTexture(Mesh mesh, Mat mvpMatrix, int viewportWidth, int viewportHeight, Mat image) {
// optional param cv::Mat textureMap = cv::Mat(512, 512, CV_8UC3) ?
//cv::Mat textureMap(512, 512, inputImage.type());
cv::Mat textureMap(512, 512, CV_8UC3);

for (const auto& triangleIndices : mesh.tvi) {

// Find out if the current triangle is visible:
// We do a second rendering-pass here. We use the depth-buffer of the final image, and then, here,
// check if each pixel in a triangle is visible. If the whole triangle is visible, we use it to extract
// the texture.
// Possible improvement: - If only part of the triangle is visible, split it
// - Share more code with the renderer?


cv::Point2f srcTri[3];
cv::Point2f dstTri[3];
cv::Vec4f vec(mesh.vertex[triangleIndices[0]].position[0], mesh.vertex[triangleIndices[0]].position[1], mesh.vertex[triangleIndices[0]].position[2], 1.0f);
cv::Vec4f res = Mat(mvpMatrix * Mat(vec));
res /= res[3];
float x_w = (res[0] + 1)*(viewportWidth / 2.0f) + 0.0f; // OpenGL viewport transform (from NDC to viewport) (NDC=clipspace?)
float y_w = (res[1] + 1)*(viewportHeight / 2.0f) + 0.0f;
y_w = viewportHeight - y_w; // Qt: Origin top-left. OpenGL: bottom-left.
srcTri[0] = cv::Point2f(x_w, y_w);
cv::Vec2f screenSpace = utils::clipToScreenSpace(cv::Vec2f(res[0], res[1]), viewportWidth, viewportHeight);
srcTri[0] = screenSpace;// cv::Point2f(x_w, y_w);

vec = cv::Vec4f(mesh.vertex[triangleIndices[1]].position[0], mesh.vertex[triangleIndices[1]].position[1], mesh.vertex[triangleIndices[1]].position[2], 1.0f);
res = Mat(mvpMatrix * Mat(vec));
res /= res[3];
x_w = (res[0] + 1)*(viewportWidth / 2.0f) + 0.0f;
y_w = (res[1] + 1)*(viewportHeight / 2.0f) + 0.0f;
y_w = viewportHeight - y_w; // Qt: Origin top-left. OpenGL: bottom-left.
srcTri[1] = cv::Point2f(x_w, y_w);
screenSpace = utils::clipToScreenSpace(cv::Vec2f(res[0], res[1]), viewportWidth, viewportHeight);
srcTri[1] = screenSpace;

vec = cv::Vec4f(mesh.vertex[triangleIndices[2]].position[0], mesh.vertex[triangleIndices[2]].position[1], mesh.vertex[triangleIndices[2]].position[2], 1.0f);
res = Mat(mvpMatrix * Mat(vec));
res /= res[3];
x_w = (res[0] + 1)*(viewportWidth / 2.0f) + 0.0f;
y_w = (res[1] + 1)*(viewportHeight / 2.0f) + 0.0f;
y_w = viewportHeight - y_w; // Qt: Origin top-left. OpenGL: bottom-left.
srcTri[2] = cv::Point2f(x_w, y_w);
screenSpace = utils::clipToScreenSpace(cv::Vec2f(res[0], res[1]), viewportWidth, viewportHeight);
srcTri[2] = screenSpace;

// ROI in the source image:
// Todo: Check if the triangle is on screen. If it's outside, we crash here.
Expand Down
2 changes: 1 addition & 1 deletion libRender/src/render/utils.cpp
Expand Up @@ -13,7 +13,7 @@ cv::Vec2f clipToScreenSpace(cv::Vec2f clipCoordinates, int screenWidth, int scre
{
// Window transform:
float x_ss = (clipCoordinates[0] + 1.0f) * (screenWidth / 2.0f);
float y_ss = screenHeight - (clipCoordinates[1] + 1.0f) * (screenHeight / 2.0f); // also flip y
float y_ss = screenHeight - (clipCoordinates[1] + 1.0f) * (screenHeight / 2.0f); // also flip y; // Qt: Origin top-left. OpenGL: bottom-left.
return cv::Vec2f(x_ss, y_ss);
}

Expand Down

0 comments on commit f7dbce4

Please sign in to comment.