日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

图像清晰度检测程序

發布時間:2023/12/8 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图像清晰度检测程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在抓拍人臉時,為丟掉抓拍質量不高的數據。寫了一個程序來測試三種清晰度檢測的算法。

程序的主要功能是,依次讀取圖片文件夾中的圖片,進行清晰度檢測,每張圖片會得到一個清晰度打分結果。為了提高程序執行速度,將清晰度的閾值寫在cpg文件里,讓程序去讀cpg文件里的閾值,與每張圖片的打分結果比較,低于此閾值的將放入這個路徑的子文件夾(命名為threshold1)中。

并且將每張圖片的打分結果,寫入txt文件中,可視化打分結果。

?

》首先需注意的是,為了保證程序在不同閾值下正確運行,需要在每次運行時先清空掉threshold1文件夾,并將其中的圖片重新放回遍歷到的文件夾中。

這里采用rename方式,將圖片路徑名改變,使得threshold1文件夾內的圖片移出。

》程序主體部分

FindFirstFileAFindNextFileA遍歷圖片文件夾內的文件。

如果圖片文件夾中還有子文件夾,則遞歸操作。

獲得圖片路徑后再加上圖片名稱,就可以放入計算清晰度的函數中。

這里清晰度檢測有三種方法,sobel laplacian,和meanvalue

得到清晰度值后,進入對清晰度值進行判斷操作部分。

如果小于閾值,就調用rename函數,將圖片移到threshold1文件夾中。

參考:

OpenCV 圖像清晰度評價(相機自動對焦) - CSDN博客

#include <highgui/highgui.hpp> #include <imgproc/imgproc.hpp> #include <iostream> #include <opencv2/opencv.hpp> #include <string> #include <fstream> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <Windows.h> #include <string> #include <shlwapi.h> #pragma comment(lib,"shlwapi.lib") #define INI_FILE _T("cpg.ini")using namespace cv; using namespace std;//int main(int argc, char *argv[])double calculate(string fileName) {string newfileName, grayFile;stringstream meanValueStream;string meanValueString;Mat imageSource = imread(fileName);Mat imageGrey;Mat meanValueImage, meanStdValueImage;cvtColor(imageSource, imageGrey, CV_RGB2GRAY);Mat imageSobel;Laplacian(imageGrey, imageSobel, CV_16U, 1, 1);//Sobel(imageGrey, imageSobel, CV_16U, 1, 1);//求灰度圖像的標準差/*meanStdDev(imageGrey, meanValueImage, meanStdValueImage);double meanValue = 0.0;meanValue = meanStdValueImage.at<double>(0, 0); *///圖像的平均灰度double meanValue = 0.0;meanValue = mean(imageSobel)[0];meanValueStream << meanValue;meanValueStream >> meanValueString;meanValueString = fileName + ": Articulation(Laplacian):" + meanValueString;ofstream outfile("路徑/ArticulationLaplacianresult.txt", ios::app);outfile << meanValueString;outfile << endl;outfile.close();return meanValue; } //double to string void opt(string fileName, string imgname, double meanValue) {char ThresholdValue[260];double fThresholdValue;string newfileName;WIN32_FIND_DATAA winFindData;GetPrivateProfileStringA("Threshold", "ThresholdValue", "", ThresholdValue, 260, "D:/AItensor/blurdetector/cpg.ini");fThresholdValue = atof(ThresholdValue);string str1 = winFindData.cFileName;newfileName = "路徑/" + imgname;if (meanValue <= fThresholdValue){rename(fileName.c_str(), newfileName.c_str());}}void judge(const string &strPath) {string fileName, filePath;double meanValue;string strRawPath = strPath;//傳地址strRawPath.append("\\");//加分隔符string strFindPath = strRawPath;//在新設一個strFindPath.append("*.*");//在最外面的目錄下查找文件WIN32_FIND_DATAA winFindData;HANDLE hTemp = FindFirstFileA(strFindPath.c_str(), &winFindData);//c.str是因為這個函數需要cha類型,返回找到的數據//if (INVALID_HANDLE_VALUE == hTemp)// return 0;while (FindNextFileA(hTemp, &winFindData)){string strOldName = winFindData.cFileName;if ("." == strOldName || ".." == strOldName)continue;//如果是目錄,則遞歸繼續操作if (winFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){string strAgain = strPath;strAgain.append("\\");strAgain.append(winFindData.cFileName);judge(strAgain);continue;}//獲得絕對路徑strOldName = strRawPath;//strOldName.append(winFindData.cFileName);filePath = strRawPath;string fileName = strOldName + winFindData.cFileName;//string strNewName = strOldName;string imgname = winFindData.cFileName;meanValue = calculate(fileName);opt(fileName, imgname, meanValue);//return fileName, filePath, imgname;}FindClose(hTemp); }void rename(const string &strPath, const string &strPathroot) {string fileName, filePath;double meanValue;string strRawPath = strPath;//傳地址strRawPath.append("\\");//加分隔符string strFindPath = strRawPath;//在新設一個strFindPath.append("*.*");//在最外面的目錄下查找文件WIN32_FIND_DATAA winFindData;HANDLE hTemp = FindFirstFileA(strFindPath.c_str(), &winFindData);//c.str是因為這個函數需要cha類型,返回找到的數據//if (INVALID_HANDLE_VALUE == hTemp)// return 0;while (FindNextFileA(hTemp, &winFindData)){string imgname = winFindData.cFileName;//newfilePath = strRawPath;string fileName = strRawPath + winFindData.cFileName;//string strNewName = strOldName;string newfileName = strPathroot + winFindData.cFileName;rename(fileName.c_str(), newfileName.c_str());//return fileName, filePath, imgname;}FindClose(hTemp); }int main(int argc, char *argv[]) {string thresholdName = "路徑/threshold1";string newthresholdName = "路徑/";rename(thresholdName, newthresholdName);string path = "路徑";judge(path); }

?

總結

以上是生活随笔為你收集整理的图像清晰度检测程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。