• 大小: 504KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-26
  • 语言: 其他
  • 标签: opencv  源代码  

资源简介

opencv 多指尖检测 源代码 opencv 多指尖检测 源代码

资源截图

代码片段和文件信息

#include 

#include 
#include 
#include 

#include 
#include 
#include 
#include 
using namespace std;

#pragma comment(lib“cv210.lib“)
#pragma comment(lib“cxcore210.lib“)
#pragma comment(lib“highgui210.lib“)

void ErrorHandler(char* message)
{
cout< exit(0);
}
#undef UNICODE

void fingerTip(char* imgname);

int main()
{
WIN32_FIND_DATA FileData; 
HANDLE hSearch; 
BOOL fFinished = FALSE; 

if(!SetCurrentDirectory(“images“)){
cout<<“failed to change work directory“< exit(0);
}

hSearch = FindFirstFile(“*.bmp“ &FileData); 
if (hSearch == INVALID_HANDLE_VALUE){ 
ErrorHandler(“No .bmp files found.“); 

while (!fFinished){ 
fingerTip(FileData.cFileName);
if (!FindNextFile(hSearch &FileData)){
if (GetLastError() == ERROR_NO_MORE_FILES){ 
fFinished = TRUE; 
} else { 
ErrorHandler(“Couldn‘t find next file.“); 

}
cvWaitKey(0);


// Close the search handle. 
if (!FindClose(hSearch)){ 
ErrorHandler(“Couldn‘t close search handle.“); 


return 0;
}

void fingerTip(char* imgname)
{
IplImage* pImgColor=NULL;
IplImage* pImgGray=NULL;
IplImage* pImgContourAll=NULL;
IplImage* pImgContourAppr=NULL;
IplImage* pImgHull=NULL;
IplImage* pImgDefects=NULL;
pImgColor=cvLoadImage(imgnameCV_LOAD_IMAGE_COLOR);
if (!pImgColor){
cout<<“failed to load image“< exit(0);
}

pImgGray=cvCreateImage(cvGetSize(pImgColor)81);
cvCvtColor(pImgColorpImgGrayCV_RGB2GRAY);
pImgContourAppr=cvCreateImage(cvGetSize(pImgGray)83);
pImgContourAll=cvCreateImage(cvGetSize(pImgGray)83);
pImgHull=cvCreateImage(cvGetSize(pImgGray)83);
pImgDefects=cvCreateImage(cvGetSize(pImgGray)83);
cvZero(pImgContourAppr);
cvZero(pImgContourAll);
cvZero(pImgHull);
cvZero(pImgDefects);

//canny
CvMemStorage* storage=cvCreateMemStorage();
CvSeq* contourSeqAll=cvCreateSeq(0sizeof(CvSeq)sizeof(CvPoint)storage);
cvCanny(pImgGraypImgGray10305);
cvFindContours(pImgGraystorage&contourSeqAllsizeof(CvContour)CV_RETR_LISTCV_link_RUNS);
//original contours
CvSeq* tseq=contourSeqAll;
for (;contourSeqAll;contourSeqAll=contourSeqAll->h_next){
cvDrawContours(pImgContourAllcontourSeqAllcvScalar(25500)cvScalar(00255)02);
}
contourSeqAll=tseq;

CvMemStorage* storageAppr=cvCreateMemStorage();
CvSeq* contourAppr=cvCreateSeq(0sizeof(CvSeq)sizeof(CvPoint)storageAppr);
contourAppr=cvApproxPoly(contourSeqAllsizeof(CvContour)storageApprCV_POLY_APPROX_DP51);
//approximated contours
tseq=contourAppr;
for (;contourAppr;contourAppr=contourAppr->h_next){
cvDrawContours(pImgContourApprcontourApprcvScalar(25500)cvScalar(00255)02);
}
contourAppr=tseq;

//print contours
/*cout<<“contours:“< for (int i=0;itotal;i++){
CvPoint* p=(CvPoint*)CV_GET_SEQ_ELEM

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3928  2010-11-28 13:39  fingertips\fingertips.vcproj

     文件        885  2010-11-27 21:45  fingertips\fingertips.sln

    ..A..H.      9728  2010-12-01 09:14  fingertips\fingertips.suo

     文件       1423  2010-12-01 09:14  fingertips\fingertips.vcproj.FOOLPP-REGION.Administrator.user

     文件      41078  2010-11-26 16:35  fingertips\images\down-001.bmp

     文件      41078  2010-11-26 16:34  fingertips\images\straight-000.bmp

     文件      41078  2010-11-26 16:34  fingertips\images\left-000.bmp

     文件      41078  2010-11-26 16:34  fingertips\images\right-000.bmp

     文件      41078  2010-11-26 16:34  fingertips\images\up-000.bmp

     文件      41078  2010-11-26 16:34  fingertips\images\down-000.bmp

     文件      41078  2010-11-26 16:35  fingertips\images\straight-001.bmp

     文件      41078  2010-11-26 16:35  fingertips\images\left-001.bmp

     文件      41078  2010-11-26 16:35  fingertips\images\right-001.bmp

     文件      41078  2010-11-26 16:35  fingertips\images\up-001.bmp

     文件       6646  2010-11-28 13:43  fingertips\Debug\BuildLog.htm

     文件        663  2010-11-27 22:14  fingertips\Debug\fingertips.exe.embed.manifest

     文件     601088  2010-11-28 13:43  fingertips\Debug\vc90.idb

     文件     552960  2010-11-28 13:43  fingertips\Debug\vc90.pdb

     文件        728  2010-11-27 22:14  fingertips\Debug\fingertips.exe.embed.manifest.res

     文件      42496  2010-11-28 13:43  fingertips\Debug\fingertips.exe

     文件     969728  2010-11-28 13:43  fingertips\Debug\fingertips.pdb

     文件        621  2010-11-28 13:43  fingertips\Debug\fingertips.exe.intermediate.manifest

     文件         64  2010-11-28 13:43  fingertips\Debug\mt.dep

     文件     716432  2010-11-28 13:43  fingertips\Debug\fingertips.ilk

     文件      86914  2010-11-28 13:43  fingertips\Debug\fingertips.obj

     文件       4415  2010-11-28 13:43  fingertips\fingertips.cpp

     目录          0  2010-11-27 21:46  fingertips\images

     目录          0  2010-11-27 22:12  fingertips\Debug

     目录          0  2010-11-27 21:45  fingertips

----------- ---------  ---------- -----  ----

............此处省略2个文件信息

评论

共有 条评论