Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move all iterations to c++ object #5

Merged
merged 6 commits into from
Sep 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
moved iterations over row-wise and col-wise to inside c++ object
  • Loading branch information
tobybreckon committed Sep 4, 2017
commit d3638ff5eea6d535b5daf57849b1b98243d023e7
198 changes: 197 additions & 1 deletion depthComp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,203 @@ Mat DepthComp::preProcess(Mat depthIn, const Mat& labelRszd, bool depthNormalize

// *****************************************************************************

Mat DepthComp::identFillHoles(Mat depthIn, const Mat& labelRszd){
Mat DepthComp::identFillHoles(Mat depthIn, Mat labelRszd, bool logStats){

//to write time and result information to a file

ofstream myfile;
if (logStats){
myfile.open ("data.txt", ios::ate );
}

// the very main while loop to run several times with rotated image
// row-wise and then column-wise (with latter being rotation of former)
// with final secondary row-wise pass if needed

while((times == 0) || ((times == 1) && (holesExist == 1)) ||
((times == 2) && (holesExist == 2))) {

// we are running the same filling process one (more) time

times++;

// get start time

auto start = get_time::now();

// perform identification and filling of holes - one pass

depthIn = identFillHolesPass(depthIn, labelRszd);

// get end time

auto end = get_time::now();
auto diff = end - start;

// **** perform logging (file will be closed if logStats = false)

if(myfile.is_open()) {

myfile <<"********************************************************** RUN (( " << times << " )) *************************************************************\n\n";

myfile << "Important Information\n";
myfile << "For depth image and segmented image pair in the run number " << times << endl;

myfile << "\nIn the image, the number of ROWS is : " << "\t\t\t" << depthIn.rows << "\n\t\tAnd the number of COLUMNS is : " << "\t\t\t" << depthIn.cols << endl;


myfile <<"\nThe frequency of the cases in run number " << times << endl;
myfile << "\nnumber of case 1 holes = \t" << case1;
myfile << "\nnumber of case 2 holes = \t" << case2;
myfile << "\nnumber of case 3 holes = \t" << case3;
myfile << "\nnumber of case 4 holes = \t" << case4;
myfile << "\nnumber of case 5 holes = \t" << case5;
myfile << "\nnumber of case 6 holes = \t" << case6;
myfile << "\nnumber of case 7 holes = \t" << case7;
myfile << "\nnumber of case 8 holes = \t" << case8;
myfile << "\nnumber of case 9 holes = \t" << case9;
myfile << "\nnumber of case 10 holes = \t" << case10;
myfile << "\nnumber of case 11 holes = \t" << case11;
myfile << "\nnumber of case 12 holes = \t" << case12;

myfile <<"\n\nThe TIME:\n";
myfile << "Elapsed time is : " << std::chrono::duration_cast<std::chrono::milliseconds>(diff).count()<< " milliseconds " << "\n\n";

myfile <<"********************************************************** RUN (( " << times << " )) *************************************************************\n\n\n\n\n\n";

}

// **** end logging

// check to see of there are any hole pixels left in the image

for(int i=0; i < (depthIn.rows); i++) { // for loop checking rows for holes
for(int j = 0; j < (depthIn.cols); j++) { // for loop checking columns for holes

if(depthIn.at<uchar>(i,j) == 0) { // checking to see if holes remain

if (times == 1) { // the thing has been run ONCE and now we have to flip it

holesExist = 1; // this means holes still exist after the FIRST run

goto nestBreak; //goto is used to break out of a nested loop

} // end of if for when the thing has been run ONCE and we have to flip it


else if (times == 2) { // the thing has been run TWICE and flipped already so we now flip it back

holesExist = 2; // this means holes still exist after the SECOND run

goto nestBreak; //goto is used to break out of a nested loop

} // end of else of for when the thing has been run TWICE and flipped already so we now flip it back

else if (times == 3) { // the thing has been run THREE times and flipped twice already

holesExist = 3; // this means holes still exist after the SECOND run

goto nestBreak; //goto is used to break out of a nested loop

} // end of else if for the thing has been run THREE times and flipped twice already

} // end of if for checking if holes remain

} // end of for loop checking columns for holes
} // end of for loop checking rows for holes

nestBreak:

if((times == 1) && (holesExist == 0)) { // this means it has been run once and all holes are FILLED before any flipping

myfile << "process was run once only and ALL holes are filled." << endl;

} // end of else if for when it has been run once and all holes are FILLED before any flipping


else if((times == 1) && (holesExist == 1)) {
// this means it has been run once and now we must flip to do column-wise


// flipping all image clockwise
transpose(depthIn, depthIn);
transpose(labelRszd, labelRszd);
flip(depthIn, depthIn, 1);
flip(labelRszd, labelRszd, 1);

} // end of if for when it has been run once and now we must flip

else if((times == 2) && (holesExist == 2)) {
// this means it has been run twice and holes still exist and now we must
// flip again for for a secondary (final) row-wise pass

// flipping all image clockwise
transpose(depthIn, depthIn);
transpose(labelRszd, labelRszd);
flip(depthIn, depthIn, 1);
flip(labelRszd, labelRszd, 1);

} // end of else if for when it has been run twice and holes still exist and now we must flip

else if((times == 2) && (holesExist == 1)) {
// this means it has been run twice and all holes are FILLED and now we must flip back

// flipping all image counter-clockwise
transpose(depthIn, depthIn);
transpose(labelRszd, labelRszd);
flip(depthIn, depthIn, 0);
flip(labelRszd, labelRszd, 0);

} // end of else if for when it has been run twice and all holes are FILLED and now we must flip

else if((times == 3) && (holesExist == 3)) { // this means it has been run THREE and holes still exist

// flipping all image clockwise
transpose(depthIn, depthIn);
transpose(labelRszd, labelRszd);
flip(depthIn, depthIn, 1);
flip(labelRszd, labelRszd, 1);
// flipping all image clockwise
transpose(depthIn, depthIn);
transpose(labelRszd, labelRszd);
flip(depthIn, depthIn, 1);
flip(labelRszd, labelRszd, 1);

} // end of else if for when it has been run THREE and holes still exist

else if((times == 3) && (holesExist == 2)) { // this means it has been run THREE and holes still exist

// flipping all image clockwise
transpose(depthIn, depthIn);
transpose(labelRszd, labelRszd);
flip(depthIn, depthIn, 1);
flip(labelRszd, labelRszd, 1);
// flipping all image clockwise
transpose(depthIn, depthIn);
transpose(labelRszd, labelRszd);
flip(depthIn, depthIn, 1);
flip(labelRszd, labelRszd, 1);

} // end of else if for when it has been run THREE and holes still exist

}// end of the main while loop

// close logging file

if (logStats){
myfile.close();
cout << "Process Log: run-times + # filling cases saved in - \"data.txt\".\n";
}

// return final completed depth image (completion performed in place)

return depthIn;

}

// *****************************************************************************

Mat DepthComp::identFillHolesPass(Mat depthIn, const Mat& labelRszd){


int begin1; // beginning of hole in a row
Expand Down
17 changes: 12 additions & 5 deletions depthComp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ using namespace std;

class DepthComp {
private:

int holeFound;

public:
//counting case numbers

int case1;
Expand All @@ -72,23 +72,30 @@ int case12;
int holesExist; // used to check if holes still exist after each run
int times; // shows how many times we have iterated over the image

// worker function to perform each pass of the completion process

Mat identFillHolesPass(Mat depthIn, const Mat& labelIn);

public:

DepthComp();
~DepthComp();

// perform pre-processing on the depth image prior to completion
// depthIn - input depth
// depthIn - input depth (N.B. modified inplace)
// labelIn - input segmented label image
// depthNormalize - perform depth normalization (stretching) for visualization
// return value - pre-processed depth image

Mat preProcess(Mat depthIn, const Mat& labelIn, bool depthNormalize=true);

// perform the identification and filling of depth holes
// depthIn - input depth
// labelIn - input segmented label image
// depthIn - input depth (N.B. modified inplace)
// labelIn - input segmented label image (N.B. modified inplace)
// logStats - log the statistics of the completion process to file data.txt
// return value - completed output depth image

Mat identFillHoles(Mat depthIn, const Mat& labelIn);
Mat identFillHoles(Mat depthIn, const Mat labelIn, bool logStats=false);

};

Expand Down