Skip to content

Commit 73b5d3e

Browse files
committed
training data generation from PASCAL3D
add light
1 parent d712740 commit 73b5d3e

File tree

3 files changed

+128
-34
lines changed

3 files changed

+128
-34
lines changed

modules/cnn_3dobj/samples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 2.8)
22
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb ")
33
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
4-
project(sphereview_test)
4+
project(cnn_3dobj)
55
find_package(OpenCV REQUIRED)
66
set(SOURCES_generator demo_sphereview_data.cpp)
77
include_directories(${OpenCV_INCLUDE_DIRS})

modules/cnn_3dobj/samples/datagen.sh

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,90 @@
1-
rm -rf ../data/binary_image
2-
rm -rf ../data/binary_label
3-
rm -rf ../data/header_for_image
4-
rm -rf ../data/header_for_label
5-
6-
./sphereview_test -plymodel=../data/3Dmodel/ape.ply -label_class=0 -cam_head_x=0 -cam_head_y=0 -cam_head_z=1
7-
./sphereview_test -plymodel=../data/3Dmodel/ant.ply -label_class=1 -cam_head_x=0 -cam_head_y=-1 -cam_head_z=0
8-
./sphereview_test -plymodel=../data/3Dmodel/cow.ply -label_class=2 -cam_head_x=0 -cam_head_y=-1 -cam_head_z=0
9-
./sphereview_test -plymodel=../data/3Dmodel/plane.ply -label_class=3 -cam_head_x=0 -cam_head_y=-1 -cam_head_z=0
10-
./sphereview_test -plymodel=../data/3Dmodel/bunny.ply -label_class=4 -cam_head_x=0 -cam_head_y=-1 -cam_head_z=0
11-
./sphereview_test -plymodel=../data/3Dmodel/horse.ply -label_class=5 -cam_head_x=0 -cam_head_y=0 -cam_head_z=-1
1+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/aeroplane/01.ply -label_class=1 -label_item=1
2+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/aeroplane/02.ply -label_class=1 -label_item=2
3+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/aeroplane/03.ply -label_class=1 -label_item=3
4+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/aeroplane/04.ply -label_class=1 -label_item=4
5+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/aeroplane/05.ply -label_class=1 -label_item=5
6+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/aeroplane/06.ply -label_class=1 -label_item=6
7+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/aeroplane/07.ply -label_class=1 -label_item=7
8+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/aeroplane/08.ply -label_class=1 -label_item=8
9+
10+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bicycle/01.ply -label_class=2 -label_item=1
11+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bicycle/02.ply -label_class=2 -label_item=2
12+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bicycle/03.ply -label_class=2 -label_item=3
13+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bicycle/04.ply -label_class=2 -label_item=4
14+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bicycle/05.ply -label_class=2 -label_item=5
15+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bicycle/06.ply -label_class=2 -label_item=6
16+
17+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/boat/01.ply -label_class=3 -label_item=1
18+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/boat/02.ply -label_class=3 -label_item=2
19+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/boat/03.ply -label_class=3 -label_item=3
20+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/boat/04.ply -label_class=3 -label_item=4
21+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/boat/05.ply -label_class=3 -label_item=5
22+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/boat/06.ply -label_class=3 -label_item=6
23+
24+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bottle/01.ply -label_class=4 -label_item=1
25+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bottle/02.ply -label_class=4 -label_item=2
26+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bottle/03.ply -label_class=4 -label_item=3
27+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bottle/04.ply -label_class=4 -label_item=4
28+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bottle/05.ply -label_class=4 -label_item=5
29+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bottle/06.ply -label_class=4 -label_item=6
30+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bottle/07.ply -label_class=4 -label_item=7
31+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bottle/08.ply -label_class=4 -label_item=8
32+
33+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bus/01.ply -label_class=5 -label_item=1
34+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bus/02.ply -label_class=5 -label_item=2
35+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bus/03.ply -label_class=5 -label_item=3
36+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bus/04.ply -label_class=5 -label_item=4
37+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bus/05.ply -label_class=5 -label_item=5
38+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/bus/06.ply -label_class=5 -label_item=6
39+
40+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/car/01.ply -label_class=6 -label_item=1
41+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/car/02.ply -label_class=6 -label_item=2
42+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/car/03.ply -label_class=6 -label_item=3
43+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/car/04.ply -label_class=6 -label_item=4
44+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/car/05.ply -label_class=6 -label_item=5
45+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/car/06.ply -label_class=6 -label_item=6
46+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/car/07.ply -label_class=6 -label_item=7
47+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/car/08.ply -label_class=6 -label_item=8
48+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/car/09.ply -label_class=6 -label_item=9
49+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/car/10.ply -label_class=6 -label_item=10
50+
51+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/chair/01.ply -label_class=7 -label_item=1
52+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/chair/02.ply -label_class=7 -label_item=2
53+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/chair/03.ply -label_class=7 -label_item=3
54+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/chair/04.ply -label_class=7 -label_item=4
55+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/chair/05.ply -label_class=7 -label_item=5
56+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/chair/06.ply -label_class=7 -label_item=6
57+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/chair/07.ply -label_class=7 -label_item=7
58+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/chair/08.ply -label_class=7 -label_item=8
59+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/chair/09.ply -label_class=7 -label_item=9
60+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/chair/10.ply -label_class=7 -label_item=10
61+
62+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/diningtable/01.ply -label_class=8 -label_item=1
63+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/diningtable/02.ply -label_class=8 -label_item=2
64+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/diningtable/03.ply -label_class=8 -label_item=3
65+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/diningtable/04.ply -label_class=8 -label_item=4
66+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/diningtable/05.ply -label_class=8 -label_item=5
67+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/diningtable/06.ply -label_class=8 -label_item=6
68+
69+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/motorbike/01.ply -label_class=9 -label_item=1
70+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/motorbike/02.ply -label_class=9 -label_item=2
71+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/motorbike/03.ply -label_class=9 -label_item=3
72+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/motorbike/04.ply -label_class=9 -label_item=4
73+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/motorbike/05.ply -label_class=9 -label_item=5
74+
75+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/sofa/01.ply -label_class=10 -label_item=1
76+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/sofa/02.ply -label_class=10 -label_item=2
77+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/sofa/03.ply -label_class=10 -label_item=3
78+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/sofa/04.ply -label_class=10 -label_item=4
79+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/sofa/05.ply -label_class=10 -label_item=5
80+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/sofa/06.ply -label_class=10 -label_item=6
81+
82+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/train/01.ply -label_class=11 -label_item=1
83+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/train/02.ply -label_class=11 -label_item=2
84+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/train/03.ply -label_class=11 -label_item=3
85+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/train/04.ply -label_class=11 -label_item=4
86+
87+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/tvmonitor/01.ply -label_class=12 -label_item=1
88+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/tvmonitor/02.ply -label_class=12 -label_item=2
89+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/tvmonitor/03.ply -label_class=12 -label_item=3
90+
./sphereview_test -plymodel=/Users/yidawang/Downloads/PASCAL3D+_release1.1/CAD/tvmonitor/04.ply -label_class=12 -label_item=4

