commit
6447c7b2f4
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,10 +1,10 @@
|
||||
*.autosave
|
||||
*.pyc
|
||||
*.user
|
||||
*~
|
||||
.*.swp
|
||||
.DS_Store
|
||||
.sw[a-z]
|
||||
/modules/refman.rst
|
||||
Thumbs.db
|
||||
tags
|
||||
tegra/
|
||||
|
2
.tgitconfig
Normal file
2
.tgitconfig
Normal file
@ -0,0 +1,2 @@
|
||||
[tgit]
|
||||
icon = doc/opencv.ico
|
2
3rdparty/ffmpeg/make.bat
vendored
2
3rdparty/ffmpeg/make.bat
vendored
@ -1,2 +1,2 @@
|
||||
set path=c:\dev\msys32\bin;%path% & gcc -Wall -shared -o opencv_ffmpeg.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat -lavcodec -lavdevice -lswscale -lavutil -liconv -lws2_32
|
||||
set path=c:\dev\msys32\bin;%path% & gcc -Wall -shared -o opencv_ffmpeg.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat -lavcodec -lavdevice -lswscale -lavutil -lws2_32
|
||||
set path=c:\dev\msys64\bin;%path% & gcc -m64 -Wall -shared -o opencv_ffmpeg_64.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat64 -lavcodec64 -lavdevice64 -lswscale64 -lavutil64 -lws2_32
|
BIN
3rdparty/ffmpeg/opencv_ffmpeg.dll
vendored
BIN
3rdparty/ffmpeg/opencv_ffmpeg.dll
vendored
Binary file not shown.
502
3rdparty/include/MultiMon.h
vendored
502
3rdparty/include/MultiMon.h
vendored
@ -1,502 +0,0 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// multimon.h -- Stub module that fakes multiple monitor apis on Win32 OSes
|
||||
// without them.
|
||||
//
|
||||
// By using this header your code will get back default values from
|
||||
// GetSystemMetrics() for new metrics, and the new multimonitor APIs
|
||||
// will act like only one display is present on a Win32 OS without
|
||||
// multimonitor APIs.
|
||||
//
|
||||
// Exactly one source must include this with COMPILE_MULTIMON_STUBS defined.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Assume C declarations for C++
|
||||
#endif // __cplusplus
|
||||
|
||||
//
|
||||
// If we are building with Win95/NT4 headers, we need to declare
|
||||
// the multimonitor-related metrics and APIs ourselves.
|
||||
//
|
||||
#ifndef SM_CMONITORS
|
||||
|
||||
#define SM_XVIRTUALSCREEN 76
|
||||
#define SM_YVIRTUALSCREEN 77
|
||||
#define SM_CXVIRTUALSCREEN 78
|
||||
#define SM_CYVIRTUALSCREEN 79
|
||||
#define SM_CMONITORS 80
|
||||
#define SM_SAMEDISPLAYFORMAT 81
|
||||
|
||||
// HMONITOR is already declared if WINVER >= 0x0500 in windef.h
|
||||
// This is for components built with an older version number.
|
||||
//
|
||||
#if !defined(HMONITOR_DECLARED) && (WINVER < 0x0500)
|
||||
DECLARE_HANDLE(HMONITOR);
|
||||
#define HMONITOR_DECLARED
|
||||
#endif
|
||||
|
||||
#define MONITOR_DEFAULTTONULL 0x00000000
|
||||
#define MONITOR_DEFAULTTOPRIMARY 0x00000001
|
||||
#define MONITOR_DEFAULTTONEAREST 0x00000002
|
||||
|
||||
#define MONITORINFOF_PRIMARY 0x00000001
|
||||
|
||||
typedef struct tagMONITORINFO
|
||||
{
|
||||
DWORD cbSize;
|
||||
RECT rcMonitor;
|
||||
RECT rcWork;
|
||||
DWORD dwFlags;
|
||||
} MONITORINFO, *LPMONITORINFO;
|
||||
|
||||
#ifndef CCHDEVICENAME
|
||||
#define CCHDEVICENAME 32
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
typedef struct tagMONITORINFOEXA : public tagMONITORINFO
|
||||
{
|
||||
CHAR szDevice[CCHDEVICENAME];
|
||||
} MONITORINFOEXA, *LPMONITORINFOEXA;
|
||||
typedef struct tagMONITORINFOEXW : public tagMONITORINFO
|
||||
{
|
||||
WCHAR szDevice[CCHDEVICENAME];
|
||||
} MONITORINFOEXW, *LPMONITORINFOEXW;
|
||||
#ifdef UNICODE
|
||||
typedef MONITORINFOEXW MONITORINFOEX;
|
||||
typedef LPMONITORINFOEXW LPMONITORINFOEX;
|
||||
#else
|
||||
typedef MONITORINFOEXA MONITORINFOEX;
|
||||
typedef LPMONITORINFOEXA LPMONITORINFOEX;
|
||||
#endif // UNICODE
|
||||
#else // ndef __cplusplus
|
||||
typedef struct tagMONITORINFOEXA
|
||||
{
|
||||
MONITORINFO;
|
||||
CHAR szDevice[CCHDEVICENAME];
|
||||
} MONITORINFOEXA, *LPMONITORINFOEXA;
|
||||
typedef struct tagMONITORINFOEXW
|
||||
{
|
||||
MONITORINFO;
|
||||
WCHAR szDevice[CCHDEVICENAME];
|
||||
} MONITORINFOEXW, *LPMONITORINFOEXW;
|
||||
#ifdef UNICODE
|
||||
typedef MONITORINFOEXW MONITORINFOEX;
|
||||
typedef LPMONITORINFOEXW LPMONITORINFOEX;
|
||||
#else
|
||||
typedef MONITORINFOEXA MONITORINFOEX;
|
||||
typedef LPMONITORINFOEXA LPMONITORINFOEX;
|
||||
#endif // UNICODE
|
||||
#endif
|
||||
|
||||
typedef BOOL (CALLBACK* MONITORENUMPROC)(HMONITOR, HDC, LPRECT, LPARAM);
|
||||
|
||||
#ifndef DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
||||
typedef struct _DISPLAY_DEVICEA {
|
||||
DWORD cb;
|
||||
CHAR DeviceName[32];
|
||||
CHAR DeviceString[128];
|
||||
DWORD StateFlags;
|
||||
CHAR DeviceID[128];
|
||||
CHAR DeviceKey[128];
|
||||
} DISPLAY_DEVICEA, *PDISPLAY_DEVICEA, *LPDISPLAY_DEVICEA;
|
||||
typedef struct _DISPLAY_DEVICEW {
|
||||
DWORD cb;
|
||||
WCHAR DeviceName[32];
|
||||
WCHAR DeviceString[128];
|
||||
DWORD StateFlags;
|
||||
WCHAR DeviceID[128];
|
||||
WCHAR DeviceKey[128];
|
||||
} DISPLAY_DEVICEW, *PDISPLAY_DEVICEW, *LPDISPLAY_DEVICEW;
|
||||
#ifdef UNICODE
|
||||
typedef DISPLAY_DEVICEW DISPLAY_DEVICE;
|
||||
typedef PDISPLAY_DEVICEW PDISPLAY_DEVICE;
|
||||
typedef LPDISPLAY_DEVICEW LPDISPLAY_DEVICE;
|
||||
#else
|
||||
typedef DISPLAY_DEVICEA DISPLAY_DEVICE;
|
||||
typedef PDISPLAY_DEVICEA PDISPLAY_DEVICE;
|
||||
typedef LPDISPLAY_DEVICEA LPDISPLAY_DEVICE;
|
||||
#endif // UNICODE
|
||||
|
||||
#define DISPLAY_DEVICE_ATTACHED_TO_DESKTOP 0x00000001
|
||||
#define DISPLAY_DEVICE_MULTI_DRIVER 0x00000002
|
||||
#define DISPLAY_DEVICE_PRIMARY_DEVICE 0x00000004
|
||||
#define DISPLAY_DEVICE_MIRRORING_DRIVER 0x00000008
|
||||
#define DISPLAY_DEVICE_VGA_COMPATIBLE 0x00000010
|
||||
#endif
|
||||
|
||||
#endif // SM_CMONITORS
|
||||
|
||||
#undef GetMonitorInfo
|
||||
#undef GetSystemMetrics
|
||||
#undef MonitorFromWindow
|
||||
#undef MonitorFromRect
|
||||
#undef MonitorFromPoint
|
||||
#undef EnumDisplayMonitors
|
||||
#undef EnumDisplayDevices
|
||||
|
||||
//
|
||||
// Define COMPILE_MULTIMON_STUBS to compile the stubs;
|
||||
// otherwise, you get the declarations.
|
||||
//
|
||||
#ifdef COMPILE_MULTIMON_STUBS
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Implement the API stubs.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _MULTIMON_USE_SECURE_CRT
|
||||
#if defined(__GOT_SECURE_LIB__) && __GOT_SECURE_LIB__ >= 200402L
|
||||
#define _MULTIMON_USE_SECURE_CRT 1
|
||||
#else
|
||||
#define _MULTIMON_USE_SECURE_CRT 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef MULTIMON_FNS_DEFINED
|
||||
|
||||
int (WINAPI* g_pfnGetSystemMetrics)(int) = NULL;
|
||||
HMONITOR (WINAPI* g_pfnMonitorFromWindow)(HWND, DWORD) = NULL;
|
||||
HMONITOR (WINAPI* g_pfnMonitorFromRect)(LPCRECT, DWORD) = NULL;
|
||||
HMONITOR (WINAPI* g_pfnMonitorFromPoint)(POINT, DWORD) = NULL;
|
||||
BOOL (WINAPI* g_pfnGetMonitorInfo)(HMONITOR, LPMONITORINFO) = NULL;
|
||||
BOOL (WINAPI* g_pfnEnumDisplayMonitors)(HDC, LPCRECT, MONITORENUMPROC, LPARAM) = NULL;
|
||||
BOOL (WINAPI* g_pfnEnumDisplayDevices)(PVOID, DWORD, PDISPLAY_DEVICE,DWORD) = NULL;
|
||||
BOOL g_fMultiMonInitDone = FALSE;
|
||||
BOOL g_fMultimonPlatformNT = FALSE;
|
||||
|
||||
#endif
|
||||
|
||||
BOOL IsPlatformNT()
|
||||
{
|
||||
OSVERSIONINFOA osvi = {0};
|
||||
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
||||
GetVersionExA((OSVERSIONINFOA*)&osvi);
|
||||
return (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId);
|
||||
}
|
||||
|
||||
BOOL InitMultipleMonitorStubs(void)
|
||||
{
|
||||
HMODULE hUser32;
|
||||
if (g_fMultiMonInitDone)
|
||||
{
|
||||
return g_pfnGetMonitorInfo != NULL;
|
||||
}
|
||||
|
||||
g_fMultimonPlatformNT = IsPlatformNT();
|
||||
hUser32 = GetModuleHandle(TEXT("USER32"));
|
||||
if (hUser32 &&
|
||||
(*(FARPROC*)&g_pfnGetSystemMetrics = GetProcAddress(hUser32,"GetSystemMetrics")) != NULL &&
|
||||
(*(FARPROC*)&g_pfnMonitorFromWindow = GetProcAddress(hUser32,"MonitorFromWindow")) != NULL &&
|
||||
(*(FARPROC*)&g_pfnMonitorFromRect = GetProcAddress(hUser32,"MonitorFromRect")) != NULL &&
|
||||
(*(FARPROC*)&g_pfnMonitorFromPoint = GetProcAddress(hUser32,"MonitorFromPoint")) != NULL &&
|
||||
(*(FARPROC*)&g_pfnEnumDisplayMonitors = GetProcAddress(hUser32,"EnumDisplayMonitors")) != NULL &&
|
||||
#ifdef UNICODE
|
||||
(*(FARPROC*)&g_pfnEnumDisplayDevices = GetProcAddress(hUser32,"EnumDisplayDevicesW")) != NULL &&
|
||||
(*(FARPROC*)&g_pfnGetMonitorInfo = g_fMultimonPlatformNT ? GetProcAddress(hUser32,"GetMonitorInfoW") :
|
||||
GetProcAddress(hUser32,"GetMonitorInfoA")) != NULL
|
||||
#else
|
||||
(*(FARPROC*)&g_pfnGetMonitorInfo = GetProcAddress(hUser32,"GetMonitorInfoA")) != NULL &&
|
||||
(*(FARPROC*)&g_pfnEnumDisplayDevices = GetProcAddress(hUser32,"EnumDisplayDevicesA")) != NULL
|
||||
#endif
|
||||
) {
|
||||
g_fMultiMonInitDone = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pfnGetSystemMetrics = NULL;
|
||||
g_pfnMonitorFromWindow = NULL;
|
||||
g_pfnMonitorFromRect = NULL;
|
||||
g_pfnMonitorFromPoint = NULL;
|
||||
g_pfnGetMonitorInfo = NULL;
|
||||
g_pfnEnumDisplayMonitors = NULL;
|
||||
g_pfnEnumDisplayDevices = NULL;
|
||||
|
||||
g_fMultiMonInitDone = TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// fake implementations of Monitor APIs that work with the primary display
|
||||
// no special parameter validation is made since these run in client code
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int WINAPI
|
||||
xGetSystemMetrics(int nIndex)
|
||||
{
|
||||
if (InitMultipleMonitorStubs())
|
||||
return g_pfnGetSystemMetrics(nIndex);
|
||||
|
||||
switch (nIndex)
|
||||
{
|
||||
case SM_CMONITORS:
|
||||
case SM_SAMEDISPLAYFORMAT:
|
||||
return 1;
|
||||
|
||||
case SM_XVIRTUALSCREEN:
|
||||
case SM_YVIRTUALSCREEN:
|
||||
return 0;
|
||||
|
||||
case SM_CXVIRTUALSCREEN:
|
||||
nIndex = SM_CXSCREEN;
|
||||
break;
|
||||
|
||||
case SM_CYVIRTUALSCREEN:
|
||||
nIndex = SM_CYSCREEN;
|
||||
break;
|
||||
}
|
||||
|
||||
return GetSystemMetrics(nIndex);
|
||||
}
|
||||
|
||||
#define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
|
||||
|
||||
HMONITOR WINAPI
|
||||
xMonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
|
||||
{
|
||||
if (InitMultipleMonitorStubs())
|
||||
return g_pfnMonitorFromPoint(ptScreenCoords, dwFlags);
|
||||
|
||||
if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
|
||||
((ptScreenCoords.x >= 0) &&
|
||||
(ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
|
||||
(ptScreenCoords.y >= 0) &&
|
||||
(ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
|
||||
{
|
||||
return xPRIMARY_MONITOR;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HMONITOR WINAPI
|
||||
xMonitorFromRect(LPCRECT lprcScreenCoords, DWORD dwFlags)
|
||||
{
|
||||
if (InitMultipleMonitorStubs())
|
||||
return g_pfnMonitorFromRect(lprcScreenCoords, dwFlags);
|
||||
|
||||
if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
|
||||
((lprcScreenCoords->right > 0) &&
|
||||
(lprcScreenCoords->bottom > 0) &&
|
||||
(lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
|
||||
(lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
|
||||
{
|
||||
return xPRIMARY_MONITOR;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HMONITOR WINAPI
|
||||
xMonitorFromWindow(HWND hWnd, DWORD dwFlags)
|
||||
{
|
||||
WINDOWPLACEMENT wp;
|
||||
|
||||
if (InitMultipleMonitorStubs())
|
||||
return g_pfnMonitorFromWindow(hWnd, dwFlags);
|
||||
|
||||
if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
|
||||
return xPRIMARY_MONITOR;
|
||||
|
||||
if (IsIconic(hWnd) ?
|
||||
GetWindowPlacement(hWnd, &wp) :
|
||||
GetWindowRect(hWnd, &wp.rcNormalPosition)) {
|
||||
|
||||
return xMonitorFromRect(&wp.rcNormalPosition, dwFlags);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BOOL WINAPI
|
||||
xGetMonitorInfo(HMONITOR hMonitor, __inout LPMONITORINFO lpMonitorInfo)
|
||||
{
|
||||
RECT rcWork;
|
||||
|
||||
if (InitMultipleMonitorStubs())
|
||||
{
|
||||
BOOL f = g_pfnGetMonitorInfo(hMonitor, lpMonitorInfo);
|
||||
#ifdef UNICODE
|
||||
if (f && !g_fMultimonPlatformNT && (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEX)))
|
||||
{
|
||||
MultiByteToWideChar(CP_ACP, 0,
|
||||
(LPSTR)((MONITORINFOEX*)lpMonitorInfo)->szDevice, -1,
|
||||
((MONITORINFOEX*)lpMonitorInfo)->szDevice, (sizeof(((MONITORINFOEX*)lpMonitorInfo)->szDevice)/sizeof(TCHAR)));
|
||||
}
|
||||
#endif
|
||||
return f;
|
||||
}
|
||||
|
||||
if ((hMonitor == xPRIMARY_MONITOR) &&
|
||||
lpMonitorInfo &&
|
||||
(lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
|
||||
SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
|
||||
{
|
||||
lpMonitorInfo->rcMonitor.left = 0;
|
||||
lpMonitorInfo->rcMonitor.top = 0;
|
||||
lpMonitorInfo->rcMonitor.right = GetSystemMetrics(SM_CXSCREEN);
|
||||
lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
|
||||
lpMonitorInfo->rcWork = rcWork;
|
||||
lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
|
||||
|
||||
if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEX))
|
||||
{
|
||||
#ifdef UNICODE
|
||||
MultiByteToWideChar(CP_ACP, 0, "DISPLAY", -1, ((MONITORINFOEX*)lpMonitorInfo)->szDevice, (sizeof(((MONITORINFOEX*)lpMonitorInfo)->szDevice)/sizeof(TCHAR)));
|
||||
#else // UNICODE
|
||||
#if _MULTIMON_USE_SECURE_CRT
|
||||
strncpy_s(((MONITORINFOEX*)lpMonitorInfo)->szDevice, (sizeof(((MONITORINFOEX*)lpMonitorInfo)->szDevice)/sizeof(TCHAR)), TEXT("DISPLAY"), (sizeof(((MONITORINFOEX*)lpMonitorInfo)->szDevice)/sizeof(TCHAR)) - 1);
|
||||
#else
|
||||
lstrcpyn(((MONITORINFOEX*)lpMonitorInfo)->szDevice, TEXT("DISPLAY"), (sizeof(((MONITORINFOEX*)lpMonitorInfo)->szDevice)/sizeof(TCHAR)));
|
||||
#endif // _MULTIMON_USE_SECURE_CRT
|
||||
#endif // UNICODE
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL WINAPI
|
||||
xEnumDisplayMonitors(
|
||||
HDC hdcOptionalForPainting,
|
||||
LPCRECT lprcEnumMonitorsThatIntersect,
|
||||
MONITORENUMPROC lpfnEnumProc,
|
||||
LPARAM dwData)
|
||||
{
|
||||
RECT rcLimit;
|
||||
|
||||
if (InitMultipleMonitorStubs()) {
|
||||
return g_pfnEnumDisplayMonitors(
|
||||
hdcOptionalForPainting,
|
||||
lprcEnumMonitorsThatIntersect,
|
||||
lpfnEnumProc,
|
||||
dwData);
|
||||
}
|
||||
|
||||
if (!lpfnEnumProc)
|
||||
return FALSE;
|
||||
|
||||
rcLimit.left = 0;
|
||||
rcLimit.top = 0;
|
||||
rcLimit.right = GetSystemMetrics(SM_CXSCREEN);
|
||||
rcLimit.bottom = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
if (hdcOptionalForPainting)
|
||||
{
|
||||
RECT rcClip;
|
||||
POINT ptOrg;
|
||||
|
||||
switch (GetClipBox(hdcOptionalForPainting, &rcClip))
|
||||
{
|
||||
default:
|
||||
if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
|
||||
return FALSE;
|
||||
|
||||
OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
|
||||
if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
|
||||
(!lprcEnumMonitorsThatIntersect ||
|
||||
IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
|
||||
|
||||
break;
|
||||
}
|
||||
//fall thru
|
||||
case NULLREGION:
|
||||
return TRUE;
|
||||
case ERROR:
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
if ( lprcEnumMonitorsThatIntersect &&
|
||||
!IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return lpfnEnumProc(
|
||||
xPRIMARY_MONITOR,
|
||||
hdcOptionalForPainting,
|
||||
&rcLimit,
|
||||
dwData);
|
||||
}
|
||||
|
||||
BOOL WINAPI
|
||||
xEnumDisplayDevices(
|
||||
PVOID Unused,
|
||||
DWORD iDevNum,
|
||||
__inout PDISPLAY_DEVICE lpDisplayDevice,
|
||||
DWORD dwFlags)
|
||||
{
|
||||
if (InitMultipleMonitorStubs())
|
||||
return g_pfnEnumDisplayDevices(Unused, iDevNum, lpDisplayDevice, dwFlags);
|
||||
|
||||
if (Unused != NULL)
|
||||
return FALSE;
|
||||
|
||||
if (iDevNum != 0)
|
||||
return FALSE;
|
||||
|
||||
if (lpDisplayDevice == NULL || lpDisplayDevice->cb < sizeof(DISPLAY_DEVICE))
|
||||
return FALSE;
|
||||
|
||||
#ifdef UNICODE
|
||||
MultiByteToWideChar(CP_ACP, 0, "DISPLAY", -1, lpDisplayDevice->DeviceName, (sizeof(lpDisplayDevice->DeviceName)/sizeof(TCHAR)));
|
||||
MultiByteToWideChar(CP_ACP, 0, "DISPLAY", -1, lpDisplayDevice->DeviceString, (sizeof(lpDisplayDevice->DeviceString)/sizeof(TCHAR)));
|
||||
#else // UNICODE
|
||||
#if _MULTIMON_USE_SECURE_CRT
|
||||
strncpy_s((LPTSTR)lpDisplayDevice->DeviceName, (sizeof(lpDisplayDevice->DeviceName)/sizeof(TCHAR)), TEXT("DISPLAY"), (sizeof(lpDisplayDevice->DeviceName)/sizeof(TCHAR)) - 1);
|
||||
strncpy_s((LPTSTR)lpDisplayDevice->DeviceString, (sizeof(lpDisplayDevice->DeviceString)/sizeof(TCHAR)), TEXT("DISPLAY"), (sizeof(lpDisplayDevice->DeviceName)/sizeof(TCHAR)) - 1);
|
||||
#else
|
||||
lstrcpyn((LPTSTR)lpDisplayDevice->DeviceName, TEXT("DISPLAY"), (sizeof(lpDisplayDevice->DeviceName)/sizeof(TCHAR)));
|
||||
lstrcpyn((LPTSTR)lpDisplayDevice->DeviceString, TEXT("DISPLAY"), (sizeof(lpDisplayDevice->DeviceString)/sizeof(TCHAR)));
|
||||
#endif // _MULTIMON_USE_SECURE_CRT
|
||||
#endif // UNICODE
|
||||
|
||||
lpDisplayDevice->StateFlags = DISPLAY_DEVICE_ATTACHED_TO_DESKTOP | DISPLAY_DEVICE_PRIMARY_DEVICE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#undef xPRIMARY_MONITOR
|
||||
#undef COMPILE_MULTIMON_STUBS
|
||||
|
||||
#else // COMPILE_MULTIMON_STUBS
|
||||
|
||||
extern int WINAPI xGetSystemMetrics(int);
|
||||
extern HMONITOR WINAPI xMonitorFromWindow(HWND, DWORD);
|
||||
extern HMONITOR WINAPI xMonitorFromRect(LPCRECT, DWORD);
|
||||
extern HMONITOR WINAPI xMonitorFromPoint(POINT, DWORD);
|
||||
extern BOOL WINAPI xGetMonitorInfo(HMONITOR, LPMONITORINFO);
|
||||
extern BOOL WINAPI xEnumDisplayMonitors(HDC, LPCRECT, MONITORENUMPROC, LPARAM);
|
||||
extern BOOL WINAPI xEnumDisplayDevices(PVOID, DWORD, PDISPLAY_DEVICE, DWORD);
|
||||
|
||||
#endif // COMPILE_MULTIMON_STUBS
|
||||
|
||||
//
|
||||
// build defines that replace the regular APIs with our versions
|
||||
//
|
||||
#define GetSystemMetrics xGetSystemMetrics
|
||||
#define MonitorFromWindow xMonitorFromWindow
|
||||
#define MonitorFromRect xMonitorFromRect
|
||||
#define MonitorFromPoint xMonitorFromPoint
|
||||
#define GetMonitorInfo xGetMonitorInfo
|
||||
#define EnumDisplayMonitors xEnumDisplayMonitors
|
||||
#define EnumDisplayDevices xEnumDisplayDevices
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
|
2
3rdparty/include/opencl/1.2/CL/cl.hpp
vendored
2
3rdparty/include/opencl/1.2/CL/cl.hpp
vendored
@ -210,7 +210,7 @@
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#if defined(linux) || defined(__APPLE__) || defined(__MACOSX)
|
||||
#if defined(__linux__) || defined(__APPLE__) || defined(__MACOSX)
|
||||
#include <alloca.h>
|
||||
|
||||
#include <emmintrin.h>
|
||||
|
18
3rdparty/include/opencl/1.2/CL/cl_platform.h
vendored
18
3rdparty/include/opencl/1.2/CL/cl_platform.h
vendored
@ -92,7 +92,7 @@ extern "C" {
|
||||
#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED __attribute__((deprecated))
|
||||
#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
|
||||
#endif
|
||||
#elif _WIN32
|
||||
#elif defined(_WIN32)
|
||||
#ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS
|
||||
#define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED
|
||||
#define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED
|
||||
@ -332,13 +332,13 @@ typedef unsigned int cl_GLenum;
|
||||
/* Define basic vector types */
|
||||
#if defined( __VEC__ )
|
||||
#include <altivec.h> /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */
|
||||
typedef vector unsigned char __cl_uchar16;
|
||||
typedef vector signed char __cl_char16;
|
||||
typedef vector unsigned short __cl_ushort8;
|
||||
typedef vector signed short __cl_short8;
|
||||
typedef vector unsigned int __cl_uint4;
|
||||
typedef vector signed int __cl_int4;
|
||||
typedef vector float __cl_float4;
|
||||
typedef __vector unsigned char __cl_uchar16;
|
||||
typedef __vector signed char __cl_char16;
|
||||
typedef __vector unsigned short __cl_ushort8;
|
||||
typedef __vector signed short __cl_short8;
|
||||
typedef __vector unsigned int __cl_uint4;
|
||||
typedef __vector signed int __cl_int4;
|
||||
typedef __vector float __cl_float4;
|
||||
#define __CL_UCHAR16__ 1
|
||||
#define __CL_CHAR16__ 1
|
||||
#define __CL_USHORT8__ 1
|
||||
@ -454,7 +454,7 @@ typedef unsigned int cl_GLenum;
|
||||
/* Define alignment keys */
|
||||
#if defined( __GNUC__ )
|
||||
#define CL_ALIGNED(_x) __attribute__ ((aligned(_x)))
|
||||
#elif defined( _WIN32) && (_MSC_VER)
|
||||
#elif defined( _WIN32) && defined(_MSC_VER)
|
||||
/* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */
|
||||
/* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */
|
||||
/* #include <crtdefs.h> */
|
||||
|
2
3rdparty/ippicv/.gitignore
vendored
Normal file
2
3rdparty/ippicv/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
downloads/
|
||||
unpack/
|
108
3rdparty/ippicv/downloader.cmake
vendored
Normal file
108
3rdparty/ippicv/downloader.cmake
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
#
|
||||
# The script downloads ICV package
|
||||
#
|
||||
# On return this will define:
|
||||
# OPENCV_ICV_PATH - path to unpacked downloaded package
|
||||
#
|
||||
|
||||
function(_icv_downloader)
|
||||
# Define actual ICV versions
|
||||
if(APPLE)
|
||||
set(OPENCV_ICV_PACKAGE_NAME "ippicv_macosx_20141027.tgz")
|
||||
set(OPENCV_ICV_PACKAGE_HASH "9662fe0694a67e59491a0dcc82fa26e0")
|
||||
set(OPENCV_ICV_PLATFORM "macosx")
|
||||
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_osx")
|
||||
elseif(UNIX)
|
||||
if(ANDROID AND (NOT ANDROID_ABI STREQUAL x86))
|
||||
return()
|
||||
endif()
|
||||
set(OPENCV_ICV_PACKAGE_NAME "ippicv_linux_20141027.tgz")
|
||||
set(OPENCV_ICV_PACKAGE_HASH "8b449a536a2157bcad08a2b9f266828b")
|
||||
set(OPENCV_ICV_PLATFORM "linux")
|
||||
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_lnx")
|
||||
elseif(WIN32 AND NOT ARM)
|
||||
set(OPENCV_ICV_PACKAGE_NAME "ippicv_windows_20141027.zip")
|
||||
set(OPENCV_ICV_PACKAGE_HASH "b59f865d1ba16e8c84124e19d78eec57")
|
||||
set(OPENCV_ICV_PLATFORM "windows")
|
||||
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_win")
|
||||
else()
|
||||
return() # Not supported
|
||||
endif()
|
||||
|
||||
set(OPENCV_ICV_UNPACK_PATH "${CMAKE_CURRENT_LIST_DIR}/unpack")
|
||||
set(OPENCV_ICV_PATH "${OPENCV_ICV_UNPACK_PATH}${OPENCV_ICV_PACKAGE_SUBDIR}")
|
||||
|
||||
if(DEFINED OPENCV_ICV_PACKAGE_DOWNLOADED
|
||||
AND OPENCV_ICV_PACKAGE_DOWNLOADED STREQUAL OPENCV_ICV_PACKAGE_HASH
|
||||
AND EXISTS ${OPENCV_ICV_PATH})
|
||||
# Package has been downloaded and checked by the previous build
|
||||
set(OPENCV_ICV_PATH "${OPENCV_ICV_PATH}" PARENT_SCOPE)
|
||||
return()
|
||||
else()
|
||||
if(EXISTS ${OPENCV_ICV_UNPACK_PATH})
|
||||
message(STATUS "ICV: Removing previous unpacked package: ${OPENCV_ICV_UNPACK_PATH}")
|
||||
file(REMOVE_RECURSE ${OPENCV_ICV_UNPACK_PATH})
|
||||
endif()
|
||||
endif()
|
||||
unset(OPENCV_ICV_PACKAGE_DOWNLOADED CACHE)
|
||||
|
||||
set(OPENCV_ICV_PACKAGE_ARCHIVE "${CMAKE_CURRENT_LIST_DIR}/downloads/${OPENCV_ICV_PLATFORM}-${OPENCV_ICV_PACKAGE_HASH}/${OPENCV_ICV_PACKAGE_NAME}")
|
||||
get_filename_component(OPENCV_ICV_PACKAGE_ARCHIVE_DIR "${OPENCV_ICV_PACKAGE_ARCHIVE}" PATH)
|
||||
if(EXISTS "${OPENCV_ICV_PACKAGE_ARCHIVE}")
|
||||
file(MD5 "${OPENCV_ICV_PACKAGE_ARCHIVE}" archive_md5)
|
||||
if(NOT archive_md5 STREQUAL OPENCV_ICV_PACKAGE_HASH)
|
||||
message(WARNING "ICV: Local copy of ICV package has invalid MD5 hash: ${archive_md5} (expected: ${OPENCV_ICV_PACKAGE_HASH})")
|
||||
file(REMOVE "${OPENCV_ICV_PACKAGE_ARCHIVE}")
|
||||
file(REMOVE_RECURSE "${OPENCV_ICV_PACKAGE_ARCHIVE_DIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS "${OPENCV_ICV_PACKAGE_ARCHIVE}")
|
||||
if(NOT DEFINED OPENCV_ICV_URL)
|
||||
if(DEFINED ENV{OPENCV_ICV_URL})
|
||||
set(OPENCV_ICV_URL $ENV{OPENCV_ICV_URL})
|
||||
else()
|
||||
set(OPENCV_ICV_URL "http://sourceforge.net/projects/opencvlibrary/files/3rdparty/ippicv")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(MAKE_DIRECTORY ${OPENCV_ICV_PACKAGE_ARCHIVE_DIR})
|
||||
message(STATUS "ICV: Downloading ${OPENCV_ICV_PACKAGE_NAME}...")
|
||||
file(DOWNLOAD "${OPENCV_ICV_URL}/${OPENCV_ICV_PACKAGE_NAME}" "${OPENCV_ICV_PACKAGE_ARCHIVE}"
|
||||
TIMEOUT 600 STATUS __status
|
||||
EXPECTED_MD5 ${OPENCV_ICV_PACKAGE_HASH})
|
||||
if(NOT __status EQUAL 0)
|
||||
message(FATAL_ERROR "ICV: Failed to download ICV package: ${OPENCV_ICV_PACKAGE_NAME}. Status=${__status}")
|
||||
else()
|
||||
# Don't remove this code, because EXPECTED_MD5 parameter doesn't fail "file(DOWNLOAD)" step
|
||||
# on wrong hash
|
||||
file(MD5 "${OPENCV_ICV_PACKAGE_ARCHIVE}" archive_md5)
|
||||
if(NOT archive_md5 STREQUAL OPENCV_ICV_PACKAGE_HASH)
|
||||
message(FATAL_ERROR "ICV: Downloaded copy of ICV package has invalid MD5 hash: ${archive_md5} (expected: ${OPENCV_ICV_PACKAGE_HASH})")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
ocv_assert(EXISTS "${OPENCV_ICV_PACKAGE_ARCHIVE}")
|
||||
ocv_assert(NOT EXISTS "${OPENCV_ICV_UNPACK_PATH}")
|
||||
file(MAKE_DIRECTORY ${OPENCV_ICV_UNPACK_PATH})
|
||||
ocv_assert(EXISTS "${OPENCV_ICV_UNPACK_PATH}")
|
||||
|
||||
message(STATUS "ICV: Unpacking ${OPENCV_ICV_PACKAGE_NAME} to ${OPENCV_ICV_UNPACK_PATH}...")
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xz "${OPENCV_ICV_PACKAGE_ARCHIVE}"
|
||||
WORKING_DIRECTORY "${OPENCV_ICV_UNPACK_PATH}"
|
||||
RESULT_VARIABLE __result)
|
||||
|
||||
if(NOT __result EQUAL 0)
|
||||
message(FATAL_ERROR "ICV: Failed to unpack ICV package from ${OPENCV_ICV_PACKAGE_ARCHIVE} to ${OPENCV_ICV_UNPACK_PATH} with error ${__result}")
|
||||
endif()
|
||||
|
||||
ocv_assert(EXISTS "${OPENCV_ICV_PATH}")
|
||||
|
||||
set(OPENCV_ICV_PACKAGE_DOWNLOADED "${OPENCV_ICV_PACKAGE_HASH}" CACHE INTERNAL "ICV package hash")
|
||||
|
||||
message(STATUS "ICV: Package successfully downloaded")
|
||||
set(OPENCV_ICV_PATH "${OPENCV_ICV_PATH}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
_icv_downloader()
|
4
3rdparty/jinja2/markupsafe/__init__.py
vendored
4
3rdparty/jinja2/markupsafe/__init__.py
vendored
@ -9,7 +9,7 @@
|
||||
:license: BSD, see LICENSE for more details.
|
||||
"""
|
||||
import re
|
||||
from _compat import text_type, string_types, int_types, \
|
||||
from ._compat import text_type, string_types, int_types, \
|
||||
unichr, PY2
|
||||
|
||||
|
||||
@ -227,7 +227,7 @@ class _MarkupEscapeHelper(object):
|
||||
try:
|
||||
from _speedups import escape, escape_silent, soft_unicode
|
||||
except ImportError:
|
||||
from _native import escape, escape_silent, soft_unicode
|
||||
from ._native import escape, escape_silent, soft_unicode
|
||||
|
||||
if not PY2:
|
||||
soft_str = soft_unicode
|
||||
|
2
3rdparty/jinja2/markupsafe/_native.py
vendored
2
3rdparty/jinja2/markupsafe/_native.py
vendored
@ -8,7 +8,7 @@
|
||||
:copyright: (c) 2010 by Armin Ronacher.
|
||||
:license: BSD, see LICENSE for more details.
|
||||
"""
|
||||
from _compat import text_type
|
||||
from ._compat import text_type
|
||||
|
||||
|
||||
def escape(s):
|
||||
|
2
3rdparty/jinja2/utils.py
vendored
2
3rdparty/jinja2/utils.py
vendored
@ -517,4 +517,4 @@ class Joiner(object):
|
||||
|
||||
|
||||
# Imported here because that's where it was in the past
|
||||
from markupsafe import Markup, escape, soft_unicode
|
||||
from .markupsafe import Markup, escape, soft_unicode
|
||||
|
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r2.2.0.so
vendored
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r2.2.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r2.3.3.so
vendored
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r2.3.3.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r3.0.1.so
vendored
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r3.0.1.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.0.so
vendored
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.3.so
vendored
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.3.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.1.1.so
vendored
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.1.1.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.2.0.so
vendored
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.2.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.3.0.so
vendored
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.3.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.4.0.so
vendored
Executable file
BIN
3rdparty/lib/armeabi-v7a/libnative_camera_r4.4.0.so
vendored
Executable file
Binary file not shown.
BIN
3rdparty/lib/armeabi/libnative_camera_r2.2.0.so
vendored
BIN
3rdparty/lib/armeabi/libnative_camera_r2.2.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi/libnative_camera_r2.3.3.so
vendored
BIN
3rdparty/lib/armeabi/libnative_camera_r2.3.3.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi/libnative_camera_r3.0.1.so
vendored
BIN
3rdparty/lib/armeabi/libnative_camera_r3.0.1.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi/libnative_camera_r4.0.0.so
vendored
BIN
3rdparty/lib/armeabi/libnative_camera_r4.0.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi/libnative_camera_r4.0.3.so
vendored
BIN
3rdparty/lib/armeabi/libnative_camera_r4.0.3.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi/libnative_camera_r4.1.1.so
vendored
BIN
3rdparty/lib/armeabi/libnative_camera_r4.1.1.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi/libnative_camera_r4.2.0.so
vendored
BIN
3rdparty/lib/armeabi/libnative_camera_r4.2.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi/libnative_camera_r4.3.0.so
vendored
BIN
3rdparty/lib/armeabi/libnative_camera_r4.3.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/armeabi/libnative_camera_r4.4.0.so
vendored
Executable file
BIN
3rdparty/lib/armeabi/libnative_camera_r4.4.0.so
vendored
Executable file
Binary file not shown.
BIN
3rdparty/lib/libavcodec.a
vendored
BIN
3rdparty/lib/libavcodec.a
vendored
Binary file not shown.
BIN
3rdparty/lib/libavdevice.a
vendored
BIN
3rdparty/lib/libavdevice.a
vendored
Binary file not shown.
BIN
3rdparty/lib/libavformat.a
vendored
BIN
3rdparty/lib/libavformat.a
vendored
Binary file not shown.
BIN
3rdparty/lib/libavutil.a
vendored
BIN
3rdparty/lib/libavutil.a
vendored
Binary file not shown.
BIN
3rdparty/lib/libswscale.a
vendored
BIN
3rdparty/lib/libswscale.a
vendored
Binary file not shown.
BIN
3rdparty/lib/mips/libnative_camera_r4.0.3.so
vendored
BIN
3rdparty/lib/mips/libnative_camera_r4.0.3.so
vendored
Binary file not shown.
BIN
3rdparty/lib/mips/libnative_camera_r4.1.1.so
vendored
BIN
3rdparty/lib/mips/libnative_camera_r4.1.1.so
vendored
Binary file not shown.
BIN
3rdparty/lib/mips/libnative_camera_r4.2.0.so
vendored
BIN
3rdparty/lib/mips/libnative_camera_r4.2.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/mips/libnative_camera_r4.3.0.so
vendored
BIN
3rdparty/lib/mips/libnative_camera_r4.3.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/mips/libnative_camera_r4.4.0.so
vendored
Executable file
BIN
3rdparty/lib/mips/libnative_camera_r4.4.0.so
vendored
Executable file
Binary file not shown.
BIN
3rdparty/lib/x86/libnative_camera_r2.3.3.so
vendored
BIN
3rdparty/lib/x86/libnative_camera_r2.3.3.so
vendored
Binary file not shown.
BIN
3rdparty/lib/x86/libnative_camera_r3.0.1.so
vendored
BIN
3rdparty/lib/x86/libnative_camera_r3.0.1.so
vendored
Binary file not shown.
BIN
3rdparty/lib/x86/libnative_camera_r4.0.3.so
vendored
BIN
3rdparty/lib/x86/libnative_camera_r4.0.3.so
vendored
Binary file not shown.
BIN
3rdparty/lib/x86/libnative_camera_r4.1.1.so
vendored
BIN
3rdparty/lib/x86/libnative_camera_r4.1.1.so
vendored
Binary file not shown.
BIN
3rdparty/lib/x86/libnative_camera_r4.2.0.so
vendored
BIN
3rdparty/lib/x86/libnative_camera_r4.2.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/x86/libnative_camera_r4.3.0.so
vendored
BIN
3rdparty/lib/x86/libnative_camera_r4.3.0.so
vendored
Binary file not shown.
BIN
3rdparty/lib/x86/libnative_camera_r4.4.0.so
vendored
Executable file
BIN
3rdparty/lib/x86/libnative_camera_r4.4.0.so
vendored
Executable file
Binary file not shown.
2
3rdparty/libjasper/CMakeLists.txt
vendored
2
3rdparty/libjasper/CMakeLists.txt
vendored
@ -47,5 +47,5 @@ if(ENABLE_SOLUTION_FOLDERS)
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
ocv_install_target(${JASPER_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main)
|
||||
ocv_install_target(${JASPER_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
|
||||
endif()
|
||||
|
4
3rdparty/libjpeg/CMakeLists.txt
vendored
4
3rdparty/libjpeg/CMakeLists.txt
vendored
@ -9,7 +9,7 @@ ocv_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
file(GLOB lib_srcs *.c)
|
||||
file(GLOB lib_hdrs *.h)
|
||||
|
||||
if(ANDROID OR IOS)
|
||||
if(ANDROID OR IOS OR APPLE)
|
||||
ocv_list_filterout(lib_srcs jmemansi.c)
|
||||
else()
|
||||
ocv_list_filterout(lib_srcs jmemnobs.c)
|
||||
@ -46,5 +46,5 @@ if(ENABLE_SOLUTION_FOLDERS)
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main)
|
||||
ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
|
||||
endif()
|
||||
|
4
3rdparty/libpng/CMakeLists.txt
vendored
4
3rdparty/libpng/CMakeLists.txt
vendored
@ -14,7 +14,7 @@ ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" ${ZLIB_INCLUDE_DIRS})
|
||||
file(GLOB lib_srcs *.c)
|
||||
file(GLOB lib_hdrs *.h)
|
||||
|
||||
if(NEON)
|
||||
if(NEON AND CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
list(APPEND lib_srcs arm/filter_neon.S)
|
||||
add_definitions(-DPNG_ARM_NEON)
|
||||
endif()
|
||||
@ -55,5 +55,5 @@ if(ENABLE_SOLUTION_FOLDERS)
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
ocv_install_target(${PNG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main)
|
||||
ocv_install_target(${PNG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
|
||||
endif()
|
||||
|
2
3rdparty/libtiff/CMakeLists.txt
vendored
2
3rdparty/libtiff/CMakeLists.txt
vendored
@ -115,5 +115,5 @@ if(ENABLE_SOLUTION_FOLDERS)
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main)
|
||||
ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
|
||||
endif()
|
||||
|
12
3rdparty/libtiff/tif_config.h.cmakein
vendored
12
3rdparty/libtiff/tif_config.h.cmakein
vendored
@ -54,7 +54,7 @@
|
||||
|
||||
/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian
|
||||
(Intel) */
|
||||
#define HOST_BIGENDIAN 0
|
||||
#define HOST_BIGENDIAN @WORDS_BIGENDIAN@
|
||||
|
||||
/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */
|
||||
#define HOST_FILLORDER FILLORDER_LSB2MSB
|
||||
@ -156,15 +156,7 @@
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
# if defined __BIG_ENDIAN__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WORDS_BIGENDIAN
|
||||
/* # undef WORDS_BIGENDIAN */
|
||||
# endif
|
||||
#endif
|
||||
#cmakedefine WORDS_BIGENDIAN 1
|
||||
|
||||
/* Support Deflate compression */
|
||||
#define ZIP_SUPPORT 1
|
||||
|
2
3rdparty/openexr/CMakeLists.txt
vendored
2
3rdparty/openexr/CMakeLists.txt
vendored
@ -64,7 +64,7 @@ if(ENABLE_SOLUTION_FOLDERS)
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
ocv_install_target(IlmImf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main)
|
||||
ocv_install_target(IlmImf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
|
||||
endif()
|
||||
|
||||
set(OPENEXR_INCLUDE_PATHS ${OPENEXR_INCLUDE_PATHS} PARENT_SCOPE)
|
||||
|
10
3rdparty/readme.txt
vendored
10
3rdparty/readme.txt
vendored
@ -1,5 +1,5 @@
|
||||
This folder contains libraries and headers of a few very popular still image codecs
|
||||
used by highgui module.
|
||||
used by imgcodecs module.
|
||||
The libraries and headers are preferably to build Win32 and Win64 versions of OpenCV.
|
||||
On UNIX systems all the libraries are automatically detected by configure script.
|
||||
In order to use these versions of libraries instead of system ones on UNIX systems you
|
||||
@ -11,7 +11,7 @@ libjpeg 8d (8.4) - The Independent JPEG Group's JPEG software.
|
||||
See IGJ home page http://www.ijg.org
|
||||
for details and links to the source code
|
||||
|
||||
HAVE_JPEG preprocessor flag must be set to make highgui use libjpeg.
|
||||
HAVE_JPEG preprocessor flag must be set to make imgcodecs use libjpeg.
|
||||
On UNIX systems configure script takes care of it.
|
||||
------------------------------------------------------------------------------------
|
||||
libpng 1.5.12 - Portable Network Graphics library.
|
||||
@ -19,7 +19,7 @@ libpng 1.5.12 - Portable Network Graphics library.
|
||||
See libpng home page http://www.libpng.org
|
||||
for details and links to the source code
|
||||
|
||||
HAVE_PNG preprocessor flag must be set to make highgui use libpng.
|
||||
HAVE_PNG preprocessor flag must be set to make imgcodecs use libpng.
|
||||
On UNIX systems configure script takes care of it.
|
||||
------------------------------------------------------------------------------------
|
||||
libtiff 4.0.2 - Tag Image File Format (TIFF) Software
|
||||
@ -28,7 +28,7 @@ libtiff 4.0.2 - Tag Image File Format (TIFF) Software
|
||||
See libtiff home page http://www.remotesensing.org/libtiff/
|
||||
for details and links to the source code
|
||||
|
||||
HAVE_TIFF preprocessor flag must be set to make highgui use libtiff.
|
||||
HAVE_TIFF preprocessor flag must be set to make imgcodecs use libtiff.
|
||||
On UNIX systems configure script takes care of it.
|
||||
In this build support for ZIP (LZ77 compression) is turned on.
|
||||
------------------------------------------------------------------------------------
|
||||
@ -37,7 +37,7 @@ zlib 1.2.7 - General purpose LZ77 compression library
|
||||
See zlib home page http://www.zlib.net
|
||||
for details and links to the source code
|
||||
|
||||
No preprocessor definition is needed to make highgui use this library -
|
||||
No preprocessor definition is needed to make imgcodecs use this library -
|
||||
it is included automatically if either libpng or libtiff are used.
|
||||
------------------------------------------------------------------------------------
|
||||
jasper-1.900.1 - JasPer is a collection of software
|
||||
|
6
3rdparty/tbb/CMakeLists.txt
vendored
6
3rdparty/tbb/CMakeLists.txt
vendored
@ -232,9 +232,9 @@ if(ENABLE_SOLUTION_FOLDERS)
|
||||
endif()
|
||||
|
||||
ocv_install_target(tbb EXPORT OpenCVModules
|
||||
RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main
|
||||
LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
|
||||
ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main
|
||||
RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs
|
||||
LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs
|
||||
ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev
|
||||
)
|
||||
|
||||
# get TBB version
|
||||
|
4
3rdparty/zlib/CMakeLists.txt
vendored
4
3rdparty/zlib/CMakeLists.txt
vendored
@ -82,7 +82,7 @@ if(UNIX)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wattributes -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations)
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wshorten-64-to-32 -Wattributes -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations)
|
||||
|
||||
set_target_properties(${ZLIB_LIBRARY} PROPERTIES
|
||||
OUTPUT_NAME ${ZLIB_LIBRARY}
|
||||
@ -95,5 +95,5 @@ if(ENABLE_SOLUTION_FOLDERS)
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
ocv_install_target(${ZLIB_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main)
|
||||
ocv_install_target(${ZLIB_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
|
||||
endif()
|
||||
|
292
CMakeLists.txt
292
CMakeLists.txt
@ -6,6 +6,8 @@
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
include(cmake/OpenCVMinDepVersions.cmake)
|
||||
|
||||
if(CMAKE_GENERATOR MATCHES Xcode AND XCODE_VERSION VERSION_GREATER 4.3)
|
||||
@ -36,6 +38,11 @@ if(POLICY CMP0022)
|
||||
cmake_policy(SET CMP0022 OLD)
|
||||
endif()
|
||||
|
||||
if(POLICY CMP0026)
|
||||
# silence cmake 3.0+ warnings about reading LOCATION attribute
|
||||
cmake_policy(SET CMP0026 OLD)
|
||||
endif()
|
||||
|
||||
# must go before the project command
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
|
||||
if(DEFINED CMAKE_BUILD_TYPE)
|
||||
@ -116,23 +123,26 @@ endif()
|
||||
OCV_OPTION(WITH_1394 "Include IEEE1394 support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O" ON IF IOS)
|
||||
OCV_OPTION(WITH_CARBON "Use Carbon for UI instead of Cocoa" OFF IF APPLE )
|
||||
OCV_OPTION(WITH_CUDA "Include NVidia Cuda Runtime support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_CUFFT "Include NVidia Cuda Fast Fourier Transform (FFT) library support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_CUBLAS "Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support" OFF IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_NVCUVID "Include NVidia Video Decoding library support" OFF IF (NOT ANDROID AND NOT IOS AND NOT APPLE) )
|
||||
OCV_OPTION(WITH_VTK "Include VTK library support (and build opencv_viz module eiher)" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_CUDA "Include NVidia Cuda Runtime support" ON IF (NOT IOS) )
|
||||
OCV_OPTION(WITH_CUFFT "Include NVidia Cuda Fast Fourier Transform (FFT) library support" ON IF (NOT IOS) )
|
||||
OCV_OPTION(WITH_CUBLAS "Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support" OFF IF (NOT IOS) )
|
||||
OCV_OPTION(WITH_NVCUVID "Include NVidia Video Decoding library support" OFF IF (NOT IOS AND NOT APPLE) )
|
||||
OCV_OPTION(WITH_EIGEN "Include Eigen2/Eigen3 support" ON)
|
||||
OCV_OPTION(WITH_VFW "Include Video for Windows support" ON IF WIN32 )
|
||||
OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON IF (NOT ANDROID AND NOT IOS))
|
||||
OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) )
|
||||
OCV_OPTION(WITH_GSTREAMER_1_X "Include Gstreamer 1.x support" OFF)
|
||||
OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON IF (UNIX AND NOT ANDROID) )
|
||||
OCV_OPTION(WITH_GSTREAMER_0_10 "Enable Gstreamer 0.10 support (instead of 1.x)" OFF )
|
||||
OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) )
|
||||
OCV_OPTION(WITH_IPP "Include Intel IPP support" OFF IF (MSVC OR X86 OR X86_64) )
|
||||
OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) )
|
||||
OCV_OPTION(WITH_IPP "Include Intel IPP support" ON IF (X86_64 OR X86) )
|
||||
OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) )
|
||||
OCV_OPTION(WITH_JPEG "Include JPEG support" ON)
|
||||
OCV_OPTION(WITH_WEBP "Include WebP support" ON IF (NOT IOS) )
|
||||
OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" ON IF (NOT IOS) )
|
||||
OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF IF (NOT ANDROID AND NOT APPLE) )
|
||||
OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF IF (NOT ANDROID) )
|
||||
OCV_OPTION(WITH_OPENNI "Include OpenNI support" OFF IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_OPENNI2 "Include OpenNI2 support" OFF IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_PNG "Include PNG support" ON)
|
||||
OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_GIGEAPI "Include Smartek GigE support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
@ -146,15 +156,19 @@ OCV_OPTION(WITH_TIFF "Include TIFF support" ON
|
||||
OCV_OPTION(WITH_UNICAP "Include Unicap support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) )
|
||||
OCV_OPTION(WITH_V4L "Include Video 4 Linux support" ON IF (UNIX AND NOT ANDROID) )
|
||||
OCV_OPTION(WITH_LIBV4L "Use libv4l for Video 4 Linux support" ON IF (UNIX AND NOT ANDROID) )
|
||||
OCV_OPTION(WITH_DSHOW "Build HighGUI with DirectShow support" ON IF (WIN32 AND NOT ARM) )
|
||||
OCV_OPTION(WITH_MSMF "Build HighGUI with Media Foundation support" OFF IF WIN32 )
|
||||
OCV_OPTION(WITH_XIMEA "Include XIMEA cameras support" OFF IF (NOT ANDROID AND NOT APPLE) )
|
||||
OCV_OPTION(WITH_DSHOW "Build VideoIO with DirectShow support" ON IF (WIN32 AND NOT ARM) )
|
||||
OCV_OPTION(WITH_MSMF "Build VideoIO with Media Foundation support" OFF IF WIN32 )
|
||||
OCV_OPTION(WITH_XIMEA "Include XIMEA cameras support" OFF IF (NOT ANDROID) )
|
||||
OCV_OPTION(WITH_XINE "Include Xine support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) )
|
||||
OCV_OPTION(WITH_CLP "Include Clp support (EPL)" OFF)
|
||||
OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
|
||||
OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" NOT ANDROID IF (NOT IOS) )
|
||||
OCV_OPTION(WITH_OPENCL_SVM "Include OpenCL Shared Virtual Memory support" OFF ) # experimental
|
||||
OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF WIN32 )
|
||||
OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF WIN32 )
|
||||
OCV_OPTION(WITH_IPP_A "Include Intel IPP_A support" OFF IF (MSVC OR X86 OR X86_64) )
|
||||
OCV_OPTION(WITH_GDAL "Include GDAL Support" OFF IF (NOT ANDROID AND NOT IOS) )
|
||||
|
||||
# OpenCV build components
|
||||
# ===================================================
|
||||
@ -168,9 +182,11 @@ OCV_OPTION(BUILD_PERF_TESTS "Build performance tests"
|
||||
OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" ON IF (NOT IOS) )
|
||||
OCV_OPTION(BUILD_WITH_DEBUG_INFO "Include debug info into debug libs (not MSCV only)" ON )
|
||||
OCV_OPTION(BUILD_WITH_STATIC_CRT "Enables use of staticaly linked CRT for staticaly linked OpenCV" ON IF MSVC )
|
||||
OCV_OPTION(BUILD_WITH_DYNAMIC_IPP "Enables dynamic linking of IPP (only for standalone IPP)" OFF )
|
||||
OCV_OPTION(BUILD_FAT_JAVA_LIB "Create fat java wrapper containing the whole OpenCV library" ON IF NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX )
|
||||
OCV_OPTION(BUILD_ANDROID_SERVICE "Build OpenCV Manager for Google Play" OFF IF ANDROID AND ANDROID_SOURCE_TREE )
|
||||
OCV_OPTION(BUILD_ANDROID_PACKAGE "Build platform-specific package for Google Play" OFF IF ANDROID )
|
||||
OCV_OPTION(BUILD_CUDA_STUBS "Build CUDA modules stubs when no CUDA SDK" OFF IF (NOT IOS) )
|
||||
|
||||
# 3rd party libs
|
||||
OCV_OPTION(BUILD_ZLIB "Build zlib from source" WIN32 OR APPLE )
|
||||
@ -188,27 +204,39 @@ OCV_OPTION(INSTALL_C_EXAMPLES "Install C examples" OFF )
|
||||
OCV_OPTION(INSTALL_PYTHON_EXAMPLES "Install Python examples" OFF )
|
||||
OCV_OPTION(INSTALL_ANDROID_EXAMPLES "Install Android examples" OFF IF ANDROID )
|
||||
OCV_OPTION(INSTALL_TO_MANGLED_PATHS "Enables mangled install paths, that help with side by side installs." OFF IF (UNIX AND NOT ANDROID AND NOT IOS AND BUILD_SHARED_LIBS) )
|
||||
|
||||
OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binaries and test data" OFF)
|
||||
|
||||
# OpenCV build options
|
||||
# ===================================================
|
||||
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" ON IF (NOT IOS) )
|
||||
OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )
|
||||
OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CMAKE_COMPILER_IS_GNUCXX )
|
||||
OCV_OPTION(ENABLE_COVERAGE "Enable coverage collection with GCov" OFF IF CMAKE_COMPILER_IS_GNUCXX )
|
||||
OCV_OPTION(ENABLE_OMIT_FRAME_POINTER "Enable -fomit-frame-pointer for GCC" ON IF CMAKE_COMPILER_IS_GNUCXX AND NOT (APPLE AND CMAKE_COMPILER_IS_CLANGCXX) )
|
||||
OCV_OPTION(ENABLE_POWERPC "Enable PowerPC for GCC" ON IF (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) )
|
||||
OCV_OPTION(ENABLE_FAST_MATH "Enable -ffast-math (not recommended for GCC 4.6.x)" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_SSE "Enable SSE instructions" ON IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_SSE2 "Enable SSE2 instructions" ON IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_SSE3 "Enable SSE3 instructions" ON IF ((CV_ICC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_SSSE3 "Enable SSSE3 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_SSE41 "Enable SSE4.1 instructions" OFF IF ((CV_ICC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_SSE42 "Enable SSE4.2 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_SSE3 "Enable SSE3 instructions" ON IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX OR CV_ICC) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_SSSE3 "Enable SSSE3 instructions" OFF IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_SSE41 "Enable SSE4.1 instructions" OFF IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX OR CV_ICC) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_SSE42 "Enable SSE4.2 instructions" OFF IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_POPCNT "Enable POPCNT instructions" OFF IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_AVX "Enable AVX instructions" OFF IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_NEON "Enable NEON instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND ARM) )
|
||||
OCV_OPTION(ENABLE_AVX2 "Enable AVX2 instructions" OFF IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_FMA3 "Enable FMA3 instructions" OFF IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) )
|
||||
OCV_OPTION(ENABLE_NEON "Enable NEON instructions" OFF IF CMAKE_COMPILER_IS_GNUCXX AND (ARM OR IOS) )
|
||||
OCV_OPTION(ENABLE_VFPV3 "Enable VFPv3-D32 instructions" OFF IF CMAKE_COMPILER_IS_GNUCXX AND (ARM OR IOS) )
|
||||
OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF )
|
||||
OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF )
|
||||
OCV_OPTION(ENABLE_WINRT_MODE "Build with Windows Runtime support" OFF IF WIN32 )
|
||||
OCV_OPTION(ENABLE_WINRT_MODE_NATIVE "Build with Windows Runtime native C++ support" OFF IF WIN32 )
|
||||
OCV_OPTION(ANDROID_EXAMPLES_WITH_LIBS "Build binaries of Android examples with native libraries" OFF IF ANDROID )
|
||||
OCV_OPTION(ENABLE_IMPL_COLLECTION "Collect implementation data on function call" OFF )
|
||||
|
||||
if(ENABLE_IMPL_COLLECTION)
|
||||
add_definitions(-DCV_COLLECT_IMPL_DATA)
|
||||
endif()
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
@ -224,6 +252,15 @@ include(cmake/OpenCVVersion.cmake)
|
||||
# Save libs and executables in the same place
|
||||
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Output directory for applications" )
|
||||
|
||||
if (ANDROID)
|
||||
if (ANDROID_ABI MATCHES "NEON")
|
||||
set(ENABLE_NEON ON)
|
||||
endif()
|
||||
if (ANDROID_ABI MATCHES "VFPV3")
|
||||
set(ENABLE_VFPV3 ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ANDROID OR WIN32)
|
||||
set(OPENCV_DOC_INSTALL_PATH doc)
|
||||
elseif(INSTALL_TO_MANGLED_PATHS)
|
||||
@ -232,20 +269,44 @@ else()
|
||||
set(OPENCV_DOC_INSTALL_PATH share/OpenCV/doc)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
if(WIN32 AND CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
|
||||
if(DEFINED OpenCV_RUNTIME AND DEFINED OpenCV_ARCH)
|
||||
set(OpenCV_INSTALL_BINARIES_PREFIX "${OpenCV_ARCH}/${OpenCV_RUNTIME}/")
|
||||
else()
|
||||
message(STATUS "Can't detect runtime and/or arch")
|
||||
set(OpenCV_INSTALL_BINARIES_PREFIX "")
|
||||
endif()
|
||||
elseif(ANDROID)
|
||||
set(OpenCV_INSTALL_BINARIES_PREFIX "sdk/native/")
|
||||
else()
|
||||
set(OpenCV_INSTALL_BINARIES_PREFIX "")
|
||||
endif()
|
||||
|
||||
set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples")
|
||||
if(ANDROID)
|
||||
set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples/${ANDROID_NDK_ABI_NAME}")
|
||||
else()
|
||||
set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples")
|
||||
endif()
|
||||
|
||||
set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin")
|
||||
if(ANDROID)
|
||||
set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin/${ANDROID_NDK_ABI_NAME}")
|
||||
else()
|
||||
set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin")
|
||||
endif()
|
||||
|
||||
if(NOT OPENCV_TEST_INSTALL_PATH)
|
||||
set(OPENCV_TEST_INSTALL_PATH "${OPENCV_BIN_INSTALL_PATH}")
|
||||
endif()
|
||||
|
||||
if(OPENCV_TEST_DATA_PATH AND NOT OPENCV_TEST_DATA_INSTALL_PATH)
|
||||
if(ANDROID)
|
||||
set(OPENCV_TEST_DATA_INSTALL_PATH "sdk/etc/testdata")
|
||||
elseif(WIN32)
|
||||
set(OPENCV_TEST_DATA_INSTALL_PATH "testdata")
|
||||
else()
|
||||
set(OPENCV_TEST_DATA_INSTALL_PATH "share/OpenCV/testdata")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
set(LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/lib/${ANDROID_NDK_ABI_NAME}")
|
||||
@ -254,19 +315,22 @@ if(ANDROID)
|
||||
set(OPENCV_3P_LIB_INSTALL_PATH sdk/native/3rdparty/libs/${ANDROID_NDK_ABI_NAME})
|
||||
set(OPENCV_CONFIG_INSTALL_PATH sdk/native/jni)
|
||||
set(OPENCV_INCLUDE_INSTALL_PATH sdk/native/jni/include)
|
||||
set(OPENCV_SAMPLES_SRC_INSTALL_PATH samples/native)
|
||||
else()
|
||||
set(LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/lib")
|
||||
set(3P_LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/3rdparty/lib${LIB_SUFFIX}")
|
||||
if(WIN32)
|
||||
if(WIN32 AND CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
|
||||
if(OpenCV_STATIC)
|
||||
set(OPENCV_LIB_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib${LIB_SUFFIX}")
|
||||
else()
|
||||
set(OPENCV_LIB_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}lib${LIB_SUFFIX}")
|
||||
endif()
|
||||
set(OPENCV_3P_LIB_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib${LIB_SUFFIX}")
|
||||
set(OPENCV_SAMPLES_SRC_INSTALL_PATH samples/native)
|
||||
else()
|
||||
set(OPENCV_LIB_INSTALL_PATH lib${LIB_SUFFIX})
|
||||
set(OPENCV_3P_LIB_INSTALL_PATH share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH})
|
||||
set(OPENCV_SAMPLES_SRC_INSTALL_PATH share/OpenCV/samples)
|
||||
endif()
|
||||
set(OPENCV_INCLUDE_INSTALL_PATH "include")
|
||||
|
||||
@ -299,6 +363,9 @@ if(DEFINED CMAKE_DEBUG_POSTFIX)
|
||||
set(OPENCV_DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
|
||||
endif()
|
||||
|
||||
if(INSTALL_CREATE_DISTRIB AND BUILD_SHARED_LIBS AND NOT DEFINED BUILD_opencv_world)
|
||||
set(BUILD_opencv_world ON CACHE INTERNAL "")
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Path for build/platform -specific headers
|
||||
@ -317,7 +384,7 @@ set(OPENCV_EXTRA_MODULES_PATH "" CACHE PATH "Where to look for additional OpenCV
|
||||
find_host_package(Git QUIET)
|
||||
|
||||
if(GIT_FOUND)
|
||||
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty --match "2.[0-9].[0-9]*"
|
||||
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty --match "[0-9].[0-9].[0-9]*"
|
||||
WORKING_DIRECTORY "${OpenCV_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE OPENCV_VCSVERSION
|
||||
RESULT_VARIABLE GIT_RESULT
|
||||
@ -371,6 +438,8 @@ if(UNIX)
|
||||
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} dl m log)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD|DragonFly")
|
||||
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} m pthread)
|
||||
elseif(EMSCRIPTEN)
|
||||
# no need to link to system libs with emscripten
|
||||
else()
|
||||
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} dl m pthread rt)
|
||||
endif()
|
||||
@ -382,6 +451,19 @@ endif()
|
||||
include(cmake/OpenCVPCHSupport.cmake)
|
||||
include(cmake/OpenCVModule.cmake)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Detect endianness of build platform
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL iOS)
|
||||
# test_big_endian needs try_compile, which doesn't work for iOS
|
||||
# http://public.kitware.com/Bug/view.php?id=12288
|
||||
set(WORDS_BIGENDIAN 0)
|
||||
else()
|
||||
include(TestBigEndian)
|
||||
test_big_endian(WORDS_BIGENDIAN)
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Detect 3rd-party libraries
|
||||
# ----------------------------------------------------------------------------
|
||||
@ -391,14 +473,26 @@ include(cmake/OpenCVFindLibsGUI.cmake)
|
||||
include(cmake/OpenCVFindLibsVideo.cmake)
|
||||
include(cmake/OpenCVFindLibsPerf.cmake)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Detect other 3rd-party libraries/tools
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# --- LATEX for pdf documentation ---
|
||||
# --- Doxygen and PlantUML for documentation ---
|
||||
unset(DOXYGEN_FOUND CACHE)
|
||||
if(BUILD_DOCS)
|
||||
include(cmake/OpenCVFindLATEX.cmake)
|
||||
find_package(Doxygen)
|
||||
if (PLANTUML_JAR)
|
||||
message(STATUS "Using PlantUML path from command line: ${PLANTUML_JAR}")
|
||||
elseif(DEFINED ENV{PLANTUML_JAR})
|
||||
set(PLANTUML_JAR $ENV{PLANTUML_JAR})
|
||||
message(STATUS "Using PLantUML path from environment: ${PLANTUML_JAR}")
|
||||
else()
|
||||
message(STATUS "To enable PlantUML support, set PLANTUML_JAR environment variable or pass -DPLANTUML_JAR=<filepath> option to cmake")
|
||||
endif()
|
||||
if (PLANTUML_JAR AND DOXYGEN_VERSION VERSION_LESS 1.8.8)
|
||||
message(STATUS "You need Doxygen version 1.8.8 or later to use PlantUML")
|
||||
unset(PLANTUML_JAR)
|
||||
endif()
|
||||
endif(BUILD_DOCS)
|
||||
|
||||
# --- Python Support ---
|
||||
@ -427,9 +521,16 @@ if(WITH_OPENCL)
|
||||
include(cmake/OpenCVDetectOpenCL.cmake)
|
||||
endif()
|
||||
|
||||
# --- DirectX ---
|
||||
if(WITH_DIRECTX)
|
||||
include(cmake/OpenCVDetectDirectX.cmake)
|
||||
endif()
|
||||
|
||||
# --- Matlab/Octave ---
|
||||
include(cmake/OpenCVFindMatlab.cmake)
|
||||
|
||||
include(cmake/OpenCVDetectVTK.cmake)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Add CUDA libraries (needed for apps/tools, samples)
|
||||
# ----------------------------------------------------------------------------
|
||||
@ -495,7 +596,6 @@ endif()
|
||||
# ----------------------------------------------------------------------------
|
||||
# Finalization: generate configuration-based files
|
||||
# ----------------------------------------------------------------------------
|
||||
ocv_track_build_dependencies()
|
||||
|
||||
# Generate platform-dependent and configuration-dependent headers
|
||||
include(cmake/OpenCVGenHeaders.cmake)
|
||||
@ -512,6 +612,45 @@ include(cmake/OpenCVGenConfig.cmake)
|
||||
# Generate Info.plist for the IOS framework
|
||||
include(cmake/OpenCVGenInfoPlist.cmake)
|
||||
|
||||
# Generate environment setup file
|
||||
if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH AND UNIX)
|
||||
if(ANDROID)
|
||||
get_filename_component(TEST_PATH ${OPENCV_TEST_INSTALL_PATH} DIRECTORY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_run_all_tests_android.sh.in"
|
||||
"${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" @ONLY)
|
||||
install(PROGRAMS "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh"
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT tests)
|
||||
else()
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_run_all_tests_unix.sh.in"
|
||||
"${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" @ONLY)
|
||||
install(PROGRAMS "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh"
|
||||
DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests)
|
||||
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT OPENCV_README_FILE)
|
||||
if(ANDROID)
|
||||
set(OPENCV_README_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/android/README.android)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT OPENCV_LICENSE_FILE)
|
||||
set(OPENCV_LICENSE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
|
||||
endif()
|
||||
|
||||
# for UNIX it does not make sense as LICENSE and readme will be part of the package automatically
|
||||
if(ANDROID OR NOT UNIX)
|
||||
install(FILES ${OPENCV_LICENSE_FILE}
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT libs)
|
||||
if(OPENCV_README_FILE)
|
||||
install(FILES ${OPENCV_README_FILE}
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT libs)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Summary:
|
||||
# ----------------------------------------------------------------------------
|
||||
@ -621,7 +760,7 @@ endif()
|
||||
if(WIN32)
|
||||
status("")
|
||||
status(" Windows RT support:" HAVE_WINRT THEN YES ELSE NO)
|
||||
if (ENABLE_WINRT_MODE)
|
||||
if (ENABLE_WINRT_MODE OR ENABLE_WINRT_MODE_NATIVE)
|
||||
status(" Windows SDK v8.0:" ${WINDOWS_SDK_PATH})
|
||||
status(" Visual Studio 2012:" ${VISUAL_STUDIO_PATH})
|
||||
endif()
|
||||
@ -651,14 +790,21 @@ else()
|
||||
status(" Cocoa:" YES)
|
||||
endif()
|
||||
else()
|
||||
status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO)
|
||||
status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO)
|
||||
if(HAVE_GTK3)
|
||||
status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO)
|
||||
elseif(HAVE_GTK)
|
||||
status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO)
|
||||
else()
|
||||
status(" GTK+:" NO)
|
||||
endif()
|
||||
status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO)
|
||||
status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
status(" OpenGL support:" HAVE_OPENGL THEN "YES (${OPENGL_LIBRARIES})" ELSE NO)
|
||||
status(" VTK support:" HAVE_VTK THEN "YES (ver ${VTK_VERSION})" ELSE NO)
|
||||
|
||||
# ========================== MEDIA IO ==========================
|
||||
status("")
|
||||
@ -702,6 +848,12 @@ else()
|
||||
status(" OpenEXR:" "NO")
|
||||
endif()
|
||||
|
||||
if( WITH_GDAL )
|
||||
status(" GDAL:" GDAL_FOUND THEN "${GDAL_LIBRARY}")
|
||||
else()
|
||||
status(" GDAL:" "NO")
|
||||
endif()
|
||||
|
||||
# ========================== VIDEO IO ==========================
|
||||
status("")
|
||||
status(" Video I/O:")
|
||||
@ -759,6 +911,11 @@ if(DEFINED WITH_OPENNI)
|
||||
THEN "YES (${OPENNI_PRIME_SENSOR_MODULE})" ELSE NO)
|
||||
endif(DEFINED WITH_OPENNI)
|
||||
|
||||
if(DEFINED WITH_OPENNI2)
|
||||
status(" OpenNI2:" HAVE_OPENNI2 THEN "YES (ver ${OPENNI2_VERSION_STRING}, build ${OPENNI2_VERSION_BUILD})"
|
||||
ELSE NO)
|
||||
endif(DEFINED WITH_OPENNI2)
|
||||
|
||||
if(DEFINED WITH_PVAPI)
|
||||
status(" PvAPI:" HAVE_PVAPI THEN YES ELSE NO)
|
||||
endif(DEFINED WITH_PVAPI)
|
||||
@ -810,17 +967,29 @@ if(DEFINED WITH_XINE)
|
||||
status(" Xine:" HAVE_XINE THEN "YES (ver ${ALIASOF_libxine_VERSION})" ELSE NO)
|
||||
endif(DEFINED WITH_XINE)
|
||||
|
||||
if(DEFINED WITH_INTELPERC)
|
||||
status(" Intel PerC:" HAVE_INTELPERC THEN "YES" ELSE NO)
|
||||
endif(DEFINED WITH_INTELPERC)
|
||||
|
||||
|
||||
# ========================== Other third-party libraries ==========================
|
||||
status("")
|
||||
status(" Other third-party libraries:")
|
||||
|
||||
if(WITH_IPP AND IPP_FOUND)
|
||||
status(" Use IPP:" "${IPP_LATEST_VERSION_STR} [${IPP_LATEST_VERSION_MAJOR}.${IPP_LATEST_VERSION_MINOR}.${IPP_LATEST_VERSION_BUILD}]")
|
||||
if(WITH_IPP AND HAVE_IPP)
|
||||
status(" Use IPP:" "${IPP_VERSION_STR} [${IPP_VERSION_MAJOR}.${IPP_VERSION_MINOR}.${IPP_VERSION_BUILD}]")
|
||||
status(" at:" "${IPP_ROOT_DIR}")
|
||||
if(NOT HAVE_IPP_ICV_ONLY)
|
||||
status(" linked:" BUILD_WITH_DYNAMIC_IPP THEN "dynamic" ELSE "static")
|
||||
endif()
|
||||
else()
|
||||
status(" Use IPP:" WITH_IPP AND NOT IPP_FOUND THEN "IPP not found" ELSE NO)
|
||||
status(" Use IPP:" WITH_IPP AND NOT HAVE_IPP THEN "IPP not found" ELSE NO)
|
||||
endif()
|
||||
|
||||
if(DEFINED WITH_IPP_A)
|
||||
status(" Use IPP Async:" HAVE_IPP_A THEN "YES" ELSE NO)
|
||||
endif(DEFINED WITH_IPP_A)
|
||||
|
||||
status(" Use Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO)
|
||||
status(" Use TBB:" HAVE_TBB THEN "YES (ver ${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} interface ${TBB_INTERFACE_VERSION})" ELSE NO)
|
||||
status(" Use OpenMP:" HAVE_OPENMP THEN YES ELSE NO)
|
||||
@ -876,18 +1045,34 @@ endif()
|
||||
|
||||
# ========================== python ==========================
|
||||
status("")
|
||||
status(" Python:")
|
||||
status(" Interpreter:" PYTHONINTERP_FOUND THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_STRING})" ELSE NO)
|
||||
if(BUILD_opencv_python)
|
||||
if(PYTHONLIBS_VERSION_STRING)
|
||||
status(" Libraries:" HAVE_opencv_python THEN "${PYTHON_LIBRARIES} (ver ${PYTHONLIBS_VERSION_STRING})" ELSE NO)
|
||||
status(" Python 2:")
|
||||
status(" Interpreter:" PYTHON2INTERP_FOUND THEN "${PYTHON2_EXECUTABLE} (ver ${PYTHON2_VERSION_STRING})" ELSE NO)
|
||||
if(BUILD_opencv_python2)
|
||||
if(PYTHON2LIBS_VERSION_STRING)
|
||||
status(" Libraries:" HAVE_opencv_python2 THEN "${PYTHON2_LIBRARIES} (ver ${PYTHON2LIBS_VERSION_STRING})" ELSE NO)
|
||||
else()
|
||||
status(" Libraries:" HAVE_opencv_python THEN "${PYTHON_LIBRARIES}" ELSE NO)
|
||||
status(" Libraries:" HAVE_opencv_python2 THEN "${PYTHON2_LIBRARIES}" ELSE NO)
|
||||
endif()
|
||||
status(" numpy:" PYTHON_NUMPY_INCLUDE_DIRS THEN "${PYTHON_NUMPY_INCLUDE_DIRS} (ver ${PYTHON_NUMPY_VERSION})" ELSE "NO (Python wrappers can not be generated)")
|
||||
status(" packages path:" PYTHON_EXECUTABLE THEN "${PYTHON_PACKAGES_PATH}" ELSE "-")
|
||||
status(" numpy:" PYTHON2_NUMPY_INCLUDE_DIRS THEN "${PYTHON2_NUMPY_INCLUDE_DIRS} (ver ${PYTHON2_NUMPY_VERSION})" ELSE "NO (Python wrappers can not be generated)")
|
||||
status(" packages path:" PYTHON2_EXECUTABLE THEN "${PYTHON2_PACKAGES_PATH}" ELSE "-")
|
||||
endif()
|
||||
|
||||
status("")
|
||||
status(" Python 3:")
|
||||
status(" Interpreter:" PYTHON3INTERP_FOUND THEN "${PYTHON3_EXECUTABLE} (ver ${PYTHON3_VERSION_STRING})" ELSE NO)
|
||||
if(BUILD_opencv_python3)
|
||||
if(PYTHON3LIBS_VERSION_STRING)
|
||||
status(" Libraries:" HAVE_opencv_python3 THEN "${PYTHON3_LIBRARIES} (ver ${PYTHON3LIBS_VERSION_STRING})" ELSE NO)
|
||||
else()
|
||||
status(" Libraries:" HAVE_opencv_python3 THEN "${PYTHON3_LIBRARIES}" ELSE NO)
|
||||
endif()
|
||||
status(" numpy:" PYTHON3_NUMPY_INCLUDE_DIRS THEN "${PYTHON3_NUMPY_INCLUDE_DIRS} (ver ${PYTHON3_NUMPY_VERSION})" ELSE "NO (Python3 wrappers can not be generated)")
|
||||
status(" packages path:" PYTHON3_EXECUTABLE THEN "${PYTHON3_PACKAGES_PATH}" ELSE "-")
|
||||
endif()
|
||||
|
||||
status("")
|
||||
status(" Python (for build):" PYTHON_DEFAULT_AVAILABLE THEN "${PYTHON_DEFAULT_EXECUTABLE}" ELSE NO)
|
||||
|
||||
# ========================== java ==========================
|
||||
status("")
|
||||
status(" Java:")
|
||||
@ -895,7 +1080,8 @@ status(" ant:" ANT_EXECUTABLE THEN "${ANT_EXECUTABLE} (ver ${A
|
||||
if(NOT ANDROID)
|
||||
status(" JNI:" JNI_INCLUDE_DIRS THEN "${JNI_INCLUDE_DIRS}" ELSE NO)
|
||||
endif()
|
||||
status(" Java tests:" BUILD_TESTS AND (CAN_BUILD_ANDROID_PROJECTS OR HAVE_opencv_java) THEN YES ELSE NO)
|
||||
status(" Java wrappers:" HAVE_opencv_java THEN YES ELSE NO)
|
||||
status(" Java tests:" BUILD_TESTS AND opencv_test_java_BINARY_DIR THEN YES ELSE NO)
|
||||
|
||||
# ========================= matlab =========================
|
||||
status("")
|
||||
@ -909,14 +1095,8 @@ endif()
|
||||
if(BUILD_DOCS)
|
||||
status("")
|
||||
status(" Documentation:")
|
||||
if(HAVE_SPHINX)
|
||||
status(" Build Documentation:" PDFLATEX_COMPILER THEN YES ELSE "YES (only HTML and without math expressions)")
|
||||
else()
|
||||
status(" Build Documentation:" NO)
|
||||
endif()
|
||||
status(" Sphinx:" HAVE_SPHINX THEN "${SPHINX_BUILD} (ver ${SPHINX_VERSION})" ELSE NO)
|
||||
status(" PdfLaTeX compiler:" PDFLATEX_COMPILER THEN "${PDFLATEX_COMPILER}" ELSE NO)
|
||||
status(" PlantUML:" PLANTUML THEN "${PLANTUML}" ELSE NO)
|
||||
status(" Doxygen:" DOXYGEN_FOUND THEN "${DOXYGEN_EXECUTABLE} (ver ${DOXYGEN_VERSION})" ELSE NO)
|
||||
status(" PlantUML:" PLANTUML_JAR THEN "${PLANTUML_JAR}" ELSE NO)
|
||||
endif()
|
||||
|
||||
# ========================== samples and tests ==========================
|
||||
@ -942,3 +1122,9 @@ ocv_finalize_status()
|
||||
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
message(WARNING "The source directory is the same as binary directory. \"make clean\" may damage the source tree")
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# CPack stuff
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
include(cmake/OpenCVPackaging.cmake)
|
||||
|
@ -1,16 +1,11 @@
|
||||
IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
|
||||
License Agreement
|
||||
For Open Source Computer Vision Library
|
||||
|
||||
Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
Third party copyrights are property of their respective owners.
|
||||
(3-clause BSD License)
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
@ -22,13 +17,14 @@ are permitted provided that the following conditions are met:
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* The name of the copyright holders may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
* Neither the names of the copyright holders nor the names of the contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
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 Intel Corporation or contributors be liable for any direct,
|
||||
In no event shall copyright holders 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
|
@ -1,5 +1,7 @@
|
||||
### OpenCV: Open Source Computer Vision Library
|
||||
|
||||
[![Gittip](http://img.shields.io/gittip/OpenCV.png)](https://www.gittip.com/OpenCV/)
|
||||
|
||||
#### Resources
|
||||
|
||||
* Homepage: <http://opencv.org>
|
||||
@ -18,6 +20,3 @@ Summary of guidelines:
|
||||
* Include tests and documentation;
|
||||
* Clean up "oops" commits before submitting;
|
||||
* Follow the coding style guide.
|
||||
|
||||
[![Donate OpenCV project](http://opencv.org/wp-content/uploads/2013/07/gittip1.png)](https://www.gittip.com/OpenCV/)
|
||||
[![Donate OpenCV project](http://opencv.org/wp-content/uploads/2013/07/paypal-donate-button.png)](https://www.paypal.com/cgi-bin/webscr?item_name=Donation+to+OpenCV&cmd=_donations&business=accountant%40opencv.org)
|
@ -1,6 +1,5 @@
|
||||
add_definitions(-D__OPENCV_BUILD=1)
|
||||
link_libraries(${OPENCV_LINKER_LIBS})
|
||||
|
||||
add_subdirectory(haartraining)
|
||||
add_subdirectory(traincascade)
|
||||
add_subdirectory(sft)
|
||||
add_subdirectory(createsamples)
|
||||
|
39
apps/createsamples/CMakeLists.txt
Normal file
39
apps/createsamples/CMakeLists.txt
Normal file
@ -0,0 +1,39 @@
|
||||
set(OPENCV_CREATESAMPLES_DEPS opencv_core opencv_imgproc opencv_objdetect opencv_imgcodecs opencv_highgui opencv_calib3d opencv_features2d opencv_videoio)
|
||||
ocv_check_dependencies(${OPENCV_CREATESAMPLES_DEPS})
|
||||
|
||||
if(NOT OCV_DEPENDENCIES_FOUND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(createsamples)
|
||||
set(the_target opencv_createsamples)
|
||||
|
||||
ocv_target_include_directories(${the_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv")
|
||||
ocv_target_include_modules(${the_target} ${OPENCV_CREATESAMPLES_DEPS})
|
||||
|
||||
file(GLOB SRCS *.cpp)
|
||||
file(GLOB HDRS *.h*)
|
||||
|
||||
set(createsamples_files ${SRCS} ${HDRS})
|
||||
|
||||
ocv_add_executable(${the_target} ${createsamples_files})
|
||||
ocv_target_link_libraries(${the_target} ${OPENCV_CREATESAMPLES_DEPS})
|
||||
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
|
||||
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
|
||||
INSTALL_NAME_DIR lib
|
||||
OUTPUT_NAME "opencv_createsamples")
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(${the_target} PROPERTIES FOLDER "applications")
|
||||
endif()
|
||||
|
||||
if(INSTALL_CREATE_DISTRIB)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev)
|
||||
endif()
|
||||
else()
|
||||
install(TARGETS ${the_target} OPTIONAL RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev)
|
||||
endif()
|
@ -53,7 +53,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "cvhaartraining.h"
|
||||
#include "utility.hpp"
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
@ -39,23 +39,117 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
/*
|
||||
* cvsamples.cpp
|
||||
*
|
||||
* support functions for training and test samples creation.
|
||||
*/
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#include "cvhaartraining.h"
|
||||
#include "_cvhaartraining.h"
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/* if ipl.h file is included then iplWarpPerspectiveQ function
|
||||
is used for image transformation during samples creation;
|
||||
otherwise internal cvWarpPerspective function is used */
|
||||
#include "utility.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/imgcodecs/imgcodecs_c.h"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
//#include <ipl.h>
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 512
|
||||
#endif /* PATH_MAX */
|
||||
|
||||
#include "cv.h"
|
||||
#include "highgui.h"
|
||||
#define __BEGIN__ __CV_BEGIN__
|
||||
#define __END__ __CV_END__
|
||||
#define EXIT __CV_EXIT__
|
||||
|
||||
static int icvMkDir( const char* filename )
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
char* p;
|
||||
int pos;
|
||||
|
||||
#ifdef _WIN32
|
||||
struct _stat st;
|
||||
#else /* _WIN32 */
|
||||
struct stat st;
|
||||
mode_t mode;
|
||||
|
||||
mode = 0755;
|
||||
#endif /* _WIN32 */
|
||||
|
||||
strcpy( path, filename );
|
||||
|
||||
p = path;
|
||||
for( ; ; )
|
||||
{
|
||||
pos = (int)strcspn( p, "/\\" );
|
||||
|
||||
if( pos == (int) strlen( p ) ) break;
|
||||
if( pos != 0 )
|
||||
{
|
||||
p[pos] = '\0';
|
||||
|
||||
#ifdef _WIN32
|
||||
if( p[pos-1] != ':' )
|
||||
{
|
||||
if( _stat( path, &st ) != 0 )
|
||||
{
|
||||
if( _mkdir( path ) != 0 ) return 0;
|
||||
}
|
||||
}
|
||||
#else /* _WIN32 */
|
||||
if( stat( path, &st ) != 0 )
|
||||
{
|
||||
if( mkdir( path, mode ) != 0 ) return 0;
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
p[pos] = '/';
|
||||
|
||||
p += pos + 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void icvWriteVecHeader( FILE* file, int count, int width, int height )
|
||||
{
|
||||
int vecsize;
|
||||
short tmp;
|
||||
|
||||
/* number of samples */
|
||||
fwrite( &count, sizeof( count ), 1, file );
|
||||
/* vector size */
|
||||
vecsize = width * height;
|
||||
fwrite( &vecsize, sizeof( vecsize ), 1, file );
|
||||
/* min/max values */
|
||||
tmp = 0;
|
||||
fwrite( &tmp, sizeof( tmp ), 1, file );
|
||||
fwrite( &tmp, sizeof( tmp ), 1, file );
|
||||
}
|
||||
|
||||
static void icvWriteVecSample( FILE* file, CvArr* sample )
|
||||
{
|
||||
CvMat* mat, stub;
|
||||
int r, c;
|
||||
short tmp;
|
||||
uchar chartmp;
|
||||
|
||||
mat = cvGetMat( sample, &stub );
|
||||
chartmp = 0;
|
||||
fwrite( &chartmp, sizeof( chartmp ), 1, file );
|
||||
for( r = 0; r < mat->rows; r++ )
|
||||
{
|
||||
for( c = 0; c < mat->cols; c++ )
|
||||
{
|
||||
tmp = (short) (CV_MAT_ELEM( *mat, uchar, r, c ));
|
||||
fwrite( &tmp, sizeof( tmp ), 1, file );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculates coefficients of perspective transformation
|
||||
* which maps <quad> into rectangle ((0,0), (w,0), (w,h), (h,0)):
|
||||
@ -83,8 +177,7 @@
|
||||
* cij - coeffs[i][j], coeffs[2][2] = 1
|
||||
* (ui, vi) - rectangle vertices
|
||||
*/
|
||||
static void cvGetPerspectiveTransform( CvSize src_size, double quad[4][2],
|
||||
double coeffs[3][3] )
|
||||
static void cvGetPerspectiveTransform( CvSize src_size, double quad[4][2], double coeffs[3][3] )
|
||||
{
|
||||
//CV_FUNCNAME( "cvWarpPerspective" );
|
||||
|
||||
@ -460,7 +553,58 @@ void icvRandomQuad( int width, int height, double quad[4][2],
|
||||
}
|
||||
|
||||
|
||||
int icvStartSampleDistortion( const char* imgfilename, int bgcolor, int bgthreshold,
|
||||
typedef struct CvSampleDistortionData
|
||||
{
|
||||
IplImage* src;
|
||||
IplImage* erode;
|
||||
IplImage* dilate;
|
||||
IplImage* mask;
|
||||
IplImage* img;
|
||||
IplImage* maskimg;
|
||||
int dx;
|
||||
int dy;
|
||||
int bgcolor;
|
||||
} CvSampleDistortionData;
|
||||
|
||||
#if defined CV_OPENMP && (defined _MSC_VER || defined CV_ICC)
|
||||
#define CV_OPENMP 1
|
||||
#else
|
||||
#undef CV_OPENMP
|
||||
#endif
|
||||
|
||||
typedef struct CvBackgroundData
|
||||
{
|
||||
int count;
|
||||
char** filename;
|
||||
int last;
|
||||
int round;
|
||||
CvSize winsize;
|
||||
} CvBackgroundData;
|
||||
|
||||
typedef struct CvBackgroundReader
|
||||
{
|
||||
CvMat src;
|
||||
CvMat img;
|
||||
CvPoint offset;
|
||||
float scale;
|
||||
float scalefactor;
|
||||
float stepfactor;
|
||||
CvPoint point;
|
||||
} CvBackgroundReader;
|
||||
|
||||
/*
|
||||
* Background reader
|
||||
* Created in each thread
|
||||
*/
|
||||
CvBackgroundReader* cvbgreader = NULL;
|
||||
|
||||
#if defined CV_OPENMP
|
||||
#pragma omp threadprivate(cvbgreader)
|
||||
#endif
|
||||
|
||||
CvBackgroundData* cvbgdata = NULL;
|
||||
|
||||
static int icvStartSampleDistortion( const char* imgfilename, int bgcolor, int bgthreshold,
|
||||
CvSampleDistortionData* data )
|
||||
{
|
||||
memset( data, 0, sizeof( *data ) );
|
||||
@ -546,6 +690,7 @@ int icvStartSampleDistortion( const char* imgfilename, int bgcolor, int bgthresh
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
void icvPlaceDistortedSample( CvArr* background,
|
||||
int inverse, int maxintensitydev,
|
||||
double maxxangle, double maxyangle, double maxzangle,
|
||||
@ -658,6 +803,7 @@ void icvPlaceDistortedSample( CvArr* background,
|
||||
cvReleaseImage( &maskimg );
|
||||
}
|
||||
|
||||
static
|
||||
void icvEndSampleDistortion( CvSampleDistortionData* data )
|
||||
{
|
||||
if( data->src )
|
||||
@ -686,40 +832,585 @@ void icvEndSampleDistortion( CvSampleDistortionData* data )
|
||||
}
|
||||
}
|
||||
|
||||
void icvWriteVecHeader( FILE* file, int count, int width, int height )
|
||||
static
|
||||
CvBackgroundData* icvCreateBackgroundData( const char* filename, CvSize winsize )
|
||||
{
|
||||
int vecsize;
|
||||
short tmp;
|
||||
CvBackgroundData* data = NULL;
|
||||
|
||||
/* number of samples */
|
||||
fwrite( &count, sizeof( count ), 1, file );
|
||||
/* vector size */
|
||||
vecsize = width * height;
|
||||
fwrite( &vecsize, sizeof( vecsize ), 1, file );
|
||||
/* min/max values */
|
||||
tmp = 0;
|
||||
fwrite( &tmp, sizeof( tmp ), 1, file );
|
||||
fwrite( &tmp, sizeof( tmp ), 1, file );
|
||||
const char* dir = NULL;
|
||||
char full[PATH_MAX];
|
||||
char* imgfilename = NULL;
|
||||
size_t datasize = 0;
|
||||
int count = 0;
|
||||
FILE* input = NULL;
|
||||
char* tmp = NULL;
|
||||
int len = 0;
|
||||
|
||||
assert( filename != NULL );
|
||||
|
||||
dir = strrchr( filename, '\\' );
|
||||
if( dir == NULL )
|
||||
{
|
||||
dir = strrchr( filename, '/' );
|
||||
}
|
||||
if( dir == NULL )
|
||||
{
|
||||
imgfilename = &(full[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy( &(full[0]), filename, (dir - filename + 1) );
|
||||
imgfilename = &(full[(dir - filename + 1)]);
|
||||
}
|
||||
|
||||
input = fopen( filename, "r" );
|
||||
if( input != NULL )
|
||||
{
|
||||
count = 0;
|
||||
datasize = 0;
|
||||
|
||||
/* count */
|
||||
while( !feof( input ) )
|
||||
{
|
||||
*imgfilename = '\0';
|
||||
if( !fgets( imgfilename, PATH_MAX - (int)(imgfilename - full) - 1, input ))
|
||||
break;
|
||||
len = (int)strlen( imgfilename );
|
||||
for( ; len > 0 && isspace(imgfilename[len-1]); len-- )
|
||||
imgfilename[len-1] = '\0';
|
||||
if( len > 0 )
|
||||
{
|
||||
if( (*imgfilename) == '#' ) continue; /* comment */
|
||||
count++;
|
||||
datasize += sizeof( char ) * (strlen( &(full[0]) ) + 1);
|
||||
}
|
||||
}
|
||||
if( count > 0 )
|
||||
{
|
||||
//rewind( input );
|
||||
fseek( input, 0, SEEK_SET );
|
||||
datasize += sizeof( *data ) + sizeof( char* ) * count;
|
||||
data = (CvBackgroundData*) cvAlloc( datasize );
|
||||
memset( (void*) data, 0, datasize );
|
||||
data->count = count;
|
||||
data->filename = (char**) (data + 1);
|
||||
data->last = 0;
|
||||
data->round = 0;
|
||||
data->winsize = winsize;
|
||||
tmp = (char*) (data->filename + data->count);
|
||||
count = 0;
|
||||
while( !feof( input ) )
|
||||
{
|
||||
*imgfilename = '\0';
|
||||
if( !fgets( imgfilename, PATH_MAX - (int)(imgfilename - full) - 1, input ))
|
||||
break;
|
||||
len = (int)strlen( imgfilename );
|
||||
if( len > 0 && imgfilename[len-1] == '\n' )
|
||||
imgfilename[len-1] = 0, len--;
|
||||
if( len > 0 )
|
||||
{
|
||||
if( (*imgfilename) == '#' ) continue; /* comment */
|
||||
data->filename[count++] = tmp;
|
||||
strcpy( tmp, &(full[0]) );
|
||||
tmp += strlen( &(full[0]) ) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose( input );
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void icvWriteVecSample( FILE* file, CvArr* sample )
|
||||
static
|
||||
void icvReleaseBackgroundData( CvBackgroundData** data )
|
||||
{
|
||||
CvMat* mat, stub;
|
||||
int r, c;
|
||||
short tmp;
|
||||
uchar chartmp;
|
||||
assert( data != NULL && (*data) != NULL );
|
||||
|
||||
mat = cvGetMat( sample, &stub );
|
||||
chartmp = 0;
|
||||
fwrite( &chartmp, sizeof( chartmp ), 1, file );
|
||||
for( r = 0; r < mat->rows; r++ )
|
||||
cvFree( data );
|
||||
}
|
||||
|
||||
static
|
||||
CvBackgroundReader* icvCreateBackgroundReader()
|
||||
{
|
||||
CvBackgroundReader* reader = NULL;
|
||||
|
||||
reader = (CvBackgroundReader*) cvAlloc( sizeof( *reader ) );
|
||||
memset( (void*) reader, 0, sizeof( *reader ) );
|
||||
reader->src = cvMat( 0, 0, CV_8UC1, NULL );
|
||||
reader->img = cvMat( 0, 0, CV_8UC1, NULL );
|
||||
reader->offset = cvPoint( 0, 0 );
|
||||
reader->scale = 1.0F;
|
||||
reader->scalefactor = 1.4142135623730950488016887242097F;
|
||||
reader->stepfactor = 0.5F;
|
||||
reader->point = reader->offset;
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
||||
static
|
||||
void icvReleaseBackgroundReader( CvBackgroundReader** reader )
|
||||
{
|
||||
assert( reader != NULL && (*reader) != NULL );
|
||||
|
||||
if( (*reader)->src.data.ptr != NULL )
|
||||
{
|
||||
for( c = 0; c < mat->cols; c++ )
|
||||
cvFree( &((*reader)->src.data.ptr) );
|
||||
}
|
||||
if( (*reader)->img.data.ptr != NULL )
|
||||
{
|
||||
cvFree( &((*reader)->img.data.ptr) );
|
||||
}
|
||||
|
||||
cvFree( reader );
|
||||
}
|
||||
|
||||
static
|
||||
void icvGetNextFromBackgroundData( CvBackgroundData* data,
|
||||
CvBackgroundReader* reader )
|
||||
{
|
||||
IplImage* img = NULL;
|
||||
size_t datasize = 0;
|
||||
int round = 0;
|
||||
int i = 0;
|
||||
CvPoint offset = cvPoint(0,0);
|
||||
|
||||
assert( data != NULL && reader != NULL );
|
||||
|
||||
if( reader->src.data.ptr != NULL )
|
||||
{
|
||||
cvFree( &(reader->src.data.ptr) );
|
||||
reader->src.data.ptr = NULL;
|
||||
}
|
||||
if( reader->img.data.ptr != NULL )
|
||||
{
|
||||
cvFree( &(reader->img.data.ptr) );
|
||||
reader->img.data.ptr = NULL;
|
||||
}
|
||||
|
||||
#ifdef CV_OPENMP
|
||||
#pragma omp critical(c_background_data)
|
||||
#endif /* CV_OPENMP */
|
||||
{
|
||||
for( i = 0; i < data->count; i++ )
|
||||
{
|
||||
tmp = (short) (CV_MAT_ELEM( *mat, uchar, r, c ));
|
||||
fwrite( &tmp, sizeof( tmp ), 1, file );
|
||||
round = data->round;
|
||||
|
||||
#ifdef CV_VERBOSE
|
||||
printf( "Open background image: %s\n", data->filename[data->last] );
|
||||
#endif /* CV_VERBOSE */
|
||||
|
||||
data->last = rand() % data->count;
|
||||
data->last %= data->count;
|
||||
img = cvLoadImage( data->filename[data->last], 0 );
|
||||
if( !img )
|
||||
continue;
|
||||
data->round += data->last / data->count;
|
||||
data->round = data->round % (data->winsize.width * data->winsize.height);
|
||||
|
||||
offset.x = round % data->winsize.width;
|
||||
offset.y = round / data->winsize.width;
|
||||
|
||||
offset.x = MIN( offset.x, img->width - data->winsize.width );
|
||||
offset.y = MIN( offset.y, img->height - data->winsize.height );
|
||||
|
||||
if( img != NULL && img->depth == IPL_DEPTH_8U && img->nChannels == 1 &&
|
||||
offset.x >= 0 && offset.y >= 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
if( img != NULL )
|
||||
cvReleaseImage( &img );
|
||||
img = NULL;
|
||||
}
|
||||
}
|
||||
if( img == NULL )
|
||||
{
|
||||
/* no appropriate image */
|
||||
|
||||
#ifdef CV_VERBOSE
|
||||
printf( "Invalid background description file.\n" );
|
||||
#endif /* CV_VERBOSE */
|
||||
|
||||
assert( 0 );
|
||||
exit( 1 );
|
||||
}
|
||||
datasize = sizeof( uchar ) * img->width * img->height;
|
||||
reader->src = cvMat( img->height, img->width, CV_8UC1, (void*) cvAlloc( datasize ) );
|
||||
cvCopy( img, &reader->src, NULL );
|
||||
cvReleaseImage( &img );
|
||||
img = NULL;
|
||||
|
||||
//reader->offset.x = round % data->winsize.width;
|
||||
//reader->offset.y = round / data->winsize.width;
|
||||
reader->offset = offset;
|
||||
reader->point = reader->offset;
|
||||
reader->scale = MAX(
|
||||
((float) data->winsize.width + reader->point.x) / ((float) reader->src.cols),
|
||||
((float) data->winsize.height + reader->point.y) / ((float) reader->src.rows) );
|
||||
|
||||
reader->img = cvMat( (int) (reader->scale * reader->src.rows + 0.5F),
|
||||
(int) (reader->scale * reader->src.cols + 0.5F),
|
||||
CV_8UC1, (void*) cvAlloc( datasize ) );
|
||||
cvResize( &(reader->src), &(reader->img) );
|
||||
}
|
||||
|
||||
/*
|
||||
* icvGetBackgroundImage
|
||||
*
|
||||
* Get an image from background
|
||||
* <img> must be allocated and have size, previously passed to icvInitBackgroundReaders
|
||||
*
|
||||
* Usage example:
|
||||
* icvInitBackgroundReaders( "bg.txt", cvSize( 24, 24 ) );
|
||||
* ...
|
||||
* #pragma omp parallel
|
||||
* {
|
||||
* ...
|
||||
* icvGetBackgourndImage( cvbgdata, cvbgreader, img );
|
||||
* ...
|
||||
* }
|
||||
* ...
|
||||
* icvDestroyBackgroundReaders();
|
||||
*/
|
||||
static
|
||||
void icvGetBackgroundImage( CvBackgroundData* data,
|
||||
CvBackgroundReader* reader,
|
||||
CvMat* img )
|
||||
{
|
||||
CvMat mat;
|
||||
|
||||
assert( data != NULL && reader != NULL && img != NULL );
|
||||
assert( CV_MAT_TYPE( img->type ) == CV_8UC1 );
|
||||
assert( img->cols == data->winsize.width );
|
||||
assert( img->rows == data->winsize.height );
|
||||
|
||||
if( reader->img.data.ptr == NULL )
|
||||
{
|
||||
icvGetNextFromBackgroundData( data, reader );
|
||||
}
|
||||
|
||||
mat = cvMat( data->winsize.height, data->winsize.width, CV_8UC1 );
|
||||
cvSetData( &mat, (void*) (reader->img.data.ptr + reader->point.y * reader->img.step
|
||||
+ reader->point.x * sizeof( uchar )), reader->img.step );
|
||||
|
||||
cvCopy( &mat, img, 0 );
|
||||
if( (int) ( reader->point.x + (1.0F + reader->stepfactor ) * data->winsize.width )
|
||||
< reader->img.cols )
|
||||
{
|
||||
reader->point.x += (int) (reader->stepfactor * data->winsize.width);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader->point.x = reader->offset.x;
|
||||
if( (int) ( reader->point.y + (1.0F + reader->stepfactor ) * data->winsize.height )
|
||||
< reader->img.rows )
|
||||
{
|
||||
reader->point.y += (int) (reader->stepfactor * data->winsize.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader->point.y = reader->offset.y;
|
||||
reader->scale *= reader->scalefactor;
|
||||
if( reader->scale <= 1.0F )
|
||||
{
|
||||
reader->img = cvMat( (int) (reader->scale * reader->src.rows),
|
||||
(int) (reader->scale * reader->src.cols),
|
||||
CV_8UC1, (void*) (reader->img.data.ptr) );
|
||||
cvResize( &(reader->src), &(reader->img) );
|
||||
}
|
||||
else
|
||||
{
|
||||
icvGetNextFromBackgroundData( data, reader );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* icvInitBackgroundReaders
|
||||
*
|
||||
* Initialize background reading process.
|
||||
* <cvbgreader> and <cvbgdata> are initialized.
|
||||
* Must be called before any usage of background
|
||||
*
|
||||
* filename - name of background description file
|
||||
* winsize - size of images will be obtained from background
|
||||
*
|
||||
* return 1 on success, 0 otherwise.
|
||||
*/
|
||||
static int icvInitBackgroundReaders( const char* filename, CvSize winsize )
|
||||
{
|
||||
if( cvbgdata == NULL && filename != NULL )
|
||||
{
|
||||
cvbgdata = icvCreateBackgroundData( filename, winsize );
|
||||
}
|
||||
|
||||
if( cvbgdata )
|
||||
{
|
||||
|
||||
#ifdef CV_OPENMP
|
||||
#pragma omp parallel
|
||||
#endif /* CV_OPENMP */
|
||||
{
|
||||
#ifdef CV_OPENMP
|
||||
#pragma omp critical(c_create_bg_data)
|
||||
#endif /* CV_OPENMP */
|
||||
{
|
||||
if( cvbgreader == NULL )
|
||||
{
|
||||
cvbgreader = icvCreateBackgroundReader();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (cvbgdata != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* icvDestroyBackgroundReaders
|
||||
*
|
||||
* Finish backgournd reading process
|
||||
*/
|
||||
static
|
||||
void icvDestroyBackgroundReaders()
|
||||
{
|
||||
/* release background reader in each thread */
|
||||
#ifdef CV_OPENMP
|
||||
#pragma omp parallel
|
||||
#endif /* CV_OPENMP */
|
||||
{
|
||||
#ifdef CV_OPENMP
|
||||
#pragma omp critical(c_release_bg_data)
|
||||
#endif /* CV_OPENMP */
|
||||
{
|
||||
if( cvbgreader != NULL )
|
||||
{
|
||||
icvReleaseBackgroundReader( &cvbgreader );
|
||||
cvbgreader = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( cvbgdata != NULL )
|
||||
{
|
||||
icvReleaseBackgroundData( &cvbgdata );
|
||||
cvbgdata = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void cvCreateTrainingSamples( const char* filename,
|
||||
const char* imgfilename, int bgcolor, int bgthreshold,
|
||||
const char* bgfilename, int count,
|
||||
int invert, int maxintensitydev,
|
||||
double maxxangle, double maxyangle, double maxzangle,
|
||||
int showsamples,
|
||||
int winwidth, int winheight )
|
||||
{
|
||||
CvSampleDistortionData data;
|
||||
|
||||
assert( filename != NULL );
|
||||
assert( imgfilename != NULL );
|
||||
|
||||
if( !icvMkDir( filename ) )
|
||||
{
|
||||
fprintf( stderr, "Unable to create output file: %s\n", filename );
|
||||
return;
|
||||
}
|
||||
if( icvStartSampleDistortion( imgfilename, bgcolor, bgthreshold, &data ) )
|
||||
{
|
||||
FILE* output = NULL;
|
||||
|
||||
output = fopen( filename, "wb" );
|
||||
if( output != NULL )
|
||||
{
|
||||
int hasbg;
|
||||
int i;
|
||||
CvMat sample;
|
||||
int inverse;
|
||||
|
||||
hasbg = 0;
|
||||
hasbg = (bgfilename != NULL && icvInitBackgroundReaders( bgfilename,
|
||||
cvSize( winwidth,winheight ) ) );
|
||||
|
||||
sample = cvMat( winheight, winwidth, CV_8UC1, cvAlloc( sizeof( uchar ) *
|
||||
winheight * winwidth ) );
|
||||
|
||||
icvWriteVecHeader( output, count, sample.cols, sample.rows );
|
||||
|
||||
if( showsamples )
|
||||
{
|
||||
cvNamedWindow( "Sample", CV_WINDOW_AUTOSIZE );
|
||||
}
|
||||
|
||||
inverse = invert;
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
if( hasbg )
|
||||
{
|
||||
icvGetBackgroundImage( cvbgdata, cvbgreader, &sample );
|
||||
}
|
||||
else
|
||||
{
|
||||
cvSet( &sample, cvScalar( bgcolor ) );
|
||||
}
|
||||
|
||||
if( invert == CV_RANDOM_INVERT )
|
||||
{
|
||||
inverse = (rand() > (RAND_MAX/2));
|
||||
}
|
||||
icvPlaceDistortedSample( &sample, inverse, maxintensitydev,
|
||||
maxxangle, maxyangle, maxzangle,
|
||||
0 /* nonzero means placing image without cut offs */,
|
||||
0.0 /* nozero adds random shifting */,
|
||||
0.0 /* nozero adds random scaling */,
|
||||
&data );
|
||||
|
||||
if( showsamples )
|
||||
{
|
||||
cvShowImage( "Sample", &sample );
|
||||
if( cvWaitKey( 0 ) == 27 )
|
||||
{
|
||||
showsamples = 0;
|
||||
}
|
||||
}
|
||||
|
||||
icvWriteVecSample( output, &sample );
|
||||
|
||||
#ifdef CV_VERBOSE
|
||||
if( i % 500 == 0 )
|
||||
{
|
||||
printf( "\r%3d%%", 100 * i / count );
|
||||
}
|
||||
#endif /* CV_VERBOSE */
|
||||
}
|
||||
icvDestroyBackgroundReaders();
|
||||
cvFree( &(sample.data.ptr) );
|
||||
fclose( output );
|
||||
} /* if( output != NULL ) */
|
||||
|
||||
icvEndSampleDistortion( &data );
|
||||
}
|
||||
|
||||
#ifdef CV_VERBOSE
|
||||
printf( "\r \r" );
|
||||
#endif /* CV_VERBOSE */
|
||||
|
||||
}
|
||||
|
||||
#define CV_INFO_FILENAME "info.dat"
|
||||
|
||||
void cvCreateTestSamples( const char* infoname,
|
||||
const char* imgfilename, int bgcolor, int bgthreshold,
|
||||
const char* bgfilename, int count,
|
||||
int invert, int maxintensitydev,
|
||||
double maxxangle, double maxyangle, double maxzangle,
|
||||
int showsamples,
|
||||
int winwidth, int winheight )
|
||||
{
|
||||
CvSampleDistortionData data;
|
||||
|
||||
assert( infoname != NULL );
|
||||
assert( imgfilename != NULL );
|
||||
assert( bgfilename != NULL );
|
||||
|
||||
if( !icvMkDir( infoname ) )
|
||||
{
|
||||
|
||||
#if CV_VERBOSE
|
||||
fprintf( stderr, "Unable to create directory hierarchy: %s\n", infoname );
|
||||
#endif /* CV_VERBOSE */
|
||||
|
||||
return;
|
||||
}
|
||||
if( icvStartSampleDistortion( imgfilename, bgcolor, bgthreshold, &data ) )
|
||||
{
|
||||
char fullname[PATH_MAX];
|
||||
char* filename;
|
||||
CvMat win;
|
||||
FILE* info;
|
||||
|
||||
if( icvInitBackgroundReaders( bgfilename, cvSize( 10, 10 ) ) )
|
||||
{
|
||||
int i;
|
||||
int x, y, width, height;
|
||||
float scale;
|
||||
float maxscale;
|
||||
int inverse;
|
||||
|
||||
if( showsamples )
|
||||
{
|
||||
cvNamedWindow( "Image", CV_WINDOW_AUTOSIZE );
|
||||
}
|
||||
|
||||
info = fopen( infoname, "w" );
|
||||
strcpy( fullname, infoname );
|
||||
filename = strrchr( fullname, '\\' );
|
||||
if( filename == NULL )
|
||||
{
|
||||
filename = strrchr( fullname, '/' );
|
||||
}
|
||||
if( filename == NULL )
|
||||
{
|
||||
filename = fullname;
|
||||
}
|
||||
else
|
||||
{
|
||||
filename++;
|
||||
}
|
||||
|
||||
count = MIN( count, cvbgdata->count );
|
||||
inverse = invert;
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
icvGetNextFromBackgroundData( cvbgdata, cvbgreader );
|
||||
|
||||
maxscale = MIN( 0.7F * cvbgreader->src.cols / winwidth,
|
||||
0.7F * cvbgreader->src.rows / winheight );
|
||||
if( maxscale < 1.0F ) continue;
|
||||
|
||||
scale = (maxscale - 1.0F) * rand() / RAND_MAX + 1.0F;
|
||||
width = (int) (scale * winwidth);
|
||||
height = (int) (scale * winheight);
|
||||
x = (int) ((0.1+0.8 * rand()/RAND_MAX) * (cvbgreader->src.cols - width));
|
||||
y = (int) ((0.1+0.8 * rand()/RAND_MAX) * (cvbgreader->src.rows - height));
|
||||
|
||||
cvGetSubArr( &cvbgreader->src, &win, cvRect( x, y ,width, height ) );
|
||||
if( invert == CV_RANDOM_INVERT )
|
||||
{
|
||||
inverse = (rand() > (RAND_MAX/2));
|
||||
}
|
||||
icvPlaceDistortedSample( &win, inverse, maxintensitydev,
|
||||
maxxangle, maxyangle, maxzangle,
|
||||
1, 0.0, 0.0, &data );
|
||||
|
||||
|
||||
sprintf( filename, "%04d_%04d_%04d_%04d_%04d.jpg",
|
||||
(i + 1), x, y, width, height );
|
||||
|
||||
if( info )
|
||||
{
|
||||
fprintf( info, "%s %d %d %d %d %d\n",
|
||||
filename, 1, x, y, width, height );
|
||||
}
|
||||
|
||||
cvSaveImage( fullname, &cvbgreader->src );
|
||||
if( showsamples )
|
||||
{
|
||||
cvShowImage( "Image", &cvbgreader->src );
|
||||
if( cvWaitKey( 0 ) == 27 )
|
||||
{
|
||||
showsamples = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( info ) fclose( info );
|
||||
icvDestroyBackgroundReaders();
|
||||
}
|
||||
icvEndSampleDistortion( &data );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -867,7 +1558,47 @@ int cvCreateTrainingSamplesFromInfo( const char* infoname, const char* vecfilena
|
||||
return total;
|
||||
}
|
||||
|
||||
typedef struct CvVecFile
|
||||
{
|
||||
FILE* input;
|
||||
int count;
|
||||
int vecsize;
|
||||
int last;
|
||||
short* vector;
|
||||
} CvVecFile;
|
||||
|
||||
static
|
||||
int icvGetTraininDataFromVec( CvMat* img, void* userdata )
|
||||
{
|
||||
uchar tmp = 0;
|
||||
int r = 0;
|
||||
int c = 0;
|
||||
|
||||
assert( img->rows * img->cols == ((CvVecFile*) userdata)->vecsize );
|
||||
|
||||
size_t elements_read = fread( &tmp, sizeof( tmp ), 1, ((CvVecFile*) userdata)->input );
|
||||
CV_Assert(elements_read == 1);
|
||||
elements_read = fread( ((CvVecFile*) userdata)->vector, sizeof( short ),
|
||||
((CvVecFile*) userdata)->vecsize, ((CvVecFile*) userdata)->input );
|
||||
CV_Assert(elements_read == (size_t)((CvVecFile*) userdata)->vecsize);
|
||||
|
||||
if( feof( ((CvVecFile*) userdata)->input ) ||
|
||||
(((CvVecFile*) userdata)->last)++ >= ((CvVecFile*) userdata)->count )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for( r = 0; r < img->rows; r++ )
|
||||
{
|
||||
for( c = 0; c < img->cols; c++ )
|
||||
{
|
||||
CV_MAT_ELEM( *img, uchar, r, c ) =
|
||||
(uchar) ( ((CvVecFile*) userdata)->vector[r * img->cols + c] );
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
void cvShowVecSamples( const char* filename, int winwidth, int winheight,
|
||||
double scale )
|
||||
{
|
||||
@ -936,7 +1667,7 @@ void cvShowVecSamples( const char* filename, int winwidth, int winheight,
|
||||
cvNamedWindow( "Sample", CV_WINDOW_AUTOSIZE );
|
||||
for( i = 0; i < file.count; i++ )
|
||||
{
|
||||
icvGetHaarTraininDataFromVecCallback( sample, &file );
|
||||
icvGetTraininDataFromVec( sample, &file );
|
||||
if( scale != 1.0 ) cvResize( sample, scaled_sample, CV_INTER_LINEAR);
|
||||
cvShowImage( "Sample", scaled_sample );
|
||||
if( cvWaitKey( 0 ) == 27 ) break;
|
||||
@ -947,7 +1678,4 @@ void cvShowVecSamples( const char* filename, int winwidth, int winheight,
|
||||
}
|
||||
fclose( file.input );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* End of file. */
|
||||
}
|
@ -39,14 +39,10 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
/*
|
||||
* cvhaartraining.h
|
||||
*
|
||||
* haar training functions
|
||||
*/
|
||||
#ifndef __CREATESAMPLES_UTILITY_HPP__
|
||||
#define __CREATESAMPLES_UTILITY_HPP__
|
||||
|
||||
#ifndef _CVHAARTRAINING_H_
|
||||
#define _CVHAARTRAINING_H_
|
||||
#define CV_VERBOSE 1
|
||||
|
||||
/*
|
||||
* cvCreateTrainingSamples
|
||||
@ -125,68 +121,4 @@ int cvCreateTrainingSamplesFromInfo( const char* infoname, const char* vecfilena
|
||||
*/
|
||||
void cvShowVecSamples( const char* filename, int winwidth, int winheight, double scale );
|
||||
|
||||
|
||||
/*
|
||||
* cvCreateCascadeClassifier
|
||||
*
|
||||
* Create cascade classifier
|
||||
* dirname - directory name in which cascade classifier will be created.
|
||||
* It must exist and contain subdirectories 0, 1, 2, ... (nstages-1).
|
||||
* vecfilename - name of .vec file with object's images
|
||||
* bgfilename - name of background description file
|
||||
* bg_vecfile - true if bgfilename represents a vec file with discrete negatives
|
||||
* npos - number of positive samples used in training of each stage
|
||||
* nneg - number of negative samples used in training of each stage
|
||||
* nstages - number of stages
|
||||
* numprecalculated - number of features being precalculated. Each precalculated feature
|
||||
* requires (number_of_samples*(sizeof( float ) + sizeof( short ))) bytes of memory
|
||||
* numsplits - number of binary splits in each weak classifier
|
||||
* 1 - stumps, 2 and more - trees.
|
||||
* minhitrate - desired min hit rate of each stage
|
||||
* maxfalsealarm - desired max false alarm of each stage
|
||||
* weightfraction - weight trimming parameter
|
||||
* mode - 0 - BASIC = Viola
|
||||
* 1 - CORE = All upright
|
||||
* 2 - ALL = All features
|
||||
* symmetric - if not 0 vertical symmetry is assumed
|
||||
* equalweights - if not 0 initial weights of all samples will be equal
|
||||
* winwidth - sample width
|
||||
* winheight - sample height
|
||||
* boosttype - type of applied boosting algorithm
|
||||
* 0 - Discrete AdaBoost
|
||||
* 1 - Real AdaBoost
|
||||
* 2 - LogitBoost
|
||||
* 3 - Gentle AdaBoost
|
||||
* stumperror - type of used error if Discrete AdaBoost algorithm is applied
|
||||
* 0 - misclassification error
|
||||
* 1 - gini error
|
||||
* 2 - entropy error
|
||||
*/
|
||||
void cvCreateCascadeClassifier( const char* dirname,
|
||||
const char* vecfilename,
|
||||
const char* bgfilename,
|
||||
int npos, int nneg, int nstages,
|
||||
int numprecalculated,
|
||||
int numsplits,
|
||||
float minhitrate = 0.995F, float maxfalsealarm = 0.5F,
|
||||
float weightfraction = 0.95F,
|
||||
int mode = 0, int symmetric = 1,
|
||||
int equalweights = 1,
|
||||
int winwidth = 24, int winheight = 24,
|
||||
int boosttype = 3, int stumperror = 0 );
|
||||
|
||||
void cvCreateTreeCascadeClassifier( const char* dirname,
|
||||
const char* vecfilename,
|
||||
const char* bgfilename,
|
||||
int npos, int nneg, int nstages,
|
||||
int numprecalculated,
|
||||
int numsplits,
|
||||
float minhitrate, float maxfalsealarm,
|
||||
float weightfraction,
|
||||
int mode, int symmetric,
|
||||
int equalweights,
|
||||
int winwidth, int winheight,
|
||||
int boosttype, int stumperror,
|
||||
int maxtreesplits, int minpos, bool bg_vecfile = false );
|
||||
|
||||
#endif /* _CVHAARTRAINING_H_ */
|
||||
#endif //__CREATESAMPLES_UTILITY_HPP__
|
@ -1,89 +0,0 @@
|
||||
SET(OPENCV_HAARTRAINING_DEPS opencv_core opencv_imgproc opencv_photo opencv_ml opencv_highgui opencv_objdetect opencv_calib3d opencv_video opencv_features2d opencv_flann opencv_legacy)
|
||||
ocv_check_dependencies(${OPENCV_HAARTRAINING_DEPS})
|
||||
|
||||
if(NOT OCV_DEPENDENCIES_FOUND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(haartraining)
|
||||
|
||||
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv")
|
||||
ocv_include_modules(${OPENCV_HAARTRAINING_DEPS})
|
||||
|
||||
if(WIN32)
|
||||
link_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
link_libraries(${OPENCV_HAARTRAINING_DEPS} opencv_haartraining_engine)
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Library
|
||||
# -----------------------------------------------------------
|
||||
set(cvhaartraining_lib_src
|
||||
_cvcommon.h
|
||||
cvclassifier.h
|
||||
_cvhaartraining.h
|
||||
cvhaartraining.h
|
||||
cvboost.cpp
|
||||
cvcommon.cpp
|
||||
cvhaarclassifier.cpp
|
||||
cvhaartraining.cpp
|
||||
cvsamples.cpp
|
||||
)
|
||||
|
||||
add_library(opencv_haartraining_engine STATIC ${cvhaartraining_lib_src})
|
||||
set_target_properties(opencv_haartraining_engine PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
|
||||
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
|
||||
INSTALL_NAME_DIR lib
|
||||
)
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# haartraining
|
||||
# -----------------------------------------------------------
|
||||
|
||||
add_executable(opencv_haartraining cvhaartraining.h haartraining.cpp)
|
||||
set_target_properties(opencv_haartraining PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
OUTPUT_NAME "opencv_haartraining")
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# createsamples
|
||||
# -----------------------------------------------------------
|
||||
|
||||
add_executable(opencv_createsamples cvhaartraining.h createsamples.cpp)
|
||||
set_target_properties(opencv_createsamples PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
OUTPUT_NAME "opencv_createsamples")
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# performance
|
||||
# -----------------------------------------------------------
|
||||
add_executable(opencv_performance performance.cpp)
|
||||
set_target_properties(opencv_performance PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
OUTPUT_NAME "opencv_performance")
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Install part
|
||||
# -----------------------------------------------------------
|
||||
|
||||
if(INSTALL_CREATE_DISTRIB)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main)
|
||||
install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main)
|
||||
install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main)
|
||||
endif()
|
||||
else()
|
||||
install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main)
|
||||
install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main)
|
||||
install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main)
|
||||
endif()
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(opencv_performance PROPERTIES FOLDER "applications")
|
||||
set_target_properties(opencv_createsamples PROPERTIES FOLDER "applications")
|
||||
set_target_properties(opencv_haartraining PROPERTIES FOLDER "applications")
|
||||
set_target_properties(opencv_haartraining_engine PROPERTIES FOLDER "applications")
|
||||
endif()
|
@ -1,92 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __CVCOMMON_H_
|
||||
#define __CVCOMMON_H_
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
#include "cxcore.h"
|
||||
#include "cv.h"
|
||||
#include "cxmisc.h"
|
||||
|
||||
#define __BEGIN__ __CV_BEGIN__
|
||||
#define __END__ __CV_END__
|
||||
#define EXIT __CV_EXIT__
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 512
|
||||
#endif /* PATH_MAX */
|
||||
|
||||
int icvMkDir( const char* filename );
|
||||
|
||||
/* returns index at specified position from index matrix of any type.
|
||||
if matrix is NULL, then specified position is returned */
|
||||
CV_INLINE
|
||||
int icvGetIdxAt( CvMat* idx, int pos );
|
||||
|
||||
CV_INLINE
|
||||
int icvGetIdxAt( CvMat* idx, int pos )
|
||||
{
|
||||
if( idx == NULL )
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
CvScalar sc;
|
||||
int type;
|
||||
|
||||
type = CV_MAT_TYPE( idx->type );
|
||||
cvRawDataToScalar( idx->data.ptr + pos *
|
||||
( (idx->rows == 1) ? CV_ELEM_SIZE( type ) : idx->step ), type, &sc );
|
||||
|
||||
return (int) sc.val[0];
|
||||
}
|
||||
}
|
||||
|
||||
/* debug functions */
|
||||
|
||||
#define CV_DEBUG_SAVE( ptr ) icvSave( ptr, __FILE__, __LINE__ );
|
||||
|
||||
void icvSave( const CvArr* ptr, const char* filename, int line );
|
||||
|
||||
#endif /* __CVCOMMON_H_ */
|
@ -1,414 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
/*
|
||||
* _cvhaartraining.h
|
||||
*
|
||||
* training of cascade of boosted classifiers based on haar features
|
||||
*/
|
||||
|
||||
#ifndef __CVHAARTRAINING_H_
|
||||
#define __CVHAARTRAINING_H_
|
||||
|
||||
#include "_cvcommon.h"
|
||||
#include "cvclassifier.h"
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
/* parameters for tree cascade classifier training */
|
||||
|
||||
/* max number of clusters */
|
||||
#define CV_MAX_CLUSTERS 3
|
||||
|
||||
/* term criteria for K-Means */
|
||||
#define CV_TERM_CRITERIA() cvTermCriteria( CV_TERMCRIT_EPS, 1000, 1E-5 )
|
||||
|
||||
/* print statistic info */
|
||||
#define CV_VERBOSE 1
|
||||
|
||||
#define CV_STAGE_CART_FILE_NAME "AdaBoostCARTHaarClassifier.txt"
|
||||
|
||||
#define CV_HAAR_FEATURE_MAX 3
|
||||
#define CV_HAAR_FEATURE_DESC_MAX 20
|
||||
|
||||
typedef int sum_type;
|
||||
typedef double sqsum_type;
|
||||
typedef short idx_type;
|
||||
|
||||
#define CV_SUM_MAT_TYPE CV_32SC1
|
||||
#define CV_SQSUM_MAT_TYPE CV_64FC1
|
||||
#define CV_IDX_MAT_TYPE CV_16SC1
|
||||
|
||||
#define CV_STUMP_TRAIN_PORTION 100
|
||||
|
||||
#define CV_THRESHOLD_EPS (0.00001F)
|
||||
|
||||
typedef struct CvTHaarFeature
|
||||
{
|
||||
char desc[CV_HAAR_FEATURE_DESC_MAX];
|
||||
int tilted;
|
||||
struct
|
||||
{
|
||||
CvRect r;
|
||||
float weight;
|
||||
} rect[CV_HAAR_FEATURE_MAX];
|
||||
} CvTHaarFeature;
|
||||
|
||||
typedef struct CvFastHaarFeature
|
||||
{
|
||||
int tilted;
|
||||
struct
|
||||
{
|
||||
int p0, p1, p2, p3;
|
||||
float weight;
|
||||
} rect[CV_HAAR_FEATURE_MAX];
|
||||
} CvFastHaarFeature;
|
||||
|
||||
typedef struct CvIntHaarFeatures
|
||||
{
|
||||
CvSize winsize;
|
||||
int count;
|
||||
CvTHaarFeature* feature;
|
||||
CvFastHaarFeature* fastfeature;
|
||||
} CvIntHaarFeatures;
|
||||
|
||||
CV_INLINE CvTHaarFeature cvHaarFeature( const char* desc,
|
||||
int x0, int y0, int w0, int h0, float wt0,
|
||||
int x1, int y1, int w1, int h1, float wt1,
|
||||
int x2 CV_DEFAULT( 0 ), int y2 CV_DEFAULT( 0 ),
|
||||
int w2 CV_DEFAULT( 0 ), int h2 CV_DEFAULT( 0 ),
|
||||
float wt2 CV_DEFAULT( 0.0F ) );
|
||||
|
||||
CV_INLINE CvTHaarFeature cvHaarFeature( const char* desc,
|
||||
int x0, int y0, int w0, int h0, float wt0,
|
||||
int x1, int y1, int w1, int h1, float wt1,
|
||||
int x2, int y2, int w2, int h2, float wt2 )
|
||||
{
|
||||
CvTHaarFeature hf;
|
||||
|
||||
assert( CV_HAAR_FEATURE_MAX >= 3 );
|
||||
assert( strlen( desc ) < CV_HAAR_FEATURE_DESC_MAX );
|
||||
|
||||
strcpy( &(hf.desc[0]), desc );
|
||||
hf.tilted = ( hf.desc[0] == 't' );
|
||||
|
||||
hf.rect[0].r.x = x0;
|
||||
hf.rect[0].r.y = y0;
|
||||
hf.rect[0].r.width = w0;
|
||||
hf.rect[0].r.height = h0;
|
||||
hf.rect[0].weight = wt0;
|
||||
|
||||
hf.rect[1].r.x = x1;
|
||||
hf.rect[1].r.y = y1;
|
||||
hf.rect[1].r.width = w1;
|
||||
hf.rect[1].r.height = h1;
|
||||
hf.rect[1].weight = wt1;
|
||||
|
||||
hf.rect[2].r.x = x2;
|
||||
hf.rect[2].r.y = y2;
|
||||
hf.rect[2].r.width = w2;
|
||||
hf.rect[2].r.height = h2;
|
||||
hf.rect[2].weight = wt2;
|
||||
|
||||
return hf;
|
||||
}
|
||||
|
||||
/* Prepared for training samples */
|
||||
typedef struct CvHaarTrainingData
|
||||
{
|
||||
CvSize winsize; /* training image size */
|
||||
int maxnum; /* maximum number of samples */
|
||||
CvMat sum; /* sum images (each row represents image) */
|
||||
CvMat tilted; /* tilted sum images (each row represents image) */
|
||||
CvMat normfactor; /* normalization factor */
|
||||
CvMat cls; /* classes. 1.0 - object, 0.0 - background */
|
||||
CvMat weights; /* weights */
|
||||
|
||||
CvMat* valcache; /* precalculated feature values (CV_32FC1) */
|
||||
CvMat* idxcache; /* presorted indices (CV_IDX_MAT_TYPE) */
|
||||
} CvHaarTrainigData;
|
||||
|
||||
|
||||
/* Passed to callback functions */
|
||||
typedef struct CvUserdata
|
||||
{
|
||||
CvHaarTrainingData* trainingData;
|
||||
CvIntHaarFeatures* haarFeatures;
|
||||
} CvUserdata;
|
||||
|
||||
CV_INLINE
|
||||
CvUserdata cvUserdata( CvHaarTrainingData* trainingData,
|
||||
CvIntHaarFeatures* haarFeatures );
|
||||
|
||||
CV_INLINE
|
||||
CvUserdata cvUserdata( CvHaarTrainingData* trainingData,
|
||||
CvIntHaarFeatures* haarFeatures )
|
||||
{
|
||||
CvUserdata userdata;
|
||||
|
||||
userdata.trainingData = trainingData;
|
||||
userdata.haarFeatures = haarFeatures;
|
||||
|
||||
return userdata;
|
||||
}
|
||||
|
||||
|
||||
#define CV_INT_HAAR_CLASSIFIER_FIELDS() \
|
||||
float (*eval)( CvIntHaarClassifier*, sum_type*, sum_type*, float ); \
|
||||
void (*save)( CvIntHaarClassifier*, FILE* file ); \
|
||||
void (*release)( CvIntHaarClassifier** );
|
||||
|
||||
/* internal weak classifier*/
|
||||
typedef struct CvIntHaarClassifier
|
||||
{
|
||||
CV_INT_HAAR_CLASSIFIER_FIELDS()
|
||||
} CvIntHaarClassifier;
|
||||
|
||||
/*
|
||||
* CART classifier
|
||||
*/
|
||||
typedef struct CvCARTHaarClassifier
|
||||
{
|
||||
CV_INT_HAAR_CLASSIFIER_FIELDS()
|
||||
|
||||
int count;
|
||||
int* compidx;
|
||||
CvTHaarFeature* feature;
|
||||
CvFastHaarFeature* fastfeature;
|
||||
float* threshold;
|
||||
int* left;
|
||||
int* right;
|
||||
float* val;
|
||||
} CvCARTHaarClassifier;
|
||||
|
||||
/* internal stage classifier */
|
||||
typedef struct CvStageHaarClassifier
|
||||
{
|
||||
CV_INT_HAAR_CLASSIFIER_FIELDS()
|
||||
|
||||
int count;
|
||||
float threshold;
|
||||
CvIntHaarClassifier** classifier;
|
||||
} CvStageHaarClassifier;
|
||||
|
||||
/* internal cascade classifier */
|
||||
typedef struct CvCascadeHaarClassifier
|
||||
{
|
||||
CV_INT_HAAR_CLASSIFIER_FIELDS()
|
||||
|
||||
int count;
|
||||
CvIntHaarClassifier** classifier;
|
||||
} CvCascadeHaarClassifier;
|
||||
|
||||
|
||||
/* internal tree cascade classifier node */
|
||||
typedef struct CvTreeCascadeNode
|
||||
{
|
||||
CvStageHaarClassifier* stage;
|
||||
|
||||
struct CvTreeCascadeNode* next;
|
||||
struct CvTreeCascadeNode* child;
|
||||
struct CvTreeCascadeNode* parent;
|
||||
|
||||
struct CvTreeCascadeNode* next_same_level;
|
||||
struct CvTreeCascadeNode* child_eval;
|
||||
int idx;
|
||||
int leaf;
|
||||
} CvTreeCascadeNode;
|
||||
|
||||
/* internal tree cascade classifier */
|
||||
typedef struct CvTreeCascadeClassifier
|
||||
{
|
||||
CV_INT_HAAR_CLASSIFIER_FIELDS()
|
||||
|
||||
CvTreeCascadeNode* root; /* root of the tree */
|
||||
CvTreeCascadeNode* root_eval; /* root node for the filtering */
|
||||
|
||||
int next_idx;
|
||||
} CvTreeCascadeClassifier;
|
||||
|
||||
|
||||
CV_INLINE float cvEvalFastHaarFeature( const CvFastHaarFeature* feature,
|
||||
const sum_type* sum, const sum_type* tilted )
|
||||
{
|
||||
const sum_type* img = feature->tilted ? tilted : sum;
|
||||
float ret = feature->rect[0].weight*
|
||||
(img[feature->rect[0].p0] - img[feature->rect[0].p1] -
|
||||
img[feature->rect[0].p2] + img[feature->rect[0].p3]) +
|
||||
feature->rect[1].weight*
|
||||
(img[feature->rect[1].p0] - img[feature->rect[1].p1] -
|
||||
img[feature->rect[1].p2] + img[feature->rect[1].p3]);
|
||||
|
||||
if( feature->rect[2].weight != 0.0f )
|
||||
ret += feature->rect[2].weight *
|
||||
( img[feature->rect[2].p0] - img[feature->rect[2].p1] -
|
||||
img[feature->rect[2].p2] + img[feature->rect[2].p3] );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
typedef struct CvSampleDistortionData
|
||||
{
|
||||
IplImage* src;
|
||||
IplImage* erode;
|
||||
IplImage* dilate;
|
||||
IplImage* mask;
|
||||
IplImage* img;
|
||||
IplImage* maskimg;
|
||||
int dx;
|
||||
int dy;
|
||||
int bgcolor;
|
||||
} CvSampleDistortionData;
|
||||
|
||||
/*
|
||||
* icvConvertToFastHaarFeature
|
||||
*
|
||||
* Convert to fast representation of haar features
|
||||
*
|
||||
* haarFeature - input array
|
||||
* fastHaarFeature - output array
|
||||
* size - size of arrays
|
||||
* step - row step for the integral image
|
||||
*/
|
||||
void icvConvertToFastHaarFeature( CvTHaarFeature* haarFeature,
|
||||
CvFastHaarFeature* fastHaarFeature,
|
||||
int size, int step );
|
||||
|
||||
|
||||
void icvWriteVecHeader( FILE* file, int count, int width, int height );
|
||||
void icvWriteVecSample( FILE* file, CvArr* sample );
|
||||
void icvPlaceDistortedSample( CvArr* background,
|
||||
int inverse, int maxintensitydev,
|
||||
double maxxangle, double maxyangle, double maxzangle,
|
||||
int inscribe, double maxshiftf, double maxscalef,
|
||||
CvSampleDistortionData* data );
|
||||
void icvEndSampleDistortion( CvSampleDistortionData* data );
|
||||
|
||||
int icvStartSampleDistortion( const char* imgfilename, int bgcolor, int bgthreshold,
|
||||
CvSampleDistortionData* data );
|
||||
|
||||
typedef int (*CvGetHaarTrainingDataCallback)( CvMat* img, void* userdata );
|
||||
|
||||
typedef struct CvVecFile
|
||||
{
|
||||
FILE* input;
|
||||
int count;
|
||||
int vecsize;
|
||||
int last;
|
||||
short* vector;
|
||||
} CvVecFile;
|
||||
|
||||
int icvGetHaarTraininDataFromVecCallback( CvMat* img, void* userdata );
|
||||
|
||||
/*
|
||||
* icvGetHaarTrainingDataFromVec
|
||||
*
|
||||
* Fill <data> with samples from .vec file, passed <cascade>
|
||||
int icvGetHaarTrainingDataFromVec( CvHaarTrainingData* data, int first, int count,
|
||||
CvIntHaarClassifier* cascade,
|
||||
const char* filename,
|
||||
int* consumed );
|
||||
*/
|
||||
|
||||
CvIntHaarClassifier* icvCreateCARTHaarClassifier( int count );
|
||||
|
||||
void icvReleaseHaarClassifier( CvIntHaarClassifier** classifier );
|
||||
|
||||
void icvInitCARTHaarClassifier( CvCARTHaarClassifier* carthaar, CvCARTClassifier* cart,
|
||||
CvIntHaarFeatures* intHaarFeatures );
|
||||
|
||||
float icvEvalCARTHaarClassifier( CvIntHaarClassifier* classifier,
|
||||
sum_type* sum, sum_type* tilted, float normfactor );
|
||||
|
||||
CvIntHaarClassifier* icvCreateStageHaarClassifier( int count, float threshold );
|
||||
|
||||
void icvReleaseStageHaarClassifier( CvIntHaarClassifier** classifier );
|
||||
|
||||
float icvEvalStageHaarClassifier( CvIntHaarClassifier* classifier,
|
||||
sum_type* sum, sum_type* tilted, float normfactor );
|
||||
|
||||
CvIntHaarClassifier* icvCreateCascadeHaarClassifier( int count );
|
||||
|
||||
void icvReleaseCascadeHaarClassifier( CvIntHaarClassifier** classifier );
|
||||
|
||||
float icvEvalCascadeHaarClassifier( CvIntHaarClassifier* classifier,
|
||||
sum_type* sum, sum_type* tilted, float normfactor );
|
||||
|
||||
void icvSaveHaarFeature( CvTHaarFeature* feature, FILE* file );
|
||||
|
||||
void icvLoadHaarFeature( CvTHaarFeature* feature, FILE* file );
|
||||
|
||||
void icvSaveCARTHaarClassifier( CvIntHaarClassifier* classifier, FILE* file );
|
||||
|
||||
CvIntHaarClassifier* icvLoadCARTHaarClassifier( FILE* file, int step );
|
||||
|
||||
void icvSaveStageHaarClassifier( CvIntHaarClassifier* classifier, FILE* file );
|
||||
|
||||
CvIntHaarClassifier* icvLoadCARTStageHaarClassifier( const char* filename, int step );
|
||||
|
||||
|
||||
/* tree cascade classifier */
|
||||
|
||||
float icvEvalTreeCascadeClassifier( CvIntHaarClassifier* classifier,
|
||||
sum_type* sum, sum_type* tilted, float normfactor );
|
||||
|
||||
void icvSetLeafNode( CvTreeCascadeClassifier* tree, CvTreeCascadeNode* leaf );
|
||||
|
||||
float icvEvalTreeCascadeClassifierFilter( CvIntHaarClassifier* classifier, sum_type* sum,
|
||||
sum_type* tilted, float normfactor );
|
||||
|
||||
CvTreeCascadeNode* icvCreateTreeCascadeNode();
|
||||
|
||||
void icvReleaseTreeCascadeNodes( CvTreeCascadeNode** node );
|
||||
|
||||
void icvReleaseTreeCascadeClassifier( CvIntHaarClassifier** classifier );
|
||||
|
||||
/* Prints out current tree structure to <stdout> */
|
||||
void icvPrintTreeCascade( CvTreeCascadeNode* root );
|
||||
|
||||
/* Loads tree cascade classifier */
|
||||
CvIntHaarClassifier* icvLoadTreeCascadeClassifier( const char* filename, int step,
|
||||
int* splits );
|
||||
|
||||
/* Finds leaves belonging to maximal level and connects them via leaf->next_same_level */
|
||||
CvTreeCascadeNode* icvFindDeepestLeaves( CvTreeCascadeClassifier* tree );
|
||||
|
||||
#endif /* __CVHAARTRAINING_H_ */
|
File diff suppressed because it is too large
Load Diff
@ -1,729 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
/*
|
||||
* File cvclassifier.h
|
||||
*
|
||||
* Classifier types
|
||||
*/
|
||||
|
||||
#ifndef _CVCLASSIFIER_H_
|
||||
#define _CVCLASSIFIER_H_
|
||||
|
||||
#include <cmath>
|
||||
#include "cxcore.h"
|
||||
|
||||
#define CV_BOOST_API
|
||||
|
||||
/* Convert matrix to vector */
|
||||
#define CV_MAT2VEC( mat, vdata, vstep, num ) \
|
||||
assert( (mat).rows == 1 || (mat).cols == 1 ); \
|
||||
(vdata) = ((mat).data.ptr); \
|
||||
if( (mat).rows == 1 ) \
|
||||
{ \
|
||||
(vstep) = CV_ELEM_SIZE( (mat).type ); \
|
||||
(num) = (mat).cols; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
(vstep) = (mat).step; \
|
||||
(num) = (mat).rows; \
|
||||
}
|
||||
|
||||
/* Set up <sample> matrix header to be <num> sample of <trainData> samples matrix */
|
||||
#define CV_GET_SAMPLE( trainData, tdflags, num, sample ) \
|
||||
if( CV_IS_ROW_SAMPLE( tdflags ) ) \
|
||||
{ \
|
||||
cvInitMatHeader( &(sample), 1, (trainData).cols, \
|
||||
CV_MAT_TYPE( (trainData).type ), \
|
||||
((trainData).data.ptr + (num) * (trainData).step), \
|
||||
(trainData).step ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
cvInitMatHeader( &(sample), (trainData).rows, 1, \
|
||||
CV_MAT_TYPE( (trainData).type ), \
|
||||
((trainData).data.ptr + (num) * CV_ELEM_SIZE( (trainData).type )), \
|
||||
(trainData).step ); \
|
||||
}
|
||||
|
||||
#define CV_GET_SAMPLE_STEP( trainData, tdflags, sstep ) \
|
||||
(sstep) = ( ( CV_IS_ROW_SAMPLE( tdflags ) ) \
|
||||
? (trainData).step : CV_ELEM_SIZE( (trainData).type ) );
|
||||
|
||||
|
||||
#define CV_LOGRATIO_THRESHOLD 0.00001F
|
||||
|
||||
/* log( val / (1 - val ) ) */
|
||||
CV_INLINE float cvLogRatio( float val );
|
||||
|
||||
CV_INLINE float cvLogRatio( float val )
|
||||
{
|
||||
float tval;
|
||||
|
||||
tval = MAX(CV_LOGRATIO_THRESHOLD, MIN( 1.0F - CV_LOGRATIO_THRESHOLD, (val) ));
|
||||
return logf( tval / (1.0F - tval) );
|
||||
}
|
||||
|
||||
|
||||
/* flags values for classifier consturctor flags parameter */
|
||||
|
||||
/* each trainData matrix column is a sample */
|
||||
#define CV_COL_SAMPLE 0
|
||||
|
||||
/* each trainData matrix row is a sample */
|
||||
#define CV_ROW_SAMPLE 1
|
||||
|
||||
#ifndef CV_IS_ROW_SAMPLE
|
||||
# define CV_IS_ROW_SAMPLE( flags ) ( ( flags ) & CV_ROW_SAMPLE )
|
||||
#endif
|
||||
|
||||
/* Classifier supports tune function */
|
||||
#define CV_TUNABLE (1 << 1)
|
||||
|
||||
#define CV_IS_TUNABLE( flags ) ( (flags) & CV_TUNABLE )
|
||||
|
||||
|
||||
/* classifier fields common to all classifiers */
|
||||
#define CV_CLASSIFIER_FIELDS() \
|
||||
int flags; \
|
||||
float(*eval)( struct CvClassifier*, CvMat* ); \
|
||||
void (*tune)( struct CvClassifier*, CvMat*, int flags, CvMat*, CvMat*, CvMat*, \
|
||||
CvMat*, CvMat* ); \
|
||||
int (*save)( struct CvClassifier*, const char* file_name ); \
|
||||
void (*release)( struct CvClassifier** );
|
||||
|
||||
typedef struct CvClassifier
|
||||
{
|
||||
CV_CLASSIFIER_FIELDS()
|
||||
} CvClassifier;
|
||||
|
||||
#define CV_CLASSIFIER_TRAIN_PARAM_FIELDS()
|
||||
typedef struct CvClassifierTrainParams
|
||||
{
|
||||
CV_CLASSIFIER_TRAIN_PARAM_FIELDS()
|
||||
} CvClassifierTrainParams;
|
||||
|
||||
|
||||
/*
|
||||
Common classifier constructor:
|
||||
CvClassifier* cvCreateMyClassifier( CvMat* trainData,
|
||||
int flags,
|
||||
CvMat* trainClasses,
|
||||
CvMat* typeMask,
|
||||
CvMat* missedMeasurementsMask CV_DEFAULT(0),
|
||||
CvCompIdx* compIdx CV_DEFAULT(0),
|
||||
CvMat* sampleIdx CV_DEFAULT(0),
|
||||
CvMat* weights CV_DEFAULT(0),
|
||||
CvClassifierTrainParams* trainParams CV_DEFAULT(0)
|
||||
)
|
||||
|
||||
*/
|
||||
|
||||
typedef CvClassifier* (*CvClassifierConstructor)( CvMat*, int, CvMat*, CvMat*, CvMat*,
|
||||
CvMat*, CvMat*, CvMat*,
|
||||
CvClassifierTrainParams* );
|
||||
|
||||
typedef enum CvStumpType
|
||||
{
|
||||
CV_CLASSIFICATION = 0,
|
||||
CV_CLASSIFICATION_CLASS = 1,
|
||||
CV_REGRESSION = 2
|
||||
} CvStumpType;
|
||||
|
||||
typedef enum CvStumpError
|
||||
{
|
||||
CV_MISCLASSIFICATION = 0,
|
||||
CV_GINI = 1,
|
||||
CV_ENTROPY = 2,
|
||||
CV_SQUARE = 3
|
||||
} CvStumpError;
|
||||
|
||||
|
||||
typedef struct CvStumpTrainParams
|
||||
{
|
||||
CV_CLASSIFIER_TRAIN_PARAM_FIELDS()
|
||||
CvStumpType type;
|
||||
CvStumpError error;
|
||||
} CvStumpTrainParams;
|
||||
|
||||
typedef struct CvMTStumpTrainParams
|
||||
{
|
||||
CV_CLASSIFIER_TRAIN_PARAM_FIELDS()
|
||||
CvStumpType type;
|
||||
CvStumpError error;
|
||||
int portion; /* number of components calculated in each thread */
|
||||
int numcomp; /* total number of components */
|
||||
|
||||
/* callback which fills <mat> with components [first, first+num[ */
|
||||
void (*getTrainData)( CvMat* mat, CvMat* sampleIdx, CvMat* compIdx,
|
||||
int first, int num, void* userdata );
|
||||
CvMat* sortedIdx; /* presorted samples indices */
|
||||
void* userdata; /* passed to callback */
|
||||
} CvMTStumpTrainParams;
|
||||
|
||||
typedef struct CvStumpClassifier
|
||||
{
|
||||
CV_CLASSIFIER_FIELDS()
|
||||
int compidx;
|
||||
|
||||
float lerror; /* impurity of the right node */
|
||||
float rerror; /* impurity of the left node */
|
||||
|
||||
float threshold;
|
||||
float left;
|
||||
float right;
|
||||
} CvStumpClassifier;
|
||||
|
||||
typedef struct CvCARTTrainParams
|
||||
{
|
||||
CV_CLASSIFIER_TRAIN_PARAM_FIELDS()
|
||||
/* desired number of internal nodes */
|
||||
int count;
|
||||
CvClassifierTrainParams* stumpTrainParams;
|
||||
CvClassifierConstructor stumpConstructor;
|
||||
|
||||
/*
|
||||
* Split sample indices <idx>
|
||||
* on the "left" indices <left> and "right" indices <right>
|
||||
* according to samples components <compidx> values and <threshold>.
|
||||
*
|
||||
* NOTE: Matrices <left> and <right> must be allocated using cvCreateMat function
|
||||
* since they are freed using cvReleaseMat function
|
||||
*
|
||||
* If it is NULL then the default implementation which evaluates training
|
||||
* samples from <trainData> passed to classifier constructor is used
|
||||
*/
|
||||
void (*splitIdx)( int compidx, float threshold,
|
||||
CvMat* idx, CvMat** left, CvMat** right,
|
||||
void* userdata );
|
||||
void* userdata;
|
||||
} CvCARTTrainParams;
|
||||
|
||||
typedef struct CvCARTClassifier
|
||||
{
|
||||
CV_CLASSIFIER_FIELDS()
|
||||
/* number of internal nodes */
|
||||
int count;
|
||||
|
||||
/* internal nodes (each array of <count> elements) */
|
||||
int* compidx;
|
||||
float* threshold;
|
||||
int* left;
|
||||
int* right;
|
||||
|
||||
/* leaves (array of <count>+1 elements) */
|
||||
float* val;
|
||||
} CvCARTClassifier;
|
||||
|
||||
CV_BOOST_API
|
||||
void cvGetSortedIndices( CvMat* val, CvMat* idx, int sortcols CV_DEFAULT( 0 ) );
|
||||
|
||||
CV_BOOST_API
|
||||
void cvReleaseStumpClassifier( CvClassifier** classifier );
|
||||
|
||||
CV_BOOST_API
|
||||
float cvEvalStumpClassifier( CvClassifier* classifier, CvMat* sample );
|
||||
|
||||
CV_BOOST_API
|
||||
CvClassifier* cvCreateStumpClassifier( CvMat* trainData,
|
||||
int flags,
|
||||
CvMat* trainClasses,
|
||||
CvMat* typeMask,
|
||||
CvMat* missedMeasurementsMask CV_DEFAULT(0),
|
||||
CvMat* compIdx CV_DEFAULT(0),
|
||||
CvMat* sampleIdx CV_DEFAULT(0),
|
||||
CvMat* weights CV_DEFAULT(0),
|
||||
CvClassifierTrainParams* trainParams CV_DEFAULT(0) );
|
||||
|
||||
/*
|
||||
* cvCreateMTStumpClassifier
|
||||
*
|
||||
* Multithreaded stump classifier constructor
|
||||
* Includes huge train data support through callback function
|
||||
*/
|
||||
CV_BOOST_API
|
||||
CvClassifier* cvCreateMTStumpClassifier( CvMat* trainData,
|
||||
int flags,
|
||||
CvMat* trainClasses,
|
||||
CvMat* typeMask,
|
||||
CvMat* missedMeasurementsMask,
|
||||
CvMat* compIdx,
|
||||
CvMat* sampleIdx,
|
||||
CvMat* weights,
|
||||
CvClassifierTrainParams* trainParams );
|
||||
|
||||
/*
|
||||
* cvCreateCARTClassifier
|
||||
*
|
||||
* CART classifier constructor
|
||||
*/
|
||||
CV_BOOST_API
|
||||
CvClassifier* cvCreateCARTClassifier( CvMat* trainData,
|
||||
int flags,
|
||||
CvMat* trainClasses,
|
||||
CvMat* typeMask,
|
||||
CvMat* missedMeasurementsMask,
|
||||
CvMat* compIdx,
|
||||
CvMat* sampleIdx,
|
||||
CvMat* weights,
|
||||
CvClassifierTrainParams* trainParams );
|
||||
|
||||
CV_BOOST_API
|
||||
void cvReleaseCARTClassifier( CvClassifier** classifier );
|
||||
|
||||
CV_BOOST_API
|
||||
float cvEvalCARTClassifier( CvClassifier* classifier, CvMat* sample );
|
||||
|
||||
/****************************************************************************************\
|
||||
* Boosting *
|
||||
\****************************************************************************************/
|
||||
|
||||
/*
|
||||
* CvBoostType
|
||||
*
|
||||
* The CvBoostType enumeration specifies the boosting type.
|
||||
*
|
||||
* Remarks
|
||||
* Four different boosting variants for 2 class classification problems are supported:
|
||||
* Discrete AdaBoost, Real AdaBoost, LogitBoost and Gentle AdaBoost.
|
||||
* The L2 (2 class classification problems) and LK (K class classification problems)
|
||||
* algorithms are close to LogitBoost but more numerically stable than last one.
|
||||
* For regression three different loss functions are supported:
|
||||
* Least square, least absolute deviation and huber loss.
|
||||
*/
|
||||
typedef enum CvBoostType
|
||||
{
|
||||
CV_DABCLASS = 0, /* 2 class Discrete AdaBoost */
|
||||
CV_RABCLASS = 1, /* 2 class Real AdaBoost */
|
||||
CV_LBCLASS = 2, /* 2 class LogitBoost */
|
||||
CV_GABCLASS = 3, /* 2 class Gentle AdaBoost */
|
||||
CV_L2CLASS = 4, /* classification (2 class problem) */
|
||||
CV_LKCLASS = 5, /* classification (K class problem) */
|
||||
CV_LSREG = 6, /* least squares regression */
|
||||
CV_LADREG = 7, /* least absolute deviation regression */
|
||||
CV_MREG = 8, /* M-regression (Huber loss) */
|
||||
} CvBoostType;
|
||||
|
||||
/****************************************************************************************\
|
||||
* Iterative training functions *
|
||||
\****************************************************************************************/
|
||||
|
||||
/*
|
||||
* CvBoostTrainer
|
||||
*
|
||||
* The CvBoostTrainer structure represents internal boosting trainer.
|
||||
*/
|
||||
typedef struct CvBoostTrainer CvBoostTrainer;
|
||||
|
||||
/*
|
||||
* cvBoostStartTraining
|
||||
*
|
||||
* The cvBoostStartTraining function starts training process and calculates
|
||||
* response values and weights for the first weak classifier training.
|
||||
*
|
||||
* Parameters
|
||||
* trainClasses
|
||||
* Vector of classes of training samples classes. Each element must be 0 or 1 and
|
||||
* of type CV_32FC1.
|
||||
* weakTrainVals
|
||||
* Vector of response values for the first trained weak classifier.
|
||||
* Must be of type CV_32FC1.
|
||||
* weights
|
||||
* Weight vector of training samples for the first trained weak classifier.
|
||||
* Must be of type CV_32FC1.
|
||||
* type
|
||||
* Boosting type. CV_DABCLASS, CV_RABCLASS, CV_LBCLASS, CV_GABCLASS
|
||||
* types are supported.
|
||||
*
|
||||
* Return Values
|
||||
* The return value is a pointer to internal trainer structure which is used
|
||||
* to perform next training iterations.
|
||||
*
|
||||
* Remarks
|
||||
* weakTrainVals and weights must be allocated before calling the function
|
||||
* and of the same size as trainingClasses. Usually weights should be initialized
|
||||
* with 1.0 value.
|
||||
* The function calculates response values and weights for the first weak
|
||||
* classifier training and stores them into weakTrainVals and weights
|
||||
* respectively.
|
||||
* Note, the training of the weak classifier using weakTrainVals, weight,
|
||||
* trainingData is outside of this function.
|
||||
*/
|
||||
CV_BOOST_API
|
||||
CvBoostTrainer* cvBoostStartTraining( CvMat* trainClasses,
|
||||
CvMat* weakTrainVals,
|
||||
CvMat* weights,
|
||||
CvMat* sampleIdx,
|
||||
CvBoostType type );
|
||||
/*
|
||||
* cvBoostNextWeakClassifier
|
||||
*
|
||||
* The cvBoostNextWeakClassifier function performs next training
|
||||
* iteration and caluclates response values and weights for the next weak
|
||||
* classifier training.
|
||||
*
|
||||
* Parameters
|
||||
* weakEvalVals
|
||||
* Vector of values obtained by evaluation of each sample with
|
||||
* the last trained weak classifier (iteration i). Must be of CV_32FC1 type.
|
||||
* trainClasses
|
||||
* Vector of classes of training samples. Each element must be 0 or 1,
|
||||
* and of type CV_32FC1.
|
||||
* weakTrainVals
|
||||
* Vector of response values for the next weak classifier training
|
||||
* (iteration i+1). Must be of type CV_32FC1.
|
||||
* weights
|
||||
* Weight vector of training samples for the next weak classifier training
|
||||
* (iteration i+1). Must be of type CV_32FC1.
|
||||
* trainer
|
||||
* A pointer to internal trainer returned by the cvBoostStartTraining
|
||||
* function call.
|
||||
*
|
||||
* Return Values
|
||||
* The return value is the coefficient for the last trained weak classifier.
|
||||
*
|
||||
* Remarks
|
||||
* weakTrainVals and weights must be exactly the same vectors as used in
|
||||
* the cvBoostStartTraining function call and should not be modified.
|
||||
* The function calculates response values and weights for the next weak
|
||||
* classifier training and stores them into weakTrainVals and weights
|
||||
* respectively.
|
||||
* Note, the training of the weak classifier of iteration i+1 using
|
||||
* weakTrainVals, weight, trainingData is outside of this function.
|
||||
*/
|
||||
CV_BOOST_API
|
||||
float cvBoostNextWeakClassifier( CvMat* weakEvalVals,
|
||||
CvMat* trainClasses,
|
||||
CvMat* weakTrainVals,
|
||||
CvMat* weights,
|
||||
CvBoostTrainer* trainer );
|
||||
|
||||
/*
|
||||
* cvBoostEndTraining
|
||||
*
|
||||
* The cvBoostEndTraining function finishes training process and releases
|
||||
* internally allocated memory.
|
||||
*
|
||||
* Parameters
|
||||
* trainer
|
||||
* A pointer to a pointer to internal trainer returned by the cvBoostStartTraining
|
||||
* function call.
|
||||
*/
|
||||
CV_BOOST_API
|
||||
void cvBoostEndTraining( CvBoostTrainer** trainer );
|
||||
|
||||
/****************************************************************************************\
|
||||
* Boosted tree models *
|
||||
\****************************************************************************************/
|
||||
|
||||
/*
|
||||
* CvBtClassifier
|
||||
*
|
||||
* The CvBtClassifier structure represents boosted tree model.
|
||||
*
|
||||
* Members
|
||||
* flags
|
||||
* Flags. If CV_IS_TUNABLE( flags ) != 0 then the model supports tuning.
|
||||
* eval
|
||||
* Evaluation function. Returns sample predicted class (0, 1, etc.)
|
||||
* for classification or predicted value for regression.
|
||||
* tune
|
||||
* Tune function. If the model supports tuning then tune call performs
|
||||
* one more boosting iteration if passed to the function flags parameter
|
||||
* is CV_TUNABLE otherwise releases internally allocated for tuning memory
|
||||
* and makes the model untunable.
|
||||
* NOTE: Since tuning uses the pointers to parameters,
|
||||
* passed to the cvCreateBtClassifier function, they should not be modified
|
||||
* or released between tune calls.
|
||||
* save
|
||||
* This function stores the model into given file.
|
||||
* release
|
||||
* This function releases the model.
|
||||
* type
|
||||
* Boosted tree model type.
|
||||
* numclasses
|
||||
* Number of classes for CV_LKCLASS type or 1 for all other types.
|
||||
* numiter
|
||||
* Number of iterations. Number of weak classifiers is equal to number
|
||||
* of iterations for all types except CV_LKCLASS. For CV_LKCLASS type
|
||||
* number of weak classifiers is (numiter * numclasses).
|
||||
* numfeatures
|
||||
* Number of features in sample.
|
||||
* trees
|
||||
* Stores weak classifiers when the model does not support tuning.
|
||||
* seq
|
||||
* Stores weak classifiers when the model supports tuning.
|
||||
* trainer
|
||||
* Pointer to internal tuning parameters if the model supports tuning.
|
||||
*/
|
||||
typedef struct CvBtClassifier
|
||||
{
|
||||
CV_CLASSIFIER_FIELDS()
|
||||
|
||||
CvBoostType type;
|
||||
int numclasses;
|
||||
int numiter;
|
||||
int numfeatures;
|
||||
union
|
||||
{
|
||||
CvCARTClassifier** trees;
|
||||
CvSeq* seq;
|
||||
};
|
||||
void* trainer;
|
||||
} CvBtClassifier;
|
||||
|
||||
/*
|
||||
* CvBtClassifierTrainParams
|
||||
*
|
||||
* The CvBtClassifierTrainParams structure stores training parameters for
|
||||
* boosted tree model.
|
||||
*
|
||||
* Members
|
||||
* type
|
||||
* Boosted tree model type.
|
||||
* numiter
|
||||
* Desired number of iterations.
|
||||
* param
|
||||
* Parameter Model Type Parameter Meaning
|
||||
* param[0] Any Shrinkage factor
|
||||
* param[1] CV_MREG alpha. (1-alpha) determines "break-down" point of
|
||||
* the training procedure, i.e. the fraction of samples
|
||||
* that can be arbitrary modified without serious
|
||||
* degrading the quality of the result.
|
||||
* CV_DABCLASS, Weight trimming factor.
|
||||
* CV_RABCLASS,
|
||||
* CV_LBCLASS,
|
||||
* CV_GABCLASS,
|
||||
* CV_L2CLASS,
|
||||
* CV_LKCLASS
|
||||
* numsplits
|
||||
* Desired number of splits in each tree.
|
||||
*/
|
||||
typedef struct CvBtClassifierTrainParams
|
||||
{
|
||||
CV_CLASSIFIER_TRAIN_PARAM_FIELDS()
|
||||
|
||||
CvBoostType type;
|
||||
int numiter;
|
||||
float param[2];
|
||||
int numsplits;
|
||||
} CvBtClassifierTrainParams;
|
||||
|
||||
/*
|
||||
* cvCreateBtClassifier
|
||||
*
|
||||
* The cvCreateBtClassifier function creates boosted tree model.
|
||||
*
|
||||
* Parameters
|
||||
* trainData
|
||||
* Matrix of feature values. Must have CV_32FC1 type.
|
||||
* flags
|
||||
* Determines how samples are stored in trainData.
|
||||
* One of CV_ROW_SAMPLE or CV_COL_SAMPLE.
|
||||
* Optionally may be combined with CV_TUNABLE to make tunable model.
|
||||
* trainClasses
|
||||
* Vector of responses for regression or classes (0, 1, 2, etc.) for classification.
|
||||
* typeMask,
|
||||
* missedMeasurementsMask,
|
||||
* compIdx
|
||||
* Not supported. Must be NULL.
|
||||
* sampleIdx
|
||||
* Indices of samples used in training. If NULL then all samples are used.
|
||||
* For CV_DABCLASS, CV_RABCLASS, CV_LBCLASS and CV_GABCLASS must be NULL.
|
||||
* weights
|
||||
* Not supported. Must be NULL.
|
||||
* trainParams
|
||||
* A pointer to CvBtClassifierTrainParams structure. Training parameters.
|
||||
* See CvBtClassifierTrainParams description for details.
|
||||
*
|
||||
* Return Values
|
||||
* The return value is a pointer to created boosted tree model of type CvBtClassifier.
|
||||
*
|
||||
* Remarks
|
||||
* The function performs trainParams->numiter training iterations.
|
||||
* If CV_TUNABLE flag is specified then created model supports tuning.
|
||||
* In this case additional training iterations may be performed by
|
||||
* tune function call.
|
||||
*/
|
||||
CV_BOOST_API
|
||||
CvClassifier* cvCreateBtClassifier( CvMat* trainData,
|
||||
int flags,
|
||||
CvMat* trainClasses,
|
||||
CvMat* typeMask,
|
||||
CvMat* missedMeasurementsMask,
|
||||
CvMat* compIdx,
|
||||
CvMat* sampleIdx,
|
||||
CvMat* weights,
|
||||
CvClassifierTrainParams* trainParams );
|
||||
|
||||
/*
|
||||
* cvCreateBtClassifierFromFile
|
||||
*
|
||||
* The cvCreateBtClassifierFromFile function restores previously saved
|
||||
* boosted tree model from file.
|
||||
*
|
||||
* Parameters
|
||||
* filename
|
||||
* The name of the file with boosted tree model.
|
||||
*
|
||||
* Remarks
|
||||
* The restored model does not support tuning.
|
||||
*/
|
||||
CV_BOOST_API
|
||||
CvClassifier* cvCreateBtClassifierFromFile( const char* filename );
|
||||
|
||||
/****************************************************************************************\
|
||||
* Utility functions *
|
||||
\****************************************************************************************/
|
||||
|
||||
/*
|
||||
* cvTrimWeights
|
||||
*
|
||||
* The cvTrimWeights function performs weight trimming.
|
||||
*
|
||||
* Parameters
|
||||
* weights
|
||||
* Weights vector.
|
||||
* idx
|
||||
* Indices vector of weights that should be considered.
|
||||
* If it is NULL then all weights are used.
|
||||
* factor
|
||||
* Weight trimming factor. Must be in [0, 1] range.
|
||||
*
|
||||
* Return Values
|
||||
* The return value is a vector of indices. If all samples should be used then
|
||||
* it is equal to idx. In other case the cvReleaseMat function should be called
|
||||
* to release it.
|
||||
*
|
||||
* Remarks
|
||||
*/
|
||||
CV_BOOST_API
|
||||
CvMat* cvTrimWeights( CvMat* weights, CvMat* idx, float factor );
|
||||
|
||||
/*
|
||||
* cvReadTrainData
|
||||
*
|
||||
* The cvReadTrainData function reads feature values and responses from file.
|
||||
*
|
||||
* Parameters
|
||||
* filename
|
||||
* The name of the file to be read.
|
||||
* flags
|
||||
* One of CV_ROW_SAMPLE or CV_COL_SAMPLE. Determines how feature values
|
||||
* will be stored.
|
||||
* trainData
|
||||
* A pointer to a pointer to created matrix with feature values.
|
||||
* cvReleaseMat function should be used to destroy created matrix.
|
||||
* trainClasses
|
||||
* A pointer to a pointer to created matrix with response values.
|
||||
* cvReleaseMat function should be used to destroy created matrix.
|
||||
*
|
||||
* Remarks
|
||||
* File format:
|
||||
* ============================================
|
||||
* m n
|
||||
* value_1_1 value_1_2 ... value_1_n response_1
|
||||
* value_2_1 value_2_2 ... value_2_n response_2
|
||||
* ...
|
||||
* value_m_1 value_m_2 ... value_m_n response_m
|
||||
* ============================================
|
||||
* m
|
||||
* Number of samples
|
||||
* n
|
||||
* Number of features in each sample
|
||||
* value_i_j
|
||||
* Value of j-th feature of i-th sample
|
||||
* response_i
|
||||
* Response value of i-th sample
|
||||
* For classification problems responses represent classes (0, 1, etc.)
|
||||
* All values and classes are integer or real numbers.
|
||||
*/
|
||||
CV_BOOST_API
|
||||
void cvReadTrainData( const char* filename,
|
||||
int flags,
|
||||
CvMat** trainData,
|
||||
CvMat** trainClasses );
|
||||
|
||||
|
||||
/*
|
||||
* cvWriteTrainData
|
||||
*
|
||||
* The cvWriteTrainData function stores feature values and responses into file.
|
||||
*
|
||||
* Parameters
|
||||
* filename
|
||||
* The name of the file.
|
||||
* flags
|
||||
* One of CV_ROW_SAMPLE or CV_COL_SAMPLE. Determines how feature values
|
||||
* are stored.
|
||||
* trainData
|
||||
* Feature values matrix.
|
||||
* trainClasses
|
||||
* Response values vector.
|
||||
* sampleIdx
|
||||
* Vector of idicies of the samples that should be stored. If it is NULL
|
||||
* then all samples will be stored.
|
||||
*
|
||||
* Remarks
|
||||
* See the cvReadTrainData function for file format description.
|
||||
*/
|
||||
CV_BOOST_API
|
||||
void cvWriteTrainData( const char* filename,
|
||||
int flags,
|
||||
CvMat* trainData,
|
||||
CvMat* trainClasses,
|
||||
CvMat* sampleIdx );
|
||||
|
||||
/*
|
||||
* cvRandShuffle
|
||||
*
|
||||
* The cvRandShuffle function perfroms random shuffling of given vector.
|
||||
*
|
||||
* Parameters
|
||||
* vector
|
||||
* Vector that should be shuffled.
|
||||
* Must have CV_8UC1, CV_16SC1, CV_32SC1 or CV_32FC1 type.
|
||||
*/
|
||||
CV_BOOST_API
|
||||
void cvRandShuffleVec( CvMat* vector );
|
||||
|
||||
#endif /* _CVCLASSIFIER_H_ */
|
@ -1,125 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "_cvcommon.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
int icvMkDir( const char* filename )
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
char* p;
|
||||
int pos;
|
||||
|
||||
#ifdef _WIN32
|
||||
struct _stat st;
|
||||
#else /* _WIN32 */
|
||||
struct stat st;
|
||||
mode_t mode;
|
||||
|
||||
mode = 0755;
|
||||
#endif /* _WIN32 */
|
||||
|
||||
strcpy( path, filename );
|
||||
|
||||
p = path;
|
||||
for( ; ; )
|
||||
{
|
||||
pos = (int)strcspn( p, "/\\" );
|
||||
|
||||
if( pos == (int) strlen( p ) ) break;
|
||||
if( pos != 0 )
|
||||
{
|
||||
p[pos] = '\0';
|
||||
|
||||
#ifdef _WIN32
|
||||
if( p[pos-1] != ':' )
|
||||
{
|
||||
if( _stat( path, &st ) != 0 )
|
||||
{
|
||||
if( _mkdir( path ) != 0 ) return 0;
|
||||
}
|
||||
}
|
||||
#else /* _WIN32 */
|
||||
if( stat( path, &st ) != 0 )
|
||||
{
|
||||
if( mkdir( path, mode ) != 0 ) return 0;
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
p[pos] = '/';
|
||||
|
||||
p += pos + 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* debug functions */
|
||||
void icvSave( const CvArr* ptr, const char* filename, int line )
|
||||
{
|
||||
CvFileStorage* fs;
|
||||
char buf[PATH_MAX];
|
||||
const char* name;
|
||||
|
||||
name = strrchr( filename, '\\' );
|
||||
if( !name ) name = strrchr( filename, '/' );
|
||||
if( !name ) name = filename;
|
||||
else name++; /* skip '/' or '\\' */
|
||||
|
||||
sprintf( buf, "%s-%d-%d", name, line, time( NULL ) );
|
||||
fs = cvOpenFileStorage( buf, NULL, CV_STORAGE_WRITE_TEXT );
|
||||
if( !fs ) return;
|
||||
cvWrite( fs, "debug", ptr );
|
||||
cvReleaseFileStorage( &fs );
|
||||
}
|
||||
#endif // #if 0
|
||||
|
||||
/* End of file. */
|
@ -1,835 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
/*
|
||||
* cvhaarclassifier.cpp
|
||||
*
|
||||
* haar classifiers (stump, CART, stage, cascade)
|
||||
*/
|
||||
|
||||
#include "_cvhaartraining.h"
|
||||
|
||||
|
||||
CvIntHaarClassifier* icvCreateCARTHaarClassifier( int count )
|
||||
{
|
||||
CvCARTHaarClassifier* cart;
|
||||
size_t datasize;
|
||||
|
||||
datasize = sizeof( *cart ) +
|
||||
( sizeof( int ) +
|
||||
sizeof( CvTHaarFeature ) + sizeof( CvFastHaarFeature ) +
|
||||
sizeof( float ) + sizeof( int ) + sizeof( int ) ) * count +
|
||||
sizeof( float ) * (count + 1);
|
||||
|
||||
cart = (CvCARTHaarClassifier*) cvAlloc( datasize );
|
||||
memset( cart, 0, datasize );
|
||||
|
||||
cart->feature = (CvTHaarFeature*) (cart + 1);
|
||||
cart->fastfeature = (CvFastHaarFeature*) (cart->feature + count);
|
||||
cart->threshold = (float*) (cart->fastfeature + count);
|
||||
cart->left = (int*) (cart->threshold + count);
|
||||
cart->right = (int*) (cart->left + count);
|
||||
cart->val = (float*) (cart->right + count);
|
||||
cart->compidx = (int*) (cart->val + count + 1 );
|
||||
cart->count = count;
|
||||
cart->eval = icvEvalCARTHaarClassifier;
|
||||
cart->save = icvSaveCARTHaarClassifier;
|
||||
cart->release = icvReleaseHaarClassifier;
|
||||
|
||||
return (CvIntHaarClassifier*) cart;
|
||||
}
|
||||
|
||||
|
||||
void icvReleaseHaarClassifier( CvIntHaarClassifier** classifier )
|
||||
{
|
||||
cvFree( classifier );
|
||||
*classifier = NULL;
|
||||
}
|
||||
|
||||
|
||||
void icvInitCARTHaarClassifier( CvCARTHaarClassifier* carthaar, CvCARTClassifier* cart,
|
||||
CvIntHaarFeatures* intHaarFeatures )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; i < cart->count; i++ )
|
||||
{
|
||||
carthaar->feature[i] = intHaarFeatures->feature[cart->compidx[i]];
|
||||
carthaar->fastfeature[i] = intHaarFeatures->fastfeature[cart->compidx[i]];
|
||||
carthaar->threshold[i] = cart->threshold[i];
|
||||
carthaar->left[i] = cart->left[i];
|
||||
carthaar->right[i] = cart->right[i];
|
||||
carthaar->val[i] = cart->val[i];
|
||||
carthaar->compidx[i] = cart->compidx[i];
|
||||
}
|
||||
carthaar->count = cart->count;
|
||||
carthaar->val[cart->count] = cart->val[cart->count];
|
||||
}
|
||||
|
||||
|
||||
float icvEvalCARTHaarClassifier( CvIntHaarClassifier* classifier,
|
||||
sum_type* sum, sum_type* tilted, float normfactor )
|
||||
{
|
||||
int idx = 0;
|
||||
|
||||
do
|
||||
{
|
||||
if( cvEvalFastHaarFeature(
|
||||
((CvCARTHaarClassifier*) classifier)->fastfeature + idx, sum, tilted )
|
||||
< (((CvCARTHaarClassifier*) classifier)->threshold[idx] * normfactor) )
|
||||
{
|
||||
idx = ((CvCARTHaarClassifier*) classifier)->left[idx];
|
||||
}
|
||||
else
|
||||
{
|
||||
idx = ((CvCARTHaarClassifier*) classifier)->right[idx];
|
||||
}
|
||||
} while( idx > 0 );
|
||||
|
||||
return ((CvCARTHaarClassifier*) classifier)->val[-idx];
|
||||
}
|
||||
|
||||
|
||||
CvIntHaarClassifier* icvCreateStageHaarClassifier( int count, float threshold )
|
||||
{
|
||||
CvStageHaarClassifier* stage;
|
||||
size_t datasize;
|
||||
|
||||
datasize = sizeof( *stage ) + sizeof( CvIntHaarClassifier* ) * count;
|
||||
stage = (CvStageHaarClassifier*) cvAlloc( datasize );
|
||||
memset( stage, 0, datasize );
|
||||
|
||||
stage->count = count;
|
||||
stage->threshold = threshold;
|
||||
stage->classifier = (CvIntHaarClassifier**) (stage + 1);
|
||||
|
||||
stage->eval = icvEvalStageHaarClassifier;
|
||||
stage->save = icvSaveStageHaarClassifier;
|
||||
stage->release = icvReleaseStageHaarClassifier;
|
||||
|
||||
return (CvIntHaarClassifier*) stage;
|
||||
}
|
||||
|
||||
|
||||
void icvReleaseStageHaarClassifier( CvIntHaarClassifier** classifier )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; i < ((CvStageHaarClassifier*) *classifier)->count; i++ )
|
||||
{
|
||||
if( ((CvStageHaarClassifier*) *classifier)->classifier[i] != NULL )
|
||||
{
|
||||
((CvStageHaarClassifier*) *classifier)->classifier[i]->release(
|
||||
&(((CvStageHaarClassifier*) *classifier)->classifier[i]) );
|
||||
}
|
||||
}
|
||||
|
||||
cvFree( classifier );
|
||||
*classifier = NULL;
|
||||
}
|
||||
|
||||
|
||||
float icvEvalStageHaarClassifier( CvIntHaarClassifier* classifier,
|
||||
sum_type* sum, sum_type* tilted, float normfactor )
|
||||
{
|
||||
int i;
|
||||
float stage_sum;
|
||||
|
||||
stage_sum = 0.0F;
|
||||
for( i = 0; i < ((CvStageHaarClassifier*) classifier)->count; i++ )
|
||||
{
|
||||
stage_sum +=
|
||||
((CvStageHaarClassifier*) classifier)->classifier[i]->eval(
|
||||
((CvStageHaarClassifier*) classifier)->classifier[i],
|
||||
sum, tilted, normfactor );
|
||||
}
|
||||
|
||||
return stage_sum;
|
||||
}
|
||||
|
||||
|
||||
CvIntHaarClassifier* icvCreateCascadeHaarClassifier( int count )
|
||||
{
|
||||
CvCascadeHaarClassifier* ptr;
|
||||
size_t datasize;
|
||||
|
||||
datasize = sizeof( *ptr ) + sizeof( CvIntHaarClassifier* ) * count;
|
||||
ptr = (CvCascadeHaarClassifier*) cvAlloc( datasize );
|
||||
memset( ptr, 0, datasize );
|
||||
|
||||
ptr->count = count;
|
||||
ptr->classifier = (CvIntHaarClassifier**) (ptr + 1);
|
||||
|
||||
ptr->eval = icvEvalCascadeHaarClassifier;
|
||||
ptr->save = NULL;
|
||||
ptr->release = icvReleaseCascadeHaarClassifier;
|
||||
|
||||
return (CvIntHaarClassifier*) ptr;
|
||||
}
|
||||
|
||||
|
||||
void icvReleaseCascadeHaarClassifier( CvIntHaarClassifier** classifier )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; i < ((CvCascadeHaarClassifier*) *classifier)->count; i++ )
|
||||
{
|
||||
if( ((CvCascadeHaarClassifier*) *classifier)->classifier[i] != NULL )
|
||||
{
|
||||
((CvCascadeHaarClassifier*) *classifier)->classifier[i]->release(
|
||||
&(((CvCascadeHaarClassifier*) *classifier)->classifier[i]) );
|
||||
}
|
||||
}
|
||||
|
||||
cvFree( classifier );
|
||||
*classifier = NULL;
|
||||
}
|
||||
|
||||
|
||||
float icvEvalCascadeHaarClassifier( CvIntHaarClassifier* classifier,
|
||||
sum_type* sum, sum_type* tilted, float normfactor )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; i < ((CvCascadeHaarClassifier*) classifier)->count; i++ )
|
||||
{
|
||||
if( ((CvCascadeHaarClassifier*) classifier)->classifier[i]->eval(
|
||||
((CvCascadeHaarClassifier*) classifier)->classifier[i],
|
||||
sum, tilted, normfactor )
|
||||
< ( ((CvStageHaarClassifier*)
|
||||
((CvCascadeHaarClassifier*) classifier)->classifier[i])->threshold
|
||||
- CV_THRESHOLD_EPS) )
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
|
||||
void icvSaveHaarFeature( CvTHaarFeature* feature, FILE* file )
|
||||
{
|
||||
fprintf( file, "%d\n", ( ( feature->rect[2].weight == 0.0F ) ? 2 : 3) );
|
||||
fprintf( file, "%d %d %d %d %d %d\n",
|
||||
feature->rect[0].r.x,
|
||||
feature->rect[0].r.y,
|
||||
feature->rect[0].r.width,
|
||||
feature->rect[0].r.height,
|
||||
0,
|
||||
(int) (feature->rect[0].weight) );
|
||||
fprintf( file, "%d %d %d %d %d %d\n",
|
||||
feature->rect[1].r.x,
|
||||
feature->rect[1].r.y,
|
||||
feature->rect[1].r.width,
|
||||
feature->rect[1].r.height,
|
||||
0,
|
||||
(int) (feature->rect[1].weight) );
|
||||
if( feature->rect[2].weight != 0.0F )
|
||||
{
|
||||
fprintf( file, "%d %d %d %d %d %d\n",
|
||||
feature->rect[2].r.x,
|
||||
feature->rect[2].r.y,
|
||||
feature->rect[2].r.width,
|
||||
feature->rect[2].r.height,
|
||||
0,
|
||||
(int) (feature->rect[2].weight) );
|
||||
}
|
||||
fprintf( file, "%s\n", &(feature->desc[0]) );
|
||||
}
|
||||
|
||||
|
||||
void icvLoadHaarFeature( CvTHaarFeature* feature, FILE* file )
|
||||
{
|
||||
int nrect;
|
||||
int j;
|
||||
int tmp;
|
||||
int weight;
|
||||
|
||||
nrect = 0;
|
||||
int values_read = fscanf( file, "%d", &nrect );
|
||||
CV_Assert(values_read == 1);
|
||||
|
||||
assert( nrect <= CV_HAAR_FEATURE_MAX );
|
||||
|
||||
for( j = 0; j < nrect; j++ )
|
||||
{
|
||||
values_read = fscanf( file, "%d %d %d %d %d %d",
|
||||
&(feature->rect[j].r.x),
|
||||
&(feature->rect[j].r.y),
|
||||
&(feature->rect[j].r.width),
|
||||
&(feature->rect[j].r.height),
|
||||
&tmp, &weight );
|
||||
CV_Assert(values_read == 6);
|
||||
feature->rect[j].weight = (float) weight;
|
||||
}
|
||||
for( j = nrect; j < CV_HAAR_FEATURE_MAX; j++ )
|
||||
{
|
||||
feature->rect[j].r.x = 0;
|
||||
feature->rect[j].r.y = 0;
|
||||
feature->rect[j].r.width = 0;
|
||||
feature->rect[j].r.height = 0;
|
||||
feature->rect[j].weight = 0.0f;
|
||||
}
|
||||
values_read = fscanf( file, "%s", &(feature->desc[0]) );
|
||||
CV_Assert(values_read == 1);
|
||||
feature->tilted = ( feature->desc[0] == 't' );
|
||||
}
|
||||
|
||||
|
||||
void icvSaveCARTHaarClassifier( CvIntHaarClassifier* classifier, FILE* file )
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
|
||||
count = ((CvCARTHaarClassifier*) classifier)->count;
|
||||
fprintf( file, "%d\n", count );
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
icvSaveHaarFeature( &(((CvCARTHaarClassifier*) classifier)->feature[i]), file );
|
||||
fprintf( file, "%e %d %d\n",
|
||||
((CvCARTHaarClassifier*) classifier)->threshold[i],
|
||||
((CvCARTHaarClassifier*) classifier)->left[i],
|
||||
((CvCARTHaarClassifier*) classifier)->right[i] );
|
||||
}
|
||||
for( i = 0; i <= count; i++ )
|
||||
{
|
||||
fprintf( file, "%e ", ((CvCARTHaarClassifier*) classifier)->val[i] );
|
||||
}
|
||||
fprintf( file, "\n" );
|
||||
}
|
||||
|
||||
|
||||
CvIntHaarClassifier* icvLoadCARTHaarClassifier( FILE* file, int step )
|
||||
{
|
||||
CvCARTHaarClassifier* ptr;
|
||||
int i;
|
||||
int count;
|
||||
|
||||
ptr = NULL;
|
||||
int values_read = fscanf( file, "%d", &count );
|
||||
CV_Assert(values_read == 1);
|
||||
|
||||
if( count > 0 )
|
||||
{
|
||||
ptr = (CvCARTHaarClassifier*) icvCreateCARTHaarClassifier( count );
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
icvLoadHaarFeature( &(ptr->feature[i]), file );
|
||||
values_read = fscanf( file, "%f %d %d", &(ptr->threshold[i]), &(ptr->left[i]),
|
||||
&(ptr->right[i]) );
|
||||
CV_Assert(values_read == 3);
|
||||
}
|
||||
for( i = 0; i <= count; i++ )
|
||||
{
|
||||
values_read = fscanf( file, "%f", &(ptr->val[i]) );
|
||||
CV_Assert(values_read == 1);
|
||||
}
|
||||
icvConvertToFastHaarFeature( ptr->feature, ptr->fastfeature, ptr->count, step );
|
||||
}
|
||||
|
||||
return (CvIntHaarClassifier*) ptr;
|
||||
}
|
||||
|
||||
|
||||
void icvSaveStageHaarClassifier( CvIntHaarClassifier* classifier, FILE* file )
|
||||
{
|
||||
int count;
|
||||
int i;
|
||||
float threshold;
|
||||
|
||||
count = ((CvStageHaarClassifier*) classifier)->count;
|
||||
fprintf( file, "%d\n", count );
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
((CvStageHaarClassifier*) classifier)->classifier[i]->save(
|
||||
((CvStageHaarClassifier*) classifier)->classifier[i], file );
|
||||
}
|
||||
|
||||
threshold = ((CvStageHaarClassifier*) classifier)->threshold;
|
||||
|
||||
/* to be compatible with the previous implementation */
|
||||
/* threshold = 2.0F * ((CvStageHaarClassifier*) classifier)->threshold - count; */
|
||||
|
||||
fprintf( file, "%e\n", threshold );
|
||||
}
|
||||
|
||||
|
||||
|
||||
static CvIntHaarClassifier* icvLoadCARTStageHaarClassifierF( FILE* file, int step )
|
||||
{
|
||||
CvStageHaarClassifier* ptr = NULL;
|
||||
|
||||
//CV_FUNCNAME( "icvLoadCARTStageHaarClassifierF" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if( file != NULL )
|
||||
{
|
||||
int count;
|
||||
int i;
|
||||
float threshold;
|
||||
|
||||
count = 0;
|
||||
int values_read = fscanf( file, "%d", &count );
|
||||
CV_Assert(values_read == 1);
|
||||
if( count > 0 )
|
||||
{
|
||||
ptr = (CvStageHaarClassifier*) icvCreateStageHaarClassifier( count, 0.0F );
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
ptr->classifier[i] = icvLoadCARTHaarClassifier( file, step );
|
||||
}
|
||||
|
||||
values_read = fscanf( file, "%f", &threshold );
|
||||
CV_Assert(values_read == 1);
|
||||
|
||||
ptr->threshold = threshold;
|
||||
/* to be compatible with the previous implementation */
|
||||
/* ptr->threshold = 0.5F * (threshold + count); */
|
||||
}
|
||||
if( feof( file ) )
|
||||
{
|
||||
ptr->release( (CvIntHaarClassifier**) &ptr );
|
||||
ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
__END__;
|
||||
|
||||
return (CvIntHaarClassifier*) ptr;
|
||||
}
|
||||
|
||||
|
||||
CvIntHaarClassifier* icvLoadCARTStageHaarClassifier( const char* filename, int step )
|
||||
{
|
||||
CvIntHaarClassifier* ptr = NULL;
|
||||
|
||||
CV_FUNCNAME( "icvLoadCARTStageHaarClassifier" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
FILE* file;
|
||||
|
||||
file = fopen( filename, "r" );
|
||||
if( file )
|
||||
{
|
||||
CV_CALL( ptr = icvLoadCARTStageHaarClassifierF( file, step ) );
|
||||
fclose( file );
|
||||
}
|
||||
|
||||
__END__;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* tree cascade classifier */
|
||||
|
||||
/* evaluates a tree cascade classifier */
|
||||
|
||||
float icvEvalTreeCascadeClassifier( CvIntHaarClassifier* classifier,
|
||||
sum_type* sum, sum_type* tilted, float normfactor )
|
||||
{
|
||||
CvTreeCascadeNode* ptr;
|
||||
|
||||
ptr = ((CvTreeCascadeClassifier*) classifier)->root;
|
||||
|
||||
while( ptr )
|
||||
{
|
||||
if( ptr->stage->eval( (CvIntHaarClassifier*) ptr->stage,
|
||||
sum, tilted, normfactor )
|
||||
>= ptr->stage->threshold - CV_THRESHOLD_EPS )
|
||||
{
|
||||
ptr = ptr->child;
|
||||
}
|
||||
else
|
||||
{
|
||||
while( ptr && ptr->next == NULL ) ptr = ptr->parent;
|
||||
if( ptr == NULL ) return 0.0F;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
|
||||
return 1.0F;
|
||||
}
|
||||
|
||||
/* sets path int the tree form the root to the leaf node */
|
||||
|
||||
void icvSetLeafNode( CvTreeCascadeClassifier* tcc, CvTreeCascadeNode* leaf )
|
||||
{
|
||||
CV_FUNCNAME( "icvSetLeafNode" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvTreeCascadeNode* ptr;
|
||||
|
||||
ptr = NULL;
|
||||
while( leaf )
|
||||
{
|
||||
leaf->child_eval = ptr;
|
||||
ptr = leaf;
|
||||
leaf = leaf->parent;
|
||||
}
|
||||
|
||||
leaf = tcc->root;
|
||||
while( leaf && leaf != ptr ) leaf = leaf->next;
|
||||
if( leaf != ptr )
|
||||
CV_ERROR( CV_StsError, "Invalid tcc or leaf node." );
|
||||
|
||||
tcc->root_eval = ptr;
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
/* evaluates a tree cascade classifier. used in filtering */
|
||||
|
||||
float icvEvalTreeCascadeClassifierFilter( CvIntHaarClassifier* classifier, sum_type* sum,
|
||||
sum_type* tilted, float normfactor )
|
||||
{
|
||||
CvTreeCascadeNode* ptr;
|
||||
//CvTreeCascadeClassifier* tree;
|
||||
|
||||
//tree = (CvTreeCascadeClassifier*) classifier;
|
||||
|
||||
|
||||
|
||||
ptr = ((CvTreeCascadeClassifier*) classifier)->root_eval;
|
||||
while( ptr )
|
||||
{
|
||||
if( ptr->stage->eval( (CvIntHaarClassifier*) ptr->stage,
|
||||
sum, tilted, normfactor )
|
||||
< ptr->stage->threshold - CV_THRESHOLD_EPS )
|
||||
{
|
||||
return 0.0F;
|
||||
}
|
||||
ptr = ptr->child_eval;
|
||||
}
|
||||
|
||||
return 1.0F;
|
||||
}
|
||||
|
||||
/* creates tree cascade node */
|
||||
|
||||
CvTreeCascadeNode* icvCreateTreeCascadeNode()
|
||||
{
|
||||
CvTreeCascadeNode* ptr = NULL;
|
||||
|
||||
CV_FUNCNAME( "icvCreateTreeCascadeNode" );
|
||||
|
||||
__BEGIN__;
|
||||
size_t data_size;
|
||||
|
||||
data_size = sizeof( *ptr );
|
||||
CV_CALL( ptr = (CvTreeCascadeNode*) cvAlloc( data_size ) );
|
||||
memset( ptr, 0, data_size );
|
||||
|
||||
__END__;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* releases all tree cascade nodes accessible via links */
|
||||
|
||||
void icvReleaseTreeCascadeNodes( CvTreeCascadeNode** node )
|
||||
{
|
||||
//CV_FUNCNAME( "icvReleaseTreeCascadeNodes" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if( node && *node )
|
||||
{
|
||||
CvTreeCascadeNode* ptr;
|
||||
CvTreeCascadeNode* ptr_;
|
||||
|
||||
ptr = *node;
|
||||
|
||||
while( ptr )
|
||||
{
|
||||
while( ptr->child ) ptr = ptr->child;
|
||||
|
||||
if( ptr->stage ) ptr->stage->release( (CvIntHaarClassifier**) &ptr->stage );
|
||||
ptr_ = ptr;
|
||||
|
||||
while( ptr && ptr->next == NULL ) ptr = ptr->parent;
|
||||
if( ptr ) ptr = ptr->next;
|
||||
|
||||
cvFree( &ptr_ );
|
||||
}
|
||||
}
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
|
||||
/* releases tree cascade classifier */
|
||||
|
||||
void icvReleaseTreeCascadeClassifier( CvIntHaarClassifier** classifier )
|
||||
{
|
||||
if( classifier && *classifier )
|
||||
{
|
||||
icvReleaseTreeCascadeNodes( &((CvTreeCascadeClassifier*) *classifier)->root );
|
||||
cvFree( classifier );
|
||||
*classifier = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void icvPrintTreeCascade( CvTreeCascadeNode* root )
|
||||
{
|
||||
//CV_FUNCNAME( "icvPrintTreeCascade" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvTreeCascadeNode* node;
|
||||
CvTreeCascadeNode* n;
|
||||
char buf0[256];
|
||||
char buf[256];
|
||||
int level;
|
||||
int i;
|
||||
int max_level;
|
||||
|
||||
node = root;
|
||||
level = max_level = 0;
|
||||
while( node )
|
||||
{
|
||||
while( node->child ) { node = node->child; level++; }
|
||||
if( level > max_level ) { max_level = level; }
|
||||
while( node && !node->next ) { node = node->parent; level--; }
|
||||
if( node ) node = node->next;
|
||||
}
|
||||
|
||||
printf( "\nTree Classifier\n" );
|
||||
printf( "Stage\n" );
|
||||
for( i = 0; i <= max_level; i++ ) printf( "+---" );
|
||||
printf( "+\n" );
|
||||
for( i = 0; i <= max_level; i++ ) printf( "|%3d", i );
|
||||
printf( "|\n" );
|
||||
for( i = 0; i <= max_level; i++ ) printf( "+---" );
|
||||
printf( "+\n\n" );
|
||||
|
||||
node = root;
|
||||
|
||||
buf[0] = 0;
|
||||
while( node )
|
||||
{
|
||||
sprintf( buf + strlen( buf ), "%3d", node->idx );
|
||||
while( node->child )
|
||||
{
|
||||
node = node->child;
|
||||
sprintf( buf + strlen( buf ),
|
||||
((node->idx < 10) ? "---%d" : ((node->idx < 100) ? "--%d" : "-%d")),
|
||||
node->idx );
|
||||
}
|
||||
printf( " %s\n", buf );
|
||||
|
||||
while( node && !node->next ) { node = node->parent; }
|
||||
if( node )
|
||||
{
|
||||
node = node->next;
|
||||
|
||||
n = node->parent;
|
||||
buf[0] = 0;
|
||||
while( n )
|
||||
{
|
||||
if( n->next )
|
||||
sprintf( buf0, " | %s", buf );
|
||||
else
|
||||
sprintf( buf0, " %s", buf );
|
||||
strcpy( buf, buf0 );
|
||||
n = n->parent;
|
||||
}
|
||||
printf( " %s |\n", buf );
|
||||
}
|
||||
}
|
||||
printf( "\n" );
|
||||
fflush( stdout );
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CvIntHaarClassifier* icvLoadTreeCascadeClassifier( const char* filename, int step,
|
||||
int* splits )
|
||||
{
|
||||
CvTreeCascadeClassifier* ptr = NULL;
|
||||
CvTreeCascadeNode** nodes = NULL;
|
||||
|
||||
CV_FUNCNAME( "icvLoadTreeCascadeClassifier" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
size_t data_size;
|
||||
CvStageHaarClassifier* stage;
|
||||
char stage_name[PATH_MAX];
|
||||
char* suffix;
|
||||
int i, num;
|
||||
FILE* f;
|
||||
int result, parent=0, next=0;
|
||||
int stub;
|
||||
|
||||
if( !splits ) splits = &stub;
|
||||
|
||||
*splits = 0;
|
||||
|
||||
data_size = sizeof( *ptr );
|
||||
|
||||
CV_CALL( ptr = (CvTreeCascadeClassifier*) cvAlloc( data_size ) );
|
||||
memset( ptr, 0, data_size );
|
||||
|
||||
ptr->eval = icvEvalTreeCascadeClassifier;
|
||||
ptr->release = icvReleaseTreeCascadeClassifier;
|
||||
|
||||
sprintf( stage_name, "%s/", filename );
|
||||
suffix = stage_name + strlen( stage_name );
|
||||
|
||||
for( i = 0; ; i++ )
|
||||
{
|
||||
sprintf( suffix, "%d/%s", i, CV_STAGE_CART_FILE_NAME );
|
||||
f = fopen( stage_name, "r" );
|
||||
if( !f ) break;
|
||||
fclose( f );
|
||||
}
|
||||
num = i;
|
||||
|
||||
if( num < 1 ) EXIT;
|
||||
|
||||
data_size = sizeof( *nodes ) * num;
|
||||
CV_CALL( nodes = (CvTreeCascadeNode**) cvAlloc( data_size ) );
|
||||
|
||||
for( i = 0; i < num; i++ )
|
||||
{
|
||||
sprintf( suffix, "%d/%s", i, CV_STAGE_CART_FILE_NAME );
|
||||
f = fopen( stage_name, "r" );
|
||||
CV_CALL( stage = (CvStageHaarClassifier*)
|
||||
icvLoadCARTStageHaarClassifierF( f, step ) );
|
||||
|
||||
result = ( f && stage ) ? fscanf( f, "%d%d", &parent, &next ) : 0;
|
||||
if( f ) fclose( f );
|
||||
|
||||
if( result != 2 )
|
||||
{
|
||||
num = i;
|
||||
break;
|
||||
}
|
||||
|
||||
printf( "Stage %d loaded\n", i );
|
||||
|
||||
if( parent >= i || (next != -1 && next != i + 1) )
|
||||
CV_ERROR( CV_StsError, "Invalid tree links" );
|
||||
|
||||
CV_CALL( nodes[i] = icvCreateTreeCascadeNode() );
|
||||
nodes[i]->stage = stage;
|
||||
nodes[i]->idx = i;
|
||||
nodes[i]->parent = (parent != -1 ) ? nodes[parent] : NULL;
|
||||
nodes[i]->next = ( next != -1 ) ? nodes[i] : NULL;
|
||||
nodes[i]->child = NULL;
|
||||
}
|
||||
for( i = 0; i < num; i++ )
|
||||
{
|
||||
if( nodes[i]->next )
|
||||
{
|
||||
(*splits)++;
|
||||
nodes[i]->next = nodes[i+1];
|
||||
}
|
||||
if( nodes[i]->parent && nodes[i]->parent->child == NULL )
|
||||
{
|
||||
nodes[i]->parent->child = nodes[i];
|
||||
}
|
||||
}
|
||||
ptr->root = nodes[0];
|
||||
ptr->next_idx = num;
|
||||
|
||||
__END__;
|
||||
|
||||
cvFree( &nodes );
|
||||
|
||||
return (CvIntHaarClassifier*) ptr;
|
||||
}
|
||||
|
||||
|
||||
CvTreeCascadeNode* icvFindDeepestLeaves( CvTreeCascadeClassifier* tcc )
|
||||
{
|
||||
CvTreeCascadeNode* leaves;
|
||||
|
||||
//CV_FUNCNAME( "icvFindDeepestLeaves" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
int level, cur_level;
|
||||
CvTreeCascadeNode* ptr;
|
||||
CvTreeCascadeNode* last;
|
||||
|
||||
leaves = last = NULL;
|
||||
|
||||
ptr = tcc->root;
|
||||
level = -1;
|
||||
cur_level = 0;
|
||||
|
||||
/* find leaves with maximal level */
|
||||
while( ptr )
|
||||
{
|
||||
if( ptr->child ) { ptr = ptr->child; cur_level++; }
|
||||
else
|
||||
{
|
||||
if( cur_level == level )
|
||||
{
|
||||
last->next_same_level = ptr;
|
||||
ptr->next_same_level = NULL;
|
||||
last = ptr;
|
||||
}
|
||||
if( cur_level > level )
|
||||
{
|
||||
level = cur_level;
|
||||
leaves = last = ptr;
|
||||
ptr->next_same_level = NULL;
|
||||
}
|
||||
while( ptr && ptr->next == NULL ) { ptr = ptr->parent; cur_level--; }
|
||||
if( ptr ) ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
|
||||
__END__;
|
||||
|
||||
return leaves;
|
||||
}
|
||||
|
||||
/* End of file. */
|
File diff suppressed because it is too large
Load Diff
@ -1,284 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
/*
|
||||
* haartraining.cpp
|
||||
*
|
||||
* Train cascade classifier
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "cvhaartraining.h"
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
int i = 0;
|
||||
char* nullname = (char*)"(NULL)";
|
||||
|
||||
char* vecname = NULL;
|
||||
char* dirname = NULL;
|
||||
char* bgname = NULL;
|
||||
|
||||
bool bg_vecfile = false;
|
||||
int npos = 2000;
|
||||
int nneg = 2000;
|
||||
int nstages = 14;
|
||||
int mem = 200;
|
||||
int nsplits = 1;
|
||||
float minhitrate = 0.995F;
|
||||
float maxfalsealarm = 0.5F;
|
||||
float weightfraction = 0.95F;
|
||||
int mode = 0;
|
||||
int symmetric = 1;
|
||||
int equalweights = 0;
|
||||
int width = 24;
|
||||
int height = 24;
|
||||
const char* boosttypes[] = { "DAB", "RAB", "LB", "GAB" };
|
||||
int boosttype = 3;
|
||||
const char* stumperrors[] = { "misclass", "gini", "entropy" };
|
||||
int stumperror = 0;
|
||||
int maxtreesplits = 0;
|
||||
int minpos = 500;
|
||||
|
||||
if( argc == 1 )
|
||||
{
|
||||
printf( "Usage: %s\n -data <dir_name>\n"
|
||||
" -vec <vec_file_name>\n"
|
||||
" -bg <background_file_name>\n"
|
||||
" [-bg-vecfile]\n"
|
||||
" [-npos <number_of_positive_samples = %d>]\n"
|
||||
" [-nneg <number_of_negative_samples = %d>]\n"
|
||||
" [-nstages <number_of_stages = %d>]\n"
|
||||
" [-nsplits <number_of_splits = %d>]\n"
|
||||
" [-mem <memory_in_MB = %d>]\n"
|
||||
" [-sym (default)] [-nonsym]\n"
|
||||
" [-minhitrate <min_hit_rate = %f>]\n"
|
||||
" [-maxfalsealarm <max_false_alarm_rate = %f>]\n"
|
||||
" [-weighttrimming <weight_trimming = %f>]\n"
|
||||
" [-eqw]\n"
|
||||
" [-mode <BASIC (default) | CORE | ALL>]\n"
|
||||
" [-w <sample_width = %d>]\n"
|
||||
" [-h <sample_height = %d>]\n"
|
||||
" [-bt <DAB | RAB | LB | GAB (default)>]\n"
|
||||
" [-err <misclass (default) | gini | entropy>]\n"
|
||||
" [-maxtreesplits <max_number_of_splits_in_tree_cascade = %d>]\n"
|
||||
" [-minpos <min_number_of_positive_samples_per_cluster = %d>]\n",
|
||||
argv[0], npos, nneg, nstages, nsplits, mem,
|
||||
minhitrate, maxfalsealarm, weightfraction, width, height,
|
||||
maxtreesplits, minpos );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
for( i = 1; i < argc; i++ )
|
||||
{
|
||||
if( !strcmp( argv[i], "-data" ) )
|
||||
{
|
||||
dirname = argv[++i];
|
||||
}
|
||||
else if( !strcmp( argv[i], "-vec" ) )
|
||||
{
|
||||
vecname = argv[++i];
|
||||
}
|
||||
else if( !strcmp( argv[i], "-bg" ) )
|
||||
{
|
||||
bgname = argv[++i];
|
||||
}
|
||||
else if( !strcmp( argv[i], "-bg-vecfile" ) )
|
||||
{
|
||||
bg_vecfile = true;
|
||||
}
|
||||
else if( !strcmp( argv[i], "-npos" ) )
|
||||
{
|
||||
npos = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-nneg" ) )
|
||||
{
|
||||
nneg = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-nstages" ) )
|
||||
{
|
||||
nstages = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-nsplits" ) )
|
||||
{
|
||||
nsplits = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-mem" ) )
|
||||
{
|
||||
mem = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-sym" ) )
|
||||
{
|
||||
symmetric = 1;
|
||||
}
|
||||
else if( !strcmp( argv[i], "-nonsym" ) )
|
||||
{
|
||||
symmetric = 0;
|
||||
}
|
||||
else if( !strcmp( argv[i], "-minhitrate" ) )
|
||||
{
|
||||
minhitrate = (float) atof( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-maxfalsealarm" ) )
|
||||
{
|
||||
maxfalsealarm = (float) atof( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-weighttrimming" ) )
|
||||
{
|
||||
weightfraction = (float) atof( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-eqw" ) )
|
||||
{
|
||||
equalweights = 1;
|
||||
}
|
||||
else if( !strcmp( argv[i], "-mode" ) )
|
||||
{
|
||||
char* tmp = argv[++i];
|
||||
|
||||
if( !strcmp( tmp, "CORE" ) )
|
||||
{
|
||||
mode = 1;
|
||||
}
|
||||
else if( !strcmp( tmp, "ALL" ) )
|
||||
{
|
||||
mode = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode = 0;
|
||||
}
|
||||
}
|
||||
else if( !strcmp( argv[i], "-w" ) )
|
||||
{
|
||||
width = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-h" ) )
|
||||
{
|
||||
height = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-bt" ) )
|
||||
{
|
||||
i++;
|
||||
if( !strcmp( argv[i], boosttypes[0] ) )
|
||||
{
|
||||
boosttype = 0;
|
||||
}
|
||||
else if( !strcmp( argv[i], boosttypes[1] ) )
|
||||
{
|
||||
boosttype = 1;
|
||||
}
|
||||
else if( !strcmp( argv[i], boosttypes[2] ) )
|
||||
{
|
||||
boosttype = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
boosttype = 3;
|
||||
}
|
||||
}
|
||||
else if( !strcmp( argv[i], "-err" ) )
|
||||
{
|
||||
i++;
|
||||
if( !strcmp( argv[i], stumperrors[0] ) )
|
||||
{
|
||||
stumperror = 0;
|
||||
}
|
||||
else if( !strcmp( argv[i], stumperrors[1] ) )
|
||||
{
|
||||
stumperror = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
stumperror = 2;
|
||||
}
|
||||
}
|
||||
else if( !strcmp( argv[i], "-maxtreesplits" ) )
|
||||
{
|
||||
maxtreesplits = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-minpos" ) )
|
||||
{
|
||||
minpos = atoi( argv[++i] );
|
||||
}
|
||||
}
|
||||
|
||||
printf( "Data dir name: %s\n", ((dirname == NULL) ? nullname : dirname ) );
|
||||
printf( "Vec file name: %s\n", ((vecname == NULL) ? nullname : vecname ) );
|
||||
printf( "BG file name: %s, is a vecfile: %s\n", ((bgname == NULL) ? nullname : bgname ), bg_vecfile ? "yes" : "no" );
|
||||
printf( "Num pos: %d\n", npos );
|
||||
printf( "Num neg: %d\n", nneg );
|
||||
printf( "Num stages: %d\n", nstages );
|
||||
printf( "Num splits: %d (%s as weak classifier)\n", nsplits,
|
||||
(nsplits == 1) ? "stump" : "tree" );
|
||||
printf( "Mem: %d MB\n", mem );
|
||||
printf( "Symmetric: %s\n", (symmetric) ? "TRUE" : "FALSE" );
|
||||
printf( "Min hit rate: %f\n", minhitrate );
|
||||
printf( "Max false alarm rate: %f\n", maxfalsealarm );
|
||||
printf( "Weight trimming: %f\n", weightfraction );
|
||||
printf( "Equal weights: %s\n", (equalweights) ? "TRUE" : "FALSE" );
|
||||
printf( "Mode: %s\n", ( (mode == 0) ? "BASIC" : ( (mode == 1) ? "CORE" : "ALL") ) );
|
||||
printf( "Width: %d\n", width );
|
||||
printf( "Height: %d\n", height );
|
||||
//printf( "Max num of precalculated features: %d\n", numprecalculated );
|
||||
printf( "Applied boosting algorithm: %s\n", boosttypes[boosttype] );
|
||||
printf( "Error (valid only for Discrete and Real AdaBoost): %s\n",
|
||||
stumperrors[stumperror] );
|
||||
|
||||
printf( "Max number of splits in tree cascade: %d\n", maxtreesplits );
|
||||
printf( "Min number of positive samples per cluster: %d\n", minpos );
|
||||
|
||||
cvCreateTreeCascadeClassifier( dirname, vecname, bgname,
|
||||
npos, nneg, nstages, mem,
|
||||
nsplits,
|
||||
minhitrate, maxfalsealarm, weightfraction,
|
||||
mode, symmetric,
|
||||
equalweights, width, height,
|
||||
boosttype, stumperror,
|
||||
maxtreesplits, minpos, bg_vecfile );
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,377 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
/*
|
||||
* performance.cpp
|
||||
*
|
||||
* Measure performance of classifier
|
||||
*/
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
#include "cv.h"
|
||||
#include "highgui.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
|
||||
#ifdef _WIN32
|
||||
/* use clock() function insted of time() */
|
||||
#define time( arg ) (((double) clock()) / CLOCKS_PER_SEC)
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 512
|
||||
#endif /* PATH_MAX */
|
||||
|
||||
typedef struct HidCascade
|
||||
{
|
||||
int size;
|
||||
int count;
|
||||
} HidCascade;
|
||||
|
||||
typedef struct ObjectPos
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float width;
|
||||
int found; /* for reference */
|
||||
int neghbors;
|
||||
} ObjectPos;
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
int i, j;
|
||||
char* classifierdir = NULL;
|
||||
//char* samplesdir = NULL;
|
||||
|
||||
int saveDetected = 1;
|
||||
double scale_factor = 1.2;
|
||||
float maxSizeDiff = 1.5F;
|
||||
float maxPosDiff = 0.3F;
|
||||
|
||||
/* number of stages. if <=0 all stages are used */
|
||||
int nos = -1, nos0;
|
||||
|
||||
int width = 24;
|
||||
int height = 24;
|
||||
|
||||
int rocsize;
|
||||
|
||||
FILE* info;
|
||||
char* infoname;
|
||||
char fullname[PATH_MAX];
|
||||
char detfilename[PATH_MAX];
|
||||
char* filename;
|
||||
char detname[] = "det-";
|
||||
|
||||
CvHaarClassifierCascade* cascade;
|
||||
CvMemStorage* storage;
|
||||
CvSeq* objects;
|
||||
|
||||
double totaltime;
|
||||
|
||||
infoname = (char*)"";
|
||||
rocsize = 40;
|
||||
if( argc == 1 )
|
||||
{
|
||||
printf( "Usage: %s\n -data <classifier_directory_name>\n"
|
||||
" -info <collection_file_name>\n"
|
||||
" [-maxSizeDiff <max_size_difference = %f>]\n"
|
||||
" [-maxPosDiff <max_position_difference = %f>]\n"
|
||||
" [-sf <scale_factor = %f>]\n"
|
||||
" [-ni]\n"
|
||||
" [-nos <number_of_stages = %d>]\n"
|
||||
" [-rs <roc_size = %d>]\n"
|
||||
" [-w <sample_width = %d>]\n"
|
||||
" [-h <sample_height = %d>]\n",
|
||||
argv[0], maxSizeDiff, maxPosDiff, scale_factor, nos, rocsize,
|
||||
width, height );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
for( i = 1; i < argc; i++ )
|
||||
{
|
||||
if( !strcmp( argv[i], "-data" ) )
|
||||
{
|
||||
classifierdir = argv[++i];
|
||||
}
|
||||
else if( !strcmp( argv[i], "-info" ) )
|
||||
{
|
||||
infoname = argv[++i];
|
||||
}
|
||||
else if( !strcmp( argv[i], "-maxSizeDiff" ) )
|
||||
{
|
||||
maxSizeDiff = (float) atof( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-maxPosDiff" ) )
|
||||
{
|
||||
maxPosDiff = (float) atof( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-sf" ) )
|
||||
{
|
||||
scale_factor = atof( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-ni" ) )
|
||||
{
|
||||
saveDetected = 0;
|
||||
}
|
||||
else if( !strcmp( argv[i], "-nos" ) )
|
||||
{
|
||||
nos = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-rs" ) )
|
||||
{
|
||||
rocsize = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-w" ) )
|
||||
{
|
||||
width = atoi( argv[++i] );
|
||||
}
|
||||
else if( !strcmp( argv[i], "-h" ) )
|
||||
{
|
||||
height = atoi( argv[++i] );
|
||||
}
|
||||
}
|
||||
|
||||
cascade = cvLoadHaarClassifierCascade( classifierdir, cvSize( width, height ) );
|
||||
if( cascade == NULL )
|
||||
{
|
||||
printf( "Unable to load classifier from %s\n", classifierdir );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int* numclassifiers = new int[cascade->count];
|
||||
numclassifiers[0] = cascade->stage_classifier[0].count;
|
||||
for( i = 1; i < cascade->count; i++ )
|
||||
{
|
||||
numclassifiers[i] = numclassifiers[i-1] + cascade->stage_classifier[i].count;
|
||||
}
|
||||
|
||||
storage = cvCreateMemStorage();
|
||||
|
||||
nos0 = cascade->count;
|
||||
if( nos <= 0 )
|
||||
nos = nos0;
|
||||
|
||||
strcpy( fullname, infoname );
|
||||
filename = strrchr( fullname, '\\' );
|
||||
if( filename == NULL )
|
||||
{
|
||||
filename = strrchr( fullname, '/' );
|
||||
}
|
||||
if( filename == NULL )
|
||||
{
|
||||
filename = fullname;
|
||||
}
|
||||
else
|
||||
{
|
||||
filename++;
|
||||
}
|
||||
|
||||
info = fopen( infoname, "r" );
|
||||
totaltime = 0.0;
|
||||
if( info != NULL )
|
||||
{
|
||||
int x, y;
|
||||
IplImage* img;
|
||||
int hits, missed, falseAlarms;
|
||||
int totalHits, totalMissed, totalFalseAlarms;
|
||||
int found;
|
||||
float distance;
|
||||
|
||||
int refcount;
|
||||
ObjectPos* ref;
|
||||
int detcount;
|
||||
ObjectPos* det;
|
||||
int error=0;
|
||||
|
||||
int* pos;
|
||||
int* neg;
|
||||
|
||||
pos = (int*) cvAlloc( rocsize * sizeof( *pos ) );
|
||||
neg = (int*) cvAlloc( rocsize * sizeof( *neg ) );
|
||||
for( i = 0; i < rocsize; i++ ) { pos[i] = neg[i] = 0; }
|
||||
|
||||
printf( "+================================+======+======+======+\n" );
|
||||
printf( "| File Name | Hits |Missed| False|\n" );
|
||||
printf( "+================================+======+======+======+\n" );
|
||||
|
||||
totalHits = totalMissed = totalFalseAlarms = 0;
|
||||
while( !feof( info ) )
|
||||
{
|
||||
if( fscanf( info, "%s %d", filename, &refcount ) != 2 || refcount <= 0 ) break;
|
||||
|
||||
img = cvLoadImage( fullname );
|
||||
if( !img ) continue;
|
||||
|
||||
ref = (ObjectPos*) cvAlloc( refcount * sizeof( *ref ) );
|
||||
for( i = 0; i < refcount; i++ )
|
||||
{
|
||||
int w, h;
|
||||
error = (fscanf( info, "%d %d %d %d", &x, &y, &w, &h ) != 4);
|
||||
if( error ) break;
|
||||
ref[i].x = 0.5F * w + x;
|
||||
ref[i].y = 0.5F * h + y;
|
||||
ref[i].width = sqrtf( 0.5F * (w * w + h * h) );
|
||||
ref[i].found = 0;
|
||||
ref[i].neghbors = 0;
|
||||
}
|
||||
if( !error )
|
||||
{
|
||||
cvClearMemStorage( storage );
|
||||
|
||||
cascade->count = nos;
|
||||
totaltime -= time( 0 );
|
||||
objects = cvHaarDetectObjects( img, cascade, storage, scale_factor, 1 );
|
||||
totaltime += time( 0 );
|
||||
cascade->count = nos0;
|
||||
|
||||
detcount = ( objects ? objects->total : 0);
|
||||
det = (detcount > 0) ?
|
||||
( (ObjectPos*)cvAlloc( detcount * sizeof( *det )) ) : NULL;
|
||||
hits = missed = falseAlarms = 0;
|
||||
for( i = 0; i < detcount; i++ )
|
||||
{
|
||||
CvAvgComp r = *((CvAvgComp*) cvGetSeqElem( objects, i ));
|
||||
det[i].x = 0.5F * r.rect.width + r.rect.x;
|
||||
det[i].y = 0.5F * r.rect.height + r.rect.y;
|
||||
det[i].width = sqrtf( 0.5F * (r.rect.width * r.rect.width +
|
||||
r.rect.height * r.rect.height) );
|
||||
det[i].neghbors = r.neighbors;
|
||||
|
||||
if( saveDetected )
|
||||
{
|
||||
cvRectangle( img, cvPoint( r.rect.x, r.rect.y ),
|
||||
cvPoint( r.rect.x + r.rect.width, r.rect.y + r.rect.height ),
|
||||
CV_RGB( 255, 0, 0 ), 3 );
|
||||
}
|
||||
|
||||
found = 0;
|
||||
for( j = 0; j < refcount; j++ )
|
||||
{
|
||||
distance = sqrtf( (det[i].x - ref[j].x) * (det[i].x - ref[j].x) +
|
||||
(det[i].y - ref[j].y) * (det[i].y - ref[j].y) );
|
||||
if( (distance < ref[j].width * maxPosDiff) &&
|
||||
(det[i].width > ref[j].width / maxSizeDiff) &&
|
||||
(det[i].width < ref[j].width * maxSizeDiff) )
|
||||
{
|
||||
ref[j].found = 1;
|
||||
ref[j].neghbors = MAX( ref[j].neghbors, det[i].neghbors );
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if( !found )
|
||||
{
|
||||
falseAlarms++;
|
||||
neg[MIN(det[i].neghbors, rocsize - 1)]++;
|
||||
}
|
||||
}
|
||||
for( j = 0; j < refcount; j++ )
|
||||
{
|
||||
if( ref[j].found )
|
||||
{
|
||||
hits++;
|
||||
pos[MIN(ref[j].neghbors, rocsize - 1)]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
missed++;
|
||||
}
|
||||
}
|
||||
|
||||
totalHits += hits;
|
||||
totalMissed += missed;
|
||||
totalFalseAlarms += falseAlarms;
|
||||
printf( "|%32.32s|%6d|%6d|%6d|\n", filename, hits, missed, falseAlarms );
|
||||
printf( "+--------------------------------+------+------+------+\n" );
|
||||
fflush( stdout );
|
||||
|
||||
if( saveDetected )
|
||||
{
|
||||
strcpy( detfilename, detname );
|
||||
strcat( detfilename, filename );
|
||||
strcpy( filename, detfilename );
|
||||
cvvSaveImage( fullname, img );
|
||||
}
|
||||
|
||||
if( det ) { cvFree( &det ); det = NULL; }
|
||||
} /* if( !error ) */
|
||||
|
||||
cvReleaseImage( &img );
|
||||
cvFree( &ref );
|
||||
}
|
||||
fclose( info );
|
||||
|
||||
printf( "|%32.32s|%6d|%6d|%6d|\n", "Total",
|
||||
totalHits, totalMissed, totalFalseAlarms );
|
||||
printf( "+================================+======+======+======+\n" );
|
||||
printf( "Number of stages: %d\n", nos );
|
||||
printf( "Number of weak classifiers: %d\n", numclassifiers[nos - 1] );
|
||||
printf( "Total time: %f\n", totaltime );
|
||||
|
||||
/* print ROC to stdout */
|
||||
for( i = rocsize - 1; i > 0; i-- )
|
||||
{
|
||||
pos[i-1] += pos[i];
|
||||
neg[i-1] += neg[i];
|
||||
}
|
||||
fprintf( stderr, "%d\n", nos );
|
||||
for( i = 0; i < rocsize; i++ )
|
||||
{
|
||||
fprintf( stderr, "\t%d\t%d\t%f\t%f\n", pos[i], neg[i],
|
||||
((float)pos[i]) / (totalHits + totalMissed),
|
||||
((float)neg[i]) / (totalHits + totalMissed) );
|
||||
}
|
||||
|
||||
cvFree( &pos );
|
||||
cvFree( &neg );
|
||||
}
|
||||
|
||||
delete[] numclassifiers;
|
||||
|
||||
cvReleaseHaarClassifierCascade( &cascade );
|
||||
cvReleaseMemStorage( &storage );
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
set(name sft)
|
||||
set(the_target opencv_${name})
|
||||
|
||||
set(OPENCV_${the_target}_DEPS opencv_core opencv_softcascade opencv_highgui opencv_imgproc opencv_ml)
|
||||
ocv_check_dependencies(${OPENCV_${the_target}_DEPS})
|
||||
|
||||
if(NOT OCV_DEPENDENCIES_FOUND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(${the_target})
|
||||
|
||||
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include" "${OpenCV_SOURCE_DIR}/include/opencv")
|
||||
ocv_include_modules(${OPENCV_${the_target}_DEPS})
|
||||
|
||||
file(GLOB ${the_target}_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
|
||||
add_executable(${the_target} ${${the_target}_SOURCES})
|
||||
|
||||
target_link_libraries(${the_target} ${OPENCV_${the_target}_DEPS})
|
||||
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
|
||||
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
|
||||
INSTALL_NAME_DIR lib
|
||||
OUTPUT_NAME "opencv_trainsoftcascade")
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(${the_target} PROPERTIES FOLDER "applications")
|
||||
endif()
|
||||
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
|
@ -1,162 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <sft/config.hpp>
|
||||
#include <iomanip>
|
||||
|
||||
sft::Config::Config(): seed(0) {}
|
||||
|
||||
void sft::Config::write(cv::FileStorage& fs) const
|
||||
{
|
||||
fs << "{"
|
||||
<< "trainPath" << trainPath
|
||||
<< "testPath" << testPath
|
||||
|
||||
<< "modelWinSize" << modelWinSize
|
||||
<< "offset" << offset
|
||||
<< "octaves" << octaves
|
||||
|
||||
<< "positives" << positives
|
||||
<< "negatives" << negatives
|
||||
<< "btpNegatives" << btpNegatives
|
||||
|
||||
<< "shrinkage" << shrinkage
|
||||
|
||||
<< "treeDepth" << treeDepth
|
||||
<< "weaks" << weaks
|
||||
<< "poolSize" << poolSize
|
||||
|
||||
<< "cascadeName" << cascadeName
|
||||
<< "outXmlPath" << outXmlPath
|
||||
|
||||
<< "seed" << seed
|
||||
<< "featureType" << featureType
|
||||
<< "}";
|
||||
}
|
||||
|
||||
void sft::Config::read(const cv::FileNode& node)
|
||||
{
|
||||
trainPath = (string)node["trainPath"];
|
||||
testPath = (string)node["testPath"];
|
||||
|
||||
cv::FileNodeIterator nIt = node["modelWinSize"].end();
|
||||
modelWinSize = cv::Size((int)*(--nIt), (int)*(--nIt));
|
||||
|
||||
nIt = node["offset"].end();
|
||||
offset = cv::Point2i((int)*(--nIt), (int)*(--nIt));
|
||||
|
||||
node["octaves"] >> octaves;
|
||||
|
||||
positives = (int)node["positives"];
|
||||
negatives = (int)node["negatives"];
|
||||
btpNegatives = (int)node["btpNegatives"];
|
||||
|
||||
shrinkage = (int)node["shrinkage"];
|
||||
|
||||
treeDepth = (int)node["treeDepth"];
|
||||
weaks = (int)node["weaks"];
|
||||
poolSize = (int)node["poolSize"];
|
||||
|
||||
cascadeName = (std::string)node["cascadeName"];
|
||||
outXmlPath = (std::string)node["outXmlPath"];
|
||||
|
||||
seed = (int)node["seed"];
|
||||
featureType = (std::string)node["featureType"];
|
||||
}
|
||||
|
||||
void sft::write(cv::FileStorage& fs, const string&, const Config& x)
|
||||
{
|
||||
x.write(fs);
|
||||
}
|
||||
|
||||
void sft::read(const cv::FileNode& node, Config& x, const Config& default_value)
|
||||
{
|
||||
x = default_value;
|
||||
|
||||
if(!node.empty())
|
||||
x.read(node);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct Out
|
||||
{
|
||||
Out(std::ostream& _out): out(_out) {}
|
||||
template<typename T>
|
||||
void operator ()(const T a) const {out << a << " ";}
|
||||
|
||||
std::ostream& out;
|
||||
private:
|
||||
Out& operator=(Out const& other);
|
||||
};
|
||||
}
|
||||
|
||||
std::ostream& sft::operator<<(std::ostream& out, const Config& m)
|
||||
{
|
||||
out << std::setw(14) << std::left << "trainPath" << m.trainPath << std::endl
|
||||
<< std::setw(14) << std::left << "testPath" << m.testPath << std::endl
|
||||
|
||||
<< std::setw(14) << std::left << "modelWinSize" << m.modelWinSize << std::endl
|
||||
<< std::setw(14) << std::left << "offset" << m.offset << std::endl
|
||||
<< std::setw(14) << std::left << "octaves";
|
||||
|
||||
Out o(out);
|
||||
for_each(m.octaves.begin(), m.octaves.end(), o);
|
||||
|
||||
out << std::endl
|
||||
<< std::setw(14) << std::left << "positives" << m.positives << std::endl
|
||||
<< std::setw(14) << std::left << "negatives" << m.negatives << std::endl
|
||||
<< std::setw(14) << std::left << "btpNegatives" << m.btpNegatives << std::endl
|
||||
|
||||
<< std::setw(14) << std::left << "shrinkage" << m.shrinkage << std::endl
|
||||
|
||||
<< std::setw(14) << std::left << "treeDepth" << m.treeDepth << std::endl
|
||||
<< std::setw(14) << std::left << "weaks" << m.weaks << std::endl
|
||||
<< std::setw(14) << std::left << "poolSize" << m.poolSize << std::endl
|
||||
|
||||
<< std::setw(14) << std::left << "cascadeName" << m.cascadeName << std::endl
|
||||
<< std::setw(14) << std::left << "outXmlPath" << m.outXmlPath << std::endl
|
||||
<< std::setw(14) << std::left << "seed" << m.seed << std::endl
|
||||
<< std::setw(14) << std::left << "featureType" << m.featureType << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <sft/dataset.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
|
||||
// in the default case data folders should be aligned as following:
|
||||
// 1. positives: <train or test path>/octave_<octave number>/pos/*.png
|
||||
// 2. negatives: <train or test path>/octave_<octave number>/neg/*.png
|
||||
sft::ScaledDataset::ScaledDataset(const string& path, const int oct)
|
||||
{
|
||||
dprintf("%s\n", "get dataset file names...");
|
||||
dprintf("%s\n", "Positives globing...");
|
||||
cv::glob(path + "/pos/octave_" + cv::format("%d", oct) + "/*.png", pos);
|
||||
|
||||
dprintf("%s\n", "Negatives globing...");
|
||||
cv::glob(path + "/neg/octave_" + cv::format("%d", oct) + "/*.png", neg);
|
||||
|
||||
// Check: files not empty
|
||||
CV_Assert(pos.size() != size_t(0));
|
||||
CV_Assert(neg.size() != size_t(0));
|
||||
}
|
||||
|
||||
cv::Mat sft::ScaledDataset::get(SampleType type, int idx) const
|
||||
{
|
||||
const std::string& src = (type == POSITIVE)? pos[idx]: neg[idx];
|
||||
return cv::imread(src);
|
||||
}
|
||||
|
||||
int sft::ScaledDataset::available(SampleType type) const
|
||||
{
|
||||
return (int)((type == POSITIVE)? pos.size():neg.size());
|
||||
}
|
||||
|
||||
sft::ScaledDataset::~ScaledDataset(){}
|
@ -1,138 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __SFT_CONFIG_HPP__
|
||||
#define __SFT_CONFIG_HPP__
|
||||
|
||||
#include <sft/common.hpp>
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace sft {
|
||||
|
||||
struct Config
|
||||
{
|
||||
Config();
|
||||
|
||||
void write(cv::FileStorage& fs) const;
|
||||
|
||||
void read(const cv::FileNode& node);
|
||||
|
||||
// Scaled and shrunk model size.
|
||||
cv::Size model(ivector::const_iterator it) const
|
||||
{
|
||||
float octave = powf(2.f, (float)(*it));
|
||||
return cv::Size( cvRound(modelWinSize.width * octave) / shrinkage,
|
||||
cvRound(modelWinSize.height * octave) / shrinkage );
|
||||
}
|
||||
|
||||
// Scaled but, not shrunk bounding box for object in sample image.
|
||||
cv::Rect bbox(ivector::const_iterator it) const
|
||||
{
|
||||
float octave = powf(2.f, (float)(*it));
|
||||
return cv::Rect( cvRound(offset.x * octave), cvRound(offset.y * octave),
|
||||
cvRound(modelWinSize.width * octave), cvRound(modelWinSize.height * octave));
|
||||
}
|
||||
|
||||
string resPath(ivector::const_iterator it) const
|
||||
{
|
||||
return cv::format("%s%d.xml",cascadeName.c_str(), *it);
|
||||
}
|
||||
|
||||
// Paths to a rescaled data
|
||||
string trainPath;
|
||||
string testPath;
|
||||
|
||||
// Original model size.
|
||||
cv::Size modelWinSize;
|
||||
|
||||
// example offset into positive image
|
||||
cv::Point2i offset;
|
||||
|
||||
// List of octaves for which have to be trained cascades (a list of powers of two)
|
||||
ivector octaves;
|
||||
|
||||
// Maximum number of positives that should be used during training
|
||||
int positives;
|
||||
|
||||
// Initial number of negatives used during training.
|
||||
int negatives;
|
||||
|
||||
// Number of weak negatives to add each bootstrapping step.
|
||||
int btpNegatives;
|
||||
|
||||
// Inverse of scale for feature resizing
|
||||
int shrinkage;
|
||||
|
||||
// Depth on weak classifier's decision tree
|
||||
int treeDepth;
|
||||
|
||||
// Weak classifiers number in resulted cascade
|
||||
int weaks;
|
||||
|
||||
// Feature random pool size
|
||||
int poolSize;
|
||||
|
||||
// file name to store cascade
|
||||
string cascadeName;
|
||||
|
||||
// path to resulting cascade
|
||||
string outXmlPath;
|
||||
|
||||
// seed for random generation
|
||||
int seed;
|
||||
|
||||
// channel feature type
|
||||
string featureType;
|
||||
|
||||
// // bounding rectangle for actual example into example window
|
||||
// cv::Rect exampleWindow;
|
||||
};
|
||||
|
||||
// required for cv::FileStorage serialization
|
||||
void write(cv::FileStorage& fs, const string&, const Config& x);
|
||||
void read(const cv::FileNode& node, Config& x, const Config& default_value);
|
||||
std::ostream& operator<<(std::ostream& out, const Config& m);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,67 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __SFT_OCTAVE_HPP__
|
||||
#define __SFT_OCTAVE_HPP__
|
||||
|
||||
#include <sft/common.hpp>
|
||||
namespace sft
|
||||
{
|
||||
|
||||
using cv::softcascade::Dataset;
|
||||
|
||||
class ScaledDataset : public Dataset
|
||||
{
|
||||
public:
|
||||
ScaledDataset(const sft::string& path, const int octave);
|
||||
|
||||
virtual cv::Mat get(SampleType type, int idx) const;
|
||||
virtual int available(SampleType type) const;
|
||||
virtual ~ScaledDataset();
|
||||
|
||||
private:
|
||||
svector pos;
|
||||
svector neg;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
168
apps/sft/sft.cpp
168
apps/sft/sft.cpp
@ -1,168 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
// Training application for Soft Cascades.
|
||||
|
||||
#include <sft/common.hpp>
|
||||
#include <iostream>
|
||||
#include <sft/dataset.hpp>
|
||||
#include <sft/config.hpp>
|
||||
|
||||
#include <opencv2/core/core_c.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace sft;
|
||||
|
||||
const string keys =
|
||||
"{help h usage ? | | print this message }"
|
||||
"{config c | | path to configuration xml }"
|
||||
;
|
||||
|
||||
cv::CommandLineParser parser(argc, argv, keys);
|
||||
parser.about("Soft cascade training application.");
|
||||
|
||||
if (parser.has("help"))
|
||||
{
|
||||
parser.printMessage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!parser.check())
|
||||
{
|
||||
parser.printErrors();
|
||||
return 1;
|
||||
}
|
||||
|
||||
string configPath = parser.get<string>("config");
|
||||
if (configPath.empty())
|
||||
{
|
||||
std::cout << "Configuration file is missing or empty. Could not start training." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::cout << "Read configuration from file " << configPath << std::endl;
|
||||
cv::FileStorage fs(configPath, cv::FileStorage::READ);
|
||||
if(!fs.isOpened())
|
||||
{
|
||||
std::cout << "Configuration file " << configPath << " can't be opened." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 1. load config
|
||||
sft::Config cfg;
|
||||
fs["config"] >> cfg;
|
||||
std::cout << std::endl << "Training will be executed for configuration:" << std::endl << cfg << std::endl;
|
||||
|
||||
// 2. check and open output file
|
||||
cv::FileStorage fso(cfg.outXmlPath, cv::FileStorage::WRITE);
|
||||
if(!fso.isOpened())
|
||||
{
|
||||
std::cout << "Training stopped. Output classifier Xml file " << cfg.outXmlPath << " can't be opened." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
fso << cfg.cascadeName
|
||||
<< "{"
|
||||
<< "stageType" << "BOOST"
|
||||
<< "featureType" << cfg.featureType
|
||||
<< "octavesNum" << (int)cfg.octaves.size()
|
||||
<< "width" << cfg.modelWinSize.width
|
||||
<< "height" << cfg.modelWinSize.height
|
||||
<< "shrinkage" << cfg.shrinkage
|
||||
<< "octaves" << "[";
|
||||
|
||||
// 3. Train all octaves
|
||||
for (ivector::const_iterator it = cfg.octaves.begin(); it != cfg.octaves.end(); ++it)
|
||||
{
|
||||
// a. create random feature pool
|
||||
int nfeatures = cfg.poolSize;
|
||||
cv::Size model = cfg.model(it);
|
||||
std::cout << "Model " << model << std::endl;
|
||||
|
||||
int nchannels = (cfg.featureType == "HOG6MagLuv") ? 10: 8;
|
||||
|
||||
std::cout << "number of feature channels is " << nchannels << std::endl;
|
||||
|
||||
cv::Ptr<cv::FeaturePool> pool = cv::FeaturePool::create(model, nfeatures, nchannels);
|
||||
nfeatures = pool->size();
|
||||
|
||||
|
||||
int npositives = cfg.positives;
|
||||
int nnegatives = cfg.negatives;
|
||||
int shrinkage = cfg.shrinkage;
|
||||
cv::Rect boundingBox = cfg.bbox(it);
|
||||
std::cout << "Object bounding box" << boundingBox << std::endl;
|
||||
|
||||
typedef cv::Octave Octave;
|
||||
|
||||
cv::Ptr<cv::ChannelFeatureBuilder> builder = cv::ChannelFeatureBuilder::create(cfg.featureType);
|
||||
std::cout << "Channel builder " << builder->info()->name() << std::endl;
|
||||
cv::Ptr<Octave> boost = Octave::create(boundingBox, npositives, nnegatives, *it, shrinkage, builder);
|
||||
|
||||
std::string path = cfg.trainPath;
|
||||
sft::ScaledDataset dataset(path, *it);
|
||||
|
||||
if (boost->train(&dataset, pool, cfg.weaks, cfg.treeDepth))
|
||||
{
|
||||
CvFileStorage* fout = cvOpenFileStorage(cfg.resPath(it).c_str(), 0, CV_STORAGE_WRITE);
|
||||
boost->write(fout, cfg.cascadeName);
|
||||
|
||||
cvReleaseFileStorage( &fout);
|
||||
|
||||
cv::Mat thresholds;
|
||||
boost->setRejectThresholds(thresholds);
|
||||
|
||||
boost->write(fso, pool, thresholds);
|
||||
|
||||
cv::FileStorage tfs(("thresholds." + cfg.resPath(it)).c_str(), cv::FileStorage::WRITE);
|
||||
tfs << "thresholds" << thresholds;
|
||||
|
||||
std::cout << "Octave " << *it << " was successfully trained..." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
fso << "]" << "}";
|
||||
fso.release();
|
||||
std::cout << "Training complete..." << std::endl;
|
||||
return 0;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
set(OPENCV_TRAINCASCADE_DEPS opencv_core opencv_ml opencv_imgproc opencv_photo opencv_objdetect opencv_highgui opencv_calib3d opencv_video opencv_features2d opencv_flann opencv_legacy)
|
||||
set(OPENCV_TRAINCASCADE_DEPS opencv_core opencv_imgproc opencv_objdetect opencv_imgcodecs opencv_highgui opencv_calib3d opencv_features2d)
|
||||
ocv_check_dependencies(${OPENCV_TRAINCASCADE_DEPS})
|
||||
|
||||
if(NOT OCV_DEPENDENCIES_FOUND)
|
||||
@ -6,21 +6,18 @@ if(NOT OCV_DEPENDENCIES_FOUND)
|
||||
endif()
|
||||
|
||||
project(traincascade)
|
||||
|
||||
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv")
|
||||
ocv_include_modules(${OPENCV_TRAINCASCADE_DEPS})
|
||||
|
||||
set(traincascade_files traincascade.cpp
|
||||
cascadeclassifier.cpp cascadeclassifier.h
|
||||
boost.cpp boost.h features.cpp traincascade_features.h
|
||||
haarfeatures.cpp haarfeatures.h
|
||||
lbpfeatures.cpp lbpfeatures.h
|
||||
HOGfeatures.cpp HOGfeatures.h
|
||||
imagestorage.cpp imagestorage.h)
|
||||
|
||||
set(the_target opencv_traincascade)
|
||||
add_executable(${the_target} ${traincascade_files})
|
||||
target_link_libraries(${the_target} ${OPENCV_TRAINCASCADE_DEPS} opencv_haartraining_engine)
|
||||
|
||||
ocv_target_include_directories(${the_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv")
|
||||
ocv_target_include_modules(${the_target} ${OPENCV_TRAINCASCADE_DEPS})
|
||||
|
||||
file(GLOB SRCS *.cpp)
|
||||
file(GLOB HDRS *.h*)
|
||||
|
||||
set(traincascade_files ${SRCS} ${HDRS})
|
||||
|
||||
ocv_add_executable(${the_target} ${traincascade_files})
|
||||
ocv_target_link_libraries(${the_target} ${OPENCV_TRAINCASCADE_DEPS})
|
||||
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
@ -35,8 +32,8 @@ endif()
|
||||
|
||||
if(INSTALL_CREATE_DISTRIB)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main)
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev)
|
||||
endif()
|
||||
else()
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main)
|
||||
install(TARGETS ${the_target} OPTIONAL RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev)
|
||||
endif()
|
||||
|
@ -187,11 +187,11 @@ void CvHOGEvaluator::integralHistogram(const Mat &img, vector<Mat> &histogram, M
|
||||
|
||||
for( y = 0; y < gradSize.height; y++ )
|
||||
{
|
||||
const uchar* currPtr = img.data + img.step*ymap[y];
|
||||
const uchar* prevPtr = img.data + img.step*ymap[y-1];
|
||||
const uchar* nextPtr = img.data + img.step*ymap[y+1];
|
||||
float* gradPtr = (float*)grad.ptr(y);
|
||||
uchar* qanglePtr = (uchar*)qangle.ptr(y);
|
||||
const uchar* currPtr = img.ptr(ymap[y]);
|
||||
const uchar* prevPtr = img.ptr(ymap[y-1]);
|
||||
const uchar* nextPtr = img.ptr(ymap[y+1]);
|
||||
float* gradPtr = grad.ptr<float>(y);
|
||||
uchar* qanglePtr = qangle.ptr(y);
|
||||
|
||||
for( x = 0; x < width; x++ )
|
||||
{
|
||||
@ -226,9 +226,9 @@ void CvHOGEvaluator::integralHistogram(const Mat &img, vector<Mat> &histogram, M
|
||||
int magStep = (int)( grad.step / sizeof(float) );
|
||||
for( binIdx = 0; binIdx < nbins; binIdx++ )
|
||||
{
|
||||
histBuf = (float*)histogram[binIdx].data;
|
||||
magBuf = (const float*)grad.data;
|
||||
binsBuf = (const uchar*)qangle.data;
|
||||
histBuf = histogram[binIdx].ptr<float>();
|
||||
magBuf = grad.ptr<float>();
|
||||
binsBuf = qangle.ptr();
|
||||
|
||||
memset( histBuf, 0, histSize.width * sizeof(histBuf[0]) );
|
||||
histBuf += histStep + 1;
|
||||
|
@ -14,6 +14,19 @@ using cv::FileNodeIterator;
|
||||
using cv::ParallelLoopBody;
|
||||
|
||||
|
||||
using cv::Size;
|
||||
using cv::Mat;
|
||||
using cv::Point;
|
||||
using cv::FileStorage;
|
||||
using cv::Rect;
|
||||
using cv::Ptr;
|
||||
using cv::FileNode;
|
||||
using cv::Mat_;
|
||||
using cv::Range;
|
||||
using cv::FileNodeIterator;
|
||||
using cv::ParallelLoopBody;
|
||||
|
||||
|
||||
#include "boost.h"
|
||||
#include "cascadeclassifier.h"
|
||||
#include <queue>
|
||||
@ -890,7 +903,7 @@ struct FeatureValAndIdxPrecalc : ParallelLoopBody
|
||||
*(idst + fi*sample_count + si) = si;
|
||||
}
|
||||
if ( is_buf_16u )
|
||||
std::sort(idst + fi*sample_count, idst + (fi + 1)*sample_count, LessThanIdx<float, unsigned short>(valCache->ptr<float>(fi)) );
|
||||
std::sort(udst + fi*sample_count, udst + (fi + 1)*sample_count, LessThanIdx<float, unsigned short>(valCache->ptr<float>(fi)) );
|
||||
else
|
||||
std::sort(idst + fi*sample_count, idst + (fi + 1)*sample_count, LessThanIdx<float, int>(valCache->ptr<float>(fi)) );
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define _OPENCV_BOOST_H_
|
||||
|
||||
#include "traincascade_features.h"
|
||||
#include "ml.h"
|
||||
#include "old_ml.hpp"
|
||||
|
||||
struct CvCascadeBoostParams : CvBoostParams
|
||||
{
|
||||
|
@ -137,6 +137,9 @@ bool CvCascadeClassifier::train( const string _cascadeDirName,
|
||||
const CvCascadeBoostParams& _stageParams,
|
||||
bool baseFormatSave )
|
||||
{
|
||||
// Start recording clock ticks for training time output
|
||||
const clock_t begin_time = clock();
|
||||
|
||||
if( _cascadeDirName.empty() || _posFilename.empty() || _negFilename.empty() )
|
||||
CV_Error( CV_StsBadArg, "_cascadeDirName or _bgfileName or _vecFileName is NULL" );
|
||||
|
||||
@ -247,6 +250,14 @@ bool CvCascadeClassifier::train( const string _cascadeDirName,
|
||||
fs << FileStorage::getDefaultObjectName(stageFilename) << "{";
|
||||
tempStage->write( fs, Mat() );
|
||||
fs << "}";
|
||||
|
||||
// Output training time up till now
|
||||
float seconds = float( clock () - begin_time ) / CLOCKS_PER_SEC;
|
||||
int days = int(seconds) / 60 / 60 / 24;
|
||||
int hours = (int(seconds) / 60 / 60) % 24;
|
||||
int minutes = (int(seconds) / 60) % 60;
|
||||
int seconds_left = int(seconds) % 60;
|
||||
cout << "Training until now has taken " << days << " days " << hours << " hours " << minutes << " minutes " << seconds_left <<" seconds." << endl;
|
||||
}
|
||||
|
||||
if(stageClassifiers.size() == 0)
|
||||
@ -310,6 +321,7 @@ int CvCascadeClassifier::fillPassedSamples( int first, int count, bool isPositiv
|
||||
if( predict( i ) == 1.0F )
|
||||
{
|
||||
getcount++;
|
||||
printf("%s current samples: %d\r", isPositive ? "POS":"NEG", getcount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,6 @@
|
||||
#include "lbpfeatures.h"
|
||||
#include "HOGfeatures.h" //new
|
||||
#include "boost.h"
|
||||
#include "cv.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
#define CC_CASCADE_FILENAME "cascade.xml"
|
||||
#define CC_PARAMS_FILENAME "params.xml"
|
||||
|
@ -13,9 +13,9 @@ float calcNormFactor( const Mat& sum, const Mat& sqSum )
|
||||
size_t p0, p1, p2, p3;
|
||||
CV_SUM_OFFSETS( p0, p1, p2, p3, normrect, sum.step1() )
|
||||
double area = normrect.width * normrect.height;
|
||||
const int *sp = (const int*)sum.data;
|
||||
const int *sp = sum.ptr<int>();
|
||||
int valSum = sp[p0] - sp[p1] - sp[p2] + sp[p3];
|
||||
const double *sqp = (const double *)sqSum.data;
|
||||
const double *sqp = sqSum.ptr<double>();
|
||||
double valSqSum = sqp[p0] - sqp[p1] - sqp[p2] + sqp[p3];
|
||||
return (float) sqrt( (double) (area * valSqSum - (double)valSum * valSum) );
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
|
||||
#include "imagestorage.h"
|
||||
#include <stdio.h>
|
||||
@ -70,7 +71,7 @@ bool CvCascadeImageReader::NegReader::nextImg()
|
||||
_offset.x = std::min( (int)round % winSize.width, src.cols - winSize.width );
|
||||
_offset.y = std::min( (int)round / winSize.width, src.rows - winSize.height );
|
||||
if( !src.empty() && src.type() == CV_8UC1
|
||||
&& offset.x >= 0 && offset.y >= 0 )
|
||||
&& _offset.x >= 0 && _offset.y >= 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
@ -97,7 +98,7 @@ bool CvCascadeImageReader::NegReader::get( Mat& _img )
|
||||
return false;
|
||||
|
||||
Mat mat( winSize.height, winSize.width, CV_8UC1,
|
||||
(void*)(img.data + point.y * img.step + point.x * img.elemSize()), img.step );
|
||||
(void*)(img.ptr(point.y) + point.x * img.elemSize()), img.step );
|
||||
mat.copyTo(_img);
|
||||
|
||||
if( (int)( point.x + (1.0F + stepFactor ) * winSize.width ) < img.cols )
|
||||
|
@ -1,9 +1,6 @@
|
||||
#ifndef _OPENCV_IMAGESTORAGE_H_
|
||||
#define _OPENCV_IMAGESTORAGE_H_
|
||||
|
||||
#include "highgui.h"
|
||||
|
||||
|
||||
|
||||
class CvCascadeImageReader
|
||||
{
|
||||
|
2068
apps/traincascade/old_ml.hpp
Normal file
2068
apps/traincascade/old_ml.hpp
Normal file
File diff suppressed because it is too large
Load Diff
2162
apps/traincascade/old_ml_boost.cpp
Normal file
2162
apps/traincascade/old_ml_boost.cpp
Normal file
File diff suppressed because it is too large
Load Diff
792
apps/traincascade/old_ml_data.cpp
Normal file
792
apps/traincascade/old_ml_data.cpp
Normal file
@ -0,0 +1,792 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "old_ml_precomp.hpp"
|
||||
#include <ctype.h>
|
||||
|
||||
#define MISS_VAL FLT_MAX
|
||||
#define CV_VAR_MISS 0
|
||||
|
||||
CvTrainTestSplit::CvTrainTestSplit()
|
||||
{
|
||||
train_sample_part_mode = CV_COUNT;
|
||||
train_sample_part.count = -1;
|
||||
mix = false;
|
||||
}
|
||||
|
||||
CvTrainTestSplit::CvTrainTestSplit( int _train_sample_count, bool _mix )
|
||||
{
|
||||
train_sample_part_mode = CV_COUNT;
|
||||
train_sample_part.count = _train_sample_count;
|
||||
mix = _mix;
|
||||
}
|
||||
|
||||
CvTrainTestSplit::CvTrainTestSplit( float _train_sample_portion, bool _mix )
|
||||
{
|
||||
train_sample_part_mode = CV_PORTION;
|
||||
train_sample_part.portion = _train_sample_portion;
|
||||
mix = _mix;
|
||||
}
|
||||
|
||||
////////////////
|
||||
|
||||
CvMLData::CvMLData()
|
||||
{
|
||||
values = missing = var_types = var_idx_mask = response_out = var_idx_out = var_types_out = 0;
|
||||
train_sample_idx = test_sample_idx = 0;
|
||||
header_lines_number = 0;
|
||||
sample_idx = 0;
|
||||
response_idx = -1;
|
||||
|
||||
train_sample_count = -1;
|
||||
|
||||
delimiter = ',';
|
||||
miss_ch = '?';
|
||||
//flt_separator = '.';
|
||||
|
||||
rng = &cv::theRNG();
|
||||
}
|
||||
|
||||
CvMLData::~CvMLData()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void CvMLData::free_train_test_idx()
|
||||
{
|
||||
cvReleaseMat( &train_sample_idx );
|
||||
cvReleaseMat( &test_sample_idx );
|
||||
sample_idx = 0;
|
||||
}
|
||||
|
||||
void CvMLData::clear()
|
||||
{
|
||||
class_map.clear();
|
||||
|
||||
cvReleaseMat( &values );
|
||||
cvReleaseMat( &missing );
|
||||
cvReleaseMat( &var_types );
|
||||
cvReleaseMat( &var_idx_mask );
|
||||
|
||||
cvReleaseMat( &response_out );
|
||||
cvReleaseMat( &var_idx_out );
|
||||
cvReleaseMat( &var_types_out );
|
||||
|
||||
free_train_test_idx();
|
||||
|
||||
total_class_count = 0;
|
||||
|
||||
response_idx = -1;
|
||||
|
||||
train_sample_count = -1;
|
||||
}
|
||||
|
||||
|
||||
void CvMLData::set_header_lines_number( int idx )
|
||||
{
|
||||
header_lines_number = std::max(0, idx);
|
||||
}
|
||||
|
||||
int CvMLData::get_header_lines_number() const
|
||||
{
|
||||
return header_lines_number;
|
||||
}
|
||||
|
||||
static char *fgets_chomp(char *str, int n, FILE *stream)
|
||||
{
|
||||
char *head = fgets(str, n, stream);
|
||||
if( head )
|
||||
{
|
||||
for(char *tail = head + strlen(head) - 1; tail >= head; --tail)
|
||||
{
|
||||
if( *tail != '\r' && *tail != '\n' )
|
||||
break;
|
||||
*tail = '\0';
|
||||
}
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
|
||||
int CvMLData::read_csv(const char* filename)
|
||||
{
|
||||
const int M = 1000000;
|
||||
const char str_delimiter[3] = { ' ', delimiter, '\0' };
|
||||
FILE* file = 0;
|
||||
CvMemStorage* storage;
|
||||
CvSeq* seq;
|
||||
char *ptr;
|
||||
float* el_ptr;
|
||||
CvSeqReader reader;
|
||||
int cols_count = 0;
|
||||
uchar *var_types_ptr = 0;
|
||||
|
||||
clear();
|
||||
|
||||
file = fopen( filename, "rt" );
|
||||
|
||||
if( !file )
|
||||
return -1;
|
||||
|
||||
std::vector<char> _buf(M);
|
||||
char* buf = &_buf[0];
|
||||
|
||||
// skip header lines
|
||||
for( int i = 0; i < header_lines_number; i++ )
|
||||
{
|
||||
if( fgets( buf, M, file ) == 0 )
|
||||
{
|
||||
fclose(file);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// read the first data line and determine the number of variables
|
||||
if( !fgets_chomp( buf, M, file ))
|
||||
{
|
||||
fclose(file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ptr = buf;
|
||||
while( *ptr == ' ' )
|
||||
ptr++;
|
||||
for( ; *ptr != '\0'; )
|
||||
{
|
||||
if(*ptr == delimiter || *ptr == ' ')
|
||||
{
|
||||
cols_count++;
|
||||
ptr++;
|
||||
while( *ptr == ' ' ) ptr++;
|
||||
}
|
||||
else
|
||||
ptr++;
|
||||
}
|
||||
|
||||
cols_count++;
|
||||
|
||||
if ( cols_count == 0)
|
||||
{
|
||||
fclose(file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// create temporary memory storage to store the whole database
|
||||
el_ptr = new float[cols_count];
|
||||
storage = cvCreateMemStorage();
|
||||
seq = cvCreateSeq( 0, sizeof(*seq), cols_count*sizeof(float), storage );
|
||||
|
||||
var_types = cvCreateMat( 1, cols_count, CV_8U );
|
||||
cvZero( var_types );
|
||||
var_types_ptr = var_types->data.ptr;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
char *token = NULL;
|
||||
int type;
|
||||
token = strtok(buf, str_delimiter);
|
||||
if (!token)
|
||||
break;
|
||||
for (int i = 0; i < cols_count-1; i++)
|
||||
{
|
||||
str_to_flt_elem( token, el_ptr[i], type);
|
||||
var_types_ptr[i] |= type;
|
||||
token = strtok(NULL, str_delimiter);
|
||||
if (!token)
|
||||
{
|
||||
fclose(file);
|
||||
delete [] el_ptr;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
str_to_flt_elem( token, el_ptr[cols_count-1], type);
|
||||
var_types_ptr[cols_count-1] |= type;
|
||||
cvSeqPush( seq, el_ptr );
|
||||
if( !fgets_chomp( buf, M, file ) )
|
||||
break;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
values = cvCreateMat( seq->total, cols_count, CV_32FC1 );
|
||||
missing = cvCreateMat( seq->total, cols_count, CV_8U );
|
||||
var_idx_mask = cvCreateMat( 1, values->cols, CV_8UC1 );
|
||||
cvSet( var_idx_mask, cvRealScalar(1) );
|
||||
train_sample_count = seq->total;
|
||||
|
||||
cvStartReadSeq( seq, &reader );
|
||||
for(int i = 0; i < seq->total; i++ )
|
||||
{
|
||||
const float* sdata = (float*)reader.ptr;
|
||||
float* ddata = values->data.fl + cols_count*i;
|
||||
uchar* dm = missing->data.ptr + cols_count*i;
|
||||
|
||||
for( int j = 0; j < cols_count; j++ )
|
||||
{
|
||||
ddata[j] = sdata[j];
|
||||
dm[j] = ( fabs( MISS_VAL - sdata[j] ) <= FLT_EPSILON );
|
||||
}
|
||||
CV_NEXT_SEQ_ELEM( seq->elem_size, reader );
|
||||
}
|
||||
|
||||
if ( cvNorm( missing, 0, CV_L1 ) <= FLT_EPSILON )
|
||||
cvReleaseMat( &missing );
|
||||
|
||||
cvReleaseMemStorage( &storage );
|
||||
delete []el_ptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_values() const
|
||||
{
|
||||
return values;
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_missing() const
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_missing" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
|
||||
__END__;
|
||||
|
||||
return missing;
|
||||
}
|
||||
|
||||
const std::map<cv::String, int>& CvMLData::get_class_labels_map() const
|
||||
{
|
||||
return class_map;
|
||||
}
|
||||
|
||||
void CvMLData::str_to_flt_elem( const char* token, float& flt_elem, int& type)
|
||||
{
|
||||
|
||||
char* stopstring = NULL;
|
||||
flt_elem = (float)strtod( token, &stopstring );
|
||||
assert( stopstring );
|
||||
type = CV_VAR_ORDERED;
|
||||
if ( *stopstring == miss_ch && strlen(stopstring) == 1 ) // missed value
|
||||
{
|
||||
flt_elem = MISS_VAL;
|
||||
type = CV_VAR_MISS;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (*stopstring != 0) && (*stopstring != '\n') && (strcmp(stopstring, "\r\n") != 0) ) // class label
|
||||
{
|
||||
int idx = class_map[token];
|
||||
if ( idx == 0)
|
||||
{
|
||||
total_class_count++;
|
||||
idx = total_class_count;
|
||||
class_map[token] = idx;
|
||||
}
|
||||
flt_elem = (float)idx;
|
||||
type = CV_VAR_CATEGORICAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CvMLData::set_delimiter(char ch)
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::set_delimited" );
|
||||
__BEGIN__;
|
||||
|
||||
if (ch == miss_ch /*|| ch == flt_separator*/)
|
||||
CV_ERROR(CV_StsBadArg, "delimited, miss_character and flt_separator must be different");
|
||||
|
||||
delimiter = ch;
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
char CvMLData::get_delimiter() const
|
||||
{
|
||||
return delimiter;
|
||||
}
|
||||
|
||||
void CvMLData::set_miss_ch(char ch)
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::set_miss_ch" );
|
||||
__BEGIN__;
|
||||
|
||||
if (ch == delimiter/* || ch == flt_separator*/)
|
||||
CV_ERROR(CV_StsBadArg, "delimited, miss_character and flt_separator must be different");
|
||||
|
||||
miss_ch = ch;
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
char CvMLData::get_miss_ch() const
|
||||
{
|
||||
return miss_ch;
|
||||
}
|
||||
|
||||
void CvMLData::set_response_idx( int idx )
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::set_response_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
|
||||
if ( idx >= values->cols)
|
||||
CV_ERROR( CV_StsBadArg, "idx value is not correct" );
|
||||
|
||||
if ( response_idx >= 0 )
|
||||
chahge_var_idx( response_idx, true );
|
||||
if ( idx >= 0 )
|
||||
chahge_var_idx( idx, false );
|
||||
response_idx = idx;
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
int CvMLData::get_response_idx() const
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_response_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
__END__;
|
||||
return response_idx;
|
||||
}
|
||||
|
||||
void CvMLData::change_var_type( int var_idx, int type )
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::change_var_type" );
|
||||
__BEGIN__;
|
||||
|
||||
int var_count = 0;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
|
||||
var_count = values->cols;
|
||||
|
||||
if ( var_idx < 0 || var_idx >= var_count)
|
||||
CV_ERROR( CV_StsBadArg, "var_idx is not correct" );
|
||||
|
||||
if ( type != CV_VAR_ORDERED && type != CV_VAR_CATEGORICAL)
|
||||
CV_ERROR( CV_StsBadArg, "type is not correct" );
|
||||
|
||||
assert( var_types );
|
||||
if ( var_types->data.ptr[var_idx] == CV_VAR_CATEGORICAL && type == CV_VAR_ORDERED)
|
||||
CV_ERROR( CV_StsBadArg, "it`s impossible to assign CV_VAR_ORDERED type to categorical variable" );
|
||||
var_types->data.ptr[var_idx] = (uchar)type;
|
||||
|
||||
__END__;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void CvMLData::set_var_types( const char* str )
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::set_var_types" );
|
||||
__BEGIN__;
|
||||
|
||||
const char* ord = 0, *cat = 0;
|
||||
int var_count = 0, set_var_type_count = 0;
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
|
||||
var_count = values->cols;
|
||||
|
||||
assert( var_types );
|
||||
|
||||
ord = strstr( str, "ord" );
|
||||
cat = strstr( str, "cat" );
|
||||
if ( !ord && !cat )
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
|
||||
if ( !ord && strlen(cat) == 3 ) // str == "cat"
|
||||
{
|
||||
cvSet( var_types, cvScalarAll(CV_VAR_CATEGORICAL) );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !cat && strlen(ord) == 3 ) // str == "ord"
|
||||
{
|
||||
cvSet( var_types, cvScalarAll(CV_VAR_ORDERED) );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ord ) // parse ord str
|
||||
{
|
||||
char* stopstring = NULL;
|
||||
if ( ord[3] != '[')
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
|
||||
ord += 4; // pass "ord["
|
||||
do
|
||||
{
|
||||
int b1 = (int)strtod( ord, &stopstring );
|
||||
if ( *stopstring == 0 || (*stopstring != ',' && *stopstring != ']' && *stopstring != '-') )
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
ord = stopstring + 1;
|
||||
if ( (stopstring[0] == ',') || (stopstring[0] == ']'))
|
||||
{
|
||||
if ( var_types->data.ptr[b1] == CV_VAR_CATEGORICAL)
|
||||
CV_ERROR( CV_StsBadArg, "it`s impossible to assign CV_VAR_ORDERED type to categorical variable" );
|
||||
var_types->data.ptr[b1] = CV_VAR_ORDERED;
|
||||
set_var_type_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( stopstring[0] == '-')
|
||||
{
|
||||
int b2 = (int)strtod( ord, &stopstring);
|
||||
if ( (*stopstring == 0) || (*stopstring != ',' && *stopstring != ']') )
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
ord = stopstring + 1;
|
||||
for (int i = b1; i <= b2; i++)
|
||||
{
|
||||
if ( var_types->data.ptr[i] == CV_VAR_CATEGORICAL)
|
||||
CV_ERROR( CV_StsBadArg, "it`s impossible to assign CV_VAR_ORDERED type to categorical variable" );
|
||||
var_types->data.ptr[i] = CV_VAR_ORDERED;
|
||||
}
|
||||
set_var_type_count += b2 - b1 + 1;
|
||||
}
|
||||
else
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
|
||||
}
|
||||
}
|
||||
while (*stopstring != ']');
|
||||
|
||||
if ( stopstring[1] != '\0' && stopstring[1] != ',')
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
}
|
||||
|
||||
if ( cat ) // parse cat str
|
||||
{
|
||||
char* stopstring = NULL;
|
||||
if ( cat[3] != '[')
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
|
||||
cat += 4; // pass "cat["
|
||||
do
|
||||
{
|
||||
int b1 = (int)strtod( cat, &stopstring );
|
||||
if ( *stopstring == 0 || (*stopstring != ',' && *stopstring != ']' && *stopstring != '-') )
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
cat = stopstring + 1;
|
||||
if ( (stopstring[0] == ',') || (stopstring[0] == ']'))
|
||||
{
|
||||
var_types->data.ptr[b1] = CV_VAR_CATEGORICAL;
|
||||
set_var_type_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( stopstring[0] == '-')
|
||||
{
|
||||
int b2 = (int)strtod( cat, &stopstring);
|
||||
if ( (*stopstring == 0) || (*stopstring != ',' && *stopstring != ']') )
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
cat = stopstring + 1;
|
||||
for (int i = b1; i <= b2; i++)
|
||||
var_types->data.ptr[i] = CV_VAR_CATEGORICAL;
|
||||
set_var_type_count += b2 - b1 + 1;
|
||||
}
|
||||
else
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
|
||||
}
|
||||
}
|
||||
while (*stopstring != ']');
|
||||
|
||||
if ( stopstring[1] != '\0' && stopstring[1] != ',')
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
}
|
||||
|
||||
if (set_var_type_count != var_count)
|
||||
CV_ERROR( CV_StsBadArg, "types string is not correct" );
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_var_types()
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_var_types" );
|
||||
__BEGIN__;
|
||||
|
||||
uchar *var_types_out_ptr = 0;
|
||||
int avcount, vt_size;
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
|
||||
assert( var_idx_mask );
|
||||
|
||||
avcount = cvFloor( cvNorm( var_idx_mask, 0, CV_L1 ) );
|
||||
vt_size = avcount + (response_idx >= 0);
|
||||
|
||||
if ( avcount == values->cols || (avcount == values->cols-1 && response_idx == values->cols-1) )
|
||||
return var_types;
|
||||
|
||||
if ( !var_types_out || ( var_types_out && var_types_out->cols != vt_size ) )
|
||||
{
|
||||
cvReleaseMat( &var_types_out );
|
||||
var_types_out = cvCreateMat( 1, vt_size, CV_8UC1 );
|
||||
}
|
||||
|
||||
var_types_out_ptr = var_types_out->data.ptr;
|
||||
for( int i = 0; i < var_types->cols; i++)
|
||||
{
|
||||
if (i == response_idx || !var_idx_mask->data.ptr[i]) continue;
|
||||
*var_types_out_ptr = var_types->data.ptr[i];
|
||||
var_types_out_ptr++;
|
||||
}
|
||||
if ( response_idx >= 0 )
|
||||
*var_types_out_ptr = var_types->data.ptr[response_idx];
|
||||
|
||||
__END__;
|
||||
|
||||
return var_types_out;
|
||||
}
|
||||
|
||||
int CvMLData::get_var_type( int var_idx ) const
|
||||
{
|
||||
return var_types->data.ptr[var_idx];
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_responses()
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_responses_ptr" );
|
||||
__BEGIN__;
|
||||
|
||||
int var_count = 0;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
var_count = values->cols;
|
||||
|
||||
if ( response_idx < 0 || response_idx >= var_count )
|
||||
return 0;
|
||||
if ( !response_out )
|
||||
response_out = cvCreateMatHeader( values->rows, 1, CV_32FC1 );
|
||||
else
|
||||
cvInitMatHeader( response_out, values->rows, 1, CV_32FC1);
|
||||
cvGetCol( values, response_out, response_idx );
|
||||
|
||||
__END__;
|
||||
|
||||
return response_out;
|
||||
}
|
||||
|
||||
void CvMLData::set_train_test_split( const CvTrainTestSplit * spl)
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::set_division" );
|
||||
__BEGIN__;
|
||||
|
||||
int sample_count = 0;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
|
||||
sample_count = values->rows;
|
||||
|
||||
float train_sample_portion;
|
||||
|
||||
if (spl->train_sample_part_mode == CV_COUNT)
|
||||
{
|
||||
train_sample_count = spl->train_sample_part.count;
|
||||
if (train_sample_count > sample_count)
|
||||
CV_ERROR( CV_StsBadArg, "train samples count is not correct" );
|
||||
train_sample_count = train_sample_count<=0 ? sample_count : train_sample_count;
|
||||
}
|
||||
else // dtype.train_sample_part_mode == CV_PORTION
|
||||
{
|
||||
train_sample_portion = spl->train_sample_part.portion;
|
||||
if ( train_sample_portion > 1)
|
||||
CV_ERROR( CV_StsBadArg, "train samples count is not correct" );
|
||||
train_sample_portion = train_sample_portion <= FLT_EPSILON ||
|
||||
1 - train_sample_portion <= FLT_EPSILON ? 1 : train_sample_portion;
|
||||
train_sample_count = std::max(1, cvFloor( train_sample_portion * sample_count ));
|
||||
}
|
||||
|
||||
if ( train_sample_count == sample_count )
|
||||
{
|
||||
free_train_test_idx();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( train_sample_idx && train_sample_idx->cols != train_sample_count )
|
||||
free_train_test_idx();
|
||||
|
||||
if ( !sample_idx)
|
||||
{
|
||||
int test_sample_count = sample_count- train_sample_count;
|
||||
sample_idx = (int*)cvAlloc( sample_count * sizeof(sample_idx[0]) );
|
||||
for (int i = 0; i < sample_count; i++ )
|
||||
sample_idx[i] = i;
|
||||
train_sample_idx = cvCreateMatHeader( 1, train_sample_count, CV_32SC1 );
|
||||
*train_sample_idx = cvMat( 1, train_sample_count, CV_32SC1, &sample_idx[0] );
|
||||
|
||||
CV_Assert(test_sample_count > 0);
|
||||
test_sample_idx = cvCreateMatHeader( 1, test_sample_count, CV_32SC1 );
|
||||
*test_sample_idx = cvMat( 1, test_sample_count, CV_32SC1, &sample_idx[train_sample_count] );
|
||||
}
|
||||
|
||||
mix = spl->mix;
|
||||
if ( mix )
|
||||
mix_train_and_test_idx();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_train_sample_idx() const
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_train_sample_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
__END__;
|
||||
|
||||
return train_sample_idx;
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_test_sample_idx() const
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_test_sample_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
__END__;
|
||||
|
||||
return test_sample_idx;
|
||||
}
|
||||
|
||||
void CvMLData::mix_train_and_test_idx()
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::mix_train_and_test_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
__END__;
|
||||
|
||||
if ( !sample_idx)
|
||||
return;
|
||||
|
||||
if ( train_sample_count > 0 && train_sample_count < values->rows )
|
||||
{
|
||||
int n = values->rows;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int a = (*rng)(n);
|
||||
int b = (*rng)(n);
|
||||
int t;
|
||||
CV_SWAP( sample_idx[a], sample_idx[b], t );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_var_idx()
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_var_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
int avcount = 0;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
|
||||
assert( var_idx_mask );
|
||||
|
||||
avcount = cvFloor( cvNorm( var_idx_mask, 0, CV_L1 ) );
|
||||
int* vidx;
|
||||
|
||||
if ( avcount == values->cols )
|
||||
return 0;
|
||||
|
||||
if ( !var_idx_out || ( var_idx_out && var_idx_out->cols != avcount ) )
|
||||
{
|
||||
cvReleaseMat( &var_idx_out );
|
||||
var_idx_out = cvCreateMat( 1, avcount, CV_32SC1);
|
||||
if ( response_idx >=0 )
|
||||
var_idx_mask->data.ptr[response_idx] = 0;
|
||||
}
|
||||
|
||||
vidx = var_idx_out->data.i;
|
||||
|
||||
for(int i = 0; i < var_idx_mask->cols; i++)
|
||||
if ( var_idx_mask->data.ptr[i] )
|
||||
{
|
||||
*vidx = i;
|
||||
vidx++;
|
||||
}
|
||||
|
||||
__END__;
|
||||
|
||||
return var_idx_out;
|
||||
}
|
||||
|
||||
void CvMLData::chahge_var_idx( int vi, bool state )
|
||||
{
|
||||
change_var_idx( vi, state );
|
||||
}
|
||||
|
||||
void CvMLData::change_var_idx( int vi, bool state )
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::change_var_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
int var_count = 0;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
|
||||
var_count = values->cols;
|
||||
|
||||
if ( vi < 0 || vi >= var_count)
|
||||
CV_ERROR( CV_StsBadArg, "variable index is not correct" );
|
||||
|
||||
assert( var_idx_mask );
|
||||
var_idx_mask->data.ptr[vi] = state;
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
/* End of file. */
|
1879
apps/traincascade/old_ml_inner_functions.cpp
Normal file
1879
apps/traincascade/old_ml_inner_functions.cpp
Normal file
File diff suppressed because it is too large
Load Diff
376
apps/traincascade/old_ml_precomp.hpp
Normal file
376
apps/traincascade/old_ml_precomp.hpp
Normal file
@ -0,0 +1,376 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * 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.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// 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 Intel Corporation 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.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "old_ml.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
|
||||
#include "opencv2/core/private.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#define ML_IMPL CV_IMPL
|
||||
#define __BEGIN__ __CV_BEGIN__
|
||||
#define __END__ __CV_END__
|
||||
#define EXIT __CV_EXIT__
|
||||
|
||||
#define CV_MAT_ELEM_FLAG( mat, type, comp, vect, tflag ) \
|
||||
(( tflag == CV_ROW_SAMPLE ) \
|
||||
? (CV_MAT_ELEM( mat, type, comp, vect )) \
|
||||
: (CV_MAT_ELEM( mat, type, vect, comp )))
|
||||
|
||||
/* Convert matrix to vector */
|
||||
#define ICV_MAT2VEC( mat, vdata, vstep, num ) \
|
||||
if( MIN( (mat).rows, (mat).cols ) != 1 ) \
|
||||
CV_ERROR( CV_StsBadArg, "" ); \
|
||||
(vdata) = ((mat).data.ptr); \
|
||||
if( (mat).rows == 1 ) \
|
||||
{ \
|
||||
(vstep) = CV_ELEM_SIZE( (mat).type ); \
|
||||
(num) = (mat).cols; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
(vstep) = (mat).step; \
|
||||
(num) = (mat).rows; \
|
||||
}
|
||||
|
||||
/* get raw data */
|
||||
#define ICV_RAWDATA( mat, flags, rdata, sstep, cstep, m, n ) \
|
||||
(rdata) = (mat).data.ptr; \
|
||||
if( CV_IS_ROW_SAMPLE( flags ) ) \
|
||||
{ \
|
||||
(sstep) = (mat).step; \
|
||||
(cstep) = CV_ELEM_SIZE( (mat).type ); \
|
||||
(m) = (mat).rows; \
|
||||
(n) = (mat).cols; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
(cstep) = (mat).step; \
|
||||
(sstep) = CV_ELEM_SIZE( (mat).type ); \
|
||||
(n) = (mat).rows; \
|
||||
(m) = (mat).cols; \
|
||||
}
|
||||
|
||||
#define ICV_IS_MAT_OF_TYPE( mat, mat_type) \
|
||||
(CV_IS_MAT( mat ) && CV_MAT_TYPE( mat->type ) == (mat_type) && \
|
||||
(mat)->cols > 0 && (mat)->rows > 0)
|
||||
|
||||
/*
|
||||
uchar* data; int sstep, cstep; - trainData->data
|
||||
uchar* classes; int clstep; int ncl;- trainClasses
|
||||
uchar* tmask; int tmstep; int ntm; - typeMask
|
||||
uchar* missed;int msstep, mcstep; -missedMeasurements...
|
||||
int mm, mn; == m,n == size,dim
|
||||
uchar* sidx;int sistep; - sampleIdx
|
||||
uchar* cidx;int cistep; - compIdx
|
||||
int k, l; == n,m == dim,size (length of cidx, sidx)
|
||||
int m, n; == size,dim
|
||||
*/
|
||||
#define ICV_DECLARE_TRAIN_ARGS() \
|
||||
uchar* data; \
|
||||
int sstep, cstep; \
|
||||
uchar* classes; \
|
||||
int clstep; \
|
||||
int ncl; \
|
||||
uchar* tmask; \
|
||||
int tmstep; \
|
||||
int ntm; \
|
||||
uchar* missed; \
|
||||
int msstep, mcstep; \
|
||||
int mm, mn; \
|
||||
uchar* sidx; \
|
||||
int sistep; \
|
||||
uchar* cidx; \
|
||||
int cistep; \
|
||||
int k, l; \
|
||||
int m, n; \
|
||||
\
|
||||
data = classes = tmask = missed = sidx = cidx = NULL; \
|
||||
sstep = cstep = clstep = ncl = tmstep = ntm = msstep = mcstep = mm = mn = 0; \
|
||||
sistep = cistep = k = l = m = n = 0;
|
||||
|
||||
#define ICV_TRAIN_DATA_REQUIRED( param, flags ) \
|
||||
if( !ICV_IS_MAT_OF_TYPE( (param), CV_32FC1 ) ) \
|
||||
{ \
|
||||
CV_ERROR( CV_StsBadArg, "Invalid " #param " parameter" ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ICV_RAWDATA( *(param), (flags), data, sstep, cstep, m, n ); \
|
||||
k = n; \
|
||||
l = m; \
|
||||
}
|
||||
|
||||
#define ICV_TRAIN_CLASSES_REQUIRED( param ) \
|
||||
if( !ICV_IS_MAT_OF_TYPE( (param), CV_32FC1 ) ) \
|
||||
{ \
|
||||
CV_ERROR( CV_StsBadArg, "Invalid " #param " parameter" ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ICV_MAT2VEC( *(param), classes, clstep, ncl ); \
|
||||
if( m != ncl ) \
|
||||
{ \
|
||||
CV_ERROR( CV_StsBadArg, "Unmatched sizes" ); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ICV_ARG_NULL( param ) \
|
||||
if( (param) != NULL ) \
|
||||
{ \
|
||||
CV_ERROR( CV_StsBadArg, #param " parameter must be NULL" ); \
|
||||
}
|
||||
|
||||
#define ICV_MISSED_MEASUREMENTS_OPTIONAL( param, flags ) \
|
||||
if( param ) \
|
||||
{ \
|
||||
if( !ICV_IS_MAT_OF_TYPE( param, CV_8UC1 ) ) \
|
||||
{ \
|
||||
CV_ERROR( CV_StsBadArg, "Invalid " #param " parameter" ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ICV_RAWDATA( *(param), (flags), missed, msstep, mcstep, mm, mn ); \
|
||||
if( mm != m || mn != n ) \
|
||||
{ \
|
||||
CV_ERROR( CV_StsBadArg, "Unmatched sizes" ); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ICV_COMP_IDX_OPTIONAL( param ) \
|
||||
if( param ) \
|
||||
{ \
|
||||
if( !ICV_IS_MAT_OF_TYPE( param, CV_32SC1 ) ) \
|
||||
{ \
|
||||
CV_ERROR( CV_StsBadArg, "Invalid " #param " parameter" ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ICV_MAT2VEC( *(param), cidx, cistep, k ); \
|
||||
if( k > n ) \
|
||||
CV_ERROR( CV_StsBadArg, "Invalid " #param " parameter" ); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ICV_SAMPLE_IDX_OPTIONAL( param ) \
|
||||
if( param ) \
|
||||
{ \
|
||||
if( !ICV_IS_MAT_OF_TYPE( param, CV_32SC1 ) ) \
|
||||
{ \
|
||||
CV_ERROR( CV_StsBadArg, "Invalid " #param " parameter" ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ICV_MAT2VEC( *sampleIdx, sidx, sistep, l ); \
|
||||
if( l > m ) \
|
||||
CV_ERROR( CV_StsBadArg, "Invalid " #param " parameter" ); \
|
||||
} \
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
#define ICV_CONVERT_FLOAT_ARRAY_TO_MATRICE( array, matrice ) \
|
||||
{ \
|
||||
CvMat a, b; \
|
||||
int dims = (matrice)->cols; \
|
||||
int nsamples = (matrice)->rows; \
|
||||
int type = CV_MAT_TYPE((matrice)->type); \
|
||||
int i, offset = dims; \
|
||||
\
|
||||
CV_ASSERT( type == CV_32FC1 || type == CV_64FC1 ); \
|
||||
offset *= ((type == CV_32FC1) ? sizeof(float) : sizeof(double));\
|
||||
\
|
||||
b = cvMat( 1, dims, CV_32FC1 ); \
|
||||
cvGetRow( matrice, &a, 0 ); \
|
||||
for( i = 0; i < nsamples; i++, a.data.ptr += offset ) \
|
||||
{ \
|
||||
b.data.fl = (float*)array[i]; \
|
||||
CV_CALL( cvConvert( &b, &a ) ); \
|
||||
} \
|
||||
}
|
||||
|
||||
/****************************************************************************************\
|
||||
* Auxiliary functions declarations *
|
||||
\****************************************************************************************/
|
||||
|
||||
/* Generates a set of classes centers in quantity <num_of_clusters> that are generated as
|
||||
uniform random vectors in parallelepiped, where <data> is concentrated. Vectors in
|
||||
<data> should have horizontal orientation. If <centers> != NULL, the function doesn't
|
||||
allocate any memory and stores generated centers in <centers>, returns <centers>.
|
||||
If <centers> == NULL, the function allocates memory and creates the matrice. Centers
|
||||
are supposed to be oriented horizontally. */
|
||||
CvMat* icvGenerateRandomClusterCenters( int seed,
|
||||
const CvMat* data,
|
||||
int num_of_clusters,
|
||||
CvMat* centers CV_DEFAULT(0));
|
||||
|
||||
/* Fills the <labels> using <probs> by choosing the maximal probability. Outliers are
|
||||
fixed by <oulier_tresh> and have cluster label (-1). Function also controls that there
|
||||
weren't "empty" clusters by filling empty clusters with the maximal probability vector.
|
||||
If probs_sums != NULL, filles it with the sums of probabilities for each sample (it is
|
||||
useful for normalizing probabilities' matrice of FCM) */
|
||||
void icvFindClusterLabels( const CvMat* probs, float outlier_thresh, float r,
|
||||
const CvMat* labels );
|
||||
|
||||
typedef struct CvSparseVecElem32f
|
||||
{
|
||||
int idx;
|
||||
float val;
|
||||
}
|
||||
CvSparseVecElem32f;
|
||||
|
||||
/* Prepare training data and related parameters */
|
||||
#define CV_TRAIN_STATMODEL_DEFRAGMENT_TRAIN_DATA 1
|
||||
#define CV_TRAIN_STATMODEL_SAMPLES_AS_ROWS 2
|
||||
#define CV_TRAIN_STATMODEL_SAMPLES_AS_COLUMNS 4
|
||||
#define CV_TRAIN_STATMODEL_CATEGORICAL_RESPONSE 8
|
||||
#define CV_TRAIN_STATMODEL_ORDERED_RESPONSE 16
|
||||
#define CV_TRAIN_STATMODEL_RESPONSES_ON_OUTPUT 32
|
||||
#define CV_TRAIN_STATMODEL_ALWAYS_COPY_TRAIN_DATA 64
|
||||
#define CV_TRAIN_STATMODEL_SPARSE_AS_SPARSE 128
|
||||
|
||||
int
|
||||
cvPrepareTrainData( const char* /*funcname*/,
|
||||
const CvMat* train_data, int tflag,
|
||||
const CvMat* responses, int response_type,
|
||||
const CvMat* var_idx,
|
||||
const CvMat* sample_idx,
|
||||
bool always_copy_data,
|
||||
const float*** out_train_samples,
|
||||
int* _sample_count,
|
||||
int* _var_count,
|
||||
int* _var_all,
|
||||
CvMat** out_responses,
|
||||
CvMat** out_response_map,
|
||||
CvMat** out_var_idx,
|
||||
CvMat** out_sample_idx=0 );
|
||||
|
||||
void
|
||||
cvSortSamplesByClasses( const float** samples, const CvMat* classes,
|
||||
int* class_ranges, const uchar** mask CV_DEFAULT(0) );
|
||||
|
||||
void
|
||||
cvCombineResponseMaps (CvMat* _responses,
|
||||
const CvMat* old_response_map,
|
||||
CvMat* new_response_map,
|
||||
CvMat** out_response_map);
|
||||
|
||||
void
|
||||
cvPreparePredictData( const CvArr* sample, int dims_all, const CvMat* comp_idx,
|
||||
int class_count, const CvMat* prob, float** row_sample,
|
||||
int as_sparse CV_DEFAULT(0) );
|
||||
|
||||
/* copies clustering [or batch "predict"] results
|
||||
(labels and/or centers and/or probs) back to the output arrays */
|
||||
void
|
||||
cvWritebackLabels( const CvMat* labels, CvMat* dst_labels,
|
||||
const CvMat* centers, CvMat* dst_centers,
|
||||
const CvMat* probs, CvMat* dst_probs,
|
||||
const CvMat* sample_idx, int samples_all,
|
||||
const CvMat* comp_idx, int dims_all );
|
||||
#define cvWritebackResponses cvWritebackLabels
|
||||
|
||||
#define XML_FIELD_NAME "_name"
|
||||
CvFileNode* icvFileNodeGetChild(CvFileNode* father, const char* name);
|
||||
CvFileNode* icvFileNodeGetChildArrayElem(CvFileNode* father, const char* name,int index);
|
||||
CvFileNode* icvFileNodeGetNext(CvFileNode* n, const char* name);
|
||||
|
||||
|
||||
void cvCheckTrainData( const CvMat* train_data, int tflag,
|
||||
const CvMat* missing_mask,
|
||||
int* var_all, int* sample_all );
|
||||
|
||||
CvMat* cvPreprocessIndexArray( const CvMat* idx_arr, int data_arr_size, bool check_for_duplicates=false );
|
||||
|
||||
CvMat* cvPreprocessVarType( const CvMat* type_mask, const CvMat* var_idx,
|
||||
int var_all, int* response_type );
|
||||
|
||||
CvMat* cvPreprocessOrderedResponses( const CvMat* responses,
|
||||
const CvMat* sample_idx, int sample_all );
|
||||
|
||||
CvMat* cvPreprocessCategoricalResponses( const CvMat* responses,
|
||||
const CvMat* sample_idx, int sample_all,
|
||||
CvMat** out_response_map, CvMat** class_counts=0 );
|
||||
|
||||
const float** cvGetTrainSamples( const CvMat* train_data, int tflag,
|
||||
const CvMat* var_idx, const CvMat* sample_idx,
|
||||
int* _var_count, int* _sample_count,
|
||||
bool always_copy_data=false );
|
||||
|
||||
namespace cv
|
||||
{
|
||||
struct DTreeBestSplitFinder
|
||||
{
|
||||
DTreeBestSplitFinder(){ splitSize = 0, tree = 0; node = 0; }
|
||||
DTreeBestSplitFinder( CvDTree* _tree, CvDTreeNode* _node);
|
||||
DTreeBestSplitFinder( const DTreeBestSplitFinder& finder, Split );
|
||||
virtual ~DTreeBestSplitFinder() {}
|
||||
virtual void operator()(const BlockedRange& range);
|
||||
void join( DTreeBestSplitFinder& rhs );
|
||||
Ptr<CvDTreeSplit> bestSplit;
|
||||
Ptr<CvDTreeSplit> split;
|
||||
int splitSize;
|
||||
CvDTree* tree;
|
||||
CvDTreeNode* node;
|
||||
};
|
||||
|
||||
struct ForestTreeBestSplitFinder : DTreeBestSplitFinder
|
||||
{
|
||||
ForestTreeBestSplitFinder() : DTreeBestSplitFinder() {}
|
||||
ForestTreeBestSplitFinder( CvForestTree* _tree, CvDTreeNode* _node );
|
||||
ForestTreeBestSplitFinder( const ForestTreeBestSplitFinder& finder, Split );
|
||||
virtual void operator()(const BlockedRange& range);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* __ML_H__ */
|
4151
apps/traincascade/old_ml_tree.cpp
Normal file
4151
apps/traincascade/old_ml_tree.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,4 @@
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
#include "cv.h"
|
||||
#include "cascadeclassifier.h"
|
||||
|
||||
using namespace std;
|
||||
@ -13,6 +11,7 @@ int main( int argc, char* argv[] )
|
||||
int numPos = 2000;
|
||||
int numNeg = 1000;
|
||||
int numStages = 20;
|
||||
int numThreads = getNumThreads();
|
||||
int precalcValBufSize = 256,
|
||||
precalcIdxBufSize = 256;
|
||||
bool baseFormatSave = false;
|
||||
@ -36,6 +35,7 @@ int main( int argc, char* argv[] )
|
||||
cout << " [-precalcValBufSize <precalculated_vals_buffer_size_in_Mb = " << precalcValBufSize << ">]" << endl;
|
||||
cout << " [-precalcIdxBufSize <precalculated_idxs_buffer_size_in_Mb = " << precalcIdxBufSize << ">]" << endl;
|
||||
cout << " [-baseFormatSave]" << endl;
|
||||
cout << " [-numThreads <max_number_of_threads = " << numThreads << ">]" << endl;
|
||||
cascadeParams.printDefaults();
|
||||
stageParams.printDefaults();
|
||||
for( int fi = 0; fi < fc; fi++ )
|
||||
@ -82,6 +82,10 @@ int main( int argc, char* argv[] )
|
||||
{
|
||||
baseFormatSave = true;
|
||||
}
|
||||
else if( !strcmp( argv[i], "-numThreads" ) )
|
||||
{
|
||||
numThreads = atoi(argv[++i]);
|
||||
}
|
||||
else if ( cascadeParams.scanAttr( argv[i], argv[i+1] ) ) { i++; }
|
||||
else if ( stageParams.scanAttr( argv[i], argv[i+1] ) ) { i++; }
|
||||
else if ( !set )
|
||||
@ -98,6 +102,7 @@ int main( int argc, char* argv[] )
|
||||
}
|
||||
}
|
||||
|
||||
setNumThreads( numThreads );
|
||||
classifier.train( cascadeDirName,
|
||||
vecName,
|
||||
bgName,
|
||||
|
@ -2,9 +2,6 @@
|
||||
#define _OPENCV_FEATURES_H_
|
||||
|
||||
#include "imagestorage.h"
|
||||
#include "cxcore.h"
|
||||
#include "cv.h"
|
||||
#include "ml.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define FEATURES "features"
|
||||
|
@ -31,10 +31,8 @@
|
||||
# The following variables affect the behavior of the macros in the
|
||||
# script (in alphebetical order). Note that any of these flags can be
|
||||
# changed multiple times in the same directory before calling
|
||||
# CUDA_ADD_EXECUTABLE, CUDA_ADD_LIBRARY, CUDA_COMPILE, CUDA_COMPILE_PTX
|
||||
# or CUDA_WRAP_SRCS.
|
||||
#
|
||||
# ::
|
||||
# CUDA_ADD_EXECUTABLE, CUDA_ADD_LIBRARY, CUDA_COMPILE, CUDA_COMPILE_PTX,
|
||||
# CUDA_COMPILE_FATBIN, CUDA_COMPILE_CUBIN or CUDA_WRAP_SRCS::
|
||||
#
|
||||
# CUDA_64_BIT_DEVICE_CODE (Default matches host bit size)
|
||||
# -- Set to ON to compile for 64 bit device code, OFF for 32 bit device code.
|
||||
@ -43,19 +41,11 @@
|
||||
# nvcc in the generated source. If you compile to PTX and then load the
|
||||
# file yourself, you can mix bit sizes between device and host.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE (Default ON)
|
||||
# -- Set to ON if you want the custom build rule to be attached to the source
|
||||
# file in Visual Studio. Turn OFF if you add the same cuda file to multiple
|
||||
# targets.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# This allows the user to build the target from the CUDA file; however, bad
|
||||
# things can happen if the CUDA source file is added to multiple targets.
|
||||
# When performing parallel builds it is possible for the custom build
|
||||
@ -68,44 +58,24 @@
|
||||
# this script could detect the reuse of source files across multiple targets
|
||||
# and turn the option off for the user, but no good solution could be found.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_BUILD_CUBIN (Default OFF)
|
||||
# -- Set to ON to enable and extra compilation pass with the -cubin option in
|
||||
# Device mode. The output is parsed and register, shared memory usage is
|
||||
# printed during build.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_BUILD_EMULATION (Default OFF for device mode)
|
||||
# -- Set to ON for Emulation mode. -D_DEVICEEMU is defined for CUDA C files
|
||||
# when CUDA_BUILD_EMULATION is TRUE.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_GENERATED_OUTPUT_DIR (Default CMAKE_CURRENT_BINARY_DIR)
|
||||
# -- Set to the path you wish to have the generated files placed. If it is
|
||||
# blank output files will be placed in CMAKE_CURRENT_BINARY_DIR.
|
||||
# Intermediate files will always be placed in
|
||||
# CMAKE_CURRENT_BINARY_DIR/CMakeFiles.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_HOST_COMPILATION_CPP (Default ON)
|
||||
# -- Set to OFF for C compilation of host code.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_HOST_COMPILER (Default CMAKE_C_COMPILER, $(VCInstallDir)/bin for VS)
|
||||
# -- Set the host compiler to be used by nvcc. Ignored if -ccbin or
|
||||
# --compiler-bindir is already present in the CUDA_NVCC_FLAGS or
|
||||
@ -113,19 +83,11 @@
|
||||
# $(VCInstallDir)/bin is a special value that expands out to the path when
|
||||
# the command is run from withing VS.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_NVCC_FLAGS
|
||||
# CUDA_NVCC_FLAGS_<CONFIG>
|
||||
# -- Additional NVCC command line arguments. NOTE: multiple arguments must be
|
||||
# semi-colon delimited (e.g. --compiler-options;-Wall)
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_PROPAGATE_HOST_FLAGS (Default ON)
|
||||
# -- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration
|
||||
# dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the
|
||||
@ -137,10 +99,6 @@
|
||||
# CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS. Flags used for
|
||||
# shared library compilation are not affected by this flag.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_SEPARABLE_COMPILATION (Default OFF)
|
||||
# -- If set this will enable separable compilation for all CUDA runtime object
|
||||
# files. If used outside of CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY
|
||||
@ -148,38 +106,22 @@
|
||||
# CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME and
|
||||
# CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS should be called.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_VERBOSE_BUILD (Default OFF)
|
||||
# -- Set to ON to see all the commands used when building the CUDA file. When
|
||||
# using a Makefile generator the value defaults to VERBOSE (run make
|
||||
# VERBOSE=1 to see output), although setting CUDA_VERBOSE_BUILD to ON will
|
||||
# always print the output.
|
||||
#
|
||||
#
|
||||
#
|
||||
# The script creates the following macros (in alphebetical order):
|
||||
#
|
||||
# ::
|
||||
# The script creates the following macros (in alphebetical order)::
|
||||
#
|
||||
# CUDA_ADD_CUFFT_TO_TARGET( cuda_target )
|
||||
# -- Adds the cufft library to the target (can be any target). Handles whether
|
||||
# you are in emulation mode or not.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_ADD_CUBLAS_TO_TARGET( cuda_target )
|
||||
# -- Adds the cublas library to the target (can be any target). Handles
|
||||
# whether you are in emulation mode or not.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ...
|
||||
# [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] [OPTIONS ...] )
|
||||
# -- Creates an executable "cuda_target" which is made up of the files
|
||||
@ -193,42 +135,28 @@
|
||||
# nvcc. Such flags should be modified before calling CUDA_ADD_EXECUTABLE,
|
||||
# CUDA_ADD_LIBRARY or CUDA_WRAP_SRCS.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_ADD_LIBRARY( cuda_target file0 file1 ...
|
||||
# [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] [OPTIONS ...] )
|
||||
# -- Same as CUDA_ADD_EXECUTABLE except that a library is created.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_BUILD_CLEAN_TARGET()
|
||||
# -- Creates a convience target that deletes all the dependency files
|
||||
# generated. You should make clean after running this target to ensure the
|
||||
# dependency files get regenerated.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_COMPILE( generated_files file0 file1 ... [STATIC | SHARED | MODULE]
|
||||
# [OPTIONS ...] )
|
||||
# -- Returns a list of generated files from the input source files to be used
|
||||
# with ADD_LIBRARY or ADD_EXECUTABLE.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_COMPILE_PTX( generated_files file0 file1 ... [OPTIONS ...] )
|
||||
# -- Returns a list of PTX files generated from the input source files.
|
||||
#
|
||||
# CUDA_COMPILE_FATBIN( generated_files file0 file1 ... [OPTIONS ...] )
|
||||
# -- Returns a list of FATBIN files generated from the input source files.
|
||||
#
|
||||
#
|
||||
# ::
|
||||
# CUDA_COMPILE_CUBIN( generated_files file0 file1 ... [OPTIONS ...] )
|
||||
# -- Returns a list of CUBIN files generated from the input source files.
|
||||
#
|
||||
# CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME( output_file_var
|
||||
# cuda_target
|
||||
@ -242,10 +170,6 @@
|
||||
# automatically for CUDA_ADD_LIBRARY and CUDA_ADD_EXECUTABLE. Note that
|
||||
# this is a function and not a macro.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_INCLUDE_DIRECTORIES( path0 path1 ... )
|
||||
# -- Sets the directories that should be passed to nvcc
|
||||
# (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu
|
||||
@ -253,17 +177,9 @@
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS( output_file_var cuda_target
|
||||
# nvcc_flags object_files)
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# -- Generates the link object required by separable compilation from the given
|
||||
# object files. This is called automatically for CUDA_ADD_EXECUTABLE and
|
||||
# CUDA_ADD_LIBRARY, but can be called manually when using CUDA_WRAP_SRCS
|
||||
@ -273,91 +189,51 @@
|
||||
# specified by CUDA_64_BIT_DEVICE_CODE. Note that this is a function
|
||||
# instead of a macro.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ...
|
||||
# [STATIC | SHARED | MODULE] [OPTIONS ...] )
|
||||
# -- This is where all the magic happens. CUDA_ADD_EXECUTABLE,
|
||||
# CUDA_ADD_LIBRARY, CUDA_COMPILE, and CUDA_COMPILE_PTX all call this
|
||||
# function under the hood.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# Given the list of files (file0 file1 ... fileN) this macro generates
|
||||
# custom commands that generate either PTX or linkable objects (use "PTX" or
|
||||
# "OBJ" for the format argument to switch). Files that don't end with .cu
|
||||
# or have the HEADER_FILE_ONLY property are ignored.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# The arguments passed in after OPTIONS are extra command line options to
|
||||
# give to nvcc. You can also specify per configuration options by
|
||||
# specifying the name of the configuration followed by the options. General
|
||||
# options must preceed configuration specific options. Not all
|
||||
# configurations need to be specified, only the ones provided will be used.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# OPTIONS -DFLAG=2 "-DFLAG_OTHER=space in flag"
|
||||
# DEBUG -g
|
||||
# RELEASE --use_fast_math
|
||||
# RELWITHDEBINFO --use_fast_math;-g
|
||||
# MINSIZEREL --use_fast_math
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# For certain configurations (namely VS generating object files with
|
||||
# CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE set to ON), no generated file will
|
||||
# be produced for the given cuda file. This is because when you add the
|
||||
# cuda file to Visual Studio it knows that this file produces an object file
|
||||
# and will link in the resulting object file automatically.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# This script will also generate a separate cmake script that is used at
|
||||
# build time to invoke nvcc. This is for several reasons.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# 1. nvcc can return negative numbers as return values which confuses
|
||||
# Visual Studio into thinking that the command succeeded. The script now
|
||||
# checks the error codes and produces errors when there was a problem.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# 2. nvcc has been known to not delete incomplete results when it
|
||||
# encounters problems. This confuses build systems into thinking the
|
||||
# target was generated when in fact an unusable file exists. The script
|
||||
# now deletes the output files if there was an error.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# 3. By putting all the options that affect the build into a file and then
|
||||
# make the build rule dependent on the file, the output files will be
|
||||
# regenerated when the options change.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# This script also looks at optional arguments STATIC, SHARED, or MODULE to
|
||||
# determine when to target the object compilation for a shared library.
|
||||
# BUILD_SHARED_LIBS is ignored in CUDA_WRAP_SRCS, but it is respected in
|
||||
@ -366,27 +242,17 @@
|
||||
# <target_name>_EXPORTS is defined when a shared library compilation is
|
||||
# detected.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# Flags passed into add_definitions with -D or /D are passed along to nvcc.
|
||||
#
|
||||
#
|
||||
#
|
||||
# The script defines the following variables:
|
||||
#
|
||||
# ::
|
||||
# The script defines the following variables::
|
||||
#
|
||||
# CUDA_VERSION_MAJOR -- The major version of cuda as reported by nvcc.
|
||||
# CUDA_VERSION_MINOR -- The minor version.
|
||||
# CUDA_VERSION
|
||||
# CUDA_VERSION_STRING -- CUDA_VERSION_MAJOR.CUDA_VERSION_MINOR
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CUDA_TOOLKIT_ROOT_DIR -- Path to the CUDA Toolkit (defined if not set).
|
||||
# CUDA_SDK_ROOT_DIR -- Path to the CUDA SDK. Use this to find files in the
|
||||
# SDK. This script will not directly support finding
|
||||
@ -412,13 +278,13 @@
|
||||
# Only available for CUDA version 3.2+.
|
||||
# CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library.
|
||||
# Only available for CUDA version 3.2+.
|
||||
# CUDA_npp_LIBRARY -- NVIDIA Performance Primitives library.
|
||||
# CUDA_npp_LIBRARY -- NVIDIA Performance Primitives lib.
|
||||
# Only available for CUDA version 4.0+.
|
||||
# CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives library (core).
|
||||
# CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives lib (core).
|
||||
# Only available for CUDA version 5.5+.
|
||||
# CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives library (image processing).
|
||||
# CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
|
||||
# Only available for CUDA version 5.5+.
|
||||
# CUDA_npps_LIBRARY -- NVIDIA Performance Primitives library (signal processing).
|
||||
# CUDA_npps_LIBRARY -- NVIDIA Performance Primitives lib (signal processing).
|
||||
# Only available for CUDA version 5.5+.
|
||||
# CUDA_nvcuvenc_LIBRARY -- CUDA Video Encoder library.
|
||||
# Only available for CUDA version 3.2+.
|
||||
@ -427,32 +293,15 @@
|
||||
# Only available for CUDA version 3.2+.
|
||||
# Windows only.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
|
||||
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
|
||||
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# Copyright (c) 2007-2009
|
||||
# Scientific Computing and Imaging Institute, University of Utah
|
||||
#
|
||||
#
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# This code is licensed under the MIT License. See the FindCUDA.cmake script
|
||||
# for the text of the license.
|
||||
|
||||
@ -481,11 +330,6 @@
|
||||
|
||||
# FindCUDA.cmake
|
||||
|
||||
# We need to have at least this version to support the VERSION_LESS argument to 'if' (2.6.2) and unset (2.6.3)
|
||||
cmake_policy(PUSH)
|
||||
cmake_minimum_required(VERSION 2.6.3)
|
||||
cmake_policy(POP)
|
||||
|
||||
# This macro helps us find the location of helper files we will need the full path to
|
||||
macro(CUDA_FIND_HELPER_FILE _name _extension)
|
||||
set(_full_name "${_name}.${_extension}")
|
||||
@ -608,7 +452,17 @@ set(CUDA_NVCC_FLAGS "" CACHE STRING "Semi-colon delimit multiple arguments.")
|
||||
if(CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
set(CUDA_HOST_COMPILER "$(VCInstallDir)bin" CACHE FILEPATH "Host side compiler used by NVCC")
|
||||
else()
|
||||
set(CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}" CACHE FILEPATH "Host side compiler used by NVCC")
|
||||
# Using cc which is symlink to clang may let NVCC think it is GCC and issue
|
||||
# unhandled -dumpspecs option to clang. Also in case neither
|
||||
# CMAKE_C_COMPILER is defined (project does not use C language) nor
|
||||
# CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let
|
||||
# nvcc use its own default C compiler.
|
||||
if(DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER)
|
||||
get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
|
||||
else()
|
||||
set(c_compiler_realpath "")
|
||||
endif()
|
||||
set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC")
|
||||
endif()
|
||||
|
||||
# Propagate the host flags to the host compiler via -Xcompiler
|
||||
@ -675,14 +529,16 @@ endmacro()
|
||||
|
||||
# Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed,
|
||||
# if they have then clear the cache variables, so that will be detected again.
|
||||
if(NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}")
|
||||
if(DEFINED CUDA_TOOLKIT_ROOT_DIR_INTERNAL AND (NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}"))
|
||||
unset(CUDA_TARGET_TRIPLET CACHE)
|
||||
unset(CUDA_TOOLKIT_TARGET_DIR CACHE)
|
||||
unset(CUDA_NVCC_EXECUTABLE CACHE)
|
||||
unset(CUDA_VERSION CACHE)
|
||||
cuda_unset_include_and_libraries()
|
||||
endif()
|
||||
|
||||
if(NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}")
|
||||
if(DEFINED CUDA_TARGET_TRIPLET_INTERNAL AND (NOT "${CUDA_TARGET_TRIPLET}" STREQUAL "${CUDA_TARGET_TRIPLET_INTERNAL}") OR
|
||||
(DEFINED CUDA_TOOLKIT_TARGET_DIR AND DEFINED CUDA_TOOLKIT_TARGET_DIR_INTERNAL AND NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}"))
|
||||
cuda_unset_include_and_libraries()
|
||||
endif()
|
||||
|
||||
@ -758,23 +614,46 @@ endif()
|
||||
# Always set this convenience variable
|
||||
set(CUDA_VERSION_STRING "${CUDA_VERSION}")
|
||||
|
||||
# Support for arm cross compilation with CUDA 5.5
|
||||
if(CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-gnueabihf")
|
||||
set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-gnueabihf" CACHE PATH "Toolkit target location.")
|
||||
else()
|
||||
set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}" CACHE PATH "Toolkit target location.")
|
||||
endif()
|
||||
mark_as_advanced(CUDA_TOOLKIT_TARGET_DIR)
|
||||
|
||||
# Target CPU architecture
|
||||
if(CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
|
||||
if(DEFINED CUDA_TARGET_CPU_ARCH)
|
||||
set(_cuda_target_cpu_arch_initial "${CUDA_TARGET_CPU_ARCH}")
|
||||
elseif(CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|ARM)")
|
||||
set(_cuda_target_cpu_arch_initial "ARM")
|
||||
else()
|
||||
set(_cuda_target_cpu_arch_initial "")
|
||||
endif()
|
||||
set(CUDA_TARGET_CPU_ARCH ${_cuda_target_cpu_arch_initial} CACHE STRING "Specify the name of the class of CPU architecture for which the input files must be compiled.")
|
||||
set(CUDA_TARGET_CPU_ARCH "${_cuda_target_cpu_arch_initial}" CACHE STRING "Specify the name of the class of CPU architecture for which the input files must be compiled.")
|
||||
mark_as_advanced(CUDA_TARGET_CPU_ARCH)
|
||||
|
||||
# Target OS variant
|
||||
if(DEFINED CUDA_TARGET_OS_VARIANT)
|
||||
set(_cuda_target_os_variant_initial "${CUDA_TARGET_OS_VARIANT}")
|
||||
else()
|
||||
set(_cuda_target_os_variant_initial "")
|
||||
endif()
|
||||
set(CUDA_TARGET_OS_VARIANT "${_cuda_target_os_variant_initial}" CACHE STRING "Specify the name of the class of OS for which the input files must be compiled.")
|
||||
mark_as_advanced(CUDA_TARGET_OS_VARIANT)
|
||||
|
||||
# Target triplet
|
||||
if(DEFINED CUDA_TARGET_TRIPLET)
|
||||
set(_cuda_target_triplet_initial "${CUDA_TARGET_TRIPLET}")
|
||||
elseif(CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND "${CUDA_TARGET_CPU_ARCH}" STREQUAL "ARM")
|
||||
if("${CUDA_TARGET_OS_VARIANT}" STREQUAL "Android" AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-androideabi")
|
||||
set(_cuda_target_triplet_initial "armv7-linux-androideabi")
|
||||
elseif(EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-gnueabihf")
|
||||
set(_cuda_target_triplet_initial "armv7-linux-gnueabihf")
|
||||
endif()
|
||||
endif()
|
||||
set(CUDA_TARGET_TRIPLET "${_cuda_target_triplet_initial}" CACHE STRING "Specify the target triplet for which the input files must be compiled.")
|
||||
file(GLOB __cuda_available_target_tiplets RELATIVE "${CUDA_TOOLKIT_ROOT_DIR}/targets" "${CUDA_TOOLKIT_ROOT_DIR}/targets/*" )
|
||||
set_property(CACHE CUDA_TARGET_TRIPLET PROPERTY STRINGS ${__cuda_available_target_tiplets})
|
||||
mark_as_advanced(CUDA_TARGET_TRIPLET)
|
||||
|
||||
# Target directory
|
||||
if(NOT DEFINED CUDA_TOOLKIT_TARGET_DIR AND CUDA_TARGET_TRIPLET AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/${CUDA_TARGET_TRIPLET}")
|
||||
set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}/targets/${CUDA_TARGET_TRIPLET}")
|
||||
endif()
|
||||
|
||||
# CUDA_TOOLKIT_INCLUDE
|
||||
find_path(CUDA_TOOLKIT_INCLUDE
|
||||
device_functions.h # Header included in toolkit
|
||||
@ -798,10 +677,16 @@ macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext )
|
||||
# and old paths.
|
||||
set(_cuda_64bit_lib_dir "${_path_ext}lib/x64" "${_path_ext}lib64" "${_path_ext}libx64" )
|
||||
endif()
|
||||
if(CUDA_VERSION VERSION_GREATER "6.0")
|
||||
set(_cuda_static_lib_names "")
|
||||
foreach(name ${_names})
|
||||
list(APPEND _cuda_static_lib_names "${name}_static")
|
||||
endforeach()
|
||||
endif()
|
||||
# CUDA 3.2+ on Windows moved the library directories, so we need to new
|
||||
# (lib/Win32) and the old path (lib).
|
||||
find_library(${_var}
|
||||
NAMES ${_names}
|
||||
NAMES ${_names} ${_cuda_static_lib_names}
|
||||
PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}"
|
||||
ENV CUDA_PATH
|
||||
ENV CUDA_LIB_PATH
|
||||
@ -811,7 +696,7 @@ macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext )
|
||||
)
|
||||
# Search default search paths, after we search our own set of paths.
|
||||
find_library(${_var}
|
||||
NAMES ${_names}
|
||||
NAMES ${_names} ${_cuda_static_lib_names}
|
||||
PATHS "/usr/lib/nvidia-current"
|
||||
DOC ${_doc}
|
||||
)
|
||||
@ -849,18 +734,6 @@ if(CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY)
|
||||
else()
|
||||
set(CUDA_LIBRARIES ${CUDA_CUDART_LIBRARY})
|
||||
endif()
|
||||
if(APPLE)
|
||||
# We need to add the path to cudart to the linker using rpath, since the
|
||||
# library name for the cuda libraries is prepended with @rpath.
|
||||
if(CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY)
|
||||
get_filename_component(_cuda_path_to_cudart "${CUDA_CUDARTEMU_LIBRARY}" PATH)
|
||||
else()
|
||||
get_filename_component(_cuda_path_to_cudart "${CUDA_CUDART_LIBRARY}" PATH)
|
||||
endif()
|
||||
if(_cuda_path_to_cudart)
|
||||
list(APPEND CUDA_LIBRARIES -Wl,-rpath "-Wl,${_cuda_path_to_cudart}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# 1.1 toolkit on linux doesn't appear to have a separate library on
|
||||
# some platforms.
|
||||
@ -993,6 +866,8 @@ set(CUDA_FOUND TRUE)
|
||||
|
||||
set(CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}" CACHE INTERNAL
|
||||
"This is the value of the last time CUDA_TOOLKIT_ROOT_DIR was set successfully." FORCE)
|
||||
set(CUDA_TARGET_TRIPLET_INTERNAL "${CUDA_TARGET_TRIPLET}" CACHE INTERNAL
|
||||
"This is the value of the last time CUDA_TARGET_TRIPLET was set successfully." FORCE)
|
||||
set(CUDA_TOOLKIT_TARGET_DIR_INTERNAL "${CUDA_TOOLKIT_TARGET_DIR}" CACHE INTERNAL
|
||||
"This is the value of the last time CUDA_TOOLKIT_TARGET_DIR was set successfully." FORCE)
|
||||
set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL
|
||||
@ -1040,15 +915,15 @@ macro(CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options)
|
||||
set( ${_options} )
|
||||
set( _found_options FALSE )
|
||||
foreach(arg ${ARGN})
|
||||
if(arg STREQUAL "OPTIONS")
|
||||
if("x${arg}" STREQUAL "xOPTIONS")
|
||||
set( _found_options TRUE )
|
||||
elseif(
|
||||
arg STREQUAL "WIN32" OR
|
||||
arg STREQUAL "MACOSX_BUNDLE" OR
|
||||
arg STREQUAL "EXCLUDE_FROM_ALL" OR
|
||||
arg STREQUAL "STATIC" OR
|
||||
arg STREQUAL "SHARED" OR
|
||||
arg STREQUAL "MODULE"
|
||||
"x${arg}" STREQUAL "xWIN32" OR
|
||||
"x${arg}" STREQUAL "xMACOSX_BUNDLE" OR
|
||||
"x${arg}" STREQUAL "xEXCLUDE_FROM_ALL" OR
|
||||
"x${arg}" STREQUAL "xSTATIC" OR
|
||||
"x${arg}" STREQUAL "xSHARED" OR
|
||||
"x${arg}" STREQUAL "xMODULE"
|
||||
)
|
||||
list(APPEND ${_cmake_options} ${arg})
|
||||
else()
|
||||
@ -1144,7 +1019,7 @@ function(CUDA_COMPUTE_BUILD_PATH path build_path)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# This recipie is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the
|
||||
# This recipe is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the
|
||||
# CMake source.
|
||||
|
||||
# Remove leading /
|
||||
@ -1173,7 +1048,7 @@ endfunction()
|
||||
# a .cpp or .ptx file.
|
||||
# INPUT:
|
||||
# cuda_target - Target name
|
||||
# format - PTX or OBJ
|
||||
# format - PTX, CUBIN, FATBIN or OBJ
|
||||
# FILE1 .. FILEN - The remaining arguments are the sources to be wrapped.
|
||||
# OPTIONS - Extra options to NVCC
|
||||
# OUTPUT:
|
||||
@ -1223,6 +1098,10 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||
set(nvcc_flags ${nvcc_flags} "--target-cpu-architecture=${CUDA_TARGET_CPU_ARCH}")
|
||||
endif()
|
||||
|
||||
if(CUDA_TARGET_OS_VARIANT AND CUDA_VERSION VERSION_LESS "7.0")
|
||||
set(nvcc_flags ${nvcc_flags} "-target-os-variant=${CUDA_TARGET_OS_VARIANT}")
|
||||
endif()
|
||||
|
||||
# This needs to be passed in at this stage, because VS needs to fill out the
|
||||
# value of VCInstallDir from within VS. Note that CCBIN is only used if
|
||||
# -ccbin or --compiler-bindir isn't used and CUDA_HOST_COMPILER matches
|
||||
@ -1351,7 +1230,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||
foreach(file ${ARGN})
|
||||
# Ignore any file marked as a HEADER_FILE_ONLY
|
||||
get_source_file_property(_is_header ${file} HEADER_FILE_ONLY)
|
||||
if(${file} MATCHES ".*\\.cu$" AND NOT _is_header)
|
||||
if(${file} MATCHES "\\.cu$" AND NOT _is_header)
|
||||
|
||||
# Allow per source file overrides of the format.
|
||||
get_source_file_property(_cuda_source_format ${file} CUDA_SOURCE_PROPERTY_FORMAT)
|
||||
@ -1359,16 +1238,22 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||
set(_cuda_source_format ${format})
|
||||
endif()
|
||||
|
||||
if( ${_cuda_source_format} MATCHES "PTX" )
|
||||
set( compile_to_ptx ON )
|
||||
elseif( ${_cuda_source_format} MATCHES "OBJ")
|
||||
set( compile_to_ptx OFF )
|
||||
if( ${_cuda_source_format} MATCHES "OBJ")
|
||||
set( cuda_compile_to_external_module OFF )
|
||||
else()
|
||||
message( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS for file '${file}': '${_cuda_source_format}'. Use OBJ or PTX.")
|
||||
set( cuda_compile_to_external_module ON )
|
||||
if( ${_cuda_source_format} MATCHES "PTX" )
|
||||
set( cuda_compile_to_external_module_type "ptx" )
|
||||
elseif( ${_cuda_source_format} MATCHES "CUBIN")
|
||||
set( cuda_compile_to_external_module_type "cubin" )
|
||||
elseif( ${_cuda_source_format} MATCHES "FATBIN")
|
||||
set( cuda_compile_to_external_module_type "fatbin" )
|
||||
else()
|
||||
message( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS for file '${file}': '${_cuda_source_format}'. Use OBJ, PTX, CUBIN or FATBIN.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
if(compile_to_ptx)
|
||||
if(cuda_compile_to_external_module)
|
||||
# Don't use any of the host compilation flags for PTX targets.
|
||||
set(CUDA_HOST_FLAGS)
|
||||
set(CUDA_NVCC_FLAGS_CONFIG)
|
||||
@ -1383,7 +1268,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||
if(CUDA_GENERATED_OUTPUT_DIR)
|
||||
set(cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}")
|
||||
else()
|
||||
if ( compile_to_ptx )
|
||||
if ( cuda_compile_to_external_module )
|
||||
set(cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
else()
|
||||
set(cuda_compile_output_dir "${cuda_compile_intermediate_directory}")
|
||||
@ -1393,10 +1278,10 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||
# Add a custom target to generate a c or ptx file. ######################
|
||||
|
||||
get_filename_component( basename ${file} NAME )
|
||||
if( compile_to_ptx )
|
||||
if( cuda_compile_to_external_module )
|
||||
set(generated_file_path "${cuda_compile_output_dir}")
|
||||
set(generated_file_basename "${cuda_target}_generated_${basename}.ptx")
|
||||
set(format_flag "-ptx")
|
||||
set(generated_file_basename "${cuda_target}_generated_${basename}.${cuda_compile_to_external_module_type}")
|
||||
set(format_flag "-${cuda_compile_to_external_module_type}")
|
||||
file(MAKE_DIRECTORY "${cuda_compile_output_dir}")
|
||||
else()
|
||||
set(generated_file_path "${cuda_compile_output_dir}/${CMAKE_CFG_INTDIR}")
|
||||
@ -1419,7 +1304,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||
set(custom_target_script "${cuda_compile_intermediate_directory}/${generated_file_basename}.cmake")
|
||||
|
||||
# Setup properties for obj files:
|
||||
if( NOT compile_to_ptx )
|
||||
if( NOT cuda_compile_to_external_module )
|
||||
set_source_files_properties("${generated_file}"
|
||||
PROPERTIES
|
||||
EXTERNAL_OBJECT true # This is an object file not to be compiled, but only be linked.
|
||||
@ -1434,7 +1319,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||
set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
|
||||
endif()
|
||||
|
||||
if( NOT compile_to_ptx AND CUDA_SEPARABLE_COMPILATION)
|
||||
if( NOT cuda_compile_to_external_module AND CUDA_SEPARABLE_COMPILATION)
|
||||
list(APPEND ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS "${generated_file}")
|
||||
endif()
|
||||
|
||||
@ -1451,7 +1336,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||
# Build the NVCC made dependency file ###################################
|
||||
set(build_cubin OFF)
|
||||
if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN )
|
||||
if ( NOT compile_to_ptx )
|
||||
if ( NOT cuda_compile_to_external_module )
|
||||
set ( build_cubin ON )
|
||||
endif()
|
||||
endif()
|
||||
@ -1478,8 +1363,8 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||
|
||||
# Create up the comment string
|
||||
file(RELATIVE_PATH generated_file_relative_path "${CMAKE_BINARY_DIR}" "${generated_file}")
|
||||
if(compile_to_ptx)
|
||||
set(cuda_build_comment_string "Building NVCC ptx file ${generated_file_relative_path}")
|
||||
if(cuda_compile_to_external_module)
|
||||
set(cuda_build_comment_string "Building NVCC ${cuda_compile_to_external_module_type} file ${generated_file_relative_path}")
|
||||
else()
|
||||
set(cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}")
|
||||
endif()
|
||||
@ -1572,18 +1457,27 @@ function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options
|
||||
# If -ccbin, --compiler-bindir has been specified, don't do anything. Otherwise add it here.
|
||||
list( FIND nvcc_flags "-ccbin" ccbin_found0 )
|
||||
list( FIND nvcc_flags "--compiler-bindir" ccbin_found1 )
|
||||
if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 )
|
||||
if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER )
|
||||
list(APPEND nvcc_flags -ccbin "\"${CUDA_HOST_COMPILER}\"")
|
||||
endif()
|
||||
# Create a list of flags specified by CUDA_NVCC_FLAGS_${CONFIG}
|
||||
set(config_specific_flags)
|
||||
set(flags)
|
||||
foreach(config ${CUDA_configuration_types})
|
||||
string(TOUPPER ${config} config_upper)
|
||||
# Add config specific flags
|
||||
foreach(f ${CUDA_NVCC_FLAGS_${config_upper}})
|
||||
list(APPEND config_specific_flags $<$<CONFIG:${config}>:${f}>)
|
||||
endforeach()
|
||||
set(important_host_flags)
|
||||
_cuda_get_important_host_flags(important_host_flags ${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}})
|
||||
foreach(f ${important_host_flags})
|
||||
list(APPEND flags $<$<CONFIG:${config}>:-Xcompiler> $<$<CONFIG:${config}>:${f}>)
|
||||
endforeach()
|
||||
endforeach()
|
||||
# Add our general CUDA_NVCC_FLAGS with the configuration specifig flags
|
||||
set(nvcc_flags ${CUDA_NVCC_FLAGS} ${config_specific_flags} ${nvcc_flags})
|
||||
|
||||
file(RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}")
|
||||
|
||||
# Some generators don't handle the multiple levels of custom command
|
||||
@ -1709,21 +1603,29 @@ endmacro()
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
# CUDA COMPILE
|
||||
# (Internal) helper for manually added cuda source files with specific targets
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
macro(CUDA_COMPILE generated_files)
|
||||
macro(cuda_compile_base cuda_target format generated_files)
|
||||
|
||||
# Separate the sources from the options
|
||||
CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
|
||||
# Create custom commands and targets for each file.
|
||||
CUDA_WRAP_SRCS( cuda_compile OBJ _generated_files ${_sources} ${_cmake_options}
|
||||
CUDA_WRAP_SRCS( ${cuda_target} ${format} _generated_files ${_sources} ${_cmake_options}
|
||||
OPTIONS ${_options} )
|
||||
|
||||
set( ${generated_files} ${_generated_files})
|
||||
|
||||
endmacro()
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
# CUDA COMPILE
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
macro(CUDA_COMPILE generated_files)
|
||||
cuda_compile_base(cuda_compile OBJ ${generated_files} ${ARGN})
|
||||
endmacro()
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
@ -1731,17 +1633,28 @@ endmacro()
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
macro(CUDA_COMPILE_PTX generated_files)
|
||||
|
||||
# Separate the sources from the options
|
||||
CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
|
||||
# Create custom commands and targets for each file.
|
||||
CUDA_WRAP_SRCS( cuda_compile_ptx PTX _generated_files ${_sources} ${_cmake_options}
|
||||
OPTIONS ${_options} )
|
||||
|
||||
set( ${generated_files} ${_generated_files})
|
||||
|
||||
cuda_compile_base(cuda_compile_ptx PTX ${generated_files} ${ARGN})
|
||||
endmacro()
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
# CUDA COMPILE FATBIN
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
macro(CUDA_COMPILE_FATBIN generated_files)
|
||||
cuda_compile_base(cuda_compile_fatbin FATBIN ${generated_files} ${ARGN})
|
||||
endmacro()
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
# CUDA COMPILE CUBIN
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
macro(CUDA_COMPILE_CUBIN generated_files)
|
||||
cuda_compile_base(cuda_compile_cubin CUBIN ${generated_files} ${ARGN})
|
||||
endmacro()
|
||||
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
# CUDA ADD CUFFT TO TARGET
|
||||
|
@ -37,12 +37,11 @@
|
||||
|
||||
file(READ ${input_file} depend_text)
|
||||
|
||||
if (${depend_text} MATCHES ".+")
|
||||
if (NOT "${depend_text}" STREQUAL "")
|
||||
|
||||
# message("FOUND DEPENDS")
|
||||
|
||||
# Remember, four backslashes is escaped to one backslash in the string.
|
||||
string(REGEX REPLACE "\\\\ " " " depend_text ${depend_text})
|
||||
string(REPLACE "\\ " " " depend_text ${depend_text})
|
||||
|
||||
# This works for the nvcc -M generated dependency files.
|
||||
string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
|
||||
|
@ -37,11 +37,10 @@
|
||||
|
||||
file(READ ${input_file} file_text)
|
||||
|
||||
if (${file_text} MATCHES ".+")
|
||||
if (NOT "${file_text}" STREQUAL "")
|
||||
|
||||
# Remember, four backslashes is escaped to one backslash in the string.
|
||||
string(REGEX REPLACE ";" "\\\\;" file_text ${file_text})
|
||||
string(REGEX REPLACE "\ncode" ";code" file_text ${file_text})
|
||||
string(REPLACE ";" "\\;" file_text ${file_text})
|
||||
string(REPLACE "\ncode" ";code" file_text ${file_text})
|
||||
|
||||
list(LENGTH file_text len)
|
||||
|
||||
@ -57,7 +56,7 @@ if (${file_text} MATCHES ".+")
|
||||
|
||||
# Extract kernel names.
|
||||
if (${entry} MATCHES "[^g]name = ([^ ]+)")
|
||||
string(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
|
||||
set(entry "${CMAKE_MATCH_1}")
|
||||
|
||||
# Check to see if the kernel name starts with "_"
|
||||
set(skip FALSE)
|
||||
@ -76,19 +75,19 @@ if (${file_text} MATCHES ".+")
|
||||
|
||||
# Registers
|
||||
if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)")
|
||||
string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
|
||||
set(entry "${CMAKE_MATCH_3}")
|
||||
message("Registers: ${entry}")
|
||||
endif()
|
||||
|
||||
# Local memory
|
||||
if (${entry} MATCHES "lmem([ ]+)=([ ]+)([^ ]+)")
|
||||
string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
|
||||
set(entry "${CMAKE_MATCH_3}")
|
||||
message("Local: ${entry}")
|
||||
endif()
|
||||
|
||||
# Shared memory
|
||||
if (${entry} MATCHES "smem([ ]+)=([ ]+)([^ ]+)")
|
||||
string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
|
||||
set(entry "${CMAKE_MATCH_3}")
|
||||
message("Shared: ${entry}")
|
||||
endif()
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user