Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved usability with instructions and examples #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 71 additions & 48 deletions Application/PerseusLibTest.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,27 @@

using namespace Perseus::Utils;

int main(void)
std::string folder = "/home/src/pwp3d/Files/";

// determine step size relative to current distance to the camera
inline double step_size(double x, double b, double maxval, double k = 8.0)
{
double diff = fabs(x-b) * k / b + 1;
double y = maxval / diff;
if (x > b) y = 2 * maxval - y;
return y;
}

int main(int argc, char** argv)
{
std::string sModelPath = argv[argc-11];
std::string sSrcImage = argv[1];
std::string sCameraMatrix = folder + "CameraCalibration/drill_n1.cal";
std::string sTargetMask = folder + "Masks/1280p_All_VideoMask.png";
std::string sHistSrc = argv[1];
std::string sHistMask = argv[argc-12];


// std::string sModelPath = "/Users/luma/Code/Luma/PWP3D/Files/Models/Renderer/long.obj";
// std::string sSrcImage = "/Users/luma/Code/Luma/PWP3D/Files/Images/Red.png";
// std::string sCameraMatrix = "/Users/luma/Code/Luma/PWP3D/Files/CameraCalibration/900nc.cal";
Expand All @@ -24,23 +43,26 @@ int main(void)
// std::string sHistMask = "/Users/luma/Code/Luma/PWP3D/Files/Masks/248-ID-3-LiveImage.png";

// red can demo
std::string sModelPath = "/Users/luma/Code/DataSet/Mesh/RedCan.obj";
std::string sSrcImage = "/Users/luma/Code/Luma/PWP3D/Files/Images/248-LiveRGB.png";
std::string sCameraMatrix = "/Users/luma/Code/Luma/PWP3D/Files/CameraCalibration/Kinect.cal";
std::string sTargetMask = "/Users/luma/Code/Luma/PWP3D/Files/Masks/480p_All_VideoMask.png";
std::string sHistSrc = "/Users/luma/Code/Luma/PWP3D/Files/Images/248-LiveRGB.png";
std::string sHistMask = "/Users/luma/Code/Luma/PWP3D/Files/Masks/248-ID-1-LiveImage.png";
// std::string sModelPath = "/Users/luma/Code/DataSet/Mesh/RedCan.obj";
// std::string sSrcImage = "/Users/luma/Code/Luma/PWP3D/Files/Images/248-LiveRGB.png";
// std::string sCameraMatrix = "/Users/luma/Code/Luma/PWP3D/Files/CameraCalibration/Kinect.cal";
// std::string sTargetMask = "/Users/luma/Code/Luma/PWP3D/Files/Masks/480p_All_VideoMask.png";
// std::string sHistSrc = "/Users/luma/Code/Luma/PWP3D/Files/Images/248-LiveRGB.png";
// std::string sHistMask = "/Users/luma/Code/Luma/PWP3D/Files/Masks/248-ID-1-LiveImage.png";

// ---------------------------------------------------------------------------
char str[100];
int i;
int i, n = 10;

int width = 640, height = 480;
int width = 1920, height = 1280;
int viewCount = 1, objectCount = 1;
int objectId = 0, viewIdx = 0, objectIdx = 0;
double step_r, step_xy, step_z, z, param[n];

Timer t;

for(i = 0; i < n; i++) param[i] = atof(argv[argc-n+i]);

//result visualisation
ImageUChar4* ResultImage = new ImageUChar4(width, height);

Expand Down Expand Up @@ -92,10 +114,15 @@ int main(void)
iterConfig->levelSetBandSize = 8;
iterConfig->iterObjectIds[viewIdx][objectIdx] = 0;
iterConfig->iterViewCount = 1;
iterConfig->iterCount = 1;
iterConfig->iterCount = param[0];
iterConfig->useCUDAEF = true;
iterConfig->useCUDARender = true;

objects[objectIdx]->initialPose[viewIdx]->SetFrom(
param[1], param[2], param[3], param[4], param[5], param[6]);

//step size per object and view
objects[objectIdx]->stepSize[viewIdx] = new StepSize3D(0.2f, 0.5f, 0.5f, 10.0f);
//objects[objectIdx]->stepSize[viewIdx] = new StepSize3D(0.2f, 0.5f, 0.5f, 10.0f);

//initial pose per object and view
// Notice the input pose here is angle, not radians for the rotation part
Expand All @@ -106,8 +133,8 @@ int main(void)
// objects[objectIdx]->initialPose[viewIdx]->SetFrom( -3.0f,-4.5f,28.f, -220.90f, -207.77f, 87.48f);

// for red can demo
objects[objectIdx]->initialPose[viewIdx]->SetFrom(
1.0f, 3.0f, 30.f, 180.f, 80.f, 60.f);
// objects[objectIdx]->initialPose[viewIdx]->SetFrom(
// 1.0f, 3.0f, 30.f, 180.f, 80.f, 60.f);

//primary initilisation
OptimisationEngine::Instance()->Initialise(width, height);
Expand All @@ -124,52 +151,48 @@ int main(void)

cv::Mat ResultMat(height,width,CV_8UC4, ResultImage->pixels);
cv::imshow("initial pose", ResultMat);
cv::waitKey(1000);
cv::waitKey(0);

std::cout<<"[App] Finish Rendered object initial pose."<<std::endl;
//objects[objectIdx]->histogramVarBin[views[viewIdx]->viewId]->mergeAlphaForeground = 0.03f;
//objects[objectIdx]->histogramVarBin[views[viewIdx]->viewId]->mergeAlphaBackground = 0.02f;

for (i=0; i<4; i++)
bool sequence = argc > 14;
int loopcount = sequence ? argc-12 : 101;
for (i=1; i<loopcount; i++)
{
switch (i)
{
case 0:
iterConfig->useCUDAEF = true;
iterConfig->useCUDARender = true;
break;
case 1:
iterConfig->useCUDAEF = false;
iterConfig->useCUDARender = true;
break;
case 2:
iterConfig->useCUDAEF = true;
iterConfig->useCUDARender = false;
break;
case 3:
iterConfig->useCUDAEF = false;
iterConfig->useCUDARender = false;
break;
}

printf("======= mode: useCUDAAEF: %d, use CUDARender %d ========;\n",
iterConfig->useCUDAEF, iterConfig->useCUDARender);

sprintf(str, "/Users/luma/Code/Luma/PWP3D/Files/Results/result%04d.png", i);
z = objects[objectIdx]->initialPose[viewIdx]->translation->z;

step_r = step_size(z, param[3], param[7]);
step_xy = step_size(z, param[3], param[8]);
step_z = step_size(z, param[3], param[9]);
objects[objectIdx]->stepSize[viewIdx]->SetFrom(step_r, step_xy, step_xy, step_z);

printf("%d Step: %f %f %f\n", i, step_r, step_xy, step_z);
ImageUtils::Instance()->LoadImageFromFile(camera, argv[sequence ? i : 1]);
OptimisationEngine::Instance()->RegisterViewImage(views[viewIdx], camera);

//main processing
t.restart();
OptimisationEngine::Instance()->Minimise(objects, views, iterConfig);
objects[objectIdx]->initialPose[viewIdx]->SetFrom(objects[objectIdx]->pose[viewIdx]);
t.check("Iteration");

//update at your own risk
//HistogramEngine::Instance()->UpdateVarBinHistogram(
// objects[objectIdx], views[viewIdx], camera, objects[objectIdx]->pose[viewIdx]);

//result plot
VisualisationEngine::Instance()->GetImage(
ResultImage, GETIMAGE_PROXIMITY,
objects[objectIdx], views[viewIdx], objects[objectIdx]->pose[viewIdx]);

//result save to file
// ImageUtils::Instance()->SaveImageToFile(result, str);
sprintf(str, "%sResults/result_%03d.png", folder.c_str(), i);
//ImageUtils::Instance()->SaveImageToFile(ResultImage, str);
cv::Mat ResultMat(height,width,CV_8UC4, ResultImage->pixels);
cv::imshow("result", ResultMat);
cv::waitKey(2000);
cv::waitKey(1);

printf("final pose result %f %f %f %f %f %f %f\n\n",
objects[objectIdx]->pose[viewIdx]->translation->x,
Expand All @@ -179,15 +202,15 @@ int main(void)
objects[objectIdx]->pose[viewIdx]->rotation->vector4d.y,
objects[objectIdx]->pose[viewIdx]->rotation->vector4d.z,
objects[objectIdx]->pose[viewIdx]->rotation->vector4d.w);
}

//posteriors plot
sprintf(str, "/Users/luma/Code/Luma/PWP3D/Files/Results/posteriors.png");
VisualisationEngine::Instance()->GetImage(
ResultImage, GETIMAGE_POSTERIORS,
objects[objectIdx], views[viewIdx], objects[objectIdx]->pose[viewIdx]);
//posteriors plot
sprintf(str, "%sResults/posterior_%03d.png", folder.c_str(), i);
VisualisationEngine::Instance()->GetImage(
ResultImage, GETIMAGE_POSTERIORS,
objects[objectIdx], views[viewIdx], objects[objectIdx]->pose[viewIdx]);

ImageUtils::Instance()->SaveImageToFile(ResultImage, str);
//ImageUtils::Instance()->SaveImageToFile(ResultImage, str);
}

//primary engine destructor
OptimisationEngine::Instance()->Shutdown();
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ include(SetPlatformVars)

# Overide with cmake -DCMAKE_BUILD_TYPE=Debug {dir}
if( NOT CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE Release )
set( CMAKE_BUILD_TYPE Debug )
endif()

option(BUILD_SHARED_LIBS "Build Shared Library" ON)
add_subdirectory(PerseusLib)

option(BUILD_PWP3D_APP "Build PWP3D App" OFF)
option(BUILD_PWP3D_APP "Build PWP3D App" ON)
if(BUILD_PWP3D_APP)
add_subdirectory(Application)
target_include_directories(PWP3DAPP PUBLIC .)
endif()

4 changes: 4 additions & 0 deletions Files/CameraCalibration/canon_t3.cal
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Perseus_CalFile
1920 1280
1661.4874 1650.7941
977.53137 612.69568
4 changes: 4 additions & 0 deletions Files/CameraCalibration/drill_n1.cal
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Perseus_CalFile
1920 1280
1711.7103 1711.7113
961.36137 632.54090
Binary file added Files/Images/shuttle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Files/Masks/1280p_All_VideoMask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Files/Masks/drill_n1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Files/Masks/shuttle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading