From 97d835ec93298eafe2e605d306f81bf0d3396d5e Mon Sep 17 00:00:00 2001 From: Wangyida Date: Mon, 29 Jun 2015 15:54:54 +0800 Subject: [PATCH] CommandLineParser modified CommandLineParser modified --- modules/cnn_3dobj/README.md | 5 ++-- .../cnn_3dobj/include/opencv2/cnn_3dobj.hpp | 3 +-- .../samples/sphereview_3dobj_demo.cpp | 26 +++++++++++++++---- modules/cnn_3dobj/src/cnn_3dobj.cpp | 10 +++---- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/modules/cnn_3dobj/README.md b/modules/cnn_3dobj/README.md index 7310c14d5..ff9978959 100644 --- a/modules/cnn_3dobj/README.md +++ b/modules/cnn_3dobj/README.md @@ -12,7 +12,8 @@ $ mkdir build $ cd build $ cmake .. $ make -$ ./sphereview_test 350 2 ../ape.ply +$ ./sphereview_test -radius=350 -ite_depth=1 -plymodel=../ape.ply -imagedir=../data/images_ape/ ============================================== -Then press 'q' to run the demo for images generation, parameter '350' represent the radius of the sphere and '2' stand for the depth of the sphere building iteration and '../ape.ply' represent the .ply model +demo :$ ./sphereview_test -radius=350 -ite_depth=1 -plymodel=../ape.ply -imagedir=../data/images_ape/ +Then press 'q' to run the demo for images generation when you see the gray background and a coordinate. ============================================== diff --git a/modules/cnn_3dobj/include/opencv2/cnn_3dobj.hpp b/modules/cnn_3dobj/include/opencv2/cnn_3dobj.hpp index 370d59f66..8b6dc1124 100644 --- a/modules/cnn_3dobj/include/opencv2/cnn_3dobj.hpp +++ b/modules/cnn_3dobj/include/opencv2/cnn_3dobj.hpp @@ -76,13 +76,12 @@ class CV_EXPORTS_W IcoSphere float Z; public: - - std::vector vertexNormalsList; std::vector vertexList; std::vector CameraPos; std::vector CameraPos_temp; float radius; + float diff; IcoSphere(float radius_in, int depth_in); /** @brief Make all view points having the some distance from the focal point used by the camera view. */ diff --git a/modules/cnn_3dobj/samples/sphereview_3dobj_demo.cpp b/modules/cnn_3dobj/samples/sphereview_3dobj_demo.cpp index 812ed5631..64fef5ebb 100644 --- a/modules/cnn_3dobj/samples/sphereview_3dobj_demo.cpp +++ b/modules/cnn_3dobj/samples/sphereview_3dobj_demo.cpp @@ -42,13 +42,29 @@ using namespace cv; using namespace std; using namespace cv::cnn_3dobj; int main(int argc, char *argv[]){ - float radius = atof(argv[1]); - int ite_depth = argv[2][0] - '0'; + const String keys = "{help | | demo :$ ./sphereview_test -radius=350 -ite_depth=1 -plymodel=../ape.ply -imagedir=../data/images_ape/ -labeldir=../data/label_ape.txt, then press 'q' to run the demo for images generation when you see the gray background and a coordinate.}" + "{radius | 350 | Distanse from camera to object, used for adjust view for the reason that differet scale of .ply model.}" + "{ite_depth | 1 | Iteration of sphere generation, we add points on the middle of lines of sphere and adjust the radius suit for the original radius.}" + "{plymodel | ../ape.ply | path of the '.ply' file for image rendering. }" + "{imagedir | ../data/images_ape/ | path of the generated images for one particular .ply model. }" + "{labeldir | ../data/label_ape.txt | path of the generated images for one particular .ply model. }"; + cv::CommandLineParser parser(argc, argv, keys); + parser.about("Demo for Sphere View data generation"); + if (parser.has("help")) + { + parser.printMessage(); + return 0; + } + float radius = parser.get("radius"); + int ite_depth = parser.get("ite_depth"); + string plymodel = parser.get("plymodel"); + string imagedir = parser.get("imagedir"); + string labeldir = parser.get("labeldir"); cv::cnn_3dobj::IcoSphere ViewSphere(10,ite_depth); std::vector campos = ViewSphere.CameraPos; std::fstream imglabel; - std::string plymodel = argv[3]; - imglabel.open("../data/label_ape.txt"); + char* p=(char*)labeldir.data(); + imglabel.open(p); //IcoSphere ViewSphere(16,0); //std::vector* campos = ViewSphere.CameraPos; bool camera_pov = (true); @@ -100,7 +116,7 @@ int main(int argc, char *argv[]){ char* temp = new char; sprintf (temp,"%d",pose); string filename = temp; - filename = "../data/images_ape/" + filename; + filename = imagedir + filename; filename += ".png"; myWindow.saveScreenshot(filename); } diff --git a/modules/cnn_3dobj/src/cnn_3dobj.cpp b/modules/cnn_3dobj/src/cnn_3dobj.cpp index 9b3866ce5..40c350df2 100644 --- a/modules/cnn_3dobj/src/cnn_3dobj.cpp +++ b/modules/cnn_3dobj/src/cnn_3dobj.cpp @@ -13,7 +13,7 @@ namespace cv{ namespace cnn_3dobj{ int depth = depth_in; X *= radius; Z *= radius; - + diff = 0.00000005964; float vdata[12][3] = { { -X, 0.0f, Z }, { X, 0.0f, Z }, { -X, 0.0f, -Z }, { X, 0.0f, -Z }, { 0.0f, Z, X }, { 0.0f, Z, -X }, { 0.0f, -Z, X }, { 0.0f, -Z, -X }, { Z, X, 0.0f }, { -Z, X, 0.0f }, @@ -32,15 +32,15 @@ namespace cv{ namespace cnn_3dobj{ // Iterate over points for (int i = 0; i < 20; ++i) { - subdivide(vdata[tindices[i][1]], vdata[tindices[i][2]], - vdata[tindices[i][3]], depth); + subdivide(vdata[tindices[i][0]], vdata[tindices[i][1]], + vdata[tindices[i][2]], depth); } CameraPos_temp.push_back(CameraPos[0]); for (int j = 1; j