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
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ include_directories(
${GTSAM_INCLUDE_DIR}
)


# decide if we have pangolin
if (Pangolin_FOUND)
message("--- found PANGOLIN, compiling with pangolin library.")
Expand Down Expand Up @@ -197,11 +196,13 @@ if (OpenCV_FOUND AND Pangolin_FOUND)
message("--- compiling dmvio_t265.")
set(dmvio_t265_SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/live/RealsenseT265.cpp)
add_executable(dmvio_t265 ${PROJECT_SOURCE_DIR}/src/main_dmvio_t265.cpp ${dmvio_t265_SOURCE_FILES})
target_link_libraries(dmvio_t265 dmvio ${DMVIO_LINKED_LIBRARIES} realsense2::realsense2)
target_link_libraries(dmvio_t265 dmvio ${DMVIO_LINKED_LIBRARIES} realsense2::realsense2)
endif()

else()
message("--- not building dmvio_dataset, since either don't have openCV or Pangolin.")
endif()


#add_definitions(${PCL_DEFINITIONS})
add_subdirectory(test)
83 changes: 81 additions & 2 deletions src/dso/IOWrapper/OutputWrapper/SampleOutputWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,22 @@ class SampleOutputWrapper : public Output3DWrapper
public:
inline SampleOutputWrapper()
{
numPCL = 0;
isSavePCL = true;
isPCLfileClose = false;

pclFile.open(strTmpFileName);

printf("OUT: Created SampleOutputWrapper\n");
}

virtual ~SampleOutputWrapper()
{

if (pclFile.is_open())
{
pclFile.close();
}
printf("OUT: Destroyed SampleOutputWrapper\n");
}

Expand All @@ -76,7 +87,7 @@ class SampleOutputWrapper : public Output3DWrapper

virtual void publishKeyframes( std::vector<FrameHessian*> &frames, bool final, CalibHessian* HCalib) override
{
for(FrameHessian* f : frames)
/*for(FrameHessian* f : frames)
{
printf("OUT: KF %d (%s) (id %d, tme %f): %d active, %d marginalized, %d immature points. CameraToWorld:\n",
f->frameID,
Expand All @@ -96,6 +107,74 @@ class SampleOutputWrapper : public Output3DWrapper
if(maxWrite==0) break;
}
}
*/
float fx, fy, cx, cy;
float fxi, fyi, cxi, cyi;
//float colorIntensity = 1.0f;
fx = HCalib->fxl();
fy = HCalib->fyl();
cx = HCalib->cxl();
cy = HCalib->cyl();
fxi = 1 / fx;
fyi = 1 / fy;
cxi = -cx / fx;
cyi = -cy / fy;

if (final)
{
for (FrameHessian* f : frames)
{
if (f->shell->poseValid)
{
auto const& m = f->shell->camToWorld.matrix3x4();

// use only marginalized points.
auto const& points = f->pointHessiansMarginalized;

for (auto const* p : points)
{
float depth = 1.0f / p->idepth;
auto const x = (p->u * fxi + cxi) * depth;
auto const y = (p->v * fyi + cyi) * depth;
auto const z = depth * (1 + 2 * fxi);

Eigen::Vector4d camPoint(x, y, z, 1.f);
Eigen::Vector3d worldPoint = m * camPoint;

if (isSavePCL && pclFile.is_open())
{
isWritePCL = true;

pclFile << worldPoint[0] << " " << worldPoint[1] << " " << worldPoint[2] << "\n";

printf("[%d] Point Cloud Coordinate> X: %.2f, Y: %.2f, Z: %.2f\n",
numPCL,
worldPoint[0],
worldPoint[1],
worldPoint[2]);

numPCL++;
isWritePCL = false;
}
else
{
if (!isPCLfileClose)
{
if (pclFile.is_open())
{
pclFile.flush();
pclFile.close();
isPCLfileClose = true;
}
}
}


}
}
}
}

}

virtual void publishCamPose(FrameShell* frame, CalibHessian* HCalib) override
Expand Down Expand Up @@ -145,7 +224,7 @@ class SampleOutputWrapper : public Output3DWrapper
if(maxWrite==0) break;
}
}

std::ofstream pclFile;

};

Expand Down
9 changes: 3 additions & 6 deletions src/dso/IOWrapper/Pangolin/KeyFrameDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ void KeyFrameDisplay::setFromKF(FrameHessian* fh, CalibHessian* HCalib)

KeyFrameDisplay::~KeyFrameDisplay()
{

if(originalInputSparse != 0)
delete[] originalInputSparse;

}

