📄 cubicles.cpp
字号:
{ CV_FUNCNAME( "cuSetScannerActive" ); // declare cvFuncName __BEGIN__; CHECK_CASCADE_ID; try { g_cu_scanners[cascadeID].SetActive(active); } catch (ITException& ite) { CV_ERROR(CV_StsError, ite.GetMessage().c_str()); } __END__;}void cuSetScanArea(CuCascadeID cascadeID, int left, int top, int right, int bottom){ CV_FUNCNAME( "cuSetScanArea" ); // declare cvFuncName __BEGIN__; CHECK_CASCADE_ID; try { CRect area(left, top, right, bottom); g_cu_scanners[cascadeID].SetScanArea(area); } catch (ITException& ite) { CV_ERROR(CV_StsError, ite.GetMessage().c_str()); } __END__;}void cuSetScanScales(CuCascadeID cascadeID, double start_scale, double stop_scale){ CV_FUNCNAME( "cuSetScanScales" ); // declare cvFuncName __BEGIN__; CHECK_CASCADE_ID; try { g_cu_scanners[cascadeID].SetScanScales(start_scale, stop_scale); } catch (ITException& ite) { CV_ERROR(CV_StsError, ite.GetMessage().c_str()); } __END__;}void cuScan(const IplImage* grayImage, CuScanMatchVector& matches){ CV_FUNCNAME( "cuScan" ); // declare cvFuncName __BEGIN__; if (g_cu_image_width<=0 || g_cu_image_height<=0) { CV_ERROR(CV_StsError, "cubicles has not been initialized"); } if (grayImage==NULL) { CV_ERROR(CV_HeaderIsNull, "grayImage"); } if (grayImage->nChannels!=1) { CV_ERROR(CV_BadNumChannels, "can only scan gray-level images"); } if (grayImage->depth!=IPL_DEPTH_8U) { CV_ERROR(CV_BadDepth, "can only scan unsigned byte images"); } if (grayImage->origin!=0) { CV_ERROR(CV_BadOrigin, "need image origin in top left corner"); } if (grayImage->width!=g_cu_image_width || grayImage->height!=g_cu_image_height) { CV_ERROR(CV_BadImageSize, "different from initialization"); } try { g_cu_bbox = CRect(-1, -1, -1, -1); matches.clear(); // todo: maybe sometime we should allow a maximum processing time // in order to guarantee a certain max latency. On the next call // to Process, we would pick up where we left off, e.g. at a // certain scanner with a certain scale // find bounding box around all scanners' scan_areas and // integrate image only within that bbox int num_cascades = (int) g_cu_cascades.size(); CRect bbox = CRect(INT_MAX, INT_MAX, 0, 0); for (int sc=0; sc<num_cascades; sc++) { if (g_cu_scanners[sc].IsActive()) { const CRect& scan_area = g_cu_scanners[sc].GetScanArea(); if (scan_area.left<bbox.left) bbox.left = scan_area.left; if (scan_area.right>bbox.right) bbox.right = scan_area.right; if (scan_area.top<bbox.top) bbox.top = scan_area.top; if (scan_area.bottom>bbox.bottom) bbox.bottom = scan_area.bottom; } } bbox.left = max(0, bbox.left); bbox.top = max(0, bbox.top); bbox.right = min(bbox.right, grayImage->width); bbox.bottom = min(bbox.bottom, grayImage->height); if (bbox.right-bbox.left<=0 || bbox.bottom-bbox.top<=0) { return; } CByteImage byteImage((BYTE*)grayImage->imageData, grayImage->width, grayImage->height); CIntegralImage::CreateSimpleNSquaredFrom(byteImage, g_cu_integral, g_cu_squared_integral, bbox); int num_active = 0; CScanMatchMatrix events; events.resize(num_cascades); for (int numc=0; numc<num_cascades; numc++) { if (g_cu_scanners[numc].IsActive()) { num_active++; ASSERT(g_cu_cascades[numc].GetNumStrongClassifiers()>0); // do the scan! g_cu_scanners[numc].Scan(g_cu_cascades[numc], g_cu_integral, g_cu_squared_integral, events[numc]); // this is a bit awkward and really not elegant, but we avoid // exposing all sorts of internal structures for (CScanMatchVector::const_iterator cm = events[numc].begin(); cm!=events[numc].end(); cm++) { CuScanMatch m; m.name = cm->name; m.left = cm->left; m.top = cm->top; m.right = cm->right; m.bottom = cm->bottom; m.scale = cm->scale; m.scale_x = cm->scale_x; m.scale_y = cm->scale_y; matches.push_back(m); } // must be called after the actual scan, and the behavior with // multiple active scanners is somewhat undetermined g_cu_scanners[numc].GetScaleSizes(&g_cu_min_width, &g_cu_max_width, &g_cu_min_height, &g_cu_max_height); } } if (num_active>0) { g_cu_bbox = bbox; } } catch (ITException& ite) { CV_ERROR(CV_StsError, ite.GetMessage().c_str()); } __END__;} // Scanvoid cuGetScannedArea(int* pLeft, int* pTop, int* pRight, int* pBottom){ CV_FUNCNAME( "cuGetScannedArea" ); // declare cvFuncName __BEGIN__; if (pLeft==NULL || pTop==NULL || pRight==NULL || pBottom==NULL) { CV_ERROR(CV_StsBadArg, "null pointer"); } *pLeft = g_cu_bbox.left; *pTop = g_cu_bbox.top; *pRight = g_cu_bbox.right; *pBottom = g_cu_bbox.bottom; __END__;}void cuGetScaleSizes(int* min_width, int* max_width, int* min_height, int* max_height){ CV_FUNCNAME( "cuGetScaleSizes" ); // declare cvFuncName __BEGIN__; if (min_width==NULL || max_width==NULL || min_height==NULL || max_height==NULL) { CV_ERROR(CV_StsBadArg, "null pointer"); } *min_width = g_cu_min_width; *max_width = g_cu_max_width; *min_height = g_cu_min_height; *max_height = g_cu_max_height; __END__;}/** verbosity: 0 minimal, 3 maximal*/void cuGetVersion(string& version, int verbosity){ CV_FUNCNAME( "cuGetScannedArea" ); // declare cvFuncName __BEGIN__; if (verbosity<0 || 3<verbosity) { CV_ERROR(CV_StsBadArg, "invalid verbosity"); } version = "cubicles "CU_CURRENT_VERSION_STRING; if (verbosity>=1) {#if defined(WIN32) version = version + ", win32";#elif defined(TARGET_SYSTEM) version = version + ", "TARGET_SYSTEM;#else#error TARGET_SYSTEM must be defined#endif#if defined(DEBUG) version = version + " debug";#endif#if defined(II_TYPE_FLOAT) version = version + ", float";#elif defined(II_TYPE_DOUBLE) version = version + ", double";#elif defined(II_TYPE_INT) version = version + ", int";#elif defined(II_TYPE_UINT) version = version + ", uint";#else #error you must define II_TYPE#endif#if defined(WITH_TRAINING) version = version + ", training-enabled";#endif#if defined(IMG_LIB_MAGICK) version = version + ", Magick";#elif defined(IMG_LIB_OPENCV) version = version + ", OpenCV";#elif defined(IMG_LIB_NONE) version = version + ", no image library";#else#error at least IMG_LIB_NONE must be defined#endif } if (verbosity>=2) { version = version + ", built on "__DATE__" at "__TIME__; } if (verbosity>=3) { version = version + "\nCVS id: $Id: cubicles.cpp,v 1.21 2005/10/28 17:47:04 matz Exp $"; /* todo: OpenCV info */ cvUseOptimized(0); int num_loaded_functions = cvUseOptimized(1); printf("OpenCV optimized functions: %d\n", num_loaded_functions); const char *pVersion, *pPlugins; cvGetModuleInfo(NULL, &pVersion, &pPlugins); printf("OpenCV version: %s\n", pVersion); printf("OpenCV plugins: %s\n", pPlugins); } __END__;}#ifdef __cplusplus}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -