Hotspot.hpp 1.51 KB
#pragma once

#include <vector>

#include <opencv2/core/mat.hpp>
#include <opencv2/cudaarithm.hpp>

class Hotspot {
  public:
	using Contour = std::vector<cv::Point>;
	using Surface = std::vector<cv::Point3f>;

	const unsigned long timestamp;
	const int component;
	const Contour contour;

	const cv::cuda::GpuMat mask;

	int size;
	double meanTemperature, maxTemperature;

	Hotspot(const cv::cuda::GpuMat &temperature, unsigned long timestamp,
	        int component, const Contour &contour, const Surface &surface);

	double perimeter() const;

  private:
	const Surface surface;

	Hotspot(const cv::cuda::GpuMat &temperature, unsigned long timestamp,
	        int component, const Contour &contour, const Surface &surface,
	        const cv::cuda::GpuMat &mask);

	static cv::cuda::GpuMat createMask(const cv::Size &size,
	                                   const Contour &contour);

	/* Buffors */
	cv::cuda::Stream nonZeroStream, sumStream, minMaxStream;
	cv::cuda::GpuMat nonZeroDevice{1, 1, CV_32SC1}, sumDevice{1, 1, CV_64FC1},
	    minMaxDevice{1, 2, CV_32SC1};
	cv::Mat nonZeroHost{1, 1, CV_32SC1}, sumHost{1, 1, CV_64FC1},
	    minMaxHost{1, 2, CV_32SC1};
};

class PersistentHotspot {
  public:
	explicit PersistentHotspot(const Hotspot &initial);

	void merge(const Hotspot &other);
	int area() const;

	cv::cuda::GpuMat mask;
	int component;
	std::vector<unsigned long> timestamps;
	std::vector<double> meanTemperatures;
	std::vector<double> maxTemperatures;

  private:
	void append(const Hotspot &other);

	cv::cuda::Stream stream;
};