根据https://github.com/Shiyuuuu/image_metrics/blob/main/niqe.py代码改编,结果精度会不同,如果可以调整的很好的话,欢迎告知
测试代码:
①多线程调用模式
//多线程调用
void test_speed()
{
string Path = R"(E:\2024Work\2\image_result\pathologic\0clear\0_0.jpg)";
Mat input_mat = imread(Path);
string file_path = R"(E:\2024Work\2\ILNIQE\test\Param.txt)";
ScanQualityEvaluator sqe;
sqe.start_calc(6, file_path); //启动6个线程,来计算
int loop_counts = 200;
auto st = CMyLog::getCurrentTime();
for (int i = 0; i < loop_counts; i++)
{
// 图片添加到队列
sqe.push_back(input_mat.data, input_mat.rows, input_mat.cols,1);
}
sqe.stop_calc(); //等待停止
double total_times = CMyLog::getSpanTimes(st, CMyLog::getCurrentTime());
cout << total_times / loop_counts << endl;
}
②单测模式
void test_1()
{
string Path = R"(E:\2024Work\2\image_result\pathologic\1blur\0_0.jpg)";
Mat rgbImg = imread(Path);
//模型文件
string file_path = R"(E:\2024Work\2\ILNIQE\test\Param.txt)";
ScanQualityEvaluator::_CalculateILNIQE_Ready(file_path);
ScanQualityEvaluator::_CalculateILNIQE(cut_img);
}
代码:
#pragma once
#include <opencv2/opencv.hpp>
#include "../BaseCode/BnvQueue.hpp"
//计算扫描质量的接口
class ScanQualityEvaluator
{
public:
//Path 是均值和方差文件
static double _CalculateILNIQE(const cv::Mat img, int block_size_h = 96, int block_size_w = 96);
static int _CalculateILNIQE_Ready(std::string path);
//type=0 raw 1 rgb
int push_back(unsigned char* data, int rows, int cols, int type = 0);
//启动多少个线程来处理
int start_calc(int thread_nums,std::string path);
double stop_calc(); //要等待线程结束 返回计算的值
private:
static std::tuple<float, float, float> _estimate_aggd_param(const cv::Mat& block);
static std::vector<float> _compute_feature(const cv::Mat& block);
private:
void _Start();
double _Stop();
int setStatus(int status);
int config(int thread_nums, std::string path);
private:
int m_status; //0 是表示启动 1表示停止
std::mutex m_img_q_vals_lock;
std::vector<double> m_img_q_vals;
BnvQueue<cv::Mat> m_rgb_img_queue;
std::vector<std::thread> m_threads;
//NIQE的均值,方差矩阵
static cv::Mat mu_pris_param;
static cv::Mat cov_pris_param;
static cv::Mat gaussian_window;
static std::vector<float> gam;
static std::vector<float> r_gam;
};
#include "ScanQualityEvaluator.hpp"
#include <vector>
#include <numeric>
#include "MyLog.h"
#include <fstream>
#include <Tool.h>
using namespace cv;
using namespace std;
cv::

最低0.47元/天 解锁文章
2520

被折叠的 条评论
为什么被折叠?



