文件包括测试图片和svm颜色分类的cpp文件,我用的是vs2013+opencv3.4.1版本,有两张测试图片。其中训练集数据采取的是test.png。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2088502 2018-06-13 15:35 22.png
文件 2196774 2018-05-11 11:40 siasuna.png
文件 10102 2018-05-23 14:37 svmtest.cpp
/*
这个是完整版本,添加标签,分类
*/
#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 << endl << Red_Mat << endl << endl;
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 << tim2 - tim1 << endl;
//cout << red_roi << endl << endl;
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 << red_roi_data << endl << endl;
Mat red_label = Mat(red_roi_convert.rows*red_roi_convert.cols 1 CV_32SC1 Scalar::all(1));
//cout << red_label << endl << endl;
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 << tim2 - tim1 << endl;
//cout << red_roi << endl << endl;
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 << yellow_roi_data << endl << endl;
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
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)