Skip to content

Commit a81322a

Browse files
committed
add background and semishpere to training images
1 parent 73b5d3e commit a81322a

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

modules/cnn_3dobj/samples/demo_sphereview_data.cpp

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ using namespace cv::cnn_3dobj;
4747
int main(int argc, char *argv[])
4848
{
4949
const String keys = "{help | | demo :$ ./sphereview_test -ite_depth=2 -plymodel=../data/3Dmodel/ape.ply -imagedir=../data/images_all/ -labeldir=../data/label_all.txt -num_class=6 -label_class=0, then press 'q' to run the demo for images generation when you see the gray background and a coordinate.}"
50-
"{ite_depth | 2 | Iteration of sphere generation.}"
50+
"{ite_depth | 3 | Iteration of sphere generation.}"
5151
"{plymodel | ../data/3Dmodel/ape.ply | Path of the '.ply' file for image rendering. }"
5252
"{imagedir | ../data/images_all/ | Path of the generated images for one particular .ply model. }"
5353
"{labeldir | ../data/label_all.txt | Path of the generated images for one particular .ply model. }"
5454
"{cam_head_x | 0 | Head of the camera. }"
5555
"{cam_head_y | 0 | Head of the camera. }"
5656
"{cam_head_z | -1 | Head of the camera. }"
57+
"{semisphere | 1 | Camera only has positions on half of the whole sphere. }"
58+
"{center_gen | 0 | Find center from all points. }"
5759
"{image_size | 128 | Size of captured images. }"
5860
"{label_class | 1 | Class label of current .ply model. }"
5961
"{label_item | 1 | Item label of current .ply model. }"
@@ -77,19 +79,32 @@ int main(int argc, char *argv[])
7779
float cam_head_x = parser.get<float>("cam_head_x");
7880
float cam_head_y = parser.get<float>("cam_head_y");
7981
float cam_head_z = parser.get<float>("cam_head_z");
82+
int semisphere = parser.get<int>("semisphere");
83+
int center_gen = parser.get<int>("center_gen");
8084
int image_size = parser.get<int>("image_size");
8185
int rgb_use = parser.get<int>("rgb_use");
8286
int num_class = parser.get<int>("num_class");
8387
int binary_out = parser.get<int>("binary_out");
8488
cv::cnn_3dobj::icoSphere ViewSphere(10,ite_depth);
85-
std::vector<cv::Point3d> campos = ViewSphere.CameraPos;
89+
std::vector<cv::Point3d> campos;
90+
std::vector<cv::Point3d> campos_temp = ViewSphere.CameraPos;
91+
if (semisphere)
92+
{
93+
for (int pose = 0; pose < (int)campos_temp.size(); pose++)
94+
{
95+
if (campos_temp.at(pose).z >= 0)
96+
campos.push_back(campos_temp.at(pose));
97+
}
98+
}
99+
else
100+
campos = campos_temp;
86101
std::fstream imglabel;
87102
char* p=(char*)labeldir.data();
88103
imglabel.open(p, fstream::app|fstream::out);
89104
bool camera_pov = true;
90105
/* Create a window using viz. */
91106
viz::Viz3d myWindow("Coordinate Frame");
92-
/* Set window size as 64*64, we use this scale as default. */
107+
/* Set window size. */
93108
myWindow.setWindowSize(Size(image_size,image_size));
94109
/* Set background color. */
95110
myWindow.setBackgroundColor(viz::Color::gray());
@@ -98,22 +113,27 @@ int main(int argc, char *argv[])
98113
myWindow.addLight(Vec3d(0,0,100000), Vec3d(0,0,0), viz::Color::white(), viz::Color::gray(), viz::Color::black(), viz::Color::white());
99114
/* Create a Mesh widget, loading .ply models. */
100115
viz::Mesh objmesh = viz::Mesh::load(plymodel);
101-
/* Get the center of the generated mesh widget, cause some .ply files. */
102-
Point3d cam_focal_point = ViewSphere.getCenter(objmesh.cloud);
116+
/* Get the center of the generated mesh widget, cause some .ply files, this could be ignored if you are using PASCAL database*/
117+
Point3d cam_focal_point;
118+
if (center_gen)
119+
cam_focal_point = ViewSphere.getCenter(objmesh.cloud);
120+
else
121+
cam_focal_point = Point3d(0,0,0);
122+
const char* headerPath = "../data/header_for_";
123+
const char* binaryPath = "../data/binary_";
124+
if (binary_out)
125+
{
126+
ViewSphere.createHeader((int)campos.size(), image_size, image_size, headerPath);
127+
}
103128
float radius = ViewSphere.getRadius(objmesh.cloud, cam_focal_point);
104129
objmesh.cloud = objmesh.cloud/radius*100;
105130
cam_focal_point = cam_focal_point/radius*100;
106131
Point3d cam_y_dir;
107132
cam_y_dir.x = cam_head_x;
108133
cam_y_dir.y = cam_head_y;
109134
cam_y_dir.z = cam_head_z;
110-
const char* headerPath = "../data/header_for_";
111-
const char* binaryPath = "../data/binary_";
112-
if (binary_out)
113-
{
114-
ViewSphere.createHeader((int)campos.size(), image_size, image_size, headerPath);
115-
}
116135
char* temp = new char;
136+
char* bgname = new char;
117137
/* Images will be saved as .png files. */
118138
for(int pose = 0; pose < (int)campos.size(); pose++){
119139
int label_x, label_y, label_z;
@@ -144,8 +164,12 @@ int main(int argc, char *argv[])
144164
}
145165

146166
/* Visualize widget. */
147-
mesh_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
148-
myWindow.showWidget("ape", mesh_widget, cloud_pose_global);
167+
sprintf(bgname,"/Users/yidawang/Desktop/bg%i.jpg",pose%10+1);
168+
cv::Mat img_bg = cv::imread(bgname);
169+
cv::viz::WImage3D background_widget(img_bg, Size2d(image_size*4, image_size*4), Vec3d(-campos.at(pose)*380-cam_focal_point), Vec3d(campos.at(pose)*380+cam_focal_point), Vec3d(0,0,100));
170+
// mesh_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
171+
myWindow.showWidget("targetwidget", mesh_widget, cloud_pose_global);
172+
myWindow.showWidget("bgwidget", background_widget, cloud_pose_global);
149173

150174
/* Set the viewer pose to that of camera. */
151175
if (camera_pov)

0 commit comments

Comments
 (0)