全局Haar-Like特征图像识别的C++实现

本文档详细介绍了使用C++实现全局Haar-Like特征图像识别的代码,包括`cvdirectcascade.h`和`cvdirectcascade.cpp`两个文件。涉及的数据结构有TWeakClassifier、PtrWeakClassifier、ListObjectType、TLearnedObject和TDetectSettings,以及学习和检测对象的函数`LearnClassifiers`和`DetectObject`。通过这些函数,实现了从输入图像中学习特征并检测目标对象的过程。
摘要由CSDN通过智能技术生成
 cvdirectcascade.h:
#include  " cv.h "

struct  TWeakClassifier
{
    CvRect Rectangles[
2];
}
;

struct  PtrWeakClassifier
{
    
long *tl0, *tr0, *bl0, *br0;
    
long *tl1, *tr1, *bl1, *br1;
    
int offset, size0, size1;
    
int Threshold;
}
;

struct  ListObjectType
{
    
int x, y, width, height;
    
int w;
    
bool use;
    ListObjectType 
*next;
}
;

struct  TLearnedObject
{
    TWeakClassifier 
*Classifiers;
    PtrWeakClassifier 
*ScaleClassifiers;
    
int ObjectWidth, ObjectHeight;
    
int NClassifiers;
}
;

struct  TDetectSettings
{
    
double ScaleRatio, OffsetX, OffsetY;
    
int Ignore, MinW;
    
int StartSubWindow, EndSubWindow;
}
;

bool  LoadDefaultSetting( char   * FileName, TDetectSettings  & DS);
void  LearnClassifiers(unsigned  char   * IptImage, TLearnedObject  & target,  int  IptWidth,  int  IptHeight);
int  DetectObject(TLearnedObject  & target, unsigned  char   * FrameImage,  int  Width,  int  Height, TDetectSettings  & DS, CvRect  *& Objects);

cvdirectcascade.cpp:
#include  < iostream.h >
#include 
< stdio.h >
#include 
< math.h >
#include 
< string .h >
#include 
< ctype.h >
#include 
< stdlib.h >

#include 
" cv.h "
#include 
" cvdirectcascade.h "

bool  Overlapped(ListObjectType  * obj1, ListObjectType  * obj2)
{
    
int cx = obj1->+ obj1->width / 2;
    
int cy = obj1->+ obj1->height / 2;
    
if ((cx > obj2->x) && (cx < obj2->+ obj2->width) && (cy > obj2->y) && (cy < obj2->+ obj2->height))
        
return true;
    cx 
= obj2->+ obj2->width / 2;
    cy 
= obj2->+ obj2->height / 2;
    
if ((cx > obj1->x) && (cx < obj1->+ obj1->width) && (cy > obj1->y) && (cy < obj1->+ obj1->height))
        
return true;
    
return false;
}


void  RestoreImage(unsigned  char   * IptImage,  long   *& IntegralImage,  int  IptWidth,  int  IptHeight)
{
    IntegralImage 
= new long [(IptWidth + 1* (IptHeight + 1)];

    
long *pic = IntegralImage;
    
for (int i = 0; i < IptWidth + 1; i++)
    
{
        
*pic = 0; pic++;
    }

    
for (int j = 0; j < IptHeight; j++)
    
{
        
*pic = 0; pic+=IptWidth + 1;
    }


    unsigned 
char *pc = IptImage;
    
long *picx, *picy, *picxy;
    picxy 
= IntegralImage;
    pic 
= picxy + IptWidth + 2;
    picx 
= picxy + IptWidth + 1;
    picy 
= picxy + 1;
    
for (i = 0; i < IptHeight; i++)
    
{
        
for (j = 0; j < IptWidth; j++)
        
{
            
*pic = *pc + *picx + *picy - *picxy;
            pic
++; picx++; picy++; picxy++;
            pc
++;
        }

        pic
++; picx++; picy++; picxy++;
    }

}


int  CalculateXBoundary(unsigned  char   * IptImage,  int  IptWidth,  int  IptHeight,  int  x,  int  y,  int  width,  int  height)
{
    
int T, NewT = width / 2, C1 = 0, C2 = 0, D1 = 0, D2 = 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值