Commit 9fdc78a3 authored by Wangyida's avatar Wangyida

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

parent 8aa47cac
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -13,9 +13,13 @@ cd .. ...@@ -13,9 +13,13 @@ cd ..
cmake .. cmake ..
make -j4 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 -ite_depth=2 -plymodel=../3Dmodel/ape.ply -imagedir=../data/images_ape/ -labeldir=../data/label_ape.txt -num_class=2 -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 -ite_depth=2 -plymodel=../3Dmodel/ant.ply -imagedir=../data/images_ant/ -labeldir=../data/label_ant.txt -num_class=2 -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/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..." echo "Creating leveldb..."
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <string> #include <string>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
using namespace cv; using namespace cv;
using namespace std; using namespace std;
using namespace cv::cnn_3dobj; using namespace cv::cnn_3dobj;
...@@ -45,28 +46,39 @@ uint32_t swap_endian(uint32_t val) { ...@@ -45,28 +46,39 @@ uint32_t swap_endian(uint32_t val) {
val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF);
return (val << 16) | (val >> 16); return (val << 16) | (val >> 16);
} }
Point3d getCenter(string plymodel) Point3d getCenter(cv::Mat cloud)
{ {
char* path_model=(char*)plymodel.data(); Point3f* data = cloud.ptr<cv::Point3f>();
int numPoint = 5841; Point3d dataout;
ifstream ifs(path_model); for(int i = 0; i < cloud.cols; ++i)
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; dataout.x += data[i].x;
data.x += temp_x; dataout.y += data[i].y;
data.y += temp_y; dataout.z += data[i].z;
data.z += temp_z;
} }
data.x = data.x/numPoint; dataout.x = dataout.x/cloud.cols;
data.y = data.y/numPoint; dataout.y = dataout.y/cloud.cols;
data.z = data.z/numPoint; dataout.z = dataout.z/cloud.cols;
return data; 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) 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 ...@@ -151,9 +163,8 @@ void writeBinaryfile(string filename, const char* binaryPath, const char* header
lab_file.close(); lab_file.close();
}; };
int main(int argc, char *argv[]){ 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.}" 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.}"
"{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.}"
"{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. }" "{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. }" "{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. }" "{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[]){ ...@@ -166,7 +177,6 @@ int main(int argc, char *argv[]){
parser.printMessage(); parser.printMessage();
return 0; return 0;
} }
float radius = parser.get<float>("radius");
int ite_depth = parser.get<int>("ite_depth"); int ite_depth = parser.get<int>("ite_depth");
string plymodel = parser.get<string>("plymodel"); string plymodel = parser.get<string>("plymodel");
string imagedir = parser.get<string>("imagedir"); string imagedir = parser.get<string>("imagedir");
...@@ -178,8 +188,6 @@ int main(int argc, char *argv[]){ ...@@ -178,8 +188,6 @@ int main(int argc, char *argv[]){
std::fstream imglabel; std::fstream imglabel;
char* p=(char*)labeldir.data(); char* p=(char*)labeldir.data();
imglabel.open(p); imglabel.open(p);
//IcoSphere ViewSphere(16,0);
//std::vector<cv::Point3d>* campos = ViewSphere.CameraPos;
bool camera_pov = (true); bool camera_pov = (true);
/// Create a window /// Create a window
viz::Viz3d myWindow("Coordinate Frame"); viz::Viz3d myWindow("Coordinate Frame");
...@@ -190,7 +198,10 @@ int main(int argc, char *argv[]){ ...@@ -190,7 +198,10 @@ int main(int argc, char *argv[]){
myWindow.spin(); myWindow.spin();
/// Set background color /// Set background color
/// Let's assume camera has the following properties /// 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); Point3d cam_y_dir(0.0f,0.0f,1.0f);
const char* headerPath = "./header_for_"; const char* headerPath = "./header_for_";
const char* binaryPath = "./binary_"; const char* binaryPath = "./binary_";
...@@ -198,13 +209,10 @@ int main(int argc, char *argv[]){ ...@@ -198,13 +209,10 @@ int main(int argc, char *argv[]){
for(int pose = 0; pose < (int)campos.size(); pose++){ for(int pose = 0; pose < (int)campos.size(); pose++){
imglabel << campos.at(pose).x << ' ' << campos.at(pose).y << ' ' << campos.at(pose).z << endl; imglabel << campos.at(pose).x << ' ' << campos.at(pose).y << ' ' << campos.at(pose).z << endl;
/// We can get the pose of the cam using makeCameraPoses /// 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(campos.at(pose)*radius+cam_focal_point, cam_focal_point, cam_y_dir*radius+cam_focal_point);
//Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir);
/// We can get the transformation matrix from camera coordinate system to global using /// We can get the transformation matrix from camera coordinate system to global using
/// - makeTransformToGlobal. We need the axes of the camera /// - 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)); 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); viz::WMesh mesh_widget(objmesh);
/// Pose of the widget in camera frame /// Pose of the widget in camera frame
Affine3f cloud_pose = Affine3f().translate(Vec3f(1.0f,1.0f,1.0f)); Affine3f cloud_pose = Affine3f().translate(Vec3f(1.0f,1.0f,1.0f));
...@@ -223,10 +231,6 @@ int main(int argc, char *argv[]){ ...@@ -223,10 +231,6 @@ int main(int argc, char *argv[]){
mesh_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); mesh_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("ape", mesh_widget, cloud_pose_global); 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 /// Set the viewer pose to that of camera
if (camera_pov) if (camera_pov)
myWindow.setViewerPose(cam_pose); myWindow.setViewerPose(cam_pose);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment