SurfaceLayerDetectionAlgorithm.hpp 1.42 KB
#pragma once

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

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

class SurfaceLayerDetectionAlgorithm : public Algorithm {
  public:
	/* Configurable parameters */
	std::unique_ptr<cv::cuda::Filter> medianFilter;
	cv::Scalar derivativeThreshold{7};
	cv::cuda::GpuMat deviceMinTemperature;

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

	SurfaceLayerDetectionAlgorithm() = default;

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

	cv::cuda::GpuMat deviceSurfaceLayers; /* Surface layers mask */

  private:
	/* ns to s and invert to multiply instead of divide */
	static constexpr double NS_TO_S{1e-5};

	cv::Size currentFrameSize;

	cv::cuda::GpuMat deviceRegionMask;

	cv::cuda::GpuMat devicePreviousPreviousFrame, devicePreviousFrame;
	unsigned long previousPreviousTimestamp{}, previousTimestamp{},
	    currentTimestamp{};

	void normalizedDerivative();

	/* Buffors */
	std::unique_ptr<ContinuousGpuMat> medianFilterInput, medianFilterOutput;
	cv::cuda::GpuMat deviceFrame, deviceFiltered, deviceInput, deviceFloatInput,
	    deviceDifference, deviceDifferenceAbs, deviceResult;
	/* Buffors */
};