EmguCv3中使用决策树
2015-09-30 00:27
357 查看
由于我训练的范围太小,图片也要放大到像素级才能看得清。
效果图:
public Form1() { InitializeComponent(); DTrees tree = new DTrees(); float[,] fdata = new float[5, 2] { { 1, 1 }, { 2, 2 }, { 1, 0 }, { 0, 1 }, { 0, 0 } }; Image<Gray, float> data = new Image<Gray, float>(5, 2); float[] fresponses = new float[5] { 1, 1, 0, 0, 0 }; Image<Gray, float> responses = new Image<Gray, float>(5, 1); for (int i = 0; i < 5; i++) { for (int j = 0; j < 2; j++) data[j, i] = new Gray(fdata[i, j]); } for (int i = 0; i < 5; i++) { responses[0, i] = new Gray(fresponses[i]); } tree.Use1SERule = true; tree.UseSurrogates = false; tree.TruncatePrunedTree = true; tree.MaxDepth = 8; tree.MinSampleCount = 1; tree.RegressionAccuracy = 0; tree.MaxCategories = 15; tree.CVFolds = 0; try { tree.Train(data, DataLayoutType.ColSample, responses); } catch (Exception ex) { MessageBox.Show(ex.Message); } Image<Bgr, byte> aaa = new Image<Bgr, byte>(4, 4); for (int i = 0; i < aaa.Height; i++) for (int j = 0; j < aaa.Width; j++) { //int k = i * 512 + j; Image<Gray, float> bbb = new Image<Gray, float>(5, 1); bbb[0, 0] = new Gray(i); bbb[0, 1] = new Gray(j); bbb[0, 2] = bbb[0, 3] = bbb[0, 4] = new Gray(0); //Mat res = new Mat(); float tt = tree.Predict(bbb); if (tt == 1) aaa[i, j] = new Bgr(0, 0, 255); else if (tt == 0) aaa[i, j] = new Bgr(0, 255, 0); } //CvInvoke.Circle(aaa, new Point(100, 250), 5, new MCvScalar(0, 0, 0), -1); //CvInvoke.Circle(aaa, new Point(75, 11), 5, new MCvScalar(0, 0, 0), -1); //CvInvoke.Circle(aaa, new Point(500, 400), 5, new MCvScalar(255, 255, 255), -1); //CvInvoke.Circle(aaa, new Point(350, 20), 5, new MCvScalar(255, 255, 255), -1); //CvInvoke.Circle(aaa, new Point(190, 100), 5, new MCvScalar(255, 255, 255), -1); aaa[1, 1] = new Bgr(0, 0, 0); aaa[2, 2] = new Bgr(0, 0, 0); aaa[0, 0] = new Bgr(255, 255, 255); aaa[1, 0] = new Bgr(255, 255, 255); aaa[0, 1] = new Bgr(255, 255, 255); imageBox1.Image = aaa; }
效果图:
相关文章推荐
- ZIGBEE相应问题
- java集合框架以及性能分析
- 写得很详细的apache的入门文档
- 通过MTP协议用gvfs挂载android手机
- jquery 获取子iframe和获取父框架的例子
- 基本算法
- [LeetCode] Delete Node in a Linked List
- BZOJ 1026: [SCOI2009]windy数
- 无废话WCF入门教程二[什么是WCF]
- HDU 5483 (最小生成树 + 求无向图割边)
- oracle-数据泵备份还原
- 【个人博客作业II】代码复审结果
- 速度之王 — LZ4压缩算法(三)
- Android学习路线图
- 2.9-mysql主从配置-3
- 安装SparkR
- lz4,pigz,gzip 3者比较
- linux之压缩解压缩及归档工具
- Android适配器进阶之三(抽象分类适配器)
- Enable Nux Dextop Repository on CentOS