#ifndef _WEATHER_H_
#define _WEATHER_H_

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>




using cv::Mat;


//Mat preprocessed_image(const Mat&);
cv::Mat computeDFT(const Mat&);
void fft_Shift(Mat);
Mat magnitude_spectrum(const Mat&);

int image_subtraction(const Mat&, const Mat&);



enum class EWeather_method
{
	CANNY = 0, CANNY_TRACK, CONTRAST, FFT
};

class CFog
{
	size_t edges; //pocet hran z Canny
	Mat histogram;
	Mat fft_mat;
	double contrast; //priemer Sobel
	double high_tresh;
	static size_t id;
public:
	CFog() : edges(0), histogram(), fft_mat(), contrast(), high_tresh()
	{ 
		++id;
	}
	
	/*
	konštruktor referenčného aj aktuálneho objektu
	*/
	CFog(const Mat& input, double tresh, EWeather_method method)
	{
		++id;
		high_tresh = tresh;
		weather_analysis(input, method);
	}
	~CFog() { --id; }

	size_t get_edges() const { return edges; }
	double get_contrast() const { return contrast; }
	Mat get_histogram() const { return histogram; }
	Mat get_fft_mat() const { return fft_mat; }
	double get_high_tresh() const { return high_tresh; }

	void set_lower_tresh(double tresh) { high_tresh = tresh; }

	void weather_analysis(const Mat&, EWeather_method method = EWeather_method::CANNY);

	void calculate_histogram(const Mat&);
	void Canny_track(const Mat&);
	void Canny(const Mat&);
	void calculate_contrast(const Mat&);
	double FFT(const Mat&);

	inline std::string is_foggy(const CFog& iref);

	inline double visibility(const CFog& iref);
};

std::string CFog::is_foggy(const CFog& iref)
{
	//if ((edges < iref.get_edges() * 0.85 && abs(contrast) < abs(iref.get_contrast() * 0.85)))
	//{
	//	//std::cout << "Hmlisto";
	//	return "FOGGY";
	//}
	//
	//if (edges < iref.get_edges()*0.9 && abs(contrast) > abs(iref.get_contrast()))
	//{
	//	
	//	return "Zamracene";
	//}

	//std::cout << "Nehmlisto";

	if ((visibility(iref)) < 68  || ((edges < iref.get_edges() / 5)  ||  abs(contrast) < abs(iref.get_contrast() ))) return "FOGGY ";
	return "NOT FOGGY ";
}

/*
parametrizácia viditeľnosti
*/
double CFog::visibility(const CFog& iref)
{
	cv::Scalar ref, act;
	ref = cv::mean(iref.get_fft_mat());
	act = cv::mean(fft_mat);
	//std::cout << static_cast<double>(edges) / (iref.get_edges()) << " " << (contrast / iref.get_contrast()) << " " << (act[0] / ref[0]) << std::endl;

	double  visibility = (((static_cast<double>(edges) / (iref.get_edges()))  + (act[0] / ref[0])) / 2) * 100;
	return visibility > 100 ? 100:visibility;
}




#endif

