【20160924】GOCVHelper综述
生活随笔
收集整理的這篇文章主要介紹了
【20160924】GOCVHelper综述
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? GOCVHelper(GreenOpen Computer Version Helper )是我在這幾年編寫圖像處理程序的過程中積累下來的函數庫。主要是對Opencv的適當擴展和在實現Mfc程序時候的功能增強。
? ? 這里將算法庫開放源代碼,并且編寫一系列blog對函數實現進行說明。目的是在于“取之于互聯網,用之于互聯網”。并且也希望該庫能夠繼續發展下去。 ? ? 由于算法庫基于Opencv和Mfc進行編寫,所以要求閱讀使用者具備一定基礎。 ? ? 最終提交的是GOCVHelper.h 和GOCVHelper版本號.cpp兩個文件。 ? ?? ? ? 通過閱讀頭文件,能夠對算法庫實現的功能加以了解: ? ??//名稱:GOCVHelper0.7b.cpp ????//功能:圖像處理和MFC增強 ????//作者:jsxyhelu(1755311380@qq.com?http://jsxyhelu.cnblogs.com) ????//組織:GREENOPEN ????//日期:2016-09-24 ????#include?"stdafx.h" ????#include?<windows.h> ????#include?<iostream> ????#include?<fstream> ????#include?<cstdlib> ????#include?<io.h> ????#include?<stdlib.h> ????#include?<stdio.h> ????#include?<vector> ????#include?"opencv2/core/core.hpp" ????#include?"opencv2/highgui/highgui.hpp" ????#include?"opencv2/imgproc/imgproc.hpp" ????using?namespace?std; ????using?namespace?cv; ????#define??VP??vector<cv::Point>??//用VP符號代替?vector<point> ????#define??DIRECTION_X?0 ????#define??DIRECTION_Y?1 ????//調用算法庫請在Opencv和Mfc正確配置的環境下。 ????//并且配置?項目-屬性-配置屬性-常規-字符集?設置為?使用多字節字符集 ????//和?項目-屬性-配置屬性-c/c++-預處理器-預處理器定義?加入?_CRT_SECURE_NO_WARNINGS ????namespace?GO{ ????????//讀取灰度或彩色圖片到灰度 ????????Mat?imread2gray(string?path); ????????//帶有上下限的threshold ????????Mat?threshold2(Mat?src,int?minvalue,int?maxvalue); ????????//自適應門限的canny算法? ????????Mat?canny2(Mat?src); ????????void?AdaptiveFindThreshold(?Mat?src,double?*low,double?*high,int?aperture_size=3); ????????void?_AdaptiveFindThreshold(CvMat?*dx,?CvMat?*dy,?double?*low,?double?*high); ????????//填充孔洞 ????????Mat?fillHoles(Mat?src); ????????float?getWhiteRate(Mat?src); ????????Mat?getInnerHoles(Mat?src); ????????//頂帽去光差,radius為模板半徑 ????????Mat?moveLightDiff(Mat?src,int?radius?=?40); ????????//將?DEPTH_8U型二值圖像進行細化??經典的Zhang并行快速細化算法 ????????void?thin(const?Mat?&src,?Mat?&dst,?const?int?iterations=100); ????????//使得rect區域半透明 ????????Mat?translucence(Mat?src,Rect?rect,int?idepth?=?90); ????????//使得rect區域打上馬賽克 ????????Mat?mosaic(Mat?src,Rect?rect,int?W?=?18,int?H?=?18); ????????//----------------------------------------------------------------------------------------------------------------------------------------// ????????//尋找最大的輪廓 ????????VP?FindBigestContour(Mat?src); ????????//尋找并繪制出彩色聯通區域 ????????vector<VP>?connection2(Mat?src,Mat&?draw); ????????vector<VP>?connection2(Mat?src); ????????//根據輪廓的面積大小進行選擇 ????????vector<VP>??selectShapeArea(Mat?src,Mat&?draw,vector<VP>?contours,int?minvalue,int?maxvalue); ????????vector<VP>??selectShapeArea(vector<VP>?contours,int?minvalue,int?maxvalue); ????????//根據輪廓的圓的特性進行選擇 ????????vector<VP>??selectShapeArea(Mat?src,Mat&?draw,vector<VP>?contours,int?minvalue,int?maxvalue); ????????vector<VP>??selectShapeArea(vector<VP>?contours,int?minvalue,int?maxvalue); ????????//計算輪廓的圓的特性 ????????float?calculateCircularity(VP?contour); ????????//返回兩點之間的距離 ????????float?getDistance(Point2f?f1,Point2f?f2); ????????//----------------------------------------------------------------------------------------------------------------------------------------// ????????//投影到x或Y軸上,上波形為vup,下波形為vdown,gap為誤差間隔 ????????void?projection2(Mat?src,vector<int>&?vup,vector<int>&?vdown,int?direction?=?DIRECTION_X,int?gap?=?10); ????????//----------------------------------------------------------------------------------------------------------------------------------------// ????????//遞歸讀取目錄下全部文件 ????????void?getFiles(string?path,?vector<string>&?files,string?flag?="r"/*如果不想遞歸這里不寫r就可以*/); ????????//遞歸讀取目錄下全部圖片 ????????void?getFiles(string?path,?vector<Mat>&?files,string?flag?=?"r"); ????????//遞歸讀取目錄下全部圖片和名稱 ????????void?getFiles(string?path,?vector<pair<Mat,string>>&?files,string?flag="r"); ????????//刪除目錄下的全部文件 ????????void?deleteFiles(string?path,string?flag?=?"r"); ????????//創建或續寫目錄下的csv文件,填寫“文件位置-分類”對 ????????int?writeCsv(const?string&?filename,const?Vector<pair<string,string>>srcVect,char?separator=';'); ????????//讀取目錄下的csv文件,獲得“文件位置-分類”對 ????????vector<pair<string,string>>?readCsv(const?string&?filename,?char?separator?=?';')?; ????????//----------------------------------------------------------------------------------------------------------------------------------------// ????????//C++的spilt函數 ????????void?SplitString(const?string&?s,?vector<string>&?v,?const?string&?c); ????????//!?通過文件夾名稱獲取文件名,不包括后綴 ????????void?getFileName(const?string&?filepath,?string&?name,string&?lastname); ????????//-----------------------------------------------------------------------------------------------------------------------------------------// ????????//ini?操作 ????????CString??GetInitString(?CString?Name1?,CString?Name2); ????????void?WriteInitString(?CString?Name1?,CString?Name2?,CString?strvalue); ????????//excel操作 ????????CString?ExportListToExcel(CString??sExcelFile,CListCtrl*?pList,?CString?strTitle); ????????BOOL?GetDefaultXlsFileName(CString&?sExcelFile); ????} ?總結
以上是生活随笔為你收集整理的【20160924】GOCVHelper综述的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 继承之后的使用注意事项_ArraySto
- 下一篇: GitHub 上值得关注的 iOS 开源