Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)
project(ImageBasedModellingEdu)

set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-fPIC")

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# ImageBasedModellingEduV1.0
是专门用于深蓝学院基于图像的三维模型重建课程的代码
a test!
4 changes: 2 additions & 2 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(core)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-fPIC")

set(CMAKE_BUILD_TYPE Release)

# find linpng
find_package(PNG REQUIRED)
Expand Down Expand Up @@ -73,6 +73,6 @@ set(SOURCE_FILES
mesh_io_smf.cc
mesh_io_pbrt.cc
)
add_library(core ${HEADERS} ${SOURCE_FILES})
add_library(core SHARED ${HEADERS} ${SOURCE_FILES})
target_link_libraries(core util ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES})

2 changes: 1 addition & 1 deletion examples/task1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(class1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-fPIC")

set(CMAKE_BUILD_TYPE Release)
include_directories("../..")

set(VISUAL_HEADER visualizer.h) #${VISUAL_HEADER}
Expand Down
1 change: 1 addition & 0 deletions examples/task2/class2_test_fundamental_ransac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <fstream>
#include <sstream>
#include <set>
#include <assert.h>
#include <util/system.h>
#include <sfm/ransac_fundamental.h>
#include "math/functions.h"
Expand Down
1 change: 1 addition & 0 deletions examples/task3/class3_test_bundle_adjustment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "sfm/extract_focal_length.h"

#include "sfm/triangulate.h"
#include <assert.h>

#define MAX_PIXELS 1000000

Expand Down
2 changes: 1 addition & 1 deletion examples/task3/class3_test_jacobian.cc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
//// Created by caoqi on 2018/8/31.////3D: 1.36939, -1.17123, 7.04869//obs: 0.180123 -0.156584#include "sfm/bundle_adjustment.h"/* * This function computes the Jacobian entries for the given camera and * 3D point pair that leads to one observation. * * The camera block 'cam_x_ptr' and 'cam_y_ptr' is: * - ID 0: Derivative of focal length f * - ID 1-2: Derivative of distortion parameters k0, k1 * - ID 3-5: Derivative of translation t0, t1, t2 * - ID 6-8: Derivative of rotation w0, w1, w2 * * The 3D point block 'point_x_ptr' and 'point_y_ptr' is: * - ID 0-2: Derivative in x, y, and z direction. * * The function that leads to the observation is given as follows: * * u = f * D(x,y) * x (image observation x coordinate) * v = f * D(x,y) * y (image observation y coordinate) * * with the following definitions: * * xc = R0 * X + t0 (homogeneous projection) * yc = R1 * X + t1 (homogeneous projection) * zc = R2 * X + t2 (homogeneous projection) * x = xc / zc (central projection) * y = yc / zc (central projection) * D(x, y) = 1 + k0 (x^2 + y^2) + k1 (x^2 + y^2)^2 (distortion) */ /** * /description 给定一个相机参数和一个三维点坐标,求解雅各比矩阵,即公式中的df(theta)/dtheta * @param cam 相机参数 * @param point 三维点坐标 * @param cam_x_ptr 重投影坐标x 相对于相机参数的偏导数,相机有9个参数: [0] 焦距f; [1-2] 径向畸变系数k1, k2; [3-5] 平移向量 t1, t2, t3 * [6-8] 旋转矩阵(角轴向量) * @param cam_y_ptr 重投影坐标y 相对于相机参数的偏导数,相机有9个参数 * @param point_x_ptr 重投影坐标x 相对于三维点坐标的偏导数 * @param point_y_ptr 重投影坐标y 相对于三维点坐标的偏导数 */void jacobian(sfm::ba::Camera const& cam, sfm::ba::Point3D const& point, double* cam_x_ptr, double* cam_y_ptr, double* point_x_ptr, double* point_y_ptr){ const double f = cam.focal_length; const double *R = cam.rotation; const double *t = cam.translation; const double *X = point.pos; const double k0 = cam.distortion[0]; const double k1 = cam.distortion[1]; // 相机焦距的偏导数 cam_x_ptr[0] = 0.0; cam_y_ptr[0] = 0.0; // 相机径向畸变的偏导数 cam_x_ptr[1] = 0.0; cam_x_ptr[2] = 0.0; cam_y_ptr[1] = 0.0; cam_y_ptr[2] = 0.0; // 相机将向畸变系数的偏导数 cam_x_ptr[1] = 0.0; cam_x_ptr[2] = 0.0; cam_y_ptr[1] = 0.0; cam_y_ptr[2] = 0.0; // 相机平移向量的偏导数 cam_x_ptr[3] = 0.0; cam_x_ptr[4] = 0.0; cam_x_ptr[5] = 0.0; cam_y_ptr[3] = 0.0; cam_y_ptr[4] = 0.0; cam_y_ptr[5] = 0.0; // 相机旋转矩阵的偏导数 cam_x_ptr[6] = 0.0; cam_x_ptr[7] = 0.0; cam_x_ptr[8] = 0.0; cam_y_ptr[6] = 0.0; cam_y_ptr[7] = 0.0; cam_y_ptr[8] = 0.0; // 三维点的偏导数 point_x_ptr[0] = 0.0; point_x_ptr[1] = 0.0; point_x_ptr[2] = 0.0; point_y_ptr[0] = 0.0; point_y_ptr[1] = 0.0; point_y_ptr[2] = 0.0;}int main(int argc, char*argv[]){ sfm::ba::Camera cam; cam.focal_length = 0.919654; cam.distortion[0] = -0.108298; cam.distortion[1] = 0.103775; cam.rotation[0] = 0.999999; cam.rotation[1] = -0.000676196; cam.rotation[2] = -0.0013484; cam.rotation[3] = 0.000663243; cam.rotation[4] = 0.999949; cam.rotation[5] = -0.0104095; cam.rotation[6] = 0.00135482; cam.rotation[7] = 0.0104087; cam.rotation[8] = 0.999949; cam.translation[0]=0.00278292; cam.translation[1]=0.0587996; cam.translation[2]=-0.127624; sfm::ba::Point3D pt3D; pt3D.pos[0]= 1.36939; pt3D.pos[1]= -1.17123; pt3D.pos[2]= 7.04869; double cam_x_ptr[9]={0}; double cam_y_ptr[9]={0}; double point_x_ptr[3]={0}; double point_y_ptr[3]={0}; jacobian(cam, pt3D, cam_x_ptr, cam_y_ptr, point_x_ptr, point_y_ptr); std::cout<<"Result is :"<<std::endl; std::cout<<"cam_x_ptr: "; for(int i=0; i<9; i++){ std::cout<<cam_x_ptr[i]<<" "; } std::cout<<std::endl; std::cout<<"cam_y_ptr: "; for(int i=0; i<9; i++){ std::cout<<cam_y_ptr[i]<<" "; } std::cout<<std::endl; std::cout<<"point_x_ptr: "; std::cout<<point_x_ptr[0]<<" "<<point_x_ptr[1]<<" "<<point_x_ptr[2]<<std::endl; std::cout<<"point_y_ptr: "; std::cout<<point_y_ptr[0]<<" "<<point_y_ptr[1]<<" "<<point_y_ptr[2]<<std::endl; std::cout<<"\nResult should be :\n" <<"cam_x_ptr: 0.195942 0.0123983 0.000847141 0.131188 0.000847456 -0.0257388 0.0260453 0.95832 0.164303\n" <<"cam_y_ptr: -0.170272 -0.010774 -0.000736159 0.000847456 0.131426 0.0223669 -0.952795 -0.0244697 0.179883\n" <<"point_x_ptr: 0.131153 0.000490796 -0.0259232\n" <<"point_y_ptr: 0.000964926 0.131652 0.0209965\n"; return 0;}
//// Created by caoqi on 2018/8/31.////3D: 1.36939, -1.17123, 7.04869//obs: 0.180123 -0.156584#include "sfm/bundle_adjustment.h"/* * This function computes the Jacobian entries for the given camera and * 3D point pair that leads to one observation. * * The camera block 'cam_x_ptr' and 'cam_y_ptr' is: * - ID 0: Derivative of focal length f * - ID 1-2: Derivative of distortion parameters k0, k1 * - ID 3-5: Derivative of translation t0, t1, t2 * - ID 6-8: Derivative of rotation w0, w1, w2 * * The 3D point block 'point_x_ptr' and 'point_y_ptr' is: * - ID 0-2: Derivative in x, y, and z direction. * * The function that leads to the observation is given as follows: * * u = f * D(x,y) * x (image observation x coordinate) * v = f * D(x,y) * y (image observation y coordinate) * * with the following definitions: * * xc = R0 * X + t0 (homogeneous projection) * yc = R1 * X + t1 (homogeneous projection) * zc = R2 * X + t2 (homogeneous projection) * x = xc / zc (central projection) * y = yc / zc (central projection) * D(x, y) = 1 + k0 (x^2 + y^2) + k1 (x^2 + y^2)^2 (distortion) */ /** * /description 给定一个相机参数和一个三维点坐标,求解雅各比矩阵,即公式中的df(theta)/dtheta * @param cam 相机参数 * @param point 三维点坐标 * @param cam_x_ptr 重投影坐标x 相对于相机参数的偏导数,相机有9个参数: [0] 焦距f; [1-2] 径向畸变系数k1, k2; [3-5] 平移向量 t1, t2, t3 * [6-8] 旋转矩阵(角轴向量) * @param cam_y_ptr 重投影坐标y 相对于相机参数的偏导数,相机有9个参数 * @param point_x_ptr 重投影坐标x 相对于三维点坐标的偏导数 * @param point_y_ptr 重投影坐标y 相对于三维点坐标的偏导数 */void jacobian(sfm::ba::Camera const& cam, sfm::ba::Point3D const& point, double* cam_x_ptr, double* cam_y_ptr, double* point_x_ptr, double* point_y_ptr){ const double f = cam.focal_length; const double *R = cam.rotation; const double *t = cam.translation; const double *X = point.pos; const double k0 = cam.distortion[0]; const double k1 = cam.distortion[1]; const double xc=R[0]*X[0]+R[1]*X[1]+R[2]*X[2]+t[0]; const double yc=R[3]*X[0]+R[4]*X[1]+R[5]*X[2]+t[1]; const double zc=R[6]*X[0]+R[7]*X[1]+R[8]*X[2]+t[2]; const double x=xc/zc; const double y=yc/zc; const double r2=x*x+y*y; const double d=1+(k0+k1*r2)*r2; const double u=f*d*x; const double v=f*d*y; const double u_d=f*x; const double v_d=f*y; const double d_k0=r2; const double d_k1=r2*r2; const double u_k0=f*x*r2; const double u_k1=f*x*r2*r2; const double v_k0=f*y*r2; const double v_k1=f*y*r2*r2; const double x_xc=1/zc; const double x_yc=0; const double x_zc=-x/zc; const double y_xc=0; const double y_yc=1/zc; const double y_zc=-y/zc; const double u_x=f*d; const double v_y=f*d; const double d_xc=(k0+2*k1*r2)*2*x/zc; const double d_yc=(k0+2*k1*r2)*2*y/zc; const double d_zc=-(k0+2*k1*r2)*2*r2/zc; const double u_xc=u_d*d_xc+u_x*x_xc; const double u_yc=u_d*d_yc+u_x*x_yc; const double u_zc=u_d*d_zc+u_x*x_zc; const double v_xc=v_d*d_xc+v_y*y_xc; const double v_yc=v_d*d_yc+v_y*y_yc; const double v_zc=v_d*d_zc+v_y*y_zc; const double u_t0=u_xc; const double u_t1=u_yc; const double u_t2=u_zc; const double v_t0=v_xc; const double v_t1=v_yc; const double v_t2=v_zc; const double xc_w0=0; const double xc_w1=R[6]*X[0]+R[7]*X[1]+R[8]*X[2]; const double xc_w2=-(R[3]*X[0]+R[4]*X[1]+R[5]*X[2]); const double yc_w0=-(R[6]*X[0]+R[7]*X[1]+R[8]*X[2]); const double yc_w1=0; const double yc_w2=R[0]*X[1]+R[1]*X[1]+R[2]*X[2]; const double zc_w0=R[3]*X[0]+R[4]*X[1]+R[5]*X[2]; const double zc_w1=-(R[0]*X[1]+R[1]*X[1]+R[2]*X[2]); const double zc_w2=0; const double u_w0=u_yc*yc_w0+u_zc*zc_w0; const double u_w1=u_xc*xc_w1+u_zc*zc_w1; const double u_w2=u_xc*xc_w2+u_yc*yc_w2; const double v_w0=v_yc*yc_w0+v_zc*zc_w0; const double v_w1=v_xc*xc_w1+v_zc*zc_w1; const double v_w2=v_xc*xc_w2+v_yc*yc_w2; const double u_X=u_xc*R[0]+u_yc*R[3]+u_zc*R[6]; const double u_Y=u_xc*R[1]+u_yc*R[4]+u_zc*R[7]; const double u_Z=u_xc*R[2]+u_yc*R[5]+u_zc*R[8]; const double v_X=v_xc*R[0]+v_yc*R[3]+v_zc*R[6]; const double v_Y=v_xc*R[1]+v_yc*R[4]+v_zc*R[7]; const double v_Z=v_xc*R[2]+v_yc*R[5]+v_zc*R[8]; // 相机焦距的偏导数 cam_x_ptr[0] = d*x; cam_y_ptr[0] = d*y; // 相机径向畸变的偏导数 cam_x_ptr[1] = u_k0; cam_x_ptr[2] = u_k1; cam_y_ptr[1] = v_k0; cam_y_ptr[2] = v_k1; // 相机平移向量的偏导数 cam_x_ptr[3] = u_t0; cam_x_ptr[4] = u_t1; cam_x_ptr[5] = u_t2; cam_y_ptr[3] = v_t0; cam_y_ptr[4] = v_t1; cam_y_ptr[5] = v_t2; // 相机旋转矩阵的偏导数 cam_x_ptr[6] = u_w0; cam_x_ptr[7] = u_w1; cam_x_ptr[8] = u_w2; cam_y_ptr[6] = v_w0; cam_y_ptr[7] = v_w1; cam_y_ptr[8] = v_w2; // 三维点的偏导数 point_x_ptr[0] = u_X; point_x_ptr[1] = u_Y; point_x_ptr[2] = u_Z; point_y_ptr[0] = v_X; point_y_ptr[1] = v_Y; point_y_ptr[2] = v_Z;}int main(int argc, char*argv[]){ sfm::ba::Camera cam; cam.focal_length = 0.919654; cam.distortion[0] = -0.108298; cam.distortion[1] = 0.103775; cam.rotation[0] = 0.999999; cam.rotation[1] = -0.000676196; cam.rotation[2] = -0.0013484; cam.rotation[3] = 0.000663243; cam.rotation[4] = 0.999949; cam.rotation[5] = -0.0104095; cam.rotation[6] = 0.00135482; cam.rotation[7] = 0.0104087; cam.rotation[8] = 0.999949; cam.translation[0]=0.00278292; cam.translation[1]=0.0587996; cam.translation[2]=-0.127624; sfm::ba::Point3D pt3D; pt3D.pos[0]= 1.36939; pt3D.pos[1]= -1.17123; pt3D.pos[2]= 7.04869; double cam_x_ptr[9]={0}; double cam_y_ptr[9]={0}; double point_x_ptr[3]={0}; double point_y_ptr[3]={0}; jacobian(cam, pt3D, cam_x_ptr, cam_y_ptr, point_x_ptr, point_y_ptr); //Test for change std::cout<<"Result is :"<<std::endl; std::cout<<"cam_x_ptr: "; for(int i=0; i<9; i++){ std::cout<<cam_x_ptr[i]<<" "; } std::cout<<std::endl; std::cout<<"cam_y_ptr: "; for(int i=0; i<9; i++){ std::cout<<cam_y_ptr[i]<<" "; } std::cout<<std::endl; std::cout<<"point_x_ptr: "; std::cout<<point_x_ptr[0]<<" "<<point_x_ptr[1]<<" "<<point_x_ptr[2]<<std::endl; std::cout<<"point_y_ptr: "; std::cout<<point_y_ptr[0]<<" "<<point_y_ptr[1]<<" "<<point_y_ptr[2]<<std::endl; std::cout<<"\nResult should be :\n" <<"cam_x_ptr: 0.195942 0.0123983 0.000847141 0.131188 0.000847456 -0.0257388 0.0260453 0.95832 0.164303\n" <<"cam_y_ptr: -0.170272 -0.010774 -0.000736159 0.000847456 0.131426 0.0223669 -0.952795 -0.0244697 0.179883\n" <<"point_x_ptr: 0.131153 0.000490796 -0.0259232\n" <<"point_y_ptr: 0.000964926 0.131652 0.0209965\n"; return 0;}
Expand Down
2 changes: 1 addition & 1 deletion examples/task3/class3_test_lm_optimize.cc

Large diffs are not rendered by default.

Loading