• PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 77KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 204
    下载次数
  • 2009-11-25 10:39
    上传日期
基于opencv的运动人体检测。可以通过这个程序搭建自己的检测平台。
HumanMotionTrack.rar
  • HumanMotionTrack
  • HumanMotion.cpp
    18.9KB
  • skelecton.cpp
    17.3KB
  • HumanMotionTrack.dsw
    555B
  • OpenGL.cpp
    6.2KB
  • StdAfx.cpp
    303B
  • Bone.cpp
    788B
  • Bone.h
    981B
  • StdAfx.h
    1.2KB
  • Lktrack.cpp
    8.8KB
  • VECTOR3F.H
    3KB
  • HumanMotionTrack.dsp
    5KB
  • skeletons.cpp
    1.2KB
  • Vector3f.cpp
    3.5KB
  • kalman.cpp
    3.8KB
  • main.cpp
    4KB
  • HumanMotionTrack.ncb
    137KB
  • OpenGL.h
    950B
  • HumanMotion.h
    1.2KB
  • skelecton.h
    1.7KB
  • kalman.h
    775B
  • skeletons.h
    823B
  • HumanMotionTrack.opt
    128KB
内容介绍
// HumanMotion.cpp: implementation of the HumanMotion class. // ////////////////////////////////////////////////////////////////////// #ifdef _CH_ #pragma package <opencv> #endif #ifndef _EiC #include "cv.h" #include "highgui.h" #include <stdio.h> #include <ctype.h> #include "skelecton.h" #include "skeletons.h" #include "kalman.h" #include "OpenGL.h" #include "stdafx.h" #include "HumanMotion.h" #endif IplImage *image = 0, *grey = 0, *prev_grey = 0, *pyramid = 0, *prev_pyramid = 0,*motion_track_img = 0, *swap_temp; IplImage* background_image = 0; int win_size = 10; const int MAX_COUNT = 13; //骨架节点数 CvPoint2D32f* points[2] = {0,0}, *swap_points; char* status = 0; int count = 0; int need_to_init = 1; int night_mode = 0; int flags = 0; int add_remove_pt = 0; int pause = 0; bool init_OK = false; CvPoint pt; CvSize image_sz; OpenGL *pgl; //五个U形点 U_Joint ujoints[5]; int ujoints_count = 0; //三个n形点,即手臂与身体两个,裆部一个 U_Joint njoints[3]; int njoints_count = 0; const float pi = 3.1415926f; CvMemStorage* storage = 0; // temporary storage IplImage* abs_image = 0; IplImage* add_abs_image = 0; IplImage* add_abs_image2 = 0; IplImage* dst = 0; IplImage* src = 0; CvSeq* contour = 0; IplConvKernel* element = 0; int frame_count =0; void on_mouse( int event, int x, int y, int flags, void *param ) { if( !image ) return; if( image->origin ) y = image->height - y; if( event == CV_EVENT_LBUTTONDOWN ) { pt = cvPoint(x,y); add_remove_pt = 1; } } HumanMotion::HumanMotion() { } HumanMotion::~HumanMotion() { } int HumanMotion::Start() { main_loop(1); return 0; } int HumanMotion::main_loop( int useCAM) { skelecton *ske = new skelecton(); skelectons *skes = new skelectons(); kalman *bone_kalmans = new kalman[MAX_COUNT]; CvCapture* capture = 0; if( useCAM == 1) capture = cvCaptureFromFile("e:\\mse\\movie\\capture4.avi"); else if( useCAM == 2 ) capture = cvCaptureFromCAM(-1); if( !capture ) { fprintf(stderr,"Could not initialize capturing...\n"); return -1; } printf( "Hot keys: \n" "\tESC - quit the program\n" "\tr - auto-initialize tracking\n" "\tc - delete all the points\n" "\tn - switch the \"night\" mode on/off\n" "\tp - pause on/off\n" "\n" ); cvNamedWindow( "LkDemo", 1 ); cvNamedWindow( "Contour", 1 ); cvSetMouseCallback( "LkDemo", on_mouse, 0 ); for(;;) { IplImage* frame = 0; int i, k, c; if(pause) frame = image ; else frame = cvQueryFrame( capture ); if( !frame ) break; if( !image ) { /* allocate all the buffers */ image_sz = cvGetSize(frame) ; image = cvCreateImage(image_sz , 8, 3 ); image->origin = frame->origin; motion_track_img = cvCreateImage( image_sz, 8, 3 ); motion_track_img->origin = frame->origin; grey = cvCreateImage( image_sz, 8, 1 ); prev_grey = cvCreateImage( image_sz, 8, 1 ); pyramid = cvCreateImage( image_sz, 8, 1 ); prev_pyramid = cvCreateImage( image_sz, 8, 1 ); points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0])); points[1] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0])); status = (char*)cvAlloc(MAX_COUNT); flags = 0; CvSize sz = cvSize( image->width/2 & -1, image->height/2 & -1 ); CvSize sz2 = cvSize( sz.width/2 & -1, sz.height/2 & -1 ); abs_image = cvCreateImage( cvGetSize(image), 8, 1 ); add_abs_image =cvCreateImage(sz, 8, 1 ); add_abs_image2 =cvCreateImage(sz2, 8, 1 ); dst = cvCreateImage( image_sz, 8, 3 ); dst->origin = frame->origin; background_image = cvCreateImage( image_sz, 8, 1 ); background_image->origin = frame->origin; storage = cvCreateMemStorage(0); } cvCopy( frame, image, 0 ); cvCvtColor( image, grey, CV_BGR2GRAY ); cvZero( motion_track_img ); if( night_mode ) cvZero( image ); if( need_to_init ) { //分析轮廓,开始自动标定 analyze_contour(grey); if(init_OK) { count = MAX_COUNT; cvFindCornerSubPix( grey, points[1], count, cvSize(win_size,win_size), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)); for(int s=0;s<count;s++) { ske->CalcLengthRatio (s+1,points[1][s]); bone_kalmans[s].init_kalman (points[1][s].x,0,points[1][s].y,0); } } } else if( count > 0 ) { cvCalcOpticalFlowPyrLK( prev_grey, grey, prev_pyramid, pyramid, points[0], points[1], count, cvSize(win_size,win_size), 3, status, 0, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), flags ); flags |= CV_LKFLOW_PYR_A_READY; for( i = k = 0; i < count; i++ ) { if( add_remove_pt ) { double dx = pt.x - points[1][i].x; double dy = pt.y - points[1][i].y; if( dx*dx + dy*dy <= 25 ) { add_remove_pt = 0; continue; } } if( !status[i] ) continue; points[1][k++] = points[1][i]; ske->CorrectPosition (i+1,points[1][i],bone_kalmans[i],grey); cvCircle( image, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0); } count = k; } // skelecton *pske; pske = skes->get_previous_skelecton (); if(pske!=NULL) ske->set_previous_skelecton (pske); ske->pgl = pgl; ske->drawOpenGL3D(image); //ske->draw2D(image); skes->add (ske); //to do list 不需要每次都保存,应该隔单位时间保存一次 if( add_remove_pt && count < MAX_COUNT ) { points[1][count++] = cvPointTo32f(pt); cvFindCornerSubPix( grey, points[1] + count - 1, 1, cvSize(win_size,win_size), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)); add_remove_pt = 0; bone_kalmans[count-1].init_kalman (points[1][count-1].x,0,points[1][count-1].y,0); ske->CalcLengthRatio (count,points[1][count-1]); } CV_SWAP( prev_grey, grey, swap_temp ); CV_SWAP( prev_pyramid, pyramid, swap_temp ); CV_SWAP( points[0], points[1], swap_points ); //need_to_init = 0; cvShowImage( "LkDemo", image ); //cvShowImage( "MotionTrackDemo", motion_track_img ); c = cvWaitKey(10); //printf("%c,%d",c,c); if( c == 27 ) break; switch( c ) { case 'r': need_to_init = 1; break; case 'c': count = 0; ske->reset(); break; case 'n': night_mode ^= 1; break; case 'p': pause ^= 1; break; case 'o': if(ske->ske_pause) ske->ske_pause= false; else ske->ske_pause= true; break; case 'i': ske->view_up(); break; case 'k': ske->view_down(); break; case 'j': ske->view_left(); break; case 'l': ske->view_right(); break; default: ; } frame_count++; } cvReleaseCapture( &capture ); cvDestroyWindow("LkDemo"); cvDestroyWindow("Contour"); delete ske; ske = NULL; delete s
评论
    相关推荐
    • human-detection.rar
      检测人体运动,对运动人体进行跟踪,具有不错的效果
    • human-detect-and-track-.rar
      为了检测红外图像序列中的运动人体,提出了一种基于最大后验概率 (MAP)-马尔可夫随机场(MRF)模型和亮度-距离联合直方图的人体实时检测 方法。该方法首先建立图像序列时空域联合的概率分布模型,采用基于 MAP-...
    • Real-Time Human Detection Using Contour Cues.rar
      C4行人检测论文 1.使用CENTRIST描述子检测人体轮廓 2.相邻像素间差值的符号是编码轮廓的关键信息。
    • falldetection_openpifpaf:使用OpenPifPaf的人体姿势估计模型进行跌倒检测
      使用姿势估计进行跌倒检测 介绍 基于跌倒检测模型 PyPI库: ://pypi.org/project/openpifpaf/ 该检测可以在GPU和CPU上,多个视频,RTSP流以及网络摄像头/ USB摄像机上运行。 与大多数适用于单个大对象的开源跌倒...
    • 基于QEPAS技术的气体检测研究.rar
      两篇基于QEPAS技术的气体检测研究文章。值得初学者入门浏览~
    • FDC1004电容式人体接近检测系统,附原理图/PCB/固件-电路方案
      本设计是基于FDC1004电容式人体接近检测系统解决方案,附原理图/PCB源文件/固件。该电容式人体接近检测系统基于Wolverine 混合信号微控制器MSP430FR5969设计,电路采用FDC1004 4 通道电容数字转换器。该设计提供了一...
    • 电容式人体接近检测硬件设计+源码-电路方案
      电容式人体接近检测功能描述 此 TI 设计使用德州仪器 (TI) 的电容数字转换器技术来提供一种在发生人机交互时唤醒系统的高精度方法。该设计展示了用于替代性传感器设计、环境补偿以及电磁干扰保护的技术。 系统设计...
    • Human-Falling-Detect-Tracks:AlphaPose + ST-GCN + SORT
      人体跌倒检测与追踪 使用Tiny-YOLO oneclass检测帧中的每个人,并使用获取骨骼姿势,然后使用模型从每个人跟踪的每30帧中预测动作。 现在支持7种动作:站立,行走,坐着,躺下,站起来,坐下,跌倒。 先决条件 ...
    • 人体检测和追踪:人体检测和追踪
      人体检测与追踪 介绍 在这个项目中,我们研究了人类检测,面部检测,面部识别和跟踪个人的问题。 我们的项目能够在给定的视频中检测人及其脸部,并存储所检测到的脸部的局部二进制图案直方图(LBPH)特征。 LBPH特征...
    • 人体检测的程序
      初学者入门,里面是人体检测的简单matlab程序,初学者可以参考下