OverloadHotspotDetectionAlgorithm.hpp 1.8 KB
#pragma once

#include <opencv2/cudaarithm.hpp>
#include <opencv2/cudafilters.hpp>

#include "algorithm/Algorithm.hpp"

#include "algorithm/common/PfcSegmenter.hpp"
#include "algorithm/common/SurfaceMap.hpp"

#include "algorithm/gpu/common/ClusterCorrespondence.hpp"
#include "algorithm/gpu/common/ConcurrentCopyExecute.hpp"
#include "algorithm/gpu/hotspot/Hotspot.hpp"

#include "algorithm/gpu/common/ContinuousGpuMat.hpp"
#include "algorithm/gpu/common/ManagedMat.hpp"

class OverloadHotspotDetectionAlgorithm : public Algorithm {
  public:
	/* Configurable parameters */
	std::unique_ptr<cv::cuda::Filter> medianFilter;

	std::size_t blobsLimit{5};
	std::size_t pixelsThreshold{3};

	std::unique_ptr<cv::cuda::Filter> createMedianFilter(int kernel) const;
	/* Configurable parameters */

	OverloadHotspotDetectionAlgorithm() = default;

	void setup(const cv::Size &frameSize, const CVMatLoader &loader) override;
	void handleFrame(const cv::Mat &hostFrame,
	                 unsigned long timestamp) override;

	std::vector<PersistentHotspot> uniqueHotspots; /* Set of persistent hotspots */

  private:
	using Contours = std::vector<std::vector<cv::Point>>;

	static constexpr int KELVINS{273};
	static constexpr int MAX_TEMPERATURE{(1L << 15) - 1};

	ConcurrentCopyExecute<4> concurrent;
	cv::Size currentFrameSize;

	ClusterCorrespondence clusterCorrespondence{.8, 2.};
	std::unique_ptr<const SurfaceMap> surfaceMap;

	cv::cuda::GpuMat deviceFov, deviceModel, devicePfc;
	cv::Mat hostPfcMask;

	std::vector<Hotspot> currentHotspots;

	void identifyHotspots(unsigned long timestamp);
	void matchHotspot(const Hotspot &hotspot);

	/* Buffors */
	std::unique_ptr<ContinuousGpuMat> medianFilterInput, medianFilterOutput;
	std::unique_ptr<ManagedMat> overheating;
	cv::cuda::GpuMat deviceFrame, deviceInput, deviceTemperature;
	/* Buffors */
};