main.cpp 7.02 KB
Newer Older
sarthou's avatar
sarthou committed
1
#include <iostream>
2
#include <typeinfo>
sarthou's avatar
sarthou committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "algorithm/inpainting/searchers/ISFull.h"
#include "algorithm/inpainting/searchers/ISProfiler.h"
#include "algorithm/inpainting/reconstructors/IRProfiler.h"
#include "algorithm/inpainting/reconstructors/IRBestPatch.h"

#include "algorithm/inpaintingTools/InpaintingOpenCVIO.h"
#include "algorithm/inpaintingTools/InpaintingProfiler.h"
#include "algorithm/inpainting/dataSources/IDSConcrete.h"
#include "algorithm/inpainting/InpaintingConverger.h"


int main(){
    InpaintingOpenCVIO openCVIO = InpaintingOpenCVIO();
    InpaintingProfiler profiler = InpaintingProfiler();

    const std::string videoFileName = "resources/beach_umbrella.avi";
    const std::string occFileName = "resources/beach_umbrella_occlusion.png";

21
22
23
24
    // const std::string videoFileName = "Data/resources/Oreo/Oreo.avi";
    // const std::string occFileName = "Data/resources/Oreo/OreoHD-Occlusion.png";


sarthou's avatar
sarthou committed
25
26
    profiler.BeforeInpainting();

27

sarthou's avatar
sarthou committed
28
29
    // Select and parameterize the algorithms
    InpaintingEvaluator evaluationAlgo = InpaintingEvaluator(50, 5, 5, 5);
30
    ISRandom searchAlgo = ISRandom(20, &evaluationAlgo); //initiated at 20, but 10 in Matlab code
sarthou's avatar
sarthou committed
31
32
    // ISFull searchAlgo = ISFull(&evaluationAlgo);
    IRWeightedAverage reconstructAlgo = IRWeightedAverage(0.75f, 5, 5, 5);
33
    //IRBestPatch reconstructAlgo = IRBestPatch(5, 5, 5);
sarthou's avatar
sarthou committed
34
35
36
37
38
39
40
41
42
43
44

    // To profile
    ISProfiler searchProfiler = ISProfiler(&profiler, &searchAlgo);
    IRProfiler reconstructProfiler = IRProfiler(&profiler, &reconstructAlgo);
    // Final algo
    InpaintingConverger inpainter = InpaintingConverger(3, 2, 20, 0.1f/255.0f, &searchProfiler, &reconstructProfiler, &evaluationAlgo);

    // Load the data source // TODO Move this to another class.
    int sizeX, sizeY, sizeZ;

    openCVIO.GetVideoDimensions(videoFileName, sizeX, sizeY, sizeZ);
45

sarthou's avatar
sarthou committed
46
47
48
49
50
51
52
53
54
    PaddedMatrixDim * const dim = new PaddedMatrixDim(sizeX, sizeY, sizeZ, 2, 2, 2);
    PaddedMatrix<float> * const redMatrix = new PaddedMatrix<float>(dim);
    PaddedMatrix<float> * const greenMatrix = new PaddedMatrix<float>(dim);
    PaddedMatrix<float> * const blueMatrix = new PaddedMatrix<float>(dim);
    PaddedMatrix<float> * const occMatrix = new PaddedMatrix<float>(dim);
    openCVIO.LoadRGBMatrixFromVideo(videoFileName, redMatrix, greenMatrix, blueMatrix);
    openCVIO.LoadOcclusionMatrixFromImage(occFileName, occMatrix);
    IDSConcrete baseIPS = IDSConcrete(dim, redMatrix, greenMatrix, blueMatrix, occMatrix);

55

56
57
58
59
    int level = 2;
    IDSDDownsampling downsampledDataSource = IDSDDownsampling(&baseIPS, 3, 2);
    downsampledDataSource.SetCurLevel(level);

60
    openCVIO.LoadRGBMatrixFromVideo("Data/search_ant/L3_I8/M_SA_Ante_L3_I8.avi",\
61
62
63
64
65
66
67
68
69
    downsampledDataSource.GetRed(), downsampledDataSource.GetGreen(), downsampledDataSource.GetBlue());

    PaddedMatrix<int> * const frame_x = new PaddedMatrix<int>(downsampledDataSource.GetDim());
    PaddedMatrix<int> * const frame_y = new PaddedMatrix<int>(downsampledDataSource.GetDim());
    PaddedMatrix<int> * const frame_z = new PaddedMatrix<int>(downsampledDataSource.GetDim());
    PaddedMatrix<float> * const frame_a = new PaddedMatrix<float>(downsampledDataSource.GetDim());
    PaddedMatrix<float> * const frame_gx = new PaddedMatrix<float>(downsampledDataSource.GetDim());
    PaddedMatrix<float> * const frame_gy = new PaddedMatrix<float>(downsampledDataSource.GetDim());

70
    for(int nbFrame=0; nbFrame<downsampledDataSource.GetDim()->GetSizeZ(); nbFrame++)
71
    {
72
73
      openCVIO.LoadMatrixFromCSV("Data/search_ant/L3_I8/M_SA_Ante_DispX_L"\
      +std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame)+".csv",frame_x,1);
74
75
      downsampledDataSource.GetDispX()->SetFrame(frame_x,nbFrame);

76
77
      openCVIO.LoadMatrixFromCSV("Data/search_ant/L3_I8/M_SA_Ante_DispY_L"\
      +std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame)+".csv",frame_y,1);