modules/cnn_3dobj/samples/demo_sphereview_data.cpp

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ 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 | 3 | Iteration of sphere generation.}"
51-
"{plymodel | ../data/3Dmodel/ape.ply | Path of the '.ply' file for image rendering. }"
52-
"{imagedir | ../data/images_all/ | Path of the generated images for one particular .ply model. }"
53-
"{labeldir | ../data/label_all.txt | Path of the generated images for one particular .ply model. }"
54-
"{cam_head_x | 0 | Head of the camera. }"
55-
"{cam_head_y | -1 | Head of the camera. }"
56-
"{cam_head_z | 0 | Head of the camera. }"
57-
"{num_class | 6 | Total number of classes of models}"
58-
"{label_class | 0 | Class label of current .ply model}"
59-
"{rgb_use | 0 | Use RGB image or grayscale}";
50+
"{ite_depth | 2 | Iteration of sphere generation.}"
51+
"{plymodel | ../data/3Dmodel/ape.ply | Path of the '.ply' file for image rendering. }"
52+
"{imagedir | ../data/images_all/ | Path of the generated images for one particular .ply model. }"
53+
"{labeldir | ../data/label_all.txt | Path of the generated images for one particular .ply model. }"
54+
"{cam_head_x | 0 | Head of the camera. }"
55+
"{cam_head_y | 0 | Head of the camera. }"
56+
"{cam_head_z | -1 | Head of the camera. }"
57+
"{image_size | 128 | Size of captured images. }"
58+
"{label_class | 1 | Class label of current .ply model. }"
59+
"{label_item | 1 | Item label of current .ply model. }"
60+
"{rgb_use | 0 | Use RGB image or grayscale. }"
61+
"{num_class | 6 | Total number of classes of models. }"
62+
"{binary_out | 0 | Produce binaryfiles for images and label. }";
6063
/* Get parameters from comand line. */
6164
cv::CommandLineParser parser(argc, argv, keys);
6265
parser.about("Generating training data for CNN with triplet loss");
@@ -69,12 +72,15 @@ int main(int argc, char *argv[])
6972
string plymodel = parser.get<string>("plymodel");
7073
string imagedir = parser.get<string>("imagedir");
7174
string labeldir = parser.get<string>("labeldir");
72-
int num_class = parser.get<int>("num_class");
7375
int label_class = parser.get<int>("label_class");
76+
int label_item = parser.get<int>("label_item");
7477
float cam_head_x = parser.get<float>("cam_head_x");
7578
float cam_head_y = parser.get<float>("cam_head_y");
7679
float cam_head_z = parser.get<float>("cam_head_z");
80+
int image_size = parser.get<int>("image_size");
7781
int rgb_use = parser.get<int>("rgb_use");
82+
int num_class = parser.get<int>("num_class");
83+
int binary_out = parser.get<int>("binary_out");
7884
cv::cnn_3dobj::icoSphere ViewSphere(10,ite_depth);
7985
std::vector<cv::Point3d> campos = ViewSphere.CameraPos;
8086
std::fstream imglabel;
@@ -84,10 +90,12 @@ int main(int argc, char *argv[])
8490
/* Create a window using viz. */
8591
viz::Viz3d myWindow("Coordinate Frame");
8692
/* Set window size as 64*64, we use this scale as default. */
87-
myWindow.setWindowSize(Size(64,64));
93+
myWindow.setWindowSize(Size(image_size,image_size));
8894
/* Set background color. */
8995
myWindow.setBackgroundColor(viz::Color::gray());
9096
myWindow.spin();
97+
/* Add light. */
98+
myWindow.addLight(Vec3d(0,0,100000), Vec3d(0,0,0), viz::Color::white(), viz::Color::gray(), viz::Color::black(), viz::Color::white());
9199
/* Create a Mesh widget, loading .ply models. */
92100
viz::Mesh objmesh = viz::Mesh::load(plymodel);
93101
/* Get the center of the generated mesh widget, cause some .ply files. */
@@ -101,17 +109,21 @@ int main(int argc, char *argv[])
101109
cam_y_dir.z = cam_head_z;
102110
const char* headerPath = "../data/header_for_";
103111
const char* binaryPath = "../data/binary_";
104-
ViewSphere.createHeader((int)campos.size(), 64, 64, headerPath);
112+
if (binary_out)
113+
{
114+
ViewSphere.createHeader((int)campos.size(), image_size, image_size, headerPath);
115+
}
116+
char* temp = new char;
105117
/* Images will be saved as .png files. */
106118
for(int pose = 0; pose < (int)campos.size(); pose++){
107-
char* temp = new char;
108-
sprintf (temp,"%d",label_class);
119+
int label_x, label_y, label_z;
120+
label_x = (int)(campos.at(pose).x*100);
121+
label_y = (int)(campos.at(pose).y*100);
122+
label_z = (int)(campos.at(pose).z*100);
123+
sprintf (temp,"%02d_%02d_%04i_%04i_%04i", label_class, label_item, label_x, label_y, label_z);
109124
string filename = temp;
110-
filename += "_";
111-
sprintf (temp,"%d",pose);
112-
filename += temp;
113125
filename += ".png";
114-
imglabel << filename << ' ' << (int)(campos.at(pose).x*100) << ' ' << (int)(campos.at(pose).y*100) << ' ' << (int)(campos.at(pose).z*100) << endl;
126+
imglabel << filename << ' ' << label_class << endl;
115127
filename = imagedir + filename;
116128
/* Get the pose of the camera using makeCameraPoses. */
117129
Affine3f cam_pose = viz::makeCameraPose(campos.at(pose)*380+cam_focal_point, cam_focal_point, cam_y_dir*380+cam_focal_point);
@@ -127,8 +139,8 @@ int main(int argc, char *argv[])
127139
{
128140
viz::WCameraPosition cpw(1); // Coordinate axes
129141
viz::WCameraPosition cpw_frustum(Vec2f(0.5, 0.5)); // Camera frustum
130-
myWindow.showWidget("CPW", cpw, cam_pose);
131-
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
142+
myWindow.showWidget("CPW", cpw, cam_pose);
143+
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
132144
}
133145

134146
/* Visualize widget. */
@@ -140,8 +152,11 @@ int main(int argc, char *argv[])
140152
myWindow.setViewerPose(cam_pose);
141153
/* Save screen shot as images. */
142154
myWindow.saveScreenshot(filename);
155+
if (binary_out)
156+
{
143157
/* Write images into binary files for further using in CNN training. */
144-
ViewSphere.writeBinaryfile(filename, binaryPath, headerPath,(int)campos.size()*num_class, label_class, (int)(campos.at(pose).x*100), (int)(campos.at(pose).y*100), (int)(campos.at(pose).z*100), rgb_use);
158+
ViewSphere.writeBinaryfile(filename, binaryPath, headerPath,(int)campos.size()*num_class, label_class, (int)(campos.at(pose).x*100), (int)(campos.at(pose).y*100), (int)(campos.at(pose).z*100), rgb_use);
159+
}
145160
}
146161
imglabel.close();
147162
return 1;

0 commit comments

Comments
 (0)