/**
 * @file test.cpp
 * @author Bc. Pavol Debnár
 * This is the test file with sample usage of the pointBase class
 * 2022/23
 */



/*! \mainpage Stitching Barrel Surface Images and Correcting Their Brightness
 *
 * \section intro_sec Introduction
 *
 * This is the documentation for the thesis
 * 
 * There are two files: test.cpp and pointbase.cpp
 * 
 * test.cpp contains sample use cases of the implemented library
 * 
 * pointbase.cpp is the implemented library
 * 
 * in the camera folder are scripts for dataset capture, method of operation is mentioned below
 * 
 * \section prereq Prerequisites
 * OpenCV version: 4.5.2 https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html
 *
 * C++17
 * jsoncpp:
 * 
 *     sudo apt install libjsoncpp-dev
 * 
 *     sudo ln -s /usr/include/jsoncpp/json/ /usr/include/json
 *
 * \section install_sec Installation
 *
 *  Install using make
 * 
 * \section cam_op Dataset capture
 * 
 * The scripts in the camera folder are used for image capture from BBX-mini
 * 
 * The mode of operation is following:
 * 
 * 0. (If you want to stitch images automatically, make the project and run online stitching)
 *
 * 1. Make sure, that you are connected to bbx-mini and that you have addresses that can ping each other
 * 
 * 2. Copy the contents of camera/raspberry to BBX-mini and make
 * 
 * 3. Edit the addresses in the server and client scripts
 * 
 * 4. Run a GStreamer pipeline on BBX-mini (sample pipeline is in runThisOnRpi.txt)
 * 
 * 4.5. server.py provides manual stitching with the 'v' button is pressed, server2.py saves the sharpest image each second 
 * 
 * 5. run a chosen server.py on your workstation
 * 
 * 6. run the client.py script on bbx-mini (lighting is activated by running /lights/lights - needs to be created by make as in step 2)
 */


#include "opencv2/highgui.hpp"
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include <json/json.h>
#include <fstream>
#include <filesystem>
#include "pointbase.cpp"


using namespace cv;
using namespace std;
namespace fs = std::filesystem;

//C++17
//sudo apt install libjsoncpp-dev
//sudo ln -s /usr/include/jsoncpp/json/ /usr/include/json
int main(int argc, char** argv)
{
    /* //print point values manually
    std::string path = "../data/";
    for (const auto & entry : fs::directory_iterator(path))
        {
            string filePath = entry.path();
            //cout << filePath.find(".json") << std::endl;
            if (filePath.find(".json") != string::npos) 
            {
                std::cout << filePath << std::endl;
                std::ifstream coord_file(filePath, std::ifstream::binary);
                Json::Value coords;

                coord_file >> coords;
                cout << "x: " << coords["depthPos"]["x"].asDouble() << std::endl;
                cout << "y: " << coords["depthPos"]["y"].asDouble() << std::endl;
            }

        }
    */

    ////////////////////////////////////////////////////
    //offline stitching

    //test pointbase load
    PointBase pb;
    pb.load("../155/2022-11-15_07-18-56/snapshots/");
    pb.patternMatchTry(770,605);
    pb.cumdump(770,605);

    /*
      here are sample inputs

    
    //pb.load("../data/");
    //120/2022-11-15_09-35-09
    //155/2022-11-15_07-18-56
    //2/2022-10-13_13-33-22
    //v
    //pb.load("../1/2022-10-13_11-50-12/snapshots/");
    */

    //test print all point info
    //pb.printPoints(0);

    /* test get path
    path: ../data/0000044.json; 
    x: 206.5; 
    y: 1051; 
    */
    //cout << pb.getPath(206.500,1051.00) << '\n';

    //pb.showPointImg();


    /////////////////////////////////////////////////////
    //online stitching
    /////////////////////////////////////////////////////

    //PointBase pb;
    //pb.onlineStitchSIFT(1280,720,"online/");

}