資源描述:
《opencv特征提取代碼總結(jié)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、特征提取代碼總結(jié)來(lái)自http://download.csdn.net/source/3208155#acomment特征提取代碼總結(jié)顏色提取??顏色直方圖提取:Code:#include?#include?#include?using?namespace?std;??int?main(?int?argc,?char**?argv?){IplImage?*?src=?cvLoadImage("E:\Download\test1.jpg",1);?IplImage*?hsv?=?cv
2、CreateImage(?cvGetSize(src),?8,?3?);IplImage*?h_plane?=?cvCreateImage(?cvGetSize(src),?8,?1?);IplImage*?s_plane?=?cvCreateImage(?cvGetSize(src),?8,?1?);IplImage*?v_plane?=?cvCreateImage(?cvGetSize(src),?8,?1?);IplImage*?planes[]?=?{?h_plane,?s_plane?};?/**?H?分量劃分為16個(gè)等級(jí),S
3、分量劃分為8個(gè)等級(jí)*/int?h_bins?=?16,?s_bins?=?8;int?hist_size[]?=?{h_bins,?s_bins};?/**?H?分量的變化范圍*/float?h_ranges[]?=?{?0,?180?};??/**?S?分量的變化范圍*/float?s_ranges[]?=?{?0,?255?};float*?ranges[]?=?{?h_ranges,?s_ranges?};?/**?輸入圖像轉(zhuǎn)換到HSV顏色空間*/cvCvtColor(?src,?hsv,?CV_BGR2HSV?);cvCvtPi
4、xToPlane(?hsv,?h_plane,?s_plane,?v_plane,?0?);?otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterth
5、evictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand/**?創(chuàng)建直方圖,二維,?每個(gè)維度上均分*/CvHistogram?*?hist?=?cvCreateH
6、ist(?2,?hist_size,?CV_HIST_ARRAY,?ranges,?1?);/**?根據(jù)H,S兩個(gè)平面數(shù)據(jù)統(tǒng)計(jì)直方圖*/cvCalcHist(?planes,?hist,?0,?0?);?/**?獲取直方圖統(tǒng)計(jì)的最大值,用于動(dòng)態(tài)顯示直方圖*/float?max_value;cvGetMinMaxHistValue(?hist,?0,?&max_value,?0,?0?);??/**?設(shè)置直方圖顯示圖像*/int?height?=?240;int?width?=?(h_bins*s_bins*6);IplImage*?hi
7、st_img?=?cvCreateImage(?cvSize(width,height),?8,?3?);cvZero(?hist_img?);?/**?用來(lái)進(jìn)行HSV到RGB顏色轉(zhuǎn)換的臨時(shí)單位圖像*/IplImage?*?hsv_color?=?cvCreateImage(cvSize(1,1),8,3);IplImage?*?rgb_color?=?cvCreateImage(cvSize(1,1),8,3);int?bin_w?=?width?/?(h_bins?*?s_bins);for(int?h?=?0;?h?
8、s;?h++){for(int?s?=?0;?s?