📄 cubicles.cpp
字号:
/** * cubicles * * This is an implementation of the Viola-Jones object detection * method and some extensions. The code is mostly platform- * independent and uses only standard C and C++ libraries. It * can make use of MPI for parallel training and a few Windows * MFC functions for classifier display. * * Mathias Kolsch, matz@cs.ucsb.edu * * $Id: cubicles.cpp,v 1.21 2005/10/28 17:47:04 matz Exp $**/// cubicles.cpp: Implements the public C interface to the cubicles// library. Also needed for Windows DLL creation as it defines the// entry point for the DLL application.////////////////////////////////////////////////////////////////////////// By downloading, copying, installing or using the software you // agree to this license. If you do not agree to this license, // do not download, install, copy or use the software.//// Copyright (C) 2004, Mathias Kolsch, all rights reserved.// Third party copyrights are property of their respective owners.//// Redistribution and use in binary form, with or without // modification, is permitted for non-commercial purposes only.// Redistribution in source, with or without modification, is // prohibited without prior written permission.// If granted in writing in another document, personal use and // modification are permitted provided that the following two// conditions are met://// 1.Any modification of source code must retain the above // copyright notice, this list of conditions and the following // disclaimer.//// 2.Redistribution's in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided// with the distribution.//// This software is provided by the copyright holders and // contributors "as is" and any express or implied warranties, // including, but not limited to, the implied warranties of // merchantability and fitness for a particular purpose are // disclaimed. In no event shall the copyright holder or // contributors be liable for any direct, indirect, incidental, // special, exemplary, or consequential damages (including, but not // limited to, procurement of substitute goods or services; loss of // use, data, or profits; or business interruption) however caused// and on any theory of liability, whether in contract, strict // liability, or tort (including negligence or otherwise) arising // in any way out of the use of this software, even if advised of // the possibility of such damage.//////////////////////////////////////////////////////////////////////#include "cubicles.hpp"#include "IntegralImage.h"#include "Cascade.h"#include "Scanner.h"#if defined (IMG_LIB_OPENCV)#include "cubicles.h"#else#error cubicles.cpp is currently only implemented with OpenCV#endif#if defined(WIN32)BOOL APIENTRY DllMain( HANDLE /*hModule*/, DWORD /*ul_reason_for_call*/, LPVOID /*lpReserved*/ ){ return TRUE;}#endif // WIN32#ifdef __cplusplusextern "C" {#endif//// global variables//CCascadeVector g_cu_cascades;CScannerVector g_cu_scanners;CIntegralImage g_cu_integral;CIntegralImage g_cu_squared_integral;int g_cu_image_width = -1;int g_cu_image_height = -1;CRect g_cu_bbox;int g_cu_min_width = -1;int g_cu_max_width = -1;int g_cu_min_height = -1;int g_cu_max_height = -1;// make sure cascadeID is typedef'ed as "unsigned int" or change this:#define CHECK_CASCADE_ID \ if (g_cu_cascades.size()<=cascadeID) { \ CV_ERROR(CV_StsBadArg, "invalid cascadeID"); \ }/** * Initialize */void cuInitialize(int image_width, int image_height){ CV_FUNCNAME( "cuInitialize" ); // declare cvFuncName __BEGIN__; if (image_width<0 || image_height<0) { CV_ERROR(CV_BadImageSize, "negative image width or height"); } try { g_cu_integral.SetSize(image_width, image_height); g_cu_squared_integral.SetSize(image_width, image_height); } catch (ITException& ite) { CV_ERROR(CV_StsError, ite.GetMessage().c_str()); } // this serves as "initialized" flag g_cu_image_width = image_width; g_cu_image_height = image_height; __END__;}/** * Uninitialize -- call for garbage collection of global variables; * they are all stack-allocated, so this is not really necessary */void cuUninitialize(){ CV_FUNCNAME( "cuUninitialize" ); // declare cvFuncName __BEGIN__; if (g_cu_image_width<0 || g_cu_image_height<0) { CV_ERROR(CV_StsError, "cubicles not initialized"); } // clear out memory g_cu_cascades.clear(); g_cu_scanners.clear(); g_cu_integral.~CIntegralImage(); g_cu_squared_integral.~CIntegralImage(); // this serves as "initialized" flag g_cu_image_width = -1; g_cu_image_height = -1; __END__;}void cuLoadCascade(const string& filename, CuCascadeID* pID){ CV_FUNCNAME( "cuLoadCascade" ); // declare cvFuncName __BEGIN__; if (filename.length()==0) { CV_ERROR(CV_StsBadArg, "no file name specified"); } if (pID==NULL) { CV_ERROR(CV_StsBadArg, "pID: invalid pointer"); } try { CClassifierCascade cascade;#if defined(WIN32) cascade.ParseFrom(ConvertPathToWindows(filename).c_str());#else cascade.ParseFrom(filename.c_str());#endif // WIN32 CuCascadeID cascadeID = (CuCascadeID) g_cu_cascades.size(); g_cu_cascades.push_back(cascade); CImageScanner scanner; g_cu_scanners.push_back(scanner); *pID = cascadeID; } catch (ITException& ite) { string msg = "error while parsing cascade from file "; msg = msg + filename + string(":\n") + ite.GetMessage(); CV_ERROR(CV_StsError, msg.c_str()); } __END__;}void cuGetCascadeProperties(CuCascadeID cascadeID, CuCascadeProperties& cp){ CV_FUNCNAME( "cuGetCascadeProperties" ); // declare cvFuncName __BEGIN__; CHECK_CASCADE_ID; try { cp.cascadeID = cascadeID; cp.names = g_cu_cascades[cascadeID].GetNames(); cp.template_width = g_cu_cascades[cascadeID].GetTemplateWidth(); cp.template_height = g_cu_cascades[cascadeID].GetTemplateHeight(); cp.image_area_ratio = g_cu_cascades[cascadeID].GetImageAreaRatio(); } catch (ITException& ite) { CV_ERROR(CV_StsError, ite.GetMessage().c_str()); } __END__;}void cuGetScannerParameters(CuCascadeID cascadeID, CuScannerParameters& sp){ CV_FUNCNAME( "cuGetScannerParameters" ); // declare cvFuncName __BEGIN__; CHECK_CASCADE_ID; try { CRect area; g_cu_scanners[cascadeID].GetScanParameters(&sp.start_scale, &sp.stop_scale, &sp.scale_inc_factor, &sp.translation_inc_x, &sp.translation_inc_y, area, &sp.post_process, &sp.active); sp.left = area.left; sp.top = area.top; sp.right = area.right; sp.bottom = area.bottom; } catch (ITException& ite) { CV_ERROR(CV_StsError, ite.GetMessage().c_str()); } __END__;}void cuSetScannerParameters(CuCascadeID cascadeID, const CuScannerParameters& sp){ CV_FUNCNAME( "cuSetScannerParameters" ); // declare cvFuncName __BEGIN__; CHECK_CASCADE_ID; try { CRect area(sp.left, sp.top, sp.right, sp.bottom); g_cu_scanners[cascadeID].SetActive(sp.active); g_cu_scanners[cascadeID].SetScanParameters(sp.start_scale, sp.stop_scale, sp.scale_inc_factor, sp.translation_inc_x, sp.translation_inc_y, area); g_cu_scanners[cascadeID].SetAutoPostProcessing(sp.post_process); } catch (ITException& ite) { CV_ERROR(CV_StsError, ite.GetMessage().c_str()); } __END__;}void cuSetScannerActive(CuCascadeID cascadeID, bool active)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -