#include <iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
#include<vector>
#include <algorithm>
#include <sys/time.h>
//
#include <omp.h>
using namespace cv;
#define OMP_ON
//自动色阶调整:用于图像去雾
void AutoLevelsAdjust(cv::Mat& src, cv::Mat& dst)
{
timeval begin_time;
timeval end_time;
CV_Assert(!src.empty() && src.channels() == 3);
//统计灰度直方图
gettimeofday(&begin_time, NULL);
int BHist[256] = { 0 }; //B分量
int GHist[256] = { 0 }; //G分量
int RHist[256] = { 0 }; //R分量
//
#ifdef OMP_ON
int omp_thread_nums = omp_get_num_procs() * 2;
omp_set_num_threads(omp_thread_nums);
#pragma omp parallel for
#endif
for(unsigned char* pixel = src.data; pixel < src.dataend; pixel += 3)
{
BHist[*pixel]++;
}
#ifdef OMP_ON
#pragma omp parallel for
#endif
for(unsigned char* pixel = src.data + 1; pixel < src.dataend; pixel += 3)
{
GHist[*pixel]++;
}
#ifdef OMP_ON
#pragma omp parallel for
#endif
for(unsigned char* pixel = src.data + 2; pixel < src.dataend; pixel += 3)
{
RHist[*pixel]++;
}
gettimeofday(&end_time, NULL);
printf("Hist Time: %f ms\n", (end_time.tv_sec*1000000 - begin_time.tv_sec*1000000 + end_
OpenCV自动色阶算法(可用于去雾)
于 2024-02-28 10:33:13 首次发布