#ifndef CAMERA_CALIBRATION_H
#define CAMERA_CALIBRATION_H

#pragma once
#include <opencv2/opencv.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/aruco.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>
#include <iostream>

#include <QDialog>
#include <QFileDialog>
#include <QMessageBox>

namespace calibration {
struct camera{
    bool Calibrated = false;
    cv::Mat K_matrix = cv::Mat::zeros(3,3,CV_64F);
    cv::Mat Dist_coeffs = cv::Mat::zeros(1,5,CV_64F);
    cv::Mat Rectification_transform = cv::Mat::zeros(3,3,CV_64F);
    cv::Mat Projection_matrix = cv::Mat::zeros(3,4,CV_64F);
};

struct stereo_camera{
    camera Front_cam;
    camera Side_cam;
    cv::Mat Rotation_matrix = cv::Mat::zeros(3,3,CV_64F);
    cv::Mat Translation_vector = cv::Mat::zeros(3,1,CV_64F);
    cv::Mat Essential_matrix = cv::Mat::zeros(3,3,CV_64F);
    cv::Mat Fundamental_matrix = cv::Mat::zeros(3,3,CV_64F);
    cv::Mat Q_matrix = cv::Mat::zeros(4,4,CV_64F);
};

struct _Point{
    cv::Point front, side;
};
}//namespace_calibration

namespace Ui {
class camera_calibration;
}

class camera_calibration : public QDialog
{
    Q_OBJECT

public:
    explicit camera_calibration(QWidget *parent = nullptr);
    ~camera_calibration();

    void calibrate();

    bool isValid();

    calibration::stereo_camera getData();

    calibration::_Point getCalibrationPoint();

   void setCalibrationPoint(calibration::_Point);

private slots:
    void on_selectFront_clicked();

    void on_selectSide_clicked();

    void on_ChessRow_valueChanged(int arg1);

    void on_ChessColumn_valueChanged(int arg1);

    void on_buttonBox_accepted();

    void on_CheckerSize_valueChanged(double arg1);

private:
    Ui::camera_calibration *ui;
    std::vector<cv::String> imagesF, imagesS;
    int8_t chessRow, chessCol;
    double checker_size;
    bool showFlag = false;
    bool validity = false;
    calibration::stereo_camera parameters;
    calibration::_Point calibration_point;
};

#endif // CAMERA_CALIBRATION_H

