📄 maintenanceapp.cpp
字号:
/** * HandVu - a library for computer vision-based hand gesture * recognition. * Copyright (C) 2004 Mathias Kolsch, matz@cs.ucsb.edu * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * $Id: MaintenanceApp.cpp,v 1.12 2005/10/30 23:00:43 matz Exp $**/#include "StdAfx.h"#include <initguid.h>
#include "Common.h"
#include "iHandVuFilter.h"
#include "MaintenanceApp.h"#include "HandVu.h"CMaintenanceApp::CMaintenanceApp(): m_img_width(0), m_img_height(0), m_active_app(0), m_last_ptr1_type(""), m_last_ptr1_recognized(false), m_voicerec_default_x(0), m_voicerec_ctr_y(0), m_imgcap_ctr_x(0), m_imgcap_default_y(0), m_woselect_ctr_x(0), m_show_hand_location(true), m_switchpos_x(0), m_switchpos_y(0){ m_time_last_app_switch.time = 0; m_time_last_app_switch.millitm = 0;}CMaintenanceApp::~CMaintenanceApp(){}void CMaintenanceApp::Initialize(int img_width, int img_height){ if (img_height<0) {
throw HVException("shouldn't be upside down anymore at this point"); }
m_img_width = img_width; m_img_height = img_height; BuildIconGroups();}/** gesture event handler - select a button, switch applications,* draw the right hand pointer or detection aid*/void CMaintenanceApp::Tracked(const COverlayEvent& event){ ASSERT(!event.m_ptr1_tracked || (0.0<=event.m_ptr1_x && event.m_ptr1_x<1.0 && 0.0<=event.m_ptr1_y && event.m_ptr1_y<1.0)); m_event = event; if (event.m_ptr1_tracked) { m_group_shown[IG_HAND_FLAT] = false; } else { // not detected ShowGroupExclusive(IG_HAND_FLAT);
return;
} int x = cvRound(m_event.m_ptr1_x*(m_img_width-1)); int y = cvRound(m_event.m_ptr1_y*(m_img_height-1)); int orig_x = x, orig_y = y; if (m_event.m_ptr1_tracked) { PointerOver(&x, &y); } // reset selection for (int grpcnt=0; grpcnt<(int)m_icon_groups.size(); grpcnt++) { if (m_group_shown[grpcnt]) { m_icon_groups[grpcnt].ResetSelection(); } } if (m_event.m_ptr1_recognized) { if (m_event.m_ptr1_type=="Lback") {
Select(x, y);
} else if (m_event.m_ptr1_type=="victory" || m_event.m_ptr1_type=="open") {
// how long ago was the last switch?
Time currtime;
_ftime(&currtime);
unsigned int d_t = 1000*(unsigned int)(currtime.time-m_time_last_app_switch.time);
d_t += (currtime.millitm-m_time_last_app_switch.millitm);
// or was the last recognized gesture something else but task switch?
if (d_t>MIN_TIME_BTW_APP_SWITCH
|| (m_last_ptr1_type!=m_event.m_ptr1_type
&& m_last_ptr1_recognized))
{
SwitchApplications();
m_switchpos_x = orig_x; m_switchpos_y = orig_y; m_time_last_app_switch = currtime; } } else if (m_event.m_ptr1_type=="sidepoint") {
} m_last_ptr1_type = m_event.m_ptr1_type; } m_last_ptr1_recognized = m_event.m_ptr1_recognized;} void CMaintenanceApp::PointerOver(int* pX, int* pY){ const double scale = 2.0; const CRect& old_hand = m_icon_groups[IG_HAND_POINTER].m_areas[0]; int width = old_hand.right-old_hand.left; int height = old_hand.bottom-old_hand.top; int halfwidth = width/2; int halfheight = height/2; switch (m_active_app) { case 0: // no app break; case 1: // voice recorder // constrain to movements in horizontal, scale horizontal *pX = (int)(m_img_width*m_voicerec_default_x)+(int)(scale*(double)(*pX-m_switchpos_x)); *pY = (int)(m_img_height*m_voicerec_ctr_y)+halfheight; break; case 2: // img/vid cap // constrain to movements in vertical, scale vertical *pX = (int)(m_img_width*m_imgcap_ctr_x); *pY = (int)((double)m_img_height*m_imgcap_default_y + scale*(double)(*pY-m_switchpos_y)); break; case 3: // WO select // for now: constrain to movements in vertical *pX = (int)(m_img_width*m_woselect_ctr_x); break; case 4: // number select break; case 5: // break; default: ASSERT(0); } for (int grpcnt=0; grpcnt<(int)m_icon_groups.size(); grpcnt++) { if (!m_group_shown[grpcnt]) { continue; } m_icon_groups[grpcnt].PointerOver(*pX, *pY); } int area_left = *pX-halfwidth; int area_top = *pY-halfheight; area_left = max(0, area_left); area_top = max(0, area_top); area_left = min(m_img_width-width-1, area_left); area_top = min(m_img_height-height-1, area_top); ASSERT(0<=area_left && area_left+width<m_img_width); ASSERT(0<=area_top && area_top+height<m_img_height); m_icon_groups[IG_HAND_POINTER].m_areas[0] = CRect(area_left, area_top, area_left+width, area_top+height);}void CMaintenanceApp::Select(int x, int y){ bool got_one = false; for (int grpcnt=0; grpcnt<(int)m_icon_groups.size(); grpcnt++) { if (!m_group_shown[grpcnt]) { continue; } bool this_one = m_icon_groups[grpcnt].Select(x, y); if (this_one) got_one = true; } if (got_one) { // Beep(800, 70);
}}void CMaintenanceApp::SwitchApplications(){ m_active_app++; if (m_active_app>NUM_APPS) { m_active_app = 0; } switch (m_active_app) { case 0: HideAllGroups(); break; case 1: ShowGroupExclusive(IG_VOICE_RECORDER); break; case 2: ShowGroupExclusive(IG_IMG_VID_CAP); break; case 3: ShowGroupExclusive(IG_WO_SELECT); break; case 4: ShowGroupExclusive(IG_NUM_SELECT); break; case 5: HideAllGroups(); break; default: ASSERT(0); } if (m_active_app==1 || m_active_app==2 || m_active_app==4) { m_group_shown[IG_HAND_POINTER] = true; } else { m_group_shown[IG_HAND_POINTER] = false; } m_show_hand_location = true; if (m_active_app==4) { m_show_hand_location = false; } if (m_active_app==5) { hvStartRecognition(1); } else if (m_active_app==0) { hvStopRecognition(1); }}void CMaintenanceApp::Draw(IplImage* out_img){ for (int grpcnt=0; grpcnt<(int)m_icon_groups.size(); grpcnt++) { if (!m_group_shown[grpcnt]) { continue; } for (int imgcnt=0; imgcnt<(int)m_icon_groups[grpcnt].m_images.size(); imgcnt++) { if (!m_icon_groups[grpcnt].m_display_icon[imgcnt]) { continue; } const CRect& area = m_icon_groups[grpcnt].m_areas[imgcnt]; IplImage* img = m_icon_groups[grpcnt].m_images[imgcnt];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -