adjust the view radius automatically and fix the focal point and y direction of camera

pull/276/head
Wangyida 9 years ago
parent 8aa47cac7e
commit 9fdc78a302
  1. 1408
      modules/cnn_3dobj/samples/3Dmodel/ant.ply
  2. 0
      modules/cnn_3dobj/samples/3Dmodel/ape.ply
  3. 0
      modules/cnn_3dobj/samples/3Dmodel/car.ply
  4. 8717
      modules/cnn_3dobj/samples/3Dmodel/cow.ply
  5. 6975
      modules/cnn_3dobj/samples/3Dmodel/fighter.ply
  6. 12391
      modules/cnn_3dobj/samples/3Dmodel/gun.ply
  7. 3797
      modules/cnn_3dobj/samples/3Dmodel/plane.ply
  8. 7724
      modules/cnn_3dobj/samples/3Dmodel/shark.ply
  9. 3443
      modules/cnn_3dobj/samples/3Dmodel/teapot.ply
  10. 12
      modules/cnn_3dobj/samples/build/train_linemod_triplet.sh
  11. 0
      modules/cnn_3dobj/samples/data/label_ant.txt
  12. 0
      modules/cnn_3dobj/samples/data/label_car.txt
  13. 0
      modules/cnn_3dobj/samples/data/label_cow.txt
  14. 0
      modules/cnn_3dobj/samples/data/label_fighter.txt
  15. 0
      modules/cnn_3dobj/samples/data/label_gun.txt
  16. 0
      modules/cnn_3dobj/samples/data/label_plane.txt
  17. 0
      modules/cnn_3dobj/samples/data/label_shark.txt
  18. 0
      modules/cnn_3dobj/samples/data/label_teapot.txt
  19. 76
      modules/cnn_3dobj/samples/sphereview_3dobj_demo.cpp

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -5,7 +5,7 @@ git clone https://github.com/Wangyida/caffe/tree/cnn_triplet
cd caffe
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
make -j4
make test
make install
@ -13,9 +13,13 @@ cd ..
cmake ..
make -j4
./sphereview_test -radius=250 -ite_depth=4 -plymodel=../ape.ply -imagedir=../data/images_ape/ -labeldir=../data/label_ape.txt -num_class=3 -label_class=0
./sphereview_test -radius=250 -ite_depth=4 -plymodel=../duck.ply -imagedir=../data/images_duck/ -labeldir=../data/label_duck.txt -num_class=3 -label_class=1
./sphereview_test -radius=250 -ite_depth=4 -plymodel=../cat.ply -imagedir=../data/images_cat/ -labeldir=../data/label_cat.txt -num_class=3 -label_class=2
./sphereview_test -ite_depth=2 -plymodel=../3Dmodel/ape.ply -imagedir=../data/images_ape/ -labeldir=../data/label_ape.txt -num_class=2 -label_class=0
./sphereview_test -ite_depth=2 -plymodel=../3Dmodel/ant.ply -imagedir=../data/images_ant/ -labeldir=../data/label_ant.txt -num_class=2 -label_class=1
./sphereview_test -ite_depth=2 -plymodel=../3Dmodel/apple.ply -imagedir=../data/images_apple/ -labeldir=../data/label_apple.txt -num_class=2 -label_class=2
./sphereview_test -ite_depth=2 -plymodel=../3Dmodel/lamp.ply -imagedir=../data/images_lamp/ -labeldir=../data/label_lamp.txt -num_class=2 -label_class=3
./sphereview_test -ite_depth=2 -plymodel=../3Dmodel/cow.ply -imagedir=../data/images_cow/ -labeldir=../data/label_cow.txt -num_class=2 -label_class=4
./sphereview_test -ite_depth=2 -plymodel=../3Dmodel/plane.ply -imagedir=../data/images_plane/ -labeldir=../data/label_plane.txt -num_class=2 -label_class=5
./sphereview_test -ite_depth=2 -plymodel=../3Dmodel/porsche.ply -imagedir=../data/images_porsche/ -labeldir=../data/label_porsche.txt -num_class=2 -label_class=6
echo "Creating leveldb..."

@ -38,6 +38,7 @@
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace cv;
using namespace std;
using namespace cv::cnn_3dobj;
@ -45,28 +46,39 @@ uint32_t swap_endian(uint32_t val) {
val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF);
return (val << 16) | (val >> 16);
}
Point3d getCenter(string plymodel)
Point3d getCenter(cv::Mat cloud)
{
char* path_model=(char*)plymodel.data();
int numPoint = 5841;
ifstream ifs(path_model);
string str;
for(size_t i = 0; i < 15; ++i)
getline(ifs, str);
float temp_x, temp_y, temp_z;
Point3f data;
float dummy1, dummy2, dummy3, dummy4, dummy5, dummy6;
for(int i = 0; i < numPoint; ++i)
{
ifs >> temp_x >> temp_y >> temp_z >> dummy1 >> dummy2 >> dummy3 >> dummy4 >> dummy5 >> dummy6;
data.x += temp_x;
data.y += temp_y;
data.z += temp_z;
}
data.x = data.x/numPoint;
data.y = data.y/numPoint;
data.z = data.z/numPoint;
return data;
Point3f* data = cloud.ptr<cv::Point3f>();
Point3d dataout;
for(int i = 0; i < cloud.cols; ++i)
{
dataout.x += data[i].x;
dataout.y += data[i].y;
dataout.z += data[i].z;
}
dataout.x = dataout.x/cloud.cols;
dataout.y = dataout.y/cloud.cols;
dataout.z = dataout.z/cloud.cols;
return dataout;
};
float getRadius(cv::Mat cloud, Point3d center)
{
float radius = 0;
Point3f* data = cloud.ptr<cv::Point3f>();
Point3d datatemp;
for(int i = 0; i < cloud.cols; ++i)
{
datatemp.x = data[i].x - (float)center.x;
datatemp.y = data[i].y - (float)center.y;
datatemp.z = data[i].z - (float)center.z;
float Radius = sqrt(pow(datatemp.x,2)+pow(datatemp.y,2)+pow(datatemp.z,2));
if(Radius > radius)
{
radius = Radius;
}
}
radius = radius*3;
return radius;
};
void createHeader(int num_item, int rows, int cols, const char* headerPath)
{
@ -151,9 +163,8 @@ void writeBinaryfile(string filename, const char* binaryPath, const char* header
lab_file.close();
};
int main(int argc, char *argv[]){
const String keys = "{help | | demo :$ ./sphereview_test -radius=250 -ite_depth=2 -plymodel=../ape.ply -imagedir=../data/images_ape/ -labeldir=../data/label_ape.txt -num_class=2 -label_class=0, then press 'q' to run the demo for images generation when you see the gray background and a coordinate.}"
"{radius | 250 | 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.}"
const String keys = "{help | | demo :$ ./sphereview_test -ite_depth=2 -plymodel=../3Dmodel/ape.ply -imagedir=../data/images_ape/ -labeldir=../data/label_ape.txt -num_class=2 -label_class=0, then press 'q' to run the demo for images generation when you see the gray background and a coordinate.}"
"{ite_depth | 1 | Iteration of sphere generation.}"
"{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. }"
@ -166,7 +177,6 @@ int main(int argc, char *argv[]){
parser.printMessage();
return 0;
}
float radius = parser.get<float>("radius");
int ite_depth = parser.get<int>("ite_depth");
string plymodel = parser.get<string>("plymodel");
string imagedir = parser.get<string>("imagedir");
@ -178,8 +188,6 @@ int main(int argc, char *argv[]){
std::fstream imglabel;
char* p=(char*)labeldir.data();
imglabel.open(p);
//IcoSphere ViewSphere(16,0);
//std::vector<cv::Point3d>* campos = ViewSphere.CameraPos;
bool camera_pov = (true);
/// Create a window
viz::Viz3d myWindow("Coordinate Frame");
@ -190,7 +198,10 @@ int main(int argc, char *argv[]){
myWindow.spin();
/// Set background color
/// Let's assume camera has the following properties
Point3d cam_focal_point = getCenter(plymodel);
/// Create a cloud widget.
viz::Mesh objmesh = viz::Mesh::load(plymodel);
Point3d cam_focal_point = getCenter(objmesh.cloud);
float radius = getRadius(objmesh.cloud, cam_focal_point);
Point3d cam_y_dir(0.0f,0.0f,1.0f);
const char* headerPath = "./header_for_";
const char* binaryPath = "./binary_";
@ -198,13 +209,10 @@ int main(int argc, char *argv[]){
for(int pose = 0; pose < (int)campos.size(); pose++){
imglabel << campos.at(pose).x << ' ' << campos.at(pose).y << ' ' << campos.at(pose).z << endl;
/// We can get the pose of the cam using makeCameraPoses
Affine3f cam_pose = viz::makeCameraPose(campos.at(pose)*radius, cam_focal_point, cam_y_dir);
//Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir);
Affine3f cam_pose = viz::makeCameraPose(campos.at(pose)*radius+cam_focal_point, cam_focal_point, cam_y_dir*radius+cam_focal_point);
/// We can get the transformation matrix from camera coordinate system to global using
/// - makeTransformToGlobal. We need the axes of the camera
Affine3f transform = viz::makeTransformToGlobal(Vec3f(1.0f,0.0f,0.0f), Vec3f(0.0f,1.0f,0.0f), Vec3f(0.0f,0.0f,1.0f), campos.at(pose));
/// Create a cloud widget.
viz::Mesh objmesh = viz::Mesh::load(plymodel);
viz::WMesh mesh_widget(objmesh);
/// Pose of the widget in camera frame
Affine3f cloud_pose = Affine3f().translate(Vec3f(1.0f,1.0f,1.0f));
@ -223,10 +231,6 @@ int main(int argc, char *argv[]){
mesh_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("ape", mesh_widget, cloud_pose_global);
/*viz::WLine axis(cam_focal_point, campos->at(pose)*23);
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Line Widget", axis);*/
/// Set the viewer pose to that of camera
if (camera_pov)
myWindow.setViewerPose(cam_pose);

Loading…
Cancel
Save