⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 handvu_cintf.cpp

📁 tracciatore di mani con webcam
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// HandVu_Cintf.cpp: C interface to the C++ classes in HandVu.cpp//#include "Common.h"#include "HandVu.hpp"#include "HandVu.h"#include "GestureServer.h"#if defined(WIN32)#if defined(GetMessage)#undef GetMessage#endif#include <time.h>#define CLOCKS_PER_USEC ((double)(CLOCKS_PER_SEC)/1000000.0)class RefClockWindows : public RefClock {public:  virtual RefTime GetCurrentTimeUsec() const;};RefTime RefClockWindows::GetCurrentTimeUsec() const{  clock_t ct = clock();  return (RefTime) (ct/CLOCKS_PER_USEC);}#define RefClockArch RefClockWindows#else //WIN32#define CLOCKS_PER_USEC ((double)(CLOCKS_PER_SEC)/1000000.0)class RefClockLinux : public RefClock {public:  virtual RefTime GetCurrentTimeUsec() const;};RefTime RefClockLinux::GetCurrentTimeUsec() const{  clock_t ct = clock();  return (RefTime) (ct/CLOCKS_PER_USEC);}#define RefClockArch RefClockLinux#endif //WIN32class DisplayCallbackCintf : public DisplayCallback { public:  DisplayCallbackCintf(void (*cb)(IplImage* img, hvAction action)) :    m_cb(cb) {}  virtual void Display(IplImage* img, HandVu::HVAction action); protected:  void (*m_cb)(IplImage*, hvAction);};void DisplayCallbackCintf::Display(IplImage* img, HandVu::HVAction action){  CV_FUNCNAME( "hvDisplayCallback" ); // declare cvFuncName  __BEGIN__;  hvAction act;  switch (action) {  case HandVu::HV_INVALID_ACTION:    act = HV_INVALID_ACTION; break;  case HandVu::HV_PROCESS_FRAME:    act = HV_PROCESS_FRAME; break;  case HandVu::HV_SKIP_FRAME:    act = HV_SKIP_FRAME; break;  case HandVu::HV_DROP_FRAME:    act = HV_DROP_FRAME; break;  default:    CV_ERROR(CV_StsError, "unknown HVAction code");  }    m_cb(img, act);  __END__;}typedef GestureServer* GestureServerPtr;vector<GestureServerPtr> g_pservers;HandVu* g_pHandVu = NULL;RefClockArch* g_pClock = NULL;DisplayCallbackCintf* g_displayCallback = NULL;void hvInitialize(int image_width, int image_height){  CV_FUNCNAME( "hvInitialize" ); // declare cvFuncName  __BEGIN__;  if (image_width<0 || image_height<0) {    CV_ERROR(CV_BadImageSize, "negative image width or height");  }  if (g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu already initialized");  }  try {    g_pHandVu = new HandVu();    g_pClock = new RefClockArch();    g_pHandVu->Initialize(image_width, image_height, g_pClock, NULL);  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}void hvUninitialize(){  CV_FUNCNAME( "hvUninitialize" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    g_pHandVu->~HandVu();    g_pHandVu = NULL;    delete g_pClock;    g_pClock = NULL;    if (g_displayCallback) {      delete g_displayCallback;    }    // gesture servers    for (int i=0; i<(int)g_pservers.size(); i++) delete g_pservers[i];    g_pservers.clear();  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}void hvLoadConductor(const string& filename){  CV_FUNCNAME( "hvLoadConductor" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    g_pHandVu->LoadConductor(filename);  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}bool hvConductorLoaded(){  CV_FUNCNAME( "hvConductorLoaded" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    return g_pHandVu->ConductorLoaded();  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}void hvStartRecognition(int obj_id){  CV_FUNCNAME( "hvStartRecognition" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    g_pHandVu->StartRecognition(obj_id);  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}void hvStopRecognition(int obj_id){  CV_FUNCNAME( "hvStopRecognition" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    g_pHandVu->StopRecognition(obj_id);  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}hvAction hvProcessFrame(IplImage* inOutImage, IplImage* rightImage){  CV_FUNCNAME( "hvProcessFrame" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    RefTime t = g_pClock->GetCurrentTimeUsec();    GrabbedImage gi(inOutImage, t, -1);    HandVu::HVAction action = g_pHandVu->ProcessFrame(gi, rightImage);    switch (action) {      case HandVu::HV_INVALID_ACTION:        return HV_INVALID_ACTION;      case HandVu::HV_PROCESS_FRAME:        return HV_PROCESS_FRAME;      case HandVu::HV_SKIP_FRAME:        return HV_SKIP_FRAME;      case HandVu::HV_DROP_FRAME:        return HV_DROP_FRAME;      default:        CV_ERROR(CV_StsError, "unknown HandVu::HVAction");    }  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}bool hvIsActive(){  CV_FUNCNAME( "hvIsActive" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    bool active = g_pHandVu->IsActive();    return active;  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}void hvAsyncSetup(int num_buffers, void (*cb)(IplImage* img, hvAction action)){  CV_FUNCNAME( "hvAsyncSetup" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    if (g_displayCallback) {      delete g_displayCallback;    }    g_displayCallback = new DisplayCallbackCintf(cb);    g_pHandVu->AsyncSetup(num_buffers, g_displayCallback);      } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}void hvAsyncGetImageBuffer(IplImage** pImage, int* pBufferID){  CV_FUNCNAME( "hvAsyncGetImageBuffer" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    g_pHandVu->AsyncGetImageBuffer(pImage, pBufferID);  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}void hvAsyncProcessFrame(int bufferID){  CV_FUNCNAME( "hvAsyncProcessFrame" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    RefTime t = g_pClock->GetCurrentTimeUsec();    g_pHandVu->AsyncProcessFrame(bufferID, t);  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}void hvGetState(int obj_id, hvState& state){  CV_FUNCNAME( "hvGetState" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    HVState hsta;    g_pHandVu->GetState(obj_id, hsta);    state.obj_id = hsta.m_obj_id;    state.tracked = hsta.m_tracked;    state.recognized = hsta.m_recognized;    state.center_xpos = hsta.m_center_xpos;    state.center_ypos = hsta.m_center_ypos;    state.scale = hsta.m_scale;    state.posture = hsta.m_posture;    state.tstamp = hsta.m_tstamp;  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}void hvSetDetectionArea(int left, int top, int right, int bottom){  CV_FUNCNAME( "hvSetDetectionArea" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    g_pHandVu->SetDetectionArea(left, top, right, bottom);  } catch (HVException& hve) {    CV_ERROR(CV_StsError, hve.GetMessage().c_str());  }  __END__;}void hvGetDetectionArea(int* pLeft, int* pTop, int* pRight, int* pBottom){  CV_FUNCNAME( "hvAsyncProcessFrame" ); // declare cvFuncName  __BEGIN__;  if (!g_pHandVu) {    CV_ERROR(CV_StsError, "HandVu not initialized");  }  try {    CQuadruple area;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -