BOW-SURF影像检测.docx_第1页
BOW-SURF影像检测.docx_第2页
BOW-SURF影像检测.docx_第3页
BOW-SURF影像检测.docx_第4页
BOW-SURF影像检测.docx_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

BOW-SURF 天安门影像检测#include stdafx.h#include highgui.h#include opencv2/objdetect/objdetect.hpp#include opencv2/highgui/highgui.hpp#include opencv2/imgproc/imgproc.hpp#include opencv2/legacy/legacy.hpp#include opencv2/nonfree/features2d.hpp#include opencv2/ml/ml.hpp#include opencv2/core/core.hpp#include opencv2/contrib/contrib.hpp#include #include features2d (2).hpp#include opencv.hpp#include features2d.hpp#include #include using namespace std;using namespace cv;/*SURF训练,SURF提取*/void main(int argc, char *argv)DWORD start_time = GetTickCount();/结果输出 CString data;CString OutData;CString OutData_result;CString ResultPath = _T(E:/temp/result/BOW_SURF_result.txt);CFile file(ResultPath, CFile:modeCreate | CFile:modeWrite);file.SeekToBegin();file.Write(xffxfe, 2);Mat srcImage1 = imread(E:temp天安门.bmp);Mat *srcImage2 = new Mat100;int minHessian = 1000;SURF detector(minHessian);std:vector* train_keyPoint2 = new std:vector21;SURF extractor;Mat *train_descriptor2 = new Mat21;char imagepath100;char matchResult100;int tiananmen_tiananmen_count = 0;int tiananmen_qita_count = 0;int qita_tiananmen_count = 0;int qita_qita_count = 0;/训练得到BOW特征训练集detector.detect(srcImage1, train_keyPoint20);pute(srcImage1, train_keyPoint20, train_descriptor20);for (int s = 1; s 21; s+)sprintf_s(imagepath, E:temp天安门 (%d).jpg, s);srcImage2s = imread(imagepath);if (!srcImage1.data | !srcImage2s.data)printf(读取检测图片%d错误, s);/训练影像特征检测detector.detect(srcImage2s, train_keyPoint2s);pute(srcImage2s, train_keyPoint2s, train_descriptor2s);for (int s = 21; s 100; s+)sprintf_s(imagepath, E:temp其它 (%d).jpg, s - 20);srcImage2s = imread(imagepath);if (!srcImage1.data | !srcImage2s.data)printf(读取检测图片%d错误, s);BOWKMeansTrainer bowTraining(100); /定义聚类中心1000个,其余的默认参数;for (int i = 0; i 21; i+)bowTraining.add(train_descriptor2i);Mat dictionary = bowTraining.cluster();/ Obtain the BoF descriptor/FlannBasedMatcher *matcher = new std:vector;Ptr BF_matcher(new BFMatcher);/ brute force matcherPtr Flann_matcher(new FlannBasedMatcher);/ nearest neighbor matcherPtr SURF_detector(new SurfFeatureDetector);/ SURF detctorPtr SURF_extractor(new SurfDescriptorExtractor);/ SURF extractorBOWImgDescriptorExtractor SURF_bowDE(SURF_extractor, BF_matcher);/ BoF (or BoW) SURF descriptor extractorSURF_bowDE.setVocabulary(dictionary);/ Set the dictionary with the vocabulary/关键影像探测vector SURF_keyPoint1;/ keypoints extracted by SURFMat SURF_keyDescriptor1;/ BoF descriptor of key imageSURF_detector-detect(srcImage1, SURF_keyPoint1);/ feature points/ 使用缺省阈值SURF_bowDE.compute(srcImage1, SURF_keyPoint1, SURF_keyDescriptor1);/ descriptors for keypoints /检测影像探测std:vector* SURF_keyPoint2 = new std:vector100;/ Bof descriptor of current imageMat *SURF_descriptor2 = new Mat100;double *cosa=new double100;data.Format(_T(%s%drn), _T(COSA=0.809,minHessian=), minHessian);OutData += data;data.Format(_T(%srn%srn), _T(SURF训练,SURF提取,余弦距离筛选), _T(检测影像 检测结果);OutData += data;data.Format(_T(%s), _T(检测为天安门的影像有:);OutData_result += data;for (int i = 1; i detect(srcImage2i, SURF_keyPoint2i);SURF_bowDE.compute(srcImage2i, SURF_keyPoint2i, SURF_descriptor2i);cosai = SURF_keyDescriptor1.dot(SURF_descriptor2i)/ sqrt(SURF_keyDescriptor1.dot(SURF_keyDescriptor1) * SURF_descriptor2i.dot(SURF_descriptor2i);if (i 0.809)tiananmen_tiananmen_count+;printf(天安门(%d).jpg是rn, i);data.Format(_T(%s%d%s), _T(天安门(), i, _T().jpg、);OutData_result += data;elsetiananmen_qita_count+;printf(天安门(%d).jpg不是rn, i);elseif (cosai 0.809)qita_tiananmen_count+;printf(其它(%d).jpg是rn, i - 20);data.Format(_T(%s%d%s), _T(其它(), i - 20, _T().jpg、);OutData_result += data;elseqita_qita_count+;printf(其它(%d).jpg不是rn, i - 20);double cosa_sort100;Mat *src_sort = new Mat100;char imagepath_sort100100;for (int s = 1; s 100; s+)cosa_sorts = cosas;sort(&cosa_sort0, &cosa_sort100);for (int s1 = 1; s1 100; s1+)for (int s2 = 1; s2 100; s2+)if (cosas1 = cosa_sorts2)src_sorts2 = srcImage2s1;if (s1 21)sprintf_s(imagepath_sorts2, E:temp天安门 (%d).jpg, s1);elsesprintf_s(imagepath_sorts2, E:temp其它 (%d).jpg, s1 - 20);data.Format(_T(%srn), _T(排序后的结果,用于人工选取阈值);OutData += data;for (int s = 1; s 100; s+)printf(%s %.4frn, imagepath_sorts, cosa_sorts);data.Format(_T(%s %.4frn), CString(imagepath_sorts), cosa_sorts);OutData += data;printf(天安门检测为天安门的个数为%drn, tiananmen_tiananmen_count);printf(天安门检测为其它的个数为%drn, tiananmen_qita_count);printf(其它检测为天安门的个数为%drn, qita_tiananmen_count);printf(其它检测为其它的个数为%drn, qita_qita_count);OutData += OutData_result;float total_true_rate = float(tiananmen_tiananmen_count) / float(tiananmen_qita_count + qita_tiananmen_count);float true_rate = float(tiananmen_tiananmen_count) / float(tiananmen_qita_count + tiananmen_tiananmen_count);printf(总体检测正确率%frn, total_true_rate);printf(检测正确率%frn, true_rate);data.Format(_T(rn%s%.6frn), _T(总体检测正确率:), total_true_rate);OutData += data;data.Format(_T(%s%.6frn), _T(检测正确率:), true_rate);OutData += data;DWORD end_time = GetTickC

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论