DM8148 摄像头采集 显示 识别测试 四

11 篇文章 0 订阅
9 篇文章 1 订阅

人脸识别检测头文件:

#ifndef _OBJDETECT_H_
#define _OBJDETECT_H_


extern "C"
{
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <linux/fb.h>
#include <linux/ti81xxfb.h>
#include <linux/ti81xxvin.h>
#include<linux/videodev2.h>

}


#include "opencv/highgui.h"
#include "opencv/cv.h"
#include "opencv/cxcore.h"
#include "opencv/cvaux.h"

class CObjdetect
{

   public:
      CObjdetect(){
		scale_input = 2.2;
		scale_img_size = 30;
		factor_k = 2.0;
		rangle_r = 50.0;
		if_alloct_for_detect=0;
		}
       ~CObjdetect();
public:
	int Initdetect(char * cascade_name);
	void detect_and_draw( IplImage* img,  double scale, double k, double m );

public:
     
	double scale_input ;
	int scale_img_size;
	double factor_k ;
	double rangle_r;
	double dong_k;
	char send_data[50];

     
	       
private:
	CvMemStorage* storage ;
	CvHaarClassifierCascade* cascade;
	IplImage* gray;
	IplImage* small_img;
	int if_alloct_for_detect;

}; 

#endif  /*_OBJDETECT_H_*/


源文件如下:

#include "objdetect.h"



CObjdetect::~CObjdetect()
{
  printf("exit the Objdetect \n");

}
int CObjdetect::Initdetect(char * cascade_name)
{
   
   cascade = (CvHaarClassifierCascade*) cvLoad(cascade_name, 0, 0, 0);

	if (!cascade) {
		fprintf(stderr, "ERROR: Could not load classifier cascade\n");
		return -1;
	}
   storage = cvCreateMemStorage(0);
  return 0;
}

void CObjdetect::detect_and_draw( IplImage* img,  double scale, double k, double m )
{
    CvPoint pt1;
    CvPoint pt2;
    CvScalar color2 = { 0, 255, 0 };
    static CvScalar colors[] = 
    {
        {{0,0,255}},
        {{0,128,255}},
        {{0,255,255}},
        {{0,255,0}},
        {{255,128,0}},
        {{255,255,0}},
        {{255,0,0}},
        {{255,0,255}}
    };

    //double scale = 3.3;
   if (0 == if_alloct_for_detect) {
		gray = cvCreateImage(cvSize(img->width, img->height), 8, 1);
		small_img = cvCreateImage(cvSize(cvRound(img->width / scale), cvRound(
				img->height / scale)), 8, 1);
		if_alloct_for_detect = 1;
	}
    int i;

    cvCvtColor( img, gray, CV_BGR2GRAY );
    cvResize( gray, small_img, CV_INTER_LINEAR );
    cvEqualizeHist( small_img, small_img );
    cvClearMemStorage( storage );

    if( cascade )
    {
        double t = (double)cvGetTickCount();
        CvSeq* faces = cvHaarDetectObjects( small_img, cascade, storage,
                                            k, m, 0/*CV_HAAR_DO_CANNY_PRUNING*/,
                                            cvSize(30, 30) );
        t = (double)cvGetTickCount() - t;
        printf( "detection time = %gms\n", t/((double)cvGetTickFrequency()*1000.) );
        for( i = 0; i < (faces ? faces->total : 0); i++ )
        {
            CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
            CvPoint center;
            int radius;
            center.x = cvRound((r->x + r->width*0.5)*scale);
            center.y = cvRound((r->y + r->height*0.5)*scale);
            //radius = cvRound((r->width + r->height)*0.25*scale);
            //cvCircle( img, center, radius, colors[i%8], 3, 8, 0 );
            
	pt1.x = cvRound((r->x) * scale);
	pt1.y = cvRound((r->y) * scale);
	pt2.x = cvRound((r->x + r->width) * scale);
	pt2.y = cvRound((r->y + r->height) * scale);
        cvRectangle(img, pt2, pt1, color2, 3, 8);

          
        }
    }

   // cvReleaseImage( &gray );
   // cvReleaseImage( &small_img );
}


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

听海拉拉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值