78
79
      downsampledDataSource.GetDispY()->SetFrame(frame_y,nbFrame);

80
81
      openCVIO.LoadMatrixFromCSV("Data/search_ant/L3_I8/M_SA_Ante_DispZ_L"\
      +std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame)+".csv",frame_z,1);
82
83
      downsampledDataSource.GetDispZ()->SetFrame(frame_z,nbFrame);

84
85
      openCVIO.LoadMatrixFromCSV("Data/search_ant/L3_I8/M_SA_Ante_DispA_L"\
      +std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame)+".csv",frame_a,1);
86
87
      downsampledDataSource.GetDispA()->SetFrame(frame_a,nbFrame);

88
89
      openCVIO.LoadMatrixFromCSV("Data/search_ant/L3_I8/M_SA_Ante_GradX_L"\
      +std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame)+".csv",frame_gx,1);
90
91
      downsampledDataSource.GetGradX()->SetFrame(frame_gx,nbFrame);

92
93
      openCVIO.LoadMatrixFromCSV("Data/search_ant/L3_I8/M_SA_Ante_GradY_L"\
      +std::to_string(level+1)+"_I5_F"+std::to_string(nbFrame)+".csv",frame_gy,1);
94
95
96
      downsampledDataSource.GetGradY()->SetFrame(frame_gy,nbFrame);
    }

97
    // downsampledDataSource.GetOcc()->Mprint();
98
    searchAlgo.Search(&downsampledDataSource, false);
99
    // reconstructAlgo.Reconstruct(&downsampledDataSource, false);
100
101
102

    for(int nbFrame=0;nbFrame < downsampledDataSource.GetDim()->GetSizeZ();nbFrame++)
    {
103
104
105
      // openCVIO.GeneralIOForRGB(downsampledDataSource.GetRed(), downsampledDataSource.GetGreen(),\
      //  downsampledDataSource.GetBlue(),nbFrame,InpaintingIO::IH_DBG_SAVE,\
      //  "Data/search_reconstruct/CppOut_SR_L"+std::to_string(level+1)+"_F"+ std::to_string(nbFrame));
106

107
108
109
110
111
112
      downsampledDataSource.GetDispX()->GetFrame(nbFrame)->MprintToCSV("Data/search_ant/result_L3_I8/CppOut_SA_DispX_L"+std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame));
      downsampledDataSource.GetDispY()->GetFrame(nbFrame)->MprintToCSV("Data/search_ant/result_L3_I8/CppOut_SA_DispY_L"+std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame));
      downsampledDataSource.GetDispZ()->GetFrame(nbFrame)->MprintToCSV("Data/search_ant/result_L3_I8/CppOut_SA_DispZ_L"+std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame));
      downsampledDataSource.GetDispA()->GetFrame(nbFrame)->MprintToCSV("Data/search_ant/result_L3_I8/CppOut_SA_DispA_L"+std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame));
      downsampledDataSource.GetGradX()->GetFrame(nbFrame)->MprintToCSV("Data/search_ant/result_L3_I8/CppOut_SA_GradX_L"+std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame));
      downsampledDataSource.GetGradY()->GetFrame(nbFrame)->MprintToCSV("Data/search_ant/result_L3_I8/CppOut_SA_GradY_L"+std::to_string(level+1)+"_I8_F"+std::to_string(nbFrame));
113
114
115
116

    }

    std::cout << "End of search/reconstruct test" << std::endl;
117

sarthou's avatar
sarthou committed
118
119
120
121
122
123
124
125
126
127
128
    // Execute the work
    inpainter.Inpaint(&baseIPS, &profiler);

    // Get better quality, less blurry, final images
    IDSDDetailedOcclusion detOcc = IDSDDetailedOcclusion(&baseIPS, 5, 5, 5);
    IRBestPatch bestPatch = IRBestPatch(5, 5, 5);
    bestPatch.Reconstruct(&detOcc, false);

    // Output the new images.
    for(int i = 0; i < baseIPS.GetDim()->GetSizeZ(); ++i)
        openCVIO.GeneralIOForRGB(baseIPS.GetRed(), baseIPS.GetGreen(), baseIPS.GetBlue(), i,
sarthou's avatar
sarthou committed
129
                                 InpaintingIO::IH_DBG_SAVE, "Data/upsample_ant/final/CppOut_F" + std::to_string(i));
130

sarthou's avatar
sarthou committed
131
132
133
134

    profiler.AfterInpainting();
    return 0;
}