資源簡介
文件包括測試圖片和svm顏色分類的cpp文件,我用的是vs2013+opencv3.4.1版本,有兩張測試圖片。其中訓練集數據采取的是test.png。

代碼片段和文件信息
/*
這個是完整版本,添加標簽,分類
*/
#include???
#include???
#include???
#include??
#include???
#include??
using?namespace?std;
using?namespace?cv;
using?namespace?cv::ml;
void?on_mouse(int?event?int?x?int?y?int?flags?void*?ustc);?//鼠標取樣本點
void?scale_Sampling(const?Mat?&src?Mat?&dst?double?Ratio);
int?main(int?argc?char?*argv[])
{
long?red_numb?=?0?yellow_numb?=?0?green_numb?=?0?blue_numb?=?0?back_numb?=?0;
//------------------------坐標信息----------------------//
//紅色:x245y211
//綠色:x500y710
//黃色:x770y60
//藍色:x1040y490
//背景:x13y246
int?redx?=?245?redy?=?211;
int?greenx?=?500?greeny?=?710;
int?yellowx?=?770?yellowy?=?60;
int?bluex?=?1040?bluey?=?490;
int?backx?=?13?backy?=?150;
int?radi?=?11;
Mat?arry[10];
String?a?=?“C:/Users/ncutl/Desktop/siasuna.png“;
Mat?ori_image?=?imread(a);
Point?c(0?0)?b(128?100);
Rect?rect1(c?b);
Mat?roi1;
ori_image(rect1).copyTo(roi1);?//?copy?the?region?rect1?from?the?image?to?roi1
imshow(“1“?roi1);
//namedWindow(“ori“?CV_WINDOW_NORMAL);
//imshow(“ori“?ori_image);
//setMouseCallback(“ori“?on_mouse?0);
/*Mat?Red_Mat(50?50?CV_8UC3?Scalar(0?0?255));
cout?< uchar?*p?=?Red_Mat.data;
//waitKey(0);
Mat?T3_M(Red_Mat.rows*Red_Mat.cols?3?CV_8UC1?p);//轉化成一維
cout?<“T3_M:?“?< */
//--------------------紅色訓練集---------------------//
//rectangle(red?cv::Rect(0?0?200?150)?cv::Scalar(255?0?0)?10);
Mat?red_roi_uf(ori_image?Rect(redx?redy?100?100));
Mat?red_roi;
DWORD?tim1?=?GetTickCount();
medianBlur(red_roi_uf?red_roi?radi);
DWORD?tim2?=?GetTickCount();
cout?< //cout?< Mat?red_roi_convert;
red_roi.convertTo(red_roi_convert?CV_32FC1);
Mat?red_roi_data(red_roi_convert.rows*red_roi_convert.cols?3?CV_32FC1?red_roi_convert.data);
//cout?< Mat?red_label?=?Mat(red_roi_convert.rows*red_roi_convert.cols?1?CV_32SC1?Scalar::all(1));
//cout?< imshow(“紅色“?red_roi);
//-------------------黃色訓練集-----------------//
Mat?yellow_roi_uf(ori_image?Rect(yellowx?yellowy?100?100));
Mat?yellow_roi;
tim1?=?GetTickCount();
medianBlur(yellow_roi_uf?yellow_roi?radi);
tim2?=?GetTickCount();
cout?<
//cout?< Mat?yellow_roi_convert;
yellow_roi.convertTo(yellow_roi_convert?CV_32FC1);
Mat?yellow_roi_data(yellow_roi_convert.rows*yellow_roi_convert.cols?3?CV_32FC1?yellow_roi_convert.data);
//cout?< Mat?yellow_label?=?Mat(yellow_roi_convert.rows*yellow_roi_convert.cols?1?CV_32SC1?Scalar::all(2));
imshow(“黃色“?yellow_roi);
//------------------------綠色訓練集---------------//
Mat?green_roi_uf(ori
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????2088502??2018-06-13?15:35??22.png
?????文件?????2196774??2018-05-11?11:40??siasuna.png
?????文件???????10102??2018-05-23?14:37??svmtest.cpp
評論
共有 條評論