资源描述:
《opencv特征提取代码总结》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、特征提取代码总结来自http://download.csdn.net/source/3208155#acomment特征提取代码总结颜色提取? 颜色直方图提取: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个等级,S
3、分量划分为8个等级*/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 }; /** 输入图像转换到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/** 创建直方图,二维, 每个维度上均分*/CvHistogram * hist = cvCreateH
6、ist( 2, hist_size, CV_HIST_ARRAY, ranges, 1 );/** 根据H,S两个平面数据统计直方图*/cvCalcHist( planes, hist, 0, 0 ); /** 获取直方图统计的最大值,用于动态显示直方图*/float max_value;cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 ); /** 设置直方图显示图像*/int height = 240;int width = (h_bins*s_bins*6);IplImage* hi
7、st_img = cvCreateImage( cvSize(width,height), 8, 3 );cvZero( hist_img ); /** 用来进行HSV到RGB颜色转换的临时单位图像*/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 < h_bin
8、s; h++){for(int s = 0; s < s_bins; s++){int i = h*s_bins + s;/** 获得直方图中的统计次数,计算显示在图像中的高度*/float bin_val