資源描述:
《opencv特征提取代碼總結(jié)》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在應用文檔-天天文庫。
1、特征提取代碼總結(jié)來自http://download.csdn.net/source/3208155#acomment特征提取代碼總結(jié)顏色提取??顏色直方圖提?。篊ode:#include?#include?#include?using?namespace?std;??int?main(?int?argc,?char**?argv?){IplImage?*?src=?cvLoadImage("E:\Download\test1.jpg",1);?IplImage*?hsv?=?cvCreateImage(?cvGetSi
2、ze(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個等級,S分量劃分為8個等級*/int?h_bins?=?16,?s_bins?=?8;i
3、nt?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?);cvCvtPixToPlane(?hsv,?h_plane,?s_plane,?v_plane,?0?);?/**?創(chuàng)建直方圖,二維,
4、?每個維度上均分*/CvHistogram?*?hist?=?cvCreateHist(?2,?hist_size,?CV_HIST_ARRAY,?ranges,?1?);/**?根據(jù)H,S兩個平面數(shù)據(jù)統(tǒng)計直方圖*/cvCalcHist(?planes,?hist,?0,?0?);?/**?獲取直方圖統(tǒng)計的最大值,用于動態(tài)顯示直方圖*/float?max_value;cvGetMinMaxHistValue(?hist,?0,?&max_value,?0,?0?);??/**?設(shè)置直方圖顯示圖像*/int?height?=?240;int?width?=?(h_bins*s_
5、bins*6);IplImage*?hist_img?=?cvCreateImage(?cvSize(width,height),?8,?3?);cvZero(?hist_img?);?/**?用來進行HSV到RGB顏色轉(zhuǎn)換的臨時單位圖像*/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?
6、s;?h++){for(int?s?=?0;?s?
7、cvCvtColor(hsv_color,rgb_color,CV_HSV2BGR);CvScalar?color?=?cvGet2D(rgb_color,0,0);?cvRectangle(?hist_img,?cvPoint(i*bin_w,height),cvPoint((i+1)*bin_w,height?-?intensity),color,?-1,?8,?0?);}}?cvNamedWindow(?"Source",?1?);cvShowImage(?"Source",?src?);?cvN