bool KeyFrameDisplay::refreshPC(bool canRefresh, float scaledTH, float absTH, int mode, float minBS, int sparsity)
Expand Down Expand Up @@ -220,7 +222,7 @@ bool KeyFrameDisplay::refreshPC(bool canRefresh, float scaledTH, float absTH, in
Vec3f* tmpVertexBuffer = new Vec3f[numSparsePoints*patternNum];
Vec3b* tmpColorBuffer = new Vec3b[numSparsePoints*patternNum];
int vertexBufferNumPoints=0;

for(int i=0;i<numSparsePoints;i++)
{
/* display modes:
Expand Down Expand Up @@ -262,8 +264,6 @@ bool KeyFrameDisplay::refreshPC(bool canRefresh, float scaledTH, float absTH, in
tmpVertexBuffer[vertexBufferNumPoints][1] = ((originalInputSparse[i].v+dy)*fyi + cyi) * depth;
tmpVertexBuffer[vertexBufferNumPoints][2] = depth*(1 + 2*fxi * (rand()/(float)RAND_MAX-0.5f));



if(my_displayMode==0)
{
if(originalInputSparse[i].status==0)
Expand Down Expand Up @@ -331,12 +331,9 @@ bool KeyFrameDisplay::refreshPC(bool canRefresh, float scaledTH, float absTH, in
delete[] tmpColorBuffer;
delete[] tmpVertexBuffer;


return true;
}



void KeyFrameDisplay::drawCam(float lineWidth, float* color, float sizeFactor)
{
if(width == 0)
Expand Down
1 change: 1 addition & 0 deletions src/dso/IOWrapper/Pangolin/KeyFrameDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class KeyFrameDisplay
{

public:

EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
KeyFrameDisplay();
~KeyFrameDisplay();
Expand Down
56 changes: 56 additions & 0 deletions src/dso/IOWrapper/Pangolin/PangolinDSOViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ void PangolinDSOViewer::run()

pangolin::Var<bool> settings_resetButton("ui.Reset",false,false);

pangolin::Var<bool> settings_savePCButton("ui.savePointCloud",false,false);

pangolin::Var<int> settings_nPts("ui.activePoints",setting_desiredPointDensity, 50,5000, false);
pangolin::Var<int> settings_nCandidates("ui.pointCandidates",setting_desiredImmatureDensity, 50,5000, false);
Expand Down Expand Up @@ -344,6 +345,61 @@ void PangolinDSOViewer::run()
setting_fullResetRequested = true;
}

if(settings_savePCButton.Get())
{
printf("Saving [%d] Point Cloud Data....\n", numPCL);
settings_savePCButton.Reset();

while (1)
{
if (!isWritePCL)
{
isSavePCL = false;
break;
}

boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
}


while (1)
{
if (isPCLfileClose)
{
std::ofstream finalFile(strSaveFileName);
finalFile << std::string("# .PCD v.6 - Point Cloud Data file format\n");
finalFile << std::string("FIELDS x y z\n");
finalFile << std::string("SIZE 4 4 4\n");
finalFile << std::string("TYPE F F F\n");
finalFile << std::string("COUNT 1 1 1\n");
finalFile << std::string("WIDTH ") << numPCL << std::string("\n");
finalFile << std::string("HEIGHT 1\n");
finalFile << std::string("#VIEWPOINT 0 0 0 1 0 0 0\n");
finalFile << std::string("POINTS ") << numPCL << std::string("\n");
finalFile << std::string("DATA ascii\n");

std::ifstream savedFile(strTmpFileName);

while (!savedFile.eof())
{
finalFile.put(savedFile.get());
}

finalFile.close();
savedFile.close();

printf("PCL File for 'pcl_data.pcd' is saved.\n");

break;
}

boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
}


}


// Swap frames and Process Events
pangolin::FinishFrame();

Expand Down
7 changes: 7 additions & 0 deletions src/dso/util/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ bool setting_debugout_runquiet = false;

int sparsityFactor = 5; // not actually a setting, only some legacy stuff for coarse initializer.

int numPCL = 0;
bool isSavePCL = true;
bool isWritePCL = false;
bool isPCLfileClose = false;
std::string strTmpFileName = "pcl_data_tmp.pcd";
std::string strSaveFileName = "pcl_data.pcd";


void handleKey(char k)
{
Expand Down
7 changes: 6 additions & 1 deletion src/dso/util/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ extern int staticPattern[10][40][2];
extern int staticPatternNum[10];
extern int staticPatternPadding[10];


extern bool isSavePCL;
extern bool isPCLfileClose;
extern int numPCL;
extern std::string strTmpFileName;
extern std::string strSaveFileName;
extern bool isWritePCL;


//#define patternNum staticPatternNum[setting_pattern]
Expand Down
8 changes: 8 additions & 0 deletions src/main_dmvio_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ void run(ImageFolderReader* reader, IOWrap::PangolinDSOViewer* viewer)
tmlog.close();
}

if (!isPCLfileClose)
{
((IOWrap::SampleOutputWrapper*)fullSystem->outputWrapper[1])->pclFile.flush();
((IOWrap::SampleOutputWrapper*)fullSystem->outputWrapper[1])->pclFile.close();
isPCLfileClose = true;
printf("pcl tmp file is auto closed.\n");
}

for(IOWrap::Output3DWrapper* ow : fullSystem->outputWrapper)
{
ow->join();
Expand Down