移动设备上使用opencv 1.10做图像识别的例子 .

 

 本文来自http://blog.csdn.net/hellogv/ ,引用必须注明出处!      

       上次说到了如何在WINCE/WM移植Opencv1.10,这次就说说如何在WM手机上使用裁剪移植后的Open1.10的例子,在opencv上使用OpenSURF(OpenSURF在GoogleCode的地址:http://code.google.com/p/opensurf1/),先来看看本文程序运行的截图: 

左图为SURF算法找出的特征点,右图为两个图像相似特征点的匹配。

      本文的代码可以到http://www.rayfile.com/zh-cn/files/da4d4edc-8af5-11df-9dac-0015c55db73d/这里下载,代码里包含了自己实现的MyHighGUI类,用于转换/绘制/保存IplImage图像,也包含了同时支持WINCE/WIN32的第三方BMP操作类库----DIBSectionCE类(详见http://www.codeguru.com/cpp/w-p/ce/bitmapsandthegdi/article.php/c3),接下来就贴出部分操作代码:

  1. //*****************************************************************  
  2. //取得程序当前文件夹路径   
  3. //****************************************************************  
  4. CString GetCurrentDirectory()    
  5. {    
  6.     wchar_t pBuf[256];    
  7.     GetModuleFileName(NULL,pBuf,sizeof(pBuf)/sizeof(wchar_t));    
  8.     CString strPath(pBuf);    
  9.     strPath = strPath.Left(strPath.ReverseFind('//') + 1);    
  10.     delete pBuf;  
  11.     return strPath;  
  12. }  
  13.   
  14. void CtestDlg::OnBnClickedButton1()  
  15. {  
  16.     //自定义的HighGUI,详见MyHighGUI.h   
  17.     MyHighGUI gui;  
  18.     //网上的BMP操作类,支持WINCE/WIN32,地址:http://www.codeguru.com/cpp/w-p/ce/bitmapsandthegdi/article.php/c3  
  19.     CDIBSectionCE ce;  
  20.     //step1:读取BMP,并转换为IplImage格式   
  21.     CString bmpPath=GetCurrentDirectory()+L"car1.bmp";  
  22.     ce.Load(bmpPath);  
  23.     int nChannels = ce.GetBitmapInfo()->bmiHeader.biBitCount /8 ;      
  24.     IplImage* img = gui.BMP2Ipl((BYTE*)ce.GetDIBits(),ce.GetWidth(),ce.GetHeight(),nChannels);  
  25.     ce.DeleteObject();  
  26.   
  27.     //step2:提取图片中的特征点   
  28.     IpVec ipts;  
  29.     surfDetDes(img, ipts, false, 3, 4, 2, 0.0004f);  
  30.   
  31.     // step3:画出特征点     
  32.     drawIpoints(img, ipts);  
  33.     gui.Show(img,::GetDC(this->m_hWnd),0,0,img->width,img->height);  
  34.     //gui.WriteBmp(L"img33.bmp",(BYTE *)img->imageData,img->imageSize,img->width,img->height);  
  35.      img=NULL;  
  36. }  
  37.   
  38. void CtestDlg::OnBnClickedButton2()  
  39. {  
  40.     //自定义的HighGUI,详见MyHighGUI.h   
  41.     MyHighGUI gui;  
  42.     //网上的BMP操作类,支持WINCE/WIN32,地址:http://www.codeguru.com/cpp/w-p/ce/bitmapsandthegdi/article.php/c3  
  43.     CDIBSectionCE ce;  
  44.     //step1:读取BMP,并转换为IplImage格式   
  45.     CString bmpPath=GetCurrentDirectory()+L"car1.bmp";  
  46.     ce.Load(bmpPath);  
  47.     int nChannels = ce.GetBitmapInfo()->bmiHeader.biBitCount /8 ;      
  48.     IplImage* img1 = gui.BMP2Ipl((BYTE*)ce.GetDIBits(),ce.GetWidth(),ce.GetHeight(),nChannels);  
  49.     ce.DeleteObject();  
  50.   
  51.     bmpPath=GetCurrentDirectory()+L"car2.bmp";  
  52.     ce.Load(bmpPath);  
  53.     nChannels = ce.GetBitmapInfo()->bmiHeader.biBitCount /8 ;  
  54.     IplImage* img2 = gui.BMP2Ipl((BYTE*)ce.GetDIBits(),ce.GetWidth(),ce.GetHeight(),nChannels);  
  55.     ce.DeleteObject();  
  56.   
  57.     //step2:提取图片中的特征点   
  58.     IpVec ipts1, ipts2;  
  59.     surfDetDes(img1,ipts1,false,4,4,2,0.0002f);  
  60.     surfDetDes(img2,ipts2,false,4,4,2,0.0002f);  
  61.   
  62.     //step3:特征点匹配   
  63.     IpPairVec matches;  
  64.     getMatches(ipts1,ipts2,matches);  
  65.   
  66.     //step4:画出匹配的特征点,并且连线   
  67.     for (unsigned int i = 0; i < matches.size(); ++i)  
  68.     {  
  69.         drawPoint(img1,matches[i].first);  
  70.         drawPoint(img2,matches[i].second);  
  71.         
  72.         int w = img1->width;  
  73.         cvLine(img1,cvPoint(matches[i].first.x,matches[i].first.y),cvPoint(matches[i].second.x+w,matches[i].second.y), cvScalar(123,123,123),1);  
  74.         cvLine(img2,cvPoint(matches[i].first.x-w,matches[i].first.y),cvPoint(matches[i].second.x,matches[i].second.y), cvScalar(123,123,123),1);    
  75.     }  
  76.   
  77.     //画到屏幕上   
  78.     if(img1->height>img2->height)  
  79.     {     
  80.         gui.Show(img1,::GetDC(this->m_hWnd),0,0,img1->width,img1->height);  
  81.         gui.Show(img2,::GetDC(this->m_hWnd),img1->width,img1->height-img2->height,img2->width,img2->height);  
  82.     }  
  83.     else  
  84.     {  
  85.         gui.Show(img1,::GetDC(this->m_hWnd),0,img2->height-img1->height,img1->width,img1->height);  
  86.         gui.Show(img2,::GetDC(this->m_hWnd),img1->width,0,img2->width,img2->height);  
  87.     }  
  88.   
  89. }  

用户可以根据本文的操作代码,在WINCE/WM平台上实现更多Opencv例子,不过,本文程序跑起来很慢(我用的是460MHz的K3方案 WM手机),因为只用标准C的Math做运算处理。在ARM9+DSP或者ARM11等手机上使用Opencv,建议在Opencv的运算部分用上这些手机的专用运算指令,这样可以大大提高运算速度。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值