NIQE c++实现

根据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::
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ListenAlone

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值