Overview
Dehazer C++ library implements a video defog / dehaze algorithm based on local histogram equalization (low-resolution grid CLAHE). The library improves the local contrast of the video frame to reduce the effect of haze and to increase the visibility of low-contrast objects. The library is implemented in C++ (C++17 standard) and has no external dependencies beyond the VFilter interface. This library is suitable for various types of camera (daylight, SWIR, MWIR and LWIR) and it provides simple programming interface. Each instance of the Dehazer C++ class object performs frame-by-frame processing of a video data stream, processing each video frame independently. The library includes optimized SIMD paths for x86 (AVX2 and an SSE2 fallback), for ARM (NEON) and a scalar fallback for any other architecture; the path is selected at compile time from the build flags, so the SSE2 or scalar path is what a build without /arch:AVX2 (-mavx2) produces — note that the default Release flags of this project do target AVX2, which requires an AVX2-capable CPU. The library depends on open source VFilter library (provides interface as well as defines data structures for various video filters implementation, source code included, Apache 2.0 license).
Downloads
Documentation: GO TO DOCUMENTATION
Demo application to test algorithm on your video: DOWNLOAD
Simple interface
class Dehazer : public VFilter
{
public:
/// Get string of current library version.
static std::string getVersion();
/// Initialize video filter.
bool initVFilter(VFilterParams& params) override;
/// Set parameter.
bool setParam(VFilterParam id, float value) override;
/// Get parameter value.
float getParam(VFilterParam id) override;
/// Get all library parameters.
void getParams(VFilterParams& params) override;
/// Execute action command.
bool executeCommand(VFilterCommand id) override;
/// Process frame.
bool processFrame(Frame& frame) override;
/// Set mask for the filter.
bool setMask(cr::video::Frame mask) override;
/// Decode and execute command.
bool decodeAndExecuteCommand(uint8_t* data, int size) override;
};
Simple example
#include <iostream>
#include <opencv2/opencv.hpp>
#include "Dehazer.h"
int main(void)
{
// Open video source.
cv::VideoCapture source;
if (!source.open("test.mp4"))
return -1;
// Init dehazer.
cr::video::Dehazer dehazer;
dehazer.setParam(cr::video::VFilterParam::MODE, 1);
dehazer.setParam(cr::video::VFilterParam::LEVEL, 50);
// Get frame size.
int width = (int)source.get(cv::CAP_PROP_FRAME_WIDTH);
int height = (int)source.get(cv::CAP_PROP_FRAME_HEIGHT);
// Init frames.
cv::Mat openCvBgrImg(height, width, CV_8UC3);
cr::video::Frame frame(width, height, cr::video::Fourcc::YUV24);
// Main loop.
while (true)
{
// Capture next video frame.
source >> openCvBgrImg;
if (openCvBgrImg.empty())
return 0;
// Convert BGR to YUV.
cv::Mat yuvImg(frame.height, frame.width, CV_8UC3, frame.data);
cvtColor(openCvBgrImg, yuvImg, cv::COLOR_BGR2YUV);
// Dehaze.
dehazer.processFrame(frame);
// Convert YUV to BGR.
cvtColor(yuvImg, openCvBgrImg, cv::COLOR_YUV2BGR);
// Show results.
imshow("Result", openCvBgrImg);
if (cv::waitKey(30) == 27)
return 0;
}
return 1;
}

