Merged upstream master
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
*.autosave
|
||||
*.pyc
|
||||
*.user
|
||||
*~
|
||||
.*.swp
|
||||
.DS_Store
|
||||
.sw[a-z]
|
||||
|
2
.tgitconfig
Normal file
@ -0,0 +1,2 @@
|
||||
[tgit]
|
||||
icon = doc/opencv.ico
|
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
@ -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>
|
||||
|
14
3rdparty/include/opencl/1.2/CL/cl_platform.h
vendored
@ -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
|
||||
|
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()
|
||||
|
2
3rdparty/libjpeg/CMakeLists.txt
vendored
@ -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()
|
||||
|
2
3rdparty/libpng/CMakeLists.txt
vendored
@ -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
@ -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
@ -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
@ -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)
|
||||
|
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
|
||||
|
2
3rdparty/zlib/CMakeLists.txt
vendored
@ -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()
|
||||
|
113
CMakeLists.txt
@ -116,7 +116,7 @@ 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_VTK "Include VTK library support (and build opencv_viz module eiher)" OFF IF (NOT ANDROID AND NOT IOS) )
|
||||
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) )
|
||||
@ -132,7 +132,7 @@ OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON
|
||||
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_PNG "Include PNG support" ON)
|
||||
OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
@ -156,6 +156,7 @@ OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" ON
|
||||
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 )
|
||||
|
||||
|
||||
# OpenCV build components
|
||||
@ -190,13 +191,14 @@ 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)) )
|
||||
@ -207,10 +209,12 @@ OCV_OPTION(ENABLE_SSSE3 "Enable SSSE3 instructions"
|
||||
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_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_NEON "Enable NEON instructions" OFF IF CMAKE_COMPILER_IS_GNUCXX AND ARM )
|
||||
OCV_OPTION(ENABLE_VFPV3 "Enable VFPv3-D32 instructions" OFF IF CMAKE_COMPILER_IS_GNUCXX AND ARM )
|
||||
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 )
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
@ -226,6 +230,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)
|
||||
@ -241,13 +254,27 @@ if(WIN32)
|
||||
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(ANDROID)
|
||||
set(LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/lib/${ANDROID_NDK_ABI_NAME}")
|
||||
@ -256,6 +283,7 @@ 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}")
|
||||
@ -266,9 +294,11 @@ 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")
|
||||
|
||||
@ -373,6 +403,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()
|
||||
@ -384,6 +416,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
|
||||
# ----------------------------------------------------------------------------
|
||||
@ -521,6 +566,49 @@ 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_testing.sh.in"
|
||||
"${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY)
|
||||
install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh"
|
||||
DESTINATION /etc/profile.d/ COMPONENT tests)
|
||||
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:
|
||||
# ----------------------------------------------------------------------------
|
||||
@ -630,7 +718,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()
|
||||
@ -820,6 +908,11 @@ 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:")
|
||||
@ -952,3 +1045,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,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)
|
@ -71,14 +71,14 @@ set_target_properties(opencv_performance PROPERTIES
|
||||
|
||||
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)
|
||||
install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev)
|
||||
install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev)
|
||||
install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev)
|
||||
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)
|
||||
install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev)
|
||||
install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev)
|
||||
install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev)
|
||||
endif()
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
|
@ -340,7 +340,7 @@ typedef enum CvBoostType
|
||||
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) */
|
||||
CV_MREG = 8 /* M-regression (Huber loss) */
|
||||
} CvBoostType;
|
||||
|
||||
/****************************************************************************************\
|
||||
|
@ -35,8 +35,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} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev)
|
||||
endif()
|
||||
|
@ -9,7 +9,7 @@ set(HAVE_WINRT FALSE)
|
||||
# search Windows Platform SDK
|
||||
message(STATUS "Checking for Windows Platform SDK")
|
||||
GET_FILENAME_COMPONENT(WINDOWS_SDK_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]" ABSOLUTE CACHE)
|
||||
if (WINDOWS_SDK_PATH STREQUAL "")
|
||||
if(WINDOWS_SDK_PATH STREQUAL "")
|
||||
set(HAVE_MSPDK FALSE)
|
||||
message(STATUS "Windows Platform SDK 8.0 was not found")
|
||||
else()
|
||||
@ -19,7 +19,7 @@ endif()
|
||||
#search for Visual Studio 11.0 install directory
|
||||
message(STATUS "Checking for Visual Studio 2012")
|
||||
GET_FILENAME_COMPONENT(VISUAL_STUDIO_PATH [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0\\Setup\\VS;ProductDir] REALPATH CACHE)
|
||||
if (VISUAL_STUDIO_PATH STREQUAL "")
|
||||
if(VISUAL_STUDIO_PATH STREQUAL "")
|
||||
set(HAVE_MSVC2012 FALSE)
|
||||
message(STATUS "Visual Studio 2012 was not found")
|
||||
else()
|
||||
@ -30,11 +30,15 @@ try_compile(HAVE_WINRT_SDK
|
||||
"${OpenCV_BINARY_DIR}"
|
||||
"${OpenCV_SOURCE_DIR}/cmake/checks/winrttest.cpp")
|
||||
|
||||
if (ENABLE_WINRT_MODE AND HAVE_WINRT_SDK AND HAVE_MSVC2012 AND HAVE_MSPDK)
|
||||
if(ENABLE_WINRT_MODE AND HAVE_WINRT_SDK AND HAVE_MSVC2012 AND HAVE_MSPDK)
|
||||
set(HAVE_WINRT TRUE)
|
||||
set(HAVE_WINRT_CX TRUE)
|
||||
elseif(ENABLE_WINRT_MODE_NATIVE AND HAVE_WINRT_SDK AND HAVE_MSVC2012 AND HAVE_MSPDK)
|
||||
set(HAVE_WINRT TRUE)
|
||||
set(HAVE_WINRT_CX FALSE)
|
||||
endif()
|
||||
|
||||
if (HAVE_WINRT)
|
||||
if(HAVE_WINRT)
|
||||
add_definitions(/DWINVER=0x0602 /DNTDDI_VERSION=NTDDI_WIN8 /D_WIN32_WINNT=0x0602)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /appcontainer")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /appcontainer")
|
||||
|
@ -124,6 +124,12 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
if(ENABLE_SSE2)
|
||||
add_extra_compiler_option(-msse2)
|
||||
endif()
|
||||
if (ENABLE_NEON)
|
||||
add_extra_compiler_option("-mfpu=neon")
|
||||
endif()
|
||||
if (ENABLE_VFPV3 AND NOT ENABLE_NEON)
|
||||
add_extra_compiler_option("-mfpu=vfpv3")
|
||||
endif()
|
||||
|
||||
# SSE3 and further should be disabled under MingW because it generates compiler errors
|
||||
if(NOT MINGW)
|
||||
@ -179,6 +185,11 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
add_extra_compiler_option(-ffunction-sections)
|
||||
endif()
|
||||
|
||||
if(ENABLE_COVERAGE)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} --coverage")
|
||||
set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} --coverage")
|
||||
endif()
|
||||
|
||||
set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} -DNDEBUG")
|
||||
set(OPENCV_EXTRA_FLAGS_DEBUG "${OPENCV_EXTRA_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG")
|
||||
endif()
|
||||
|
@ -344,20 +344,20 @@ macro(add_android_project target path)
|
||||
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${android_proj_bin_dir}/bin/${target}-debug.apk" "${OpenCV_BINARY_DIR}/bin/${target}.apk")
|
||||
if(INSTALL_ANDROID_EXAMPLES AND "${target}" MATCHES "^example-")
|
||||
#apk
|
||||
install(FILES "${OpenCV_BINARY_DIR}/bin/${target}.apk" DESTINATION "samples" COMPONENT main)
|
||||
install(FILES "${OpenCV_BINARY_DIR}/bin/${target}.apk" DESTINATION "samples" COMPONENT samples)
|
||||
get_filename_component(sample_dir "${path}" NAME)
|
||||
#java part
|
||||
list(REMOVE_ITEM android_proj_files ${ANDROID_MANIFEST_FILE})
|
||||
foreach(f ${android_proj_files} ${ANDROID_MANIFEST_FILE})
|
||||
get_filename_component(install_subdir "${f}" PATH)
|
||||
install(FILES "${android_proj_bin_dir}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT main)
|
||||
install(FILES "${android_proj_bin_dir}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT samples)
|
||||
endforeach()
|
||||
#jni part + eclipse files
|
||||
file(GLOB_RECURSE jni_files RELATIVE "${path}" "${path}/jni/*" "${path}/.cproject")
|
||||
ocv_list_filterout(jni_files "\\\\.svn")
|
||||
foreach(f ${jni_files} ".classpath" ".project" ".settings/org.eclipse.jdt.core.prefs")
|
||||
get_filename_component(install_subdir "${f}" PATH)
|
||||
install(FILES "${path}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT main)
|
||||
install(FILES "${path}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT samples)
|
||||
endforeach()
|
||||
#update proj
|
||||
if(android_proj_lib_deps_commands)
|
||||
@ -365,9 +365,9 @@ macro(add_android_project target path)
|
||||
endif()
|
||||
install(CODE "EXECUTE_PROCESS(COMMAND ${ANDROID_EXECUTABLE} --silent update project --path . --target \"${android_proj_sdk_target}\" --name \"${target}\" ${inst_lib_opt}
|
||||
WORKING_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}\"
|
||||
)" COMPONENT main)
|
||||
)" COMPONENT samples)
|
||||
#empty 'gen'
|
||||
install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/gen\")" COMPONENT main)
|
||||
install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/gen\")" COMPONENT samples)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
@ -178,9 +178,8 @@ if(CUDA_FOUND)
|
||||
# we remove -Wsign-promo as it generates warnings under linux
|
||||
string(REPLACE "-Wsign-promo" "" ${var} "${${var}}")
|
||||
|
||||
# we remove -fvisibility-inlines-hidden because it's used for C++ compiler
|
||||
# but NVCC uses C compiler by default
|
||||
string(REPLACE "-fvisibility-inlines-hidden" "" ${var} "${${var}}")
|
||||
# we remove -Wno-sign-promo as it generates warnings under linux
|
||||
string(REPLACE "-Wno-sign-promo" "" ${var} "${${var}}")
|
||||
|
||||
# we remove -Wno-delete-non-virtual-dtor because it's used for C++ compiler
|
||||
# but NVCC uses C compiler by default
|
||||
|
@ -24,7 +24,8 @@ if(PYTHONINTERP_FOUND)
|
||||
|
||||
if(NOT ANDROID AND NOT IOS)
|
||||
ocv_check_environment_variables(PYTHON_LIBRARY PYTHON_INCLUDE_DIR)
|
||||
find_host_package(PythonLibs "${PYTHON_VERSION_STRING}" EXACT)
|
||||
# not using PYTHON_VERSION_STRING here, because it might not conform to the CMake version format
|
||||
find_host_package(PythonLibs "${PYTHON_VERSION_MAJOR_MINOR}.${PYTHON_VERSION_PATCH}" EXACT)
|
||||
endif()
|
||||
|
||||
if(NOT ANDROID AND NOT IOS)
|
||||
@ -59,23 +60,38 @@ if(PYTHONINTERP_FOUND)
|
||||
SET(PYTHON_PACKAGES_PATH "${_PYTHON_PACKAGES_PATH}" CACHE PATH "Where to install the python packages.")
|
||||
|
||||
if(NOT PYTHON_NUMPY_INCLUDE_DIRS)
|
||||
# Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
|
||||
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
|
||||
"import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print(os.pathsep.join(numpy.distutils.misc_util.get_numpy_include_dirs()))"
|
||||
RESULT_VARIABLE PYTHON_NUMPY_PROCESS
|
||||
OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIRS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
message(STATUS "Cannot probe for Python/Numpy support (because we are cross-compiling OpenCV)")
|
||||
message(STATUS "If you want to enable Python/Numpy support, set the following variables:")
|
||||
message(STATUS " PYTHON_INCLUDE_PATH")
|
||||
message(STATUS " PYTHON_LIBRARIES")
|
||||
message(STATUS " PYTHON_NUMPY_INCLUDE_DIRS")
|
||||
else()
|
||||
# Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
|
||||
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print(os.pathsep.join(numpy.distutils.misc_util.get_numpy_include_dirs()))"
|
||||
RESULT_VARIABLE PYTHON_NUMPY_PROCESS
|
||||
OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIRS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if(PYTHON_NUMPY_PROCESS EQUAL 0)
|
||||
file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIRS}" _PYTHON_NUMPY_INCLUDE_DIRS)
|
||||
set(PYTHON_NUMPY_INCLUDE_DIRS "${_PYTHON_NUMPY_INCLUDE_DIRS}" CACHE PATH "Path to numpy headers")
|
||||
if(NOT PYTHON_NUMPY_PROCESS EQUAL 0)
|
||||
unset(PYTHON_NUMPY_INCLUDE_DIRS)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(PYTHON_NUMPY_INCLUDE_DIRS)
|
||||
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy; print(numpy.version.version)"
|
||||
OUTPUT_VARIABLE PYTHON_NUMPY_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIRS}" _PYTHON_NUMPY_INCLUDE_DIRS)
|
||||
set(PYTHON_NUMPY_INCLUDE_DIRS ${_PYTHON_NUMPY_INCLUDE_DIRS} CACHE PATH "Path to numpy headers")
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
if(NOT PYTHON_NUMPY_VERSION)
|
||||
set(PYTHON_NUMPY_VERSION "undefined - cannot be probed because of the cross-compilation")
|
||||
endif()
|
||||
else()
|
||||
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy; print(numpy.version.version)"
|
||||
RESULT_VARIABLE PYTHON_NUMPY_PROCESS
|
||||
OUTPUT_VARIABLE PYTHON_NUMPY_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
endif()
|
||||
endif()
|
||||
endif(NOT ANDROID AND NOT IOS)
|
||||
endif()
|
||||
|
@ -2,7 +2,12 @@ if(NOT WITH_VTK OR ANDROID OR IOS)
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_package(VTK 6.0 QUIET COMPONENTS vtkRenderingCore vtkInteractionWidgets vtkInteractionStyle vtkIOLegacy vtkIOPLY vtkRenderingFreeType vtkRenderingLOD vtkFiltersTexture NO_MODULE)
|
||||
if (HAVE_QT5)
|
||||
message(STATUS "VTK is disabled because OpenCV is linked with Q5. Some VTK disributives are compiled with Q4 and therefore can't be linked together Qt5.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_package(VTK 6.0 QUIET COMPONENTS vtkRenderingCore vtkInteractionWidgets vtkInteractionStyle vtkIOLegacy vtkIOPLY vtkRenderingFreeType vtkRenderingLOD vtkFiltersTexture vtkIOExport NO_MODULE)
|
||||
|
||||
if(NOT DEFINED VTK_FOUND OR NOT VTK_FOUND)
|
||||
find_package(VTK 5.10 QUIET COMPONENTS vtkCommon vtkFiltering vtkRendering vtkWidgets vtkImaging NO_MODULE)
|
||||
@ -18,4 +23,4 @@ if(VTK_FOUND)
|
||||
else()
|
||||
set(HAVE_VTK OFF)
|
||||
message(STATUS "VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or set $VTK_DIR enviroment variable to VTK install subdirectory with VTKConfig.cmake file (for windows)")
|
||||
endif()
|
||||
endif()
|
||||
|
@ -4,7 +4,7 @@
|
||||
CONFIGURE_FILE(
|
||||
"${OpenCV_SOURCE_DIR}/cmake/templates/cmake_uninstall.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
|
||||
IMMEDIATE @ONLY)
|
||||
@ONLY)
|
||||
|
||||
ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
|
@ -163,9 +163,16 @@ function(set_ipp_new_libraries _LATEST_VERSION)
|
||||
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCV}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
|
||||
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPI}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
|
||||
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPS}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
|
||||
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCORE}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
|
||||
PARENT_SCOPE)
|
||||
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCORE}${IPP_SUFFIX}${IPP_LIB_SUFFIX})
|
||||
|
||||
if (UNIX)
|
||||
set(IPP_LIBRARIES
|
||||
${IPP_LIBRARIES}
|
||||
${IPP_LIB_PREFIX}irc${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||
${IPP_LIB_PREFIX}imf${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||
${IPP_LIB_PREFIX}svml${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
endif()
|
||||
set(IPP_LIBRARIES ${IPP_LIBRARIES} PARENT_SCOPE)
|
||||
return()
|
||||
|
||||
endfunction()
|
||||
@ -208,19 +215,39 @@ function(set_ipp_variables _LATEST_VERSION)
|
||||
set(IPP_INCLUDE_DIRS ${IPP_ROOT_DIR}/include PARENT_SCOPE)
|
||||
|
||||
if (APPLE)
|
||||
set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib PARENT_SCOPE)
|
||||
set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib)
|
||||
elseif (IPP_X64)
|
||||
if(NOT EXISTS ${IPP_ROOT_DIR}/lib/intel64)
|
||||
message(SEND_ERROR "IPP EM64T libraries not found")
|
||||
endif()
|
||||
set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib/intel64 PARENT_SCOPE)
|
||||
set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib/intel64)
|
||||
else()
|
||||
if(NOT EXISTS ${IPP_ROOT_DIR}/lib/ia32)
|
||||
message(SEND_ERROR "IPP IA32 libraries not found")
|
||||
endif()
|
||||
set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib/ia32 PARENT_SCOPE)
|
||||
set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib/ia32)
|
||||
endif()
|
||||
|
||||
if (UNIX)
|
||||
get_filename_component(INTEL_COMPILER_LIBRARY_DIR ${IPP_ROOT_DIR}/../lib REALPATH)
|
||||
if (IPP_X64)
|
||||
if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/intel64)
|
||||
message(SEND_ERROR "Intel compiler EM64T libraries not found")
|
||||
endif()
|
||||
set(IPP_LIBRARY_DIRS
|
||||
${IPP_LIBRARY_DIRS}
|
||||
${INTEL_COMPILER_LIBRARY_DIR}/intel64)
|
||||
else()
|
||||
if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/ia32)
|
||||
message(SEND_ERROR "Intel compiler IA32 libraries not found")
|
||||
endif()
|
||||
set(IPP_LIBRARY_DIRS
|
||||
${IPP_LIBRARY_DIRS}
|
||||
${INTEL_COMPILER_LIBRARY_DIR}/ia32)
|
||||
endif()
|
||||
endif()
|
||||
set(IPP_LIBRARY_DIRS ${IPP_LIBRARY_DIRS} PARENT_SCOPE)
|
||||
|
||||
# set IPP_LIBRARIES variable (7.x or 8.x lib names)
|
||||
set_ipp_new_libraries(${_LATEST_VERSION})
|
||||
set(IPP_LIBRARIES ${IPP_LIBRARIES} PARENT_SCOPE)
|
||||
|
20
cmake/OpenCVFindIntelPerCSDK.cmake
Normal file
@ -0,0 +1,20 @@
|
||||
# Main variables:
|
||||
# INTELPERC_LIBRARIES and INTELPERC_INCLUDE to link Intel Perceptial Computing SDK modules
|
||||
# HAVE_INTELPERC for conditional compilation OpenCV with/without Intel Perceptial Computing SDK
|
||||
|
||||
if(X86_64)
|
||||
find_path(INTELPERC_INCLUDE_DIR "pxcsession.h" PATHS "$ENV{PCSDK_DIR}include" DOC "Path to Intel Perceptual Computing SDK interface headers")
|
||||
find_file(INTELPERC_LIBRARIES "libpxc.lib" PATHS "$ENV{PCSDK_DIR}lib/x64" DOC "Path to Intel Perceptual Computing SDK interface libraries")
|
||||
else()
|
||||
find_path(INTELPERC_INCLUDE_DIR "pxcsession.h" PATHS "$ENV{PCSDK_DIR}include" DOC "Path to Intel Perceptual Computing SDK interface headers")
|
||||
find_file(INTELPERC_LIBRARIES "libpxc.lib" PATHS "$ENV{PCSDK_DIR}lib/Win32" DOC "Path to Intel Perceptual Computing SDK interface libraries")
|
||||
endif()
|
||||
|
||||
if(INTELPERC_INCLUDE_DIR AND INTELPERC_LIBRARIES)
|
||||
set(HAVE_INTELPERC TRUE)
|
||||
else()
|
||||
set(HAVE_INTELPERC FALSE)
|
||||
message(WARNING "Intel Perceptual Computing SDK library directory (set by INTELPERC_LIB_DIR variable) is not found or does not have Intel Perceptual Computing SDK libraries.")
|
||||
endif() #if(INTELPERC_INCLUDE_DIR AND INTELPERC_LIBRARIES)
|
||||
|
||||
mark_as_advanced(FORCE INTELPERC_LIBRARIES INTELPERC_INCLUDE_DIR)
|
@ -277,3 +277,8 @@ if (NOT IOS)
|
||||
set(HAVE_QTKIT YES)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# --- Intel Perceptual Computing SDK ---
|
||||
if(WITH_INTELPERC)
|
||||
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVFindIntelPerCSDK.cmake")
|
||||
endif(WITH_INTELPERC)
|
||||
|
@ -91,7 +91,7 @@ if(ANDROID)
|
||||
set(OPENCV_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/lib/\$(OPENCV_TARGET_ARCH_ABI)")
|
||||
set(OPENCV_3RDPARTY_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/3rdparty/lib/\$(OPENCV_TARGET_ARCH_ABI)")
|
||||
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/OpenCV.mk" IMMEDIATE @ONLY)
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/OpenCV.mk" @ONLY)
|
||||
|
||||
# -------------------------------------------------------------------------------------------
|
||||
# Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install"
|
||||
@ -101,6 +101,6 @@ if(ANDROID)
|
||||
set(OPENCV_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../libs/\$(OPENCV_TARGET_ARCH_ABI)")
|
||||
set(OPENCV_3RDPARTY_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../3rdparty/libs/\$(OPENCV_TARGET_ARCH_ABI)")
|
||||
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" IMMEDIATE @ONLY)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH})
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" @ONLY)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev)
|
||||
endif(ANDROID)
|
||||
|
@ -83,9 +83,9 @@ endif()
|
||||
|
||||
export(TARGETS ${OpenCVModules_TARGETS} FILE "${CMAKE_BINARY_DIR}/OpenCVModules${modules_file_suffix}.cmake")
|
||||
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" IMMEDIATE @ONLY)
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" @ONLY)
|
||||
#support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work.
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" @ONLY)
|
||||
|
||||
# --------------------------------------------------------------------------------------------
|
||||
# Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install"
|
||||
@ -98,8 +98,8 @@ if(INSTALL_TO_MANGLED_PATHS)
|
||||
set(OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE}\"")
|
||||
endif()
|
||||
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" @ONLY)
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" @ONLY)
|
||||
|
||||
if(UNIX) # ANDROID configuration is created here also
|
||||
#http://www.vtk.org/Wiki/CMake/Tutorials/Packaging reference
|
||||
@ -109,18 +109,18 @@ if(UNIX) # ANDROID configuration is created here also
|
||||
# <prefix>/(share|lib)/<name>*/ (U)
|
||||
# <prefix>/(share|lib)/<name>*/(cmake|CMake)/ (U)
|
||||
if(INSTALL_TO_MANGLED_PATHS)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/)
|
||||
install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ FILE OpenCVModules${modules_file_suffix}.cmake)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ COMPONENT dev)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ COMPONENT dev)
|
||||
install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev)
|
||||
else()
|
||||
install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/)
|
||||
install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ FILE OpenCVModules${modules_file_suffix}.cmake)
|
||||
install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev)
|
||||
install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/)
|
||||
install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev)
|
||||
endif()
|
||||
|
||||
# --------------------------------------------------------------------------------------------
|
||||
@ -131,15 +131,15 @@ if(WIN32)
|
||||
set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"")
|
||||
|
||||
exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/win-install/\"" OUTPUT_VARIABLE RET_VAL)
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" @ONLY)
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" @ONLY)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib")
|
||||
install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" FILE OpenCVModules${modules_file_suffix}.cmake)
|
||||
install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" COMPONENT dev)
|
||||
install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev)
|
||||
else()
|
||||
install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib")
|
||||
install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" FILE OpenCVModules${modules_file_suffix}.cmake)
|
||||
install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" COMPONENT dev)
|
||||
install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev)
|
||||
endif()
|
||||
install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}")
|
||||
install(FILES "${OpenCV_SOURCE_DIR}/cmake/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/")
|
||||
install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT dev)
|
||||
install(FILES "${OpenCV_SOURCE_DIR}/cmake/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/" COMPONENT dev)
|
||||
endif()
|
||||
|
@ -23,4 +23,4 @@ set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE
|
||||
#endforeach()
|
||||
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv_modules.hpp.in" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp")
|
||||
install(FILES "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp" DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2 COMPONENT main)
|
||||
install(FILES "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp" DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2 COMPONENT dev)
|
||||
|
@ -78,8 +78,8 @@ else()
|
||||
endif()
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv-XXX.pc.in"
|
||||
"${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}"
|
||||
@ONLY IMMEDIATE)
|
||||
@ONLY)
|
||||
|
||||
if(UNIX AND NOT ANDROID)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig COMPONENT dev)
|
||||
endif()
|
||||
|
@ -135,13 +135,13 @@ macro(ocv_add_module _name)
|
||||
|
||||
# parse list of dependencies
|
||||
if("${ARGV1}" STREQUAL "INTERNAL" OR "${ARGV1}" STREQUAL "BINDINGS")
|
||||
set(OPENCV_MODULE_${the_module}_CLASS "${ARGV1}" CACHE INTERNAL "The cathegory of the module")
|
||||
set(OPENCV_MODULE_${the_module}_CLASS "${ARGV1}" CACHE INTERNAL "The category of the module")
|
||||
set(__ocv_argn__ ${ARGN})
|
||||
list(REMOVE_AT __ocv_argn__ 0)
|
||||
ocv_add_dependencies(${the_module} ${__ocv_argn__})
|
||||
unset(__ocv_argn__)
|
||||
else()
|
||||
set(OPENCV_MODULE_${the_module}_CLASS "PUBLIC" CACHE INTERNAL "The cathegory of the module")
|
||||
set(OPENCV_MODULE_${the_module}_CLASS "PUBLIC" CACHE INTERNAL "The category of the module")
|
||||
ocv_add_dependencies(${the_module} ${ARGN})
|
||||
if(BUILD_${the_module})
|
||||
set(OPENCV_MODULES_PUBLIC ${OPENCV_MODULES_PUBLIC} "${the_module}" CACHE INTERNAL "List of OpenCV modules marked for export")
|
||||
@ -583,9 +583,9 @@ macro(ocv_create_module)
|
||||
endif()
|
||||
|
||||
ocv_install_target(${the_module} EXPORT OpenCVModules
|
||||
RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main
|
||||
LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
|
||||
ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
|
||||
RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs
|
||||
LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs
|
||||
ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT dev
|
||||
)
|
||||
|
||||
# only "public" headers need to be installed
|
||||
@ -593,7 +593,7 @@ macro(ocv_create_module)
|
||||
foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS})
|
||||
string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
|
||||
if(NOT hdr2 MATCHES "opencv2/${the_module}/private.*" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" )
|
||||
install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT main)
|
||||
install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT dev)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
@ -717,6 +717,9 @@ function(ocv_add_perf_tests)
|
||||
else(OCV_DEPENDENCIES_FOUND)
|
||||
# TODO: warn about unsatisfied dependencies
|
||||
endif(OCV_DEPENDENCIES_FOUND)
|
||||
if(INSTALL_TESTS)
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
@ -770,6 +773,10 @@ function(ocv_add_accuracy_tests)
|
||||
else(OCV_DEPENDENCIES_FOUND)
|
||||
# TODO: warn about unsatisfied dependencies
|
||||
endif(OCV_DEPENDENCIES_FOUND)
|
||||
|
||||
if(INSTALL_TESTS)
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
@ -801,7 +808,7 @@ function(ocv_add_samples)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${module_id}" COMPONENT main)
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${module_id}" COMPONENT samples)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
@ -810,8 +817,8 @@ function(ocv_add_samples)
|
||||
if(INSTALL_C_EXAMPLES AND NOT WIN32 AND EXISTS "${samples_path}")
|
||||
file(GLOB sample_files "${samples_path}/*")
|
||||
install(FILES ${sample_files}
|
||||
DESTINATION share/OpenCV/samples/${module_id}
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
|
||||
DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id}
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
110
cmake/OpenCVPackaging.cmake
Normal file
@ -0,0 +1,110 @@
|
||||
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
|
||||
set(CPACK_set_DESTDIR "on")
|
||||
|
||||
if(NOT OPENCV_CUSTOM_PACKAGE_INFO)
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Open Computer Vision Library")
|
||||
set(CPACK_PACKAGE_DESCRIPTION
|
||||
"OpenCV (Open Source Computer Vision Library) is an open source computer vision
|
||||
and machine learning software library. OpenCV was built to provide a common
|
||||
infrastructure for computer vision applications and to accelerate the use of
|
||||
machine perception in the commercial products. Being a BSD-licensed product,
|
||||
OpenCV makes it easy for businesses to utilize and modify the code.")
|
||||
set(CPACK_PACKAGE_VENDOR "OpenCV Foundation")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
||||
set(CPACK_PACKAGE_CONTACT "admin@opencv.org")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR "${OPENCV_VERSION_MAJOR}")
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "${OPENCV_VERSION_MINOR}")
|
||||
set(CPACK_PACKAGE_VERSION_PATCH "${OPENCV_VERSION_PATCH}")
|
||||
set(CPACK_PACKAGE_VERSION "${OPENCV_VCSVERSION}")
|
||||
endif(NOT OPENCV_CUSTOM_PACKAGE_INFO)
|
||||
|
||||
#arch
|
||||
if(X86)
|
||||
set(CPACK_DEBIAN_ARCHITECTURE "i386")
|
||||
set(CPACK_RPM_PACKAGE_ARCHITECTURE "i686")
|
||||
elseif(X86_64)
|
||||
set(CPACK_DEBIAN_ARCHITECTURE "amd64")
|
||||
set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64")
|
||||
elseif(ARM)
|
||||
set(CPACK_DEBIAN_ARCHITECTURE "armhf")
|
||||
set(CPACK_RPM_PACKAGE_ARCHITECTURE "armhf")
|
||||
else()
|
||||
set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
|
||||
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
|
||||
endif()
|
||||
|
||||
if(CPACK_GENERATOR STREQUAL "DEB")
|
||||
set(OPENCV_PACKAGE_ARCH_SUFFIX ${CPACK_DEBIAN_ARCHITECTURE})
|
||||
elseif(CPACK_GENERATOR STREQUAL "RPM")
|
||||
set(OPENCV_PACKAGE_ARCH_SUFFIX ${CPACK_RPM_PACKAGE_ARCHITECTURE})
|
||||
else()
|
||||
set(OPENCV_PACKAGE_ARCH_SUFFIX ${CMAKE_SYSTEM_PROCESSOR})
|
||||
endif()
|
||||
|
||||
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VCSVERSION}-${OPENCV_PACKAGE_ARCH_SUFFIX}")
|
||||
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VCSVERSION}-${OPENCV_PACKAGE_ARCH_SUFFIX}")
|
||||
|
||||
#rpm options
|
||||
set(CPACK_RPM_COMPONENT_INSTALL TRUE)
|
||||
set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
|
||||
set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION})
|
||||
set(CPACK_RPM_PACKAGE_URL "http://opencv.org")
|
||||
set(CPACK_RPM_PACKAGE_LICENSE "BSD")
|
||||
|
||||
#deb options
|
||||
set(CPACK_DEB_COMPONENT_INSTALL TRUE)
|
||||
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
|
||||
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
|
||||
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://opencv.org")
|
||||
|
||||
#depencencies
|
||||
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE)
|
||||
set(CPACK_COMPONENT_samples_DEPENDS libs)
|
||||
set(CPACK_COMPONENT_dev_DEPENDS libs)
|
||||
set(CPACK_COMPONENT_docs_DEPENDS libs)
|
||||
set(CPACK_COMPONENT_java_DEPENDS libs)
|
||||
set(CPACK_COMPONENT_python_DEPENDS libs)
|
||||
set(CPACK_COMPONENT_tests_DEPENDS libs)
|
||||
|
||||
if(HAVE_CUDA)
|
||||
string(REPLACE "." "-" cuda_version_suffix ${CUDA_VERSION})
|
||||
set(CPACK_DEB_libs_PACKAGE_DEPENDS "cuda-core-libs-${cuda_version_suffix}, cuda-extra-libs-${cuda_version_suffix}")
|
||||
set(CPACK_COMPONENT_dev_DEPENDS libs)
|
||||
set(CPACK_DEB_dev_PACKAGE_DEPENDS "cuda-headers-${cuda_version_suffix}")
|
||||
endif()
|
||||
|
||||
if(NOT OPENCV_CUSTOM_PACKAGE_INFO)
|
||||
set(CPACK_COMPONENT_libs_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}")
|
||||
set(CPACK_COMPONENT_libs_DESCRIPTION "Open Computer Vision Library")
|
||||
|
||||
set(CPACK_COMPONENT_python_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-python")
|
||||
set(CPACK_COMPONENT_python_DESCRIPTION "Python bindings for Open Source Computer Vision Library")
|
||||
|
||||
set(CPACK_COMPONENT_java_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-java")
|
||||
set(CPACK_COMPONENT_java_DESCRIPTION "Java bindings for Open Source Computer Vision Library")
|
||||
|
||||
set(CPACK_COMPONENT_dev_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-dev")
|
||||
set(CPACK_COMPONENT_dev_DESCRIPTION "Development files for Open Source Computer Vision Library")
|
||||
|
||||
set(CPACK_COMPONENT_docs_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-docs")
|
||||
set(CPACK_COMPONENT_docs_DESCRIPTION "Documentation for Open Source Computer Vision Library")
|
||||
|
||||
set(CPACK_COMPONENT_samples_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-samples")
|
||||
set(CPACK_COMPONENT_samples_DESCRIPTION "Samples for Open Source Computer Vision Library")
|
||||
|
||||
set(CPACK_COMPONENT_tests_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-tests")
|
||||
set(CPACK_COMPONENT_tests_DESCRIPTION "Accuracy and performance tests for Open Source Computer Vision Library")
|
||||
endif(NOT OPENCV_CUSTOM_PACKAGE_INFO)
|
||||
|
||||
if(NOT OPENCV_CUSTOM_PACKAGE_LAYOUT)
|
||||
set(CPACK_libs_COMPONENT_INSTALL TRUE)
|
||||
set(CPACK_dev_COMPONENT_INSTALL TRUE)
|
||||
set(CPACK_docs_COMPONENT_INSTALL TRUE)
|
||||
set(CPACK_python_COMPONENT_INSTALL TRUE)
|
||||
set(CPACK_java_COMPONENT_INSTALL TRUE)
|
||||
set(CPACK_samples_COMPONENT_INSTALL TRUE)
|
||||
endif(NOT OPENCV_CUSTOM_PACKAGE_LAYOUT)
|
||||
|
||||
include(CPack)
|
||||
|
||||
ENDif(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
|
@ -467,6 +467,20 @@ macro(ocv_convert_to_full_paths VAR)
|
||||
endmacro()
|
||||
|
||||
|
||||
# convert list of paths to libraries names without lib prefix
|
||||
macro(ocv_convert_to_lib_name var)
|
||||
set(__tmp "")
|
||||
foreach(path ${ARGN})
|
||||
get_filename_component(__tmp_name "${path}" NAME_WE)
|
||||
string(REGEX REPLACE "^lib" "" __tmp_name ${__tmp_name})
|
||||
list(APPEND __tmp "${__tmp_name}")
|
||||
endforeach()
|
||||
set(${var} ${__tmp})
|
||||
unset(__tmp)
|
||||
unset(__tmp_name)
|
||||
endmacro()
|
||||
|
||||
|
||||
# add install command
|
||||
function(ocv_install_target)
|
||||
install(TARGETS ${ARGN})
|
||||
|
@ -29,6 +29,7 @@ ${nested_namespace_start}
|
||||
set(STR_HPP "// This file is auto-generated. Do not edit!
|
||||
|
||||
#include \"opencv2/core/ocl_genbase.hpp\"
|
||||
#include \"opencv2/core/opencl/ocl_defs.hpp\"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
@ -64,8 +65,8 @@ foreach(cl ${cl_list})
|
||||
set(STR_CPP_DECL "const struct ProgramEntry ${cl_filename}={\"${cl_filename}\",\n\"${lines}, \"${hash}\"};\n")
|
||||
set(STR_HPP_DECL "extern const struct ProgramEntry ${cl_filename};\n")
|
||||
if(new_mode)
|
||||
set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource2 ${cl_filename}_oclsrc(${cl_filename}.programStr);\n")
|
||||
set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource2 ${cl_filename}_oclsrc;\n")
|
||||
set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource ${cl_filename}_oclsrc(${cl_filename}.programStr);\n")
|
||||
set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource ${cl_filename}_oclsrc;\n")
|
||||
endif()
|
||||
|
||||
set(STR_CPP "${STR_CPP}${STR_CPP_DECL}")
|
||||
|
@ -2,6 +2,13 @@
|
||||
# you might need to define NDK_USE_CYGPATH=1 before calling the ndk-build
|
||||
|
||||
USER_LOCAL_PATH:=$(LOCAL_PATH)
|
||||
|
||||
USER_LOCAL_C_INCLUDES:=$(LOCAL_C_INCLUDES)
|
||||
USER_LOCAL_CFLAGS:=$(LOCAL_CFLAGS)
|
||||
USER_LOCAL_STATIC_LIBRARIES:=$(LOCAL_STATIC_LIBRARIES)
|
||||
USER_LOCAL_SHARED_LIBRARIES:=$(LOCAL_SHARED_LIBRARIES)
|
||||
USER_LOCAL_LDLIBS:=$(LOCAL_LDLIBS)
|
||||
|
||||
LOCAL_PATH:=$(subst ?,,$(firstword ?$(subst \, ,$(subst /, ,$(call my-dir)))))
|
||||
|
||||
OPENCV_TARGET_ARCH_ABI:=$(TARGET_ARCH_ABI)
|
||||
@ -47,7 +54,7 @@ else
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq (${OPENCV_CAMERA_MODULES},on)
|
||||
ifeq ($(OPENCV_CAMERA_MODULES),on)
|
||||
ifeq ($(TARGET_ARCH_ABI),armeabi)
|
||||
OPENCV_CAMERA_MODULES:=@OPENCV_CAMERA_LIBS_ARMEABI_CONFIGCMAKE@
|
||||
endif
|
||||
@ -113,6 +120,13 @@ ifeq ($(OPENCV_LOCAL_CFLAGS),)
|
||||
endif
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_C_INCLUDES:=$(USER_LOCAL_C_INCLUDES)
|
||||
LOCAL_CFLAGS:=$(USER_LOCAL_CFLAGS)
|
||||
LOCAL_STATIC_LIBRARIES:=$(USER_LOCAL_STATIC_LIBRARIES)
|
||||
LOCAL_SHARED_LIBRARIES:=$(USER_LOCAL_SHARED_LIBRARIES)
|
||||
LOCAL_LDLIBS:=$(USER_LOCAL_LDLIBS)
|
||||
|
||||
LOCAL_C_INCLUDES += $(OPENCV_LOCAL_C_INCLUDES)
|
||||
LOCAL_CFLAGS += $(OPENCV_LOCAL_CFLAGS)
|
||||
|
||||
|
@ -88,6 +88,9 @@
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#cmakedefine HAVE_INTTYPES_H 1
|
||||
|
||||
/* Intel Perceptual Computing SDK library */
|
||||
#cmakedefine HAVE_INTELPERC
|
||||
|
||||
/* Intel Integrated Performance Primitives */
|
||||
#cmakedefine HAVE_IPP
|
||||
|
||||
@ -164,6 +167,6 @@
|
||||
/* Xine video library */
|
||||
#cmakedefine HAVE_XINE
|
||||
|
||||
/* Define to 1 if your processor stores words with the most significant byte
|
||||
/* Define if your processor stores words with the most significant byte
|
||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
#cmakedefine WORDS_BIGENDIAN
|
||||
|
51
cmake/templates/opencv_run_all_tests_android.sh.in
Normal file
@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
BASE_DIR=`dirname $0`
|
||||
OPENCV_TEST_PATH=$BASE_DIR/@TEST_PATH@
|
||||
OPENCV_TEST_DATA_PATH=$BASE_DIR/sdk/etc/testdata/
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Device architecture is not preset in command line"
|
||||
echo "Tests are available for architectures: `ls -m ${OPENCV_TEST_PATH}`"
|
||||
echo "Usage: $0 <target_device_arch>"
|
||||
return 1
|
||||
else
|
||||
TARGET_ARCH=$1
|
||||
fi
|
||||
|
||||
if [ -z `which adb` ]; then
|
||||
echo "adb command was not found in PATH"
|
||||
return 1
|
||||
fi
|
||||
|
||||
adb push $OPENCV_TEST_DATA_PATH /sdcard/opencv_testdata
|
||||
|
||||
adb shell "mkdir -p /data/local/tmp/opencv_test"
|
||||
SUMMARY_STATUS=0
|
||||
for t in "$OPENCV_TEST_PATH/$TARGET_ARCH/"opencv_test_* "$OPENCV_TEST_PATH/$TARGET_ARCH/"opencv_perf_*;
|
||||
do
|
||||
test_name=`basename "$t"`
|
||||
report="$test_name-`date --rfc-3339=date`.xml"
|
||||
adb push $t /data/local/tmp/opencv_test/
|
||||
adb shell "export OPENCV_TEST_DATA_PATH=/sdcard/opencv_testdata && /data/local/tmp/opencv_test/$test_name --perf_min_samples=1 --perf_force_samples=1 --gtest_output=xml:/data/local/tmp/opencv_test/$report"
|
||||
adb pull "/data/local/tmp/opencv_test/$report" $report
|
||||
TEST_STATUS=0
|
||||
if [ -e $report ]; then
|
||||
if [ `grep -c "<fail" $report` -ne 0 ]; then
|
||||
TEST_STATUS=2
|
||||
fi
|
||||
else
|
||||
TEST_STATUS=3
|
||||
fi
|
||||
if [ $TEST_STATUS -ne 0 ]; then
|
||||
SUMMARY_STATUS=$TEST_STATUS
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $SUMMARY_STATUS -eq 0 ]; then
|
||||
echo "All OpenCV tests finished successfully"
|
||||
else
|
||||
echo "OpenCV tests finished with status $SUMMARY_STATUS"
|
||||
fi
|
||||
|
||||
return $SUMMARY_STATUS
|
25
cmake/templates/opencv_run_all_tests_unix.sh.in
Normal file
@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
OPENCV_TEST_PATH=@CMAKE_INSTALL_PREFIX@/@OPENCV_TEST_INSTALL_PATH@
|
||||
export OPENCV_TEST_DATA_PATH=@CMAKE_INSTALL_PREFIX@/share/OpenCV/testdata
|
||||
|
||||
SUMMARY_STATUS=0
|
||||
for t in "$OPENCV_TEST_PATH/"opencv_test_* "$OPENCV_TEST_PATH/"opencv_perf_*;
|
||||
do
|
||||
report="`basename "$t"`-`date --rfc-3339=date`.xml"
|
||||
"$t" --perf_min_samples=1 --perf_force_samples=1 --gtest_output=xml:"$report"
|
||||
TEST_STATUS=$?
|
||||
if [ $TEST_STATUS -ne 0 ]; then
|
||||
SUMMARY_STATUS=$TEST_STATUS
|
||||
fi
|
||||
done
|
||||
|
||||
rm -f /tmp/__opencv_temp.*
|
||||
|
||||
if [ $SUMMARY_STATUS -eq 0 ]; then
|
||||
echo "All OpenCV tests finished successfully"
|
||||
else
|
||||
echo "OpenCV tests finished with status $SUMMARY_STATUS"
|
||||
fi
|
||||
|
||||
return $SUMMARY_STATUS
|
2
cmake/templates/opencv_testing.sh.in
Normal file
@ -0,0 +1,2 @@
|
||||
# Environment setup for OpenCV testing
|
||||
export OPENCV_TEST_DATA_PATH=@CMAKE_INSTALL_PREFIX@/share/OpenCV/testdata
|
@ -2,9 +2,21 @@ file(GLOB HAAR_CASCADES haarcascades/*.xml)
|
||||
file(GLOB LBP_CASCADES lbpcascades/*.xml)
|
||||
|
||||
if(ANDROID)
|
||||
install(FILES ${HAAR_CASCADES} DESTINATION sdk/etc/haarcascades COMPONENT main)
|
||||
install(FILES ${LBP_CASCADES} DESTINATION sdk/etc/lbpcascades COMPONENT main)
|
||||
install(FILES ${HAAR_CASCADES} DESTINATION sdk/etc/haarcascades COMPONENT libs)
|
||||
install(FILES ${LBP_CASCADES} DESTINATION sdk/etc/lbpcascades COMPONENT libs)
|
||||
elseif(NOT WIN32)
|
||||
install(FILES ${HAAR_CASCADES} DESTINATION share/OpenCV/haarcascades COMPONENT main)
|
||||
install(FILES ${LBP_CASCADES} DESTINATION share/OpenCV/lbpcascades COMPONENT main)
|
||||
install(FILES ${HAAR_CASCADES} DESTINATION share/OpenCV/haarcascades COMPONENT libs)
|
||||
install(FILES ${LBP_CASCADES} DESTINATION share/OpenCV/lbpcascades COMPONENT libs)
|
||||
endif()
|
||||
|
||||
if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH)
|
||||
if(ANDROID)
|
||||
install(DIRECTORY ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests)
|
||||
elseif(NOT WIN32)
|
||||
# CPack does not set correct permissions by default, so we do it explicitly.
|
||||
install(DIRECTORY ${OPENCV_TEST_DATA_PATH}
|
||||
DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
|
||||
DESTINATION share/OpenCV/testdata COMPONENT tests)
|
||||
endif()
|
||||
endif()
|
@ -33,7 +33,7 @@ if(BUILD_DOCS AND HAVE_SPHINX)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(FIXED_ORDER_MODULES core imgproc highgui video calib3d features2d objdetect ml flann photo stitching nonfree contrib legacy bioinspired)
|
||||
set(FIXED_ORDER_MODULES core imgproc highgui video calib3d features2d objdetect ml flann photo stitching nonfree contrib legacy)
|
||||
|
||||
list(REMOVE_ITEM BASE_MODULES ${FIXED_ORDER_MODULES})
|
||||
|
||||
@ -148,11 +148,11 @@ if(BUILD_DOCS AND HAVE_SPHINX)
|
||||
endif()
|
||||
|
||||
foreach(f ${DOC_LIST})
|
||||
install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" COMPONENT main)
|
||||
install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" COMPONENT docs)
|
||||
endforeach()
|
||||
|
||||
foreach(f ${OPTIONAL_DOC_LIST})
|
||||
install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" OPTIONAL)
|
||||
install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" OPTIONAL COMPONENT docs)
|
||||
endforeach()
|
||||
|
||||
endif()
|
||||
|
@ -54,7 +54,7 @@ master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'OpenCV'
|
||||
copyright = u'2011-2013, opencv dev team'
|
||||
copyright = u'2011-2014, opencv dev team'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
|
@ -492,7 +492,7 @@ class=Typewch><span lang=EN-US>- weighttrimming <weight_trimming></span></
|
||||
<p class=MsoNormal style='margin-left:17.1pt;text-indent:-17.1pt'><span
|
||||
class=Typewch><span lang=EN-US> </span></span><span class=Typewch><span
|
||||
lang=EN-US style='font-family:"Times New Roman";font-weight:normal'>Specifies
|
||||
wheter and how much weight trimming should be used. A decent choice is 0.90.</span></span></p>
|
||||
whether and how much weight trimming should be used. A decent choice is 0.90.</span></span></p>
|
||||
|
||||
<p class=MsoNormal style='margin-left:17.1pt;text-indent:-17.1pt'><span
|
||||
class=Typewch><span lang=EN-US>- eqw</span></span></p>
|
||||
|
@ -1,37 +0,0 @@
|
||||
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-2011, 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:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions 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.
|
@ -110,11 +110,11 @@ Once we find the corners, we can increase their accuracy using **cv2.cornerSubPi
|
||||
if ret == True:
|
||||
objpoints.append(objp)
|
||||
|
||||
corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
|
||||
imgpoints.append(corners2)
|
||||
cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
|
||||
imgpoints.append(corners)
|
||||
|
||||
# Draw and display the corners
|
||||
img = cv2.drawChessboardCorners(img, (7,6), corners2,ret)
|
||||
cv2.drawChessboardCorners(img, (7,6), corners2,ret)
|
||||
cv2.imshow('img',img)
|
||||
cv2.waitKey(500)
|
||||
|
||||
|
@ -33,21 +33,21 @@ To draw a line, you need to pass starting and ending coordinates of line. We wil
|
||||
img = np.zeros((512,512,3), np.uint8)
|
||||
|
||||
# Draw a diagonal blue line with thickness of 5 px
|
||||
img = cv2.line(img,(0,0),(511,511),(255,0,0),5)
|
||||
cv2.line(img,(0,0),(511,511),(255,0,0),5)
|
||||
|
||||
Drawing Rectangle
|
||||
-------------------
|
||||
To draw a rectangle, you need top-left corner and bottom-right corner of rectangle. This time we will draw a green rectangle at the top-right corner of image.
|
||||
::
|
||||
|
||||
img = cv2.rectangle(img,(384,0),(510,128),(0,255,0),3)
|
||||
cv2.rectangle(img,(384,0),(510,128),(0,255,0),3)
|
||||
|
||||
Drawing Circle
|
||||
----------------
|
||||
To draw a circle, you need its center coordinates and radius. We will draw a circle inside the rectangle drawn above.
|
||||
::
|
||||
|
||||
img = cv2.circle(img,(447,63), 63, (0,0,255), -1)
|
||||
cv2.circle(img,(447,63), 63, (0,0,255), -1)
|
||||
|
||||
Drawing Ellipse
|
||||
--------------------
|
||||
@ -55,7 +55,7 @@ Drawing Ellipse
|
||||
To draw the ellipse, we need to pass several arguments. One argument is the center location (x,y). Next argument is axes lengths (major axis length, minor axis length). ``angle`` is the angle of rotation of ellipse in anti-clockwise direction. ``startAngle`` and ``endAngle`` denotes the starting and ending of ellipse arc measured in clockwise direction from major axis. i.e. giving values 0 and 360 gives the full ellipse. For more details, check the documentation of **cv2.ellipse()**. Below example draws a half ellipse at the center of the image.
|
||||
::
|
||||
|
||||
img = cv2.ellipse(img,(256,256),(100,50),0,0,180,255,-1)
|
||||
cv2.ellipse(img,(256,256),(100,50),0,0,180,255,-1)
|
||||
|
||||
|
||||
Drawing Polygon
|
||||
@ -65,7 +65,7 @@ To draw a polygon, first you need coordinates of vertices. Make those points int
|
||||
|
||||
pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32)
|
||||
pts = pts.reshape((-1,1,2))
|
||||
img = cv2.polylines(img,[pts],True,(0,255,255))
|
||||
cv2.polylines(img,[pts],True,(0,255,255))
|
||||
|
||||
.. Note:: If third argument is ``False``, you will get a polylines joining all the points, not a closed shape.
|
||||
|
||||
@ -103,4 +103,4 @@ Additional Resources
|
||||
|
||||
Exercises
|
||||
==============
|
||||
#. Try to create the logo of OpenCV using drawing functions available in OpenCV
|
||||
#. Try to create the logo of OpenCV using drawing functions available in OpenCV.
|
||||
|
@ -59,6 +59,8 @@ A screenshot of the window will look like this (in Fedora-Gnome machine):
|
||||
|
||||
**cv2.waitKey()** is a keyboard binding function. Its argument is the time in milliseconds. The function waits for specified milliseconds for any keyboard event. If you press any key in that time, the program continues. If **0** is passed, it waits indefinitely for a key stroke. It can also be set to detect specific key strokes like, if key `a` is pressed etc which we will discuss below.
|
||||
|
||||
.. note:: Besides binding keyboard events this function also processes many other GUI events, so you MUST use it to actually display the image.
|
||||
|
||||
**cv2.destroyAllWindows()** simply destroys all the windows we created. If you want to destroy any specific window, use the function **cv2.destroyWindow()** where you pass the exact window name as the argument.
|
||||
|
||||
.. note:: There is a special case where you can already create a window and load image to it later. In that case, you can specify whether window is resizable or not. It is done with the function **cv2.namedWindow()**. By default, the flag is ``cv2.WINDOW_AUTOSIZE``. But if you specify flag to be ``cv2.WINDOW_NORMAL``, you can resize window. It will be helpful when image is too large in dimension and adding track bar to windows.
|
||||
|
@ -119,7 +119,7 @@ Let (x,y) be the top-left coordinate of the rectangle and (w,h) be its width and
|
||||
::
|
||||
|
||||
x,y,w,h = cv2.boundingRect(cnt)
|
||||
img = cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
|
||||
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
|
||||
|
||||
7.b. Rotated Rectangle
|
||||
-----------------------
|
||||
@ -129,7 +129,7 @@ Here, bounding rectangle is drawn with minimum area, so it considers the rotatio
|
||||
rect = cv2.minAreaRect(cnt)
|
||||
box = cv2.boxPoints(rect)
|
||||
box = np.int0(box)
|
||||
im = cv2.drawContours(im,[box],0,(0,0,255),2)
|
||||
cv2.drawContours(img,[box],0,(0,0,255),2)
|
||||
|
||||
Both the rectangles are shown in a single image. Green rectangle shows the normal bounding rect. Red rectangle is the rotated rect.
|
||||
|
||||
@ -145,7 +145,7 @@ Next we find the circumcircle of an object using the function **cv2.minEnclosing
|
||||
(x,y),radius = cv2.minEnclosingCircle(cnt)
|
||||
center = (int(x),int(y))
|
||||
radius = int(radius)
|
||||
img = cv2.circle(img,center,radius,(0,255,0),2)
|
||||
cv2.circle(img,center,radius,(0,255,0),2)
|
||||
|
||||
.. image:: images/circumcircle.png
|
||||
:alt: Minimum Enclosing Circle
|
||||
@ -158,7 +158,7 @@ Next one is to fit an ellipse to an object. It returns the rotated rectangle in
|
||||
::
|
||||
|
||||
ellipse = cv2.fitEllipse(cnt)
|
||||
im = cv2.ellipse(im,ellipse,(0,255,0),2)
|
||||
cv2.ellipse(img,ellipse,(0,255,0),2)
|
||||
|
||||
.. image:: images/fitellipse.png
|
||||
:alt: Fitting an Ellipse
|
||||
@ -175,7 +175,7 @@ Similarly we can fit a line to a set of points. Below image contains a set of wh
|
||||
[vx,vy,x,y] = cv2.fitLine(cnt, cv2.DIST_L2,0,0.01,0.01)
|
||||
lefty = int((-x*vy/vx) + y)
|
||||
righty = int(((cols-x)*vy/vx)+y)
|
||||
img = cv2.line(img,(cols-1,righty),(0,lefty),(0,255,0),2)
|
||||
cv2.line(img,(cols-1,righty),(0,lefty),(0,255,0),2)
|
||||
|
||||
.. image:: images/fitline.jpg
|
||||
:alt: Fitting a Line
|
||||
|
@ -28,9 +28,9 @@ Let's see how to find contours of a binary image:
|
||||
im = cv2.imread('test.jpg')
|
||||
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
|
||||
ret,thresh = cv2.threshold(imgray,127,255,0)
|
||||
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
|
||||
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
|
||||
|
||||
See, there are three arguments in **cv2.findContours()** function, first one is source image, second is contour retrieval mode, third is contour approximation method. And it outputs the image, contours and hierarchy. ``contours`` is a Python list of all the contours in the image. Each individual contour is a Numpy array of (x,y) coordinates of boundary points of the object.
|
||||
See, there are three arguments in **cv2.findContours()** function, first one is source image, second is contour retrieval mode, third is contour approximation method. And it outputs the contours and hierarchy. ``contours`` is a Python list of all the contours in the image. Each individual contour is a Numpy array of (x,y) coordinates of boundary points of the object.
|
||||
|
||||
.. note:: We will discuss second and third arguments and about hierarchy in details later. Until then, the values given to them in code sample will work fine for all images.
|
||||
|
||||
@ -43,18 +43,18 @@ To draw the contours, ``cv2.drawContours`` function is used. It can also be used
|
||||
To draw all the contours in an image:
|
||||
::
|
||||
|
||||
img = cv2.drawContour(img, contours, -1, (0,255,0), 3)
|
||||
cv2.drawContours(img, contours, -1, (0,255,0), 3)
|
||||
|
||||
To draw an individual contour, say 4th contour:
|
||||
::
|
||||
|
||||
img = cv2.drawContours(img, contours, 3, (0,255,0), 3)
|
||||
cv2.drawContours(img, contours, 3, (0,255,0), 3)
|
||||
|
||||
But most of the time, below method will be useful:
|
||||
::
|
||||
|
||||
cnt = contours[4]
|
||||
img = cv2.drawContours(img, [cnt], 0, (0,255,0), 3)
|
||||
cv2.drawContours(img, [cnt], 0, (0,255,0), 3)
|
||||
|
||||
.. note:: Last two methods are same, but when you go forward, you will see last one is more useful.
|
||||
|
||||
|
@ -73,7 +73,7 @@ Now we find the faces in the image. If faces are found, it returns the positions
|
||||
|
||||
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
||||
for (x,y,w,h) in faces:
|
||||
img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
|
||||
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
|
||||
roi_gray = gray[y:y+h, x:x+w]
|
||||
roi_color = img[y:y+h, x:x+w]
|
||||
eyes = eye_cascade.detectMultiScale(roi_gray)
|
||||
|
Before Width: | Height: | Size: 147 KiB |
Before Width: | Height: | Size: 163 KiB |
Before Width: | Height: | Size: 78 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 68 KiB |
@ -1,418 +0,0 @@
|
||||
.. _Retina_Model:
|
||||
|
||||
Discovering the human retina and its use for image processing
|
||||
*************************************************************
|
||||
|
||||
Goal
|
||||
=====
|
||||
|
||||
I present here a model of human retina that shows some interesting properties for image preprocessing and enhancement.
|
||||
In this tutorial you will learn how to:
|
||||
|
||||
.. container:: enumeratevisibleitemswithsquare
|
||||
|
||||
+ discover the main two channels outing from your retina
|
||||
|
||||
+ see the basics to use the retina model
|
||||
|
||||
+ discover some parameters tweaks
|
||||
|
||||
|
||||
General overview
|
||||
================
|
||||
|
||||
The proposed model originates from Jeanny Herault's research [herault2010]_ at `Gipsa <http://www.gipsa-lab.inpg.fr>`_. It is involved in image processing applications with `Listic <http://www.listic.univ-savoie.fr>`_ (code maintainer and user) lab. This is not a complete model but it already present interesting properties that can be involved for enhanced image processing experience. The model allows the following human retina properties to be used :
|
||||
|
||||
* spectral whitening that has 3 important effects: high spatio-temporal frequency signals canceling (noise), mid-frequencies details enhancement and low frequencies luminance energy reduction. This *all in one* property directly allows visual signals cleaning of classical undesired distortions introduced by image sensors and input luminance range.
|
||||
|
||||
* local logarithmic luminance compression allows details to be enhanced even in low light conditions.
|
||||
|
||||
* decorrelation of the details information (Parvocellular output channel) and transient information (events, motion made available at the Magnocellular output channel).
|
||||
|
||||
The first two points are illustrated below :
|
||||
|
||||
In the figure below, the OpenEXR image sample *CrissyField.exr*, a High Dynamic Range image is shown. In order to make it visible on this web-page, the original input image is linearly rescaled to the classical image luminance range [0-255] and is converted to 8bit/channel format. Such strong conversion hides many details because of too strong local contrasts. Furthermore, noise energy is also strong and pollutes visual information.
|
||||
|
||||
.. image:: images/retina_TreeHdr_small.jpg
|
||||
:alt: A High dynamic range image linearly rescaled within range [0-255].
|
||||
:align: center
|
||||
|
||||
In the following image, applying the ideas proposed in [benoit2010]_, as your retina does, local luminance adaptation, spatial noise removal and spectral whitening work together and transmit accurate information on lower range 8bit data channels. On this picture, noise in significantly removed, local details hidden by strong luminance contrasts are enhanced. Output image keeps its naturalness and visual content is enhanced. Color processing is based on the color multiplexing/demultiplexing method proposed in [chaix2007]_.
|
||||
|
||||
.. image:: images/retina_TreeHdr_retina.jpg
|
||||
:alt: A High dynamic range image compressed within range [0-255] using the retina.
|
||||
:align: center
|
||||
|
||||
|
||||
*Note :* image sample can be downloaded from the `OpenEXR website <http://www.openexr.com>`_. Regarding this demonstration, before retina processing, input image has been linearly rescaled within 0-255 keeping its channels float format. 5% of its histogram ends has been cut (mostly removes wrong HDR pixels). Check out the sample *opencv/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp* for similar processing. The following demonstration will only consider classical 8bit/channel images.
|
||||
|
||||
The retina model output channels
|
||||
================================
|
||||
|
||||
The retina model presents two outputs that benefit from the above cited behaviors.
|
||||
|
||||
* The first one is called the Parvocellular channel. It is mainly active in the foveal retina area (high resolution central vision with color sensitive photo-receptors), its aim is to provide accurate color vision for visual details remaining static on the retina. On the other hand objects moving on the retina projection are blurred.
|
||||
|
||||
* The second well known channel is the Magnocellular channel. It is mainly active in the retina peripheral vision and send signals related to change events (motion, transient events, etc.). These outing signals also help visual system to focus/center retina on 'transient'/moving areas for more detailed analysis thus improving visual scene context and object classification.
|
||||
|
||||
**NOTE :** regarding the proposed model, contrary to the real retina, we apply these two channels on the entire input images using the same resolution. This allows enhanced visual details and motion information to be extracted on all the considered images... but remember, that these two channels are complementary. For example, if Magnocellular channel gives strong energy in an area, then, the Parvocellular channel is certainly blurred there since there is a transient event.
|
||||
|
||||
As an illustration, we apply in the following the retina model on a webcam video stream of a dark visual scene. In this visual scene, captured in an amphitheater of the university, some students are moving while talking to the teacher.
|
||||
|
||||
In this video sequence, because of the dark ambiance, signal to noise ratio is low and color artifacts are present on visual features edges because of the low quality image capture tool-chain.
|
||||
|
||||
.. image:: images/studentsSample_input.jpg
|
||||
:alt: an input video stream extract sample
|
||||
:align: center
|
||||
|
||||
Below is shown the retina foveal vision applied on the entire image. In the used retina configuration, global luminance is preserved and local contrasts are enhanced. Also, signal to noise ratio is improved : since high frequency spatio-temporal noise is reduced, enhanced details are not corrupted by any enhanced noise.
|
||||
|
||||
.. image:: images/studentsSample_parvo.jpg
|
||||
:alt: the retina Parvocellular output. Enhanced details, luminance adaptation and noise removal. A processing tool for image analysis.
|
||||
:align: center
|
||||
|
||||
Below is the output of the Magnocellular output of the retina model. Its signals are strong where transient events occur. Here, a student is moving at the bottom of the image thus generating high energy. The remaining of the image is static however, it is corrupted by a strong noise. Here, the retina filters out most of the noise thus generating low false motion area 'alarms'. This channel can be used as a transient/moving areas detector : it would provide relevant information for a low cost segmentation tool that would highlight areas in which an event is occurring.
|
||||
|
||||
.. image:: images/studentsSample_magno.jpg
|
||||
:alt: the retina Magnocellular output. Enhanced transient signals (motion, etc.). A preprocessing tool for event detection.
|
||||
:align: center
|
||||
|
||||
Retina use case
|
||||
===============
|
||||
|
||||
This model can be used basically for spatio-temporal video effects but also in the aim of :
|
||||
|
||||
* performing texture analysis with enhanced signal to noise ratio and enhanced details robust against input images luminance ranges (check out the Parvocellular retina channel output)
|
||||
|
||||
* performing motion analysis also taking benefit of the previously cited properties.
|
||||
|
||||
Literature
|
||||
==========
|
||||
For more information, refer to the following papers :
|
||||
|
||||
.. [benoit2010] Benoit A., Caplier A., Durette B., Herault, J., "Using Human Visual System Modeling For Bio-Inspired Low Level Image Processing", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773. DOI <http://dx.doi.org/10.1016/j.cviu.2010.01.011>
|
||||
|
||||
* Please have a look at the reference work of Jeanny Herault that you can read in his book :
|
||||
|
||||
.. [herault2010] Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
|
||||
This retina filter code includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
|
||||
* take a look at the *retinacolor.hpp* module to discover Brice Chaix de Lavarene phD color mosaicing/demosaicing and his reference paper:
|
||||
|
||||
.. [chaix2007] B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
|
||||
* take a look at *imagelogpolprojection.hpp* to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions. More informations in the above cited Jeanny Heraults's book.
|
||||
|
||||
Code tutorial
|
||||
=============
|
||||
|
||||
Please refer to the original tutorial source code in file *opencv_folder/samples/cpp/tutorial_code/bioinspired/retina_tutorial.cpp*.
|
||||
|
||||
**Note :** do not forget that the retina model is included in the following namespace : *cv::bioinspired*.
|
||||
|
||||
To compile it, assuming OpenCV is correctly installed, use the following command. It requires the opencv_core *(cv::Mat and friends objects management)*, opencv_highgui *(display and image/video read)* and opencv_bioinspired *(Retina description)* libraries to compile.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
// compile
|
||||
gcc retina_tutorial.cpp -o Retina_tuto -lopencv_core -lopencv_highgui -lopencv_bioinspired
|
||||
|
||||
// Run commands : add 'log' as a last parameter to apply a spatial log sampling (simulates retina sampling)
|
||||
// run on webcam
|
||||
./Retina_tuto -video
|
||||
// run on video file
|
||||
./Retina_tuto -video myVideo.avi
|
||||
// run on an image
|
||||
./Retina_tuto -image myPicture.jpg
|
||||
// run on an image with log sampling
|
||||
./Retina_tuto -image myPicture.jpg log
|
||||
|
||||
Here is a code explanation :
|
||||
|
||||
Retina definition is present in the bioinspired package and a simple include allows to use it. You can rather use the specific header : *opencv2/bioinspired.hpp* if you prefer but then include the other required openv modules : *opencv2/core.hpp* and *opencv2/highgui.hpp*
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
|
||||
Provide user some hints to run the program with a help function
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
// the help procedure
|
||||
static void help(std::string errorMessage)
|
||||
{
|
||||
std::cout<<"Program init error : "<<errorMessage<<std::endl;
|
||||
std::cout<<"\nProgram call procedure : retinaDemo [processing mode] [Optional : media target] [Optional LAST parameter: \"log\" to activate retina log sampling]"<<std::endl;
|
||||
std::cout<<"\t[processing mode] :"<<std::endl;
|
||||
std::cout<<"\t -image : for still image processing"<<std::endl;
|
||||
std::cout<<"\t -video : for video stream processing"<<std::endl;
|
||||
std::cout<<"\t[Optional : media target] :"<<std::endl;
|
||||
std::cout<<"\t if processing an image or video file, then, specify the path and filename of the target to process"<<std::endl;
|
||||
std::cout<<"\t leave empty if processing video stream coming from a connected video device"<<std::endl;
|
||||
std::cout<<"\t[Optional : activate retina log sampling] : an optional last parameter can be specified for retina spatial log sampling"<<std::endl;
|
||||
std::cout<<"\t set \"log\" without quotes to activate this sampling, output frame size will be divided by 4"<<std::endl;
|
||||
std::cout<<"\nExamples:"<<std::endl;
|
||||
std::cout<<"\t-Image processing : ./retinaDemo -image lena.jpg"<<std::endl;
|
||||
std::cout<<"\t-Image processing with log sampling : ./retinaDemo -image lena.jpg log"<<std::endl;
|
||||
std::cout<<"\t-Video processing : ./retinaDemo -video myMovie.mp4"<<std::endl;
|
||||
std::cout<<"\t-Live video processing : ./retinaDemo -video"<<std::endl;
|
||||
std::cout<<"\nPlease start again with new parameters"<<std::endl;
|
||||
std::cout<<"****************************************************"<<std::endl;
|
||||
std::cout<<" NOTE : this program generates the default retina parameters file 'RetinaDefaultParameters.xml'"<<std::endl;
|
||||
std::cout<<" => you can use this to fine tune parameters and load them if you save to file 'RetinaSpecificParameters.xml'"<<std::endl;
|
||||
}
|
||||
|
||||
Then, start the main program and first declare a *cv::Mat* matrix in which input images will be loaded. Also allocate a *cv::VideoCapture* object ready to load video streams (if necessary)
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// declare the retina input buffer... that will be fed differently in regard of the input media
|
||||
cv::Mat inputFrame;
|
||||
cv::VideoCapture videoCapture; // in case a video media is used, its manager is declared here
|
||||
|
||||
|
||||
In the main program, before processing, first check input command parameters. Here it loads a first input image coming from a single loaded image (if user chose command *-image*) or from a video stream (if user chose command *-video*). Also, if the user added *log* command at the end of its program call, the spatial logarithmic image sampling performed by the retina is taken into account by the Boolean flag *useLogSampling*.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
// welcome message
|
||||
std::cout<<"****************************************************"<<std::endl;
|
||||
std::cout<<"* Retina demonstration : demonstrates the use of is a wrapper class of the Gipsa/Listic Labs retina model."<<std::endl;
|
||||
std::cout<<"* This demo will try to load the file 'RetinaSpecificParameters.xml' (if exists).\nTo create it, copy the autogenerated template 'RetinaDefaultParameters.xml'.\nThen twaek it with your own retina parameters."<<std::endl;
|
||||
// basic input arguments checking
|
||||
if (argc<2)
|
||||
{
|
||||
help("bad number of parameter");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool useLogSampling = !strcmp(argv[argc-1], "log"); // check if user wants retina log sampling processing
|
||||
|
||||
std::string inputMediaType=argv[1];
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// checking input media type (still image, video file, live video acquisition)
|
||||
if (!strcmp(inputMediaType.c_str(), "-image") && argc >= 3)
|
||||
{
|
||||
std::cout<<"RetinaDemo: processing image "<<argv[2]<<std::endl;
|
||||
// image processing case
|
||||
inputFrame = cv::imread(std::string(argv[2]), 1); // load image in RGB mode
|
||||
}else
|
||||
if (!strcmp(inputMediaType.c_str(), "-video"))
|
||||
{
|
||||
if (argc == 2 || (argc == 3 && useLogSampling)) // attempt to grab images from a video capture device
|
||||
{
|
||||
videoCapture.open(0);
|
||||
}else// attempt to grab images from a video filestream
|
||||
{
|
||||
std::cout<<"RetinaDemo: processing video stream "<<argv[2]<<std::endl;
|
||||
videoCapture.open(argv[2]);
|
||||
}
|
||||
|
||||
// grab a first frame to check if everything is ok
|
||||
videoCapture>>inputFrame;
|
||||
}else
|
||||
{
|
||||
// bad command parameter
|
||||
help("bad command parameter");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Once all input parameters are processed, a first image should have been loaded, if not, display error and stop program :
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
if (inputFrame.empty())
|
||||
{
|
||||
help("Input media could not be loaded, aborting");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Now, everything is ready to run the retina model. I propose here to allocate a retina instance and to manage the eventual log sampling option. The Retina constructor expects at least a cv::Size object that shows the input data size that will have to be managed. One can activate other options such as color and its related color multiplexing strategy (here Bayer multiplexing is chosen using *enum cv::bioinspired::RETINA_COLOR_BAYER*). If using log sampling, the image reduction factor (smaller output images) and log sampling strengh can be adjusted.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
// pointer to a retina object
|
||||
cv::Ptr<cv::bioinspired::Retina> myRetina;
|
||||
|
||||
// if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision)
|
||||
if (useLogSampling)
|
||||
{
|
||||
myRetina = cv::bioinspired::createRetina(inputFrame.size(), true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
}
|
||||
else// -> else allocate "classical" retina :
|
||||
myRetina = cv::bioinspired::createRetina(inputFrame.size());
|
||||
|
||||
Once done, the proposed code writes a default xml file that contains the default parameters of the retina. This is useful to make your own config using this template. Here generated template xml file is called *RetinaDefaultParameters.xml*.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
// save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup"
|
||||
myRetina->write("RetinaDefaultParameters.xml");
|
||||
|
||||
In the following line, the retina attempts to load another xml file called *RetinaSpecificParameters.xml*. If you created it and introduced your own setup, it will be loaded, in the other case, default retina parameters are used.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
// load parameters if file exists
|
||||
myRetina->setup("RetinaSpecificParameters.xml");
|
||||
|
||||
It is not required here but just to show it is possible, you can reset the retina buffers to zero to force it to forget past events.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
// reset all retina buffers (imagine you close your eyes for a long time)
|
||||
myRetina->clearBuffers();
|
||||
|
||||
Now, it is time to run the retina ! First create some output buffers ready to receive the two retina channels outputs
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
// declare retina output buffers
|
||||
cv::Mat retinaOutput_parvo;
|
||||
cv::Mat retinaOutput_magno;
|
||||
|
||||
Then, run retina in a loop, load new frames from video sequence if necessary and get retina outputs back to dedicated buffers.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
// processing loop with no stop condition
|
||||
while(true)
|
||||
{
|
||||
// if using video stream, then, grabbing a new frame, else, input remains the same
|
||||
if (videoCapture.isOpened())
|
||||
videoCapture>>inputFrame;
|
||||
|
||||
// run retina filter on the loaded input frame
|
||||
myRetina->run(inputFrame);
|
||||
// Retrieve and display retina output
|
||||
myRetina->getParvo(retinaOutput_parvo);
|
||||
myRetina->getMagno(retinaOutput_magno);
|
||||
cv::imshow("retina input", inputFrame);
|
||||
cv::imshow("Retina Parvo", retinaOutput_parvo);
|
||||
cv::imshow("Retina Magno", retinaOutput_magno);
|
||||
cv::waitKey(10);
|
||||
}
|
||||
|
||||
That's done ! But if you want to secure the system, take care and manage Exceptions. The retina can throw some when it sees irrelevant data (no input frame, wrong setup, etc.).
|
||||
Then, i recommend to surround all the retina code by a try/catch system like this :
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
try{
|
||||
// pointer to a retina object
|
||||
cv::Ptr<cv::Retina> myRetina;
|
||||
[---]
|
||||
// processing loop with no stop condition
|
||||
while(true)
|
||||
{
|
||||
[---]
|
||||
}
|
||||
|
||||
}catch(cv::Exception e)
|
||||
{
|
||||
std::cerr<<"Error using Retina : "<<e.what()<<std::endl;
|
||||
}
|
||||
|
||||
Retina parameters, what to do ?
|
||||
===============================
|
||||
|
||||
First, it is recommended to read the reference paper :
|
||||
|
||||
* Benoit A., Caplier A., Durette B., Herault, J., *"Using Human Visual System Modeling For Bio-Inspired Low Level Image Processing"*, Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773. DOI <http://dx.doi.org/10.1016/j.cviu.2010.01.011>
|
||||
|
||||
Once done open the configuration file *RetinaDefaultParameters.xml* generated by the demo and let's have a look at it.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
<?xml version="1.0"?>
|
||||
<opencv_storage>
|
||||
<OPLandIPLparvo>
|
||||
<colorMode>1</colorMode>
|
||||
<normaliseOutput>1</normaliseOutput>
|
||||
<photoreceptorsLocalAdaptationSensitivity>7.5e-01</photoreceptorsLocalAdaptationSensitivity>
|
||||
<photoreceptorsTemporalConstant>9.0e-01</photoreceptorsTemporalConstant>
|
||||
<photoreceptorsSpatialConstant>5.7e-01</photoreceptorsSpatialConstant>
|
||||
<horizontalCellsGain>0.01</horizontalCellsGain>
|
||||
<hcellsTemporalConstant>0.5</hcellsTemporalConstant>
|
||||
<hcellsSpatialConstant>7.</hcellsSpatialConstant>
|
||||
<ganglionCellsSensitivity>7.5e-01</ganglionCellsSensitivity></OPLandIPLparvo>
|
||||
<IPLmagno>
|
||||
<normaliseOutput>1</normaliseOutput>
|
||||
<parasolCells_beta>0.</parasolCells_beta>
|
||||
<parasolCells_tau>0.</parasolCells_tau>
|
||||
<parasolCells_k>7.</parasolCells_k>
|
||||
<amacrinCellsTemporalCutFrequency>2.0e+00</amacrinCellsTemporalCutFrequency>
|
||||
<V0CompressionParameter>9.5e-01</V0CompressionParameter>
|
||||
<localAdaptintegration_tau>0.</localAdaptintegration_tau>
|
||||
<localAdaptintegration_k>7.</localAdaptintegration_k></IPLmagno>
|
||||
</opencv_storage>
|
||||
|
||||
Here are some hints but actually, the best parameter setup depends more on what you want to do with the retina rather than the images input that you give to retina. Apart from the more specific case of High Dynamic Range images (HDR) that require more specific setup for specific luminance compression objective, the retina behaviors should be rather stable from content to content. Note that OpenCV is able to manage such HDR format thanks to the OpenEXR images compatibility.
|
||||
|
||||
Then, if the application target requires details enhancement prior to specific image processing, you need to know if mean luminance information is required or not. If not, the the retina can cancel or significantly reduce its energy thus giving more visibility to higher spatial frequency details.
|
||||
|
||||
|
||||
Basic parameters
|
||||
----------------
|
||||
|
||||
The most simple parameters are the following :
|
||||
|
||||
* **colorMode** : let the retina process color information (if 1) or gray scale images (if 0). In this last case, only the first channel of the input will be processed.
|
||||
|
||||
* **normaliseOutput** : each channel has this parameter, if value is 1, then the considered channel output is rescaled between 0 and 255. Take care in this case at the Magnocellular output level (motion/transient channel detection). Residual noise will also be rescaled !
|
||||
|
||||
**Note :** using color requires color channels multiplexing/demultipexing which requires more processing. You can expect much faster processing using gray levels : it would require around 30 product per pixel for all the retina processes and it has recently been parallelized for multicore architectures.
|
||||
|
||||
Photo-receptors parameters
|
||||
--------------------------
|
||||
|
||||
The following parameters act on the entry point of the retina - photo-receptors - and impact all the following processes. These sensors are low pass spatio-temporal filters that smooth temporal and spatial data and also adjust there sensitivity to local luminance thus improving details extraction and high frequency noise canceling.
|
||||
|
||||
* **photoreceptorsLocalAdaptationSensitivity** between 0 and 1. Values close to 1 allow high luminance log compression effect at the photo-receptors level. Values closer to 0 give a more linear sensitivity. Increased alone, it can burn the *Parvo (details channel)* output image. If adjusted in collaboration with **ganglionCellsSensitivity** images can be very contrasted whatever the local luminance there is... at the price of a naturalness decrease.
|
||||
|
||||
* **photoreceptorsTemporalConstant** this setups the temporal constant of the low pass filter effect at the entry of the retina. High value lead to strong temporal smoothing effect : moving objects are blurred and can disappear while static object are favored. But when starting the retina processing, stable state is reached lately.
|
||||
|
||||
* **photoreceptorsSpatialConstant** specifies the spatial constant related to photo-receptors low pass filter effect. This parameters specify the minimum allowed spatial signal period allowed in the following. Typically, this filter should cut high frequency noise. Then a 0 value doesn't cut anything noise while higher values start to cut high spatial frequencies and more and more lower frequencies... Then, do not go to high if you wanna see some details of the input images ! A good compromise for color images is 0.53 since this won't affect too much the color spectrum. Higher values would lead to gray and blurred output images.
|
||||
|
||||
Horizontal cells parameters
|
||||
---------------------------
|
||||
|
||||
This parameter set tunes the neural network connected to the photo-receptors, the horizontal cells. It modulates photo-receptors sensitivity and completes the processing for final spectral whitening (part of the spatial band pass effect thus favoring visual details enhancement).
|
||||
|
||||
* **horizontalCellsGain** here is a critical parameter ! If you are not interested by the mean luminance and focus on details enhancement, then, set to zero. But if you want to keep some environment luminance data, let some low spatial frequencies pass into the system and set a higher value (<1).
|
||||
|
||||
* **hcellsTemporalConstant** similar to photo-receptors, this acts on the temporal constant of a low pass temporal filter that smooths input data. Here, a high value generates a high retina after effect while a lower value makes the retina more reactive. This value should be lower than **photoreceptorsTemporalConstant** to limit strong retina after effects.
|
||||
|
||||
* **hcellsSpatialConstant** is the spatial constant of the low pass filter of these cells filter. It specifies the lowest spatial frequency allowed in the following. Visually, a high value leads to very low spatial frequencies processing and leads to salient halo effects. Lower values reduce this effect but the limit is : do not go lower than the value of **photoreceptorsSpatialConstant**. Those 2 parameters actually specify the spatial band-pass of the retina.
|
||||
|
||||
**NOTE** after the processing managed by the previous parameters, input data is cleaned from noise and luminance in already partly enhanced. The following parameters act on the last processing stages of the two outing retina signals.
|
||||
|
||||
Parvo (details channel) dedicated parameter
|
||||
-------------------------------------------
|
||||
|
||||
* **ganglionCellsSensitivity** specifies the strength of the final local adaptation occurring at the output of this details dedicated channel. Parameter values remain between 0 and 1. Low value tend to give a linear response while higher values enforces the remaining low contrasted areas.
|
||||
|
||||
**Note :** this parameter can correct eventual burned images by favoring low energetic details of the visual scene, even in bright areas.
|
||||
|
||||
IPL Magno (motion/transient channel) parameters
|
||||
-----------------------------------------------
|
||||
|
||||
Once image information is cleaned, this channel acts as a high pass temporal filter that only selects signals related to transient signals (events, motion, etc.). A low pass spatial filter smooths extracted transient data and a final logarithmic compression enhances low transient events thus enhancing event sensitivity.
|
||||
|
||||
* **parasolCells_beta** generally set to zero, can be considered as an amplifier gain at the entry point of this processing stage. Generally set to 0.
|
||||
|
||||
* **parasolCells_tau** the temporal smoothing effect that can be added
|
||||
|
||||
* **parasolCells_k** the spatial constant of the spatial filtering effect, set it at a high value to favor low spatial frequency signals that are lower subject to residual noise.
|
||||
|
||||
* **amacrinCellsTemporalCutFrequency** specifies the temporal constant of the high pass filter. High values let slow transient events to be selected.
|
||||
|
||||
* **V0CompressionParameter** specifies the strength of the log compression. Similar behaviors to previous description but here it enforces sensitivity of transient events.
|
||||
|
||||
* **localAdaptintegration_tau** generally set to 0, no real use here actually
|
||||
|
||||
* **localAdaptintegration_k** specifies the size of the area on which local adaptation is performed. Low values lead to short range local adaptation (higher sensitivity to noise), high values secure log compression.
|
Before Width: | Height: | Size: 49 KiB |
@ -1,36 +0,0 @@
|
||||
.. _Table-Of-Content-Bioinspired:
|
||||
|
||||
*bioinspired* module. Algorithms inspired from biological models
|
||||
----------------------------------------------------------------
|
||||
|
||||
Here you will learn how to use additional modules of OpenCV defined in the "bioinspired" module.
|
||||
|
||||
.. include:: ../../definitions/tocDefinitions.rst
|
||||
|
||||
+
|
||||
.. tabularcolumns:: m{100pt} m{300pt}
|
||||
.. cssclass:: toctableopencv
|
||||
|
||||
=============== ======================================================
|
||||
|RetinaDemoImg| **Title:** :ref:`Retina_Model`
|
||||
|
||||
*Compatibility:* > OpenCV 2.4
|
||||
|
||||
*Author:* |Author_AlexB|
|
||||
|
||||
You will learn how to process images and video streams with a model of retina filter for details enhancement, spatio-temporal noise removal, luminance correction and spatio-temporal events detection.
|
||||
|
||||
=============== ======================================================
|
||||
|
||||
.. |RetinaDemoImg| image:: images/retina_TreeHdr_small.jpg
|
||||
:height: 90pt
|
||||
:width: 90pt
|
||||
|
||||
.. raw:: latex
|
||||
|
||||
\pagebreak
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
../retina_model/retina_model
|
@ -1,36 +0,0 @@
|
||||
.. _Table-Of-Content-Contrib:
|
||||
|
||||
*contrib* module. The additional contributions made available !
|
||||
----------------------------------------------------------------
|
||||
|
||||
Here you will learn how to use additional modules of OpenCV defined in the "contrib" module.
|
||||
|
||||
.. include:: ../../definitions/tocDefinitions.rst
|
||||
|
||||
+
|
||||
.. tabularcolumns:: m{100pt} m{300pt}
|
||||
.. cssclass:: toctableopencv
|
||||
|
||||
=============== ======================================================
|
||||
|RetinaDemoImg| **Title:** :ref:`Retina_Model`
|
||||
|
||||
*Compatibility:* > OpenCV 2.4
|
||||
|
||||
*Author:* |Author_AlexB|
|
||||
|
||||
You will learn how to process images and video streams with a model of retina filter for details enhancement, spatio-temporal noise removal, luminance correction and spatio-temporal events detection.
|
||||
|
||||
=============== ======================================================
|
||||
|
||||
.. |RetinaDemoImg| image:: images/retina_TreeHdr_small.jpg
|
||||
:height: 90pt
|
||||
:width: 90pt
|
||||
|
||||
.. raw:: latex
|
||||
|
||||
\pagebreak
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
../retina_model/retina_model
|
@ -85,7 +85,7 @@ d. **method=CV\_TM\_CCORR\_NORMED**
|
||||
|
||||
.. math::
|
||||
|
||||
R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I'(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}
|
||||
R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}
|
||||
|
||||
|
||||
e. **method=CV\_TM\_CCOEFF**
|
||||
|
@ -22,13 +22,13 @@ Hough Circle Transform
|
||||
|
||||
C : ( x_{center}, y_{center}, r )
|
||||
|
||||
where :math:`(x_{center}, y_{center})` define the center position (gree point) and :math:`r` is the radius, which allows us to completely define a circle, as it can be seen below:
|
||||
where :math:`(x_{center}, y_{center})` define the center position (green point) and :math:`r` is the radius, which allows us to completely define a circle, as it can be seen below:
|
||||
|
||||
.. image:: images/Hough_Circle_Tutorial_Theory_0.jpg
|
||||
:alt: Result of detecting circles with Hough Transform
|
||||
:align: center
|
||||
|
||||
* For sake of efficiency, OpenCV implements a detection method slightly trickier than the standard Hough Transform: *The Hough gradient method*. For more details, please check the book *Learning OpenCV* or your favorite Computer Vision bibliography
|
||||
* For sake of efficiency, OpenCV implements a detection method slightly trickier than the standard Hough Transform: *The Hough gradient method*, which is made up of two main stages. The first stage involves edge detection and finding the possible circle centers and the second stage finds the best radius for each candidate center. For more details, please check the book *Learning OpenCV* or your favorite Computer Vision bibliography
|
||||
|
||||
Code
|
||||
======
|
||||
@ -44,7 +44,7 @@ Code
|
||||
.. |TutorialHoughCirclesFancyDownload| replace:: here
|
||||
.. _TutorialHoughCirclesFancyDownload: https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp
|
||||
|
||||
#. The sample code that we will explain can be downloaded from |TutorialHoughCirclesSimpleDownload|_. A slightly fancier version (which shows both Hough standard and probabilistic with trackbars for changing the threshold values) can be found |TutorialHoughCirclesFancyDownload|_.
|
||||
#. The sample code that we will explain can be downloaded from |TutorialHoughCirclesSimpleDownload|_. A slightly fancier version (which shows trackbars for changing the threshold values) can be found |TutorialHoughCirclesFancyDownload|_.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
@ -132,15 +132,15 @@ Explanation
|
||||
|
||||
with the arguments:
|
||||
|
||||
* *src_gray*: Input image (grayscale)
|
||||
* *src_gray*: Input image (grayscale).
|
||||
* *circles*: A vector that stores sets of 3 values: :math:`x_{c}, y_{c}, r` for each detected circle.
|
||||
* *CV_HOUGH_GRADIENT*: Define the detection method. Currently this is the only one available in OpenCV
|
||||
* *dp = 1*: The inverse ratio of resolution
|
||||
* *min_dist = src_gray.rows/8*: Minimum distance between detected centers
|
||||
* *param_1 = 200*: Upper threshold for the internal Canny edge detector
|
||||
* *CV_HOUGH_GRADIENT*: Define the detection method. Currently this is the only one available in OpenCV.
|
||||
* *dp = 1*: The inverse ratio of resolution.
|
||||
* *min_dist = src_gray.rows/8*: Minimum distance between detected centers.
|
||||
* *param_1 = 200*: Upper threshold for the internal Canny edge detector.
|
||||
* *param_2* = 100*: Threshold for center detection.
|
||||
* *min_radius = 0*: Minimum radio to be detected. If unknown, put zero as default.
|
||||
* *max_radius = 0*: Maximum radius to be detected. If unknown, put zero as default
|
||||
* *max_radius = 0*: Maximum radius to be detected. If unknown, put zero as default.
|
||||
|
||||
#. Draw the detected circles:
|
||||
|
||||
|
@ -48,10 +48,10 @@ The structure of package contents looks as follows:
|
||||
|
||||
::
|
||||
|
||||
OpenCV-2.4.7-android-sdk
|
||||
OpenCV-2.4.8-android-sdk
|
||||
|_ apk
|
||||
| |_ OpenCV_2.4.7_binary_pack_armv7a.apk
|
||||
| |_ OpenCV_2.4.7_Manager_2.14_XXX.apk
|
||||
| |_ OpenCV_2.4.8_binary_pack_armv7a.apk
|
||||
| |_ OpenCV_2.4.8_Manager_2.16_XXX.apk
|
||||
|
|
||||
|_ doc
|
||||
|_ samples
|
||||
@ -66,7 +66,7 @@ The structure of package contents looks as follows:
|
||||
| |_ armeabi-v7a
|
||||
| |_ x86
|
||||
|
|
||||
|_ license.txt
|
||||
|_ LICENSE
|
||||
|_ README.android
|
||||
|
||||
* :file:`sdk` folder contains OpenCV API and libraries for Android:
|
||||
@ -157,10 +157,10 @@ Get the OpenCV4Android SDK
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
unzip ~/Downloads/OpenCV-2.4.7-android-sdk.zip
|
||||
unzip ~/Downloads/OpenCV-2.4.8-android-sdk.zip
|
||||
|
||||
.. |opencv_android_bin_pack| replace:: :file:`OpenCV-2.4.7-android-sdk.zip`
|
||||
.. _opencv_android_bin_pack_url: http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.7/OpenCV-2.4.7-android-sdk.zip/download
|
||||
.. |opencv_android_bin_pack| replace:: :file:`OpenCV-2.4.8-android-sdk.zip`
|
||||
.. _opencv_android_bin_pack_url: http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.8/OpenCV-2.4.8-android-sdk.zip/download
|
||||
.. |opencv_android_bin_pack_url| replace:: |opencv_android_bin_pack|
|
||||
.. |seven_zip| replace:: 7-Zip
|
||||
.. _seven_zip: http://www.7-zip.org/
|
||||
@ -295,7 +295,7 @@ Well, running samples from Eclipse is very simple:
|
||||
.. code-block:: sh
|
||||
:linenos:
|
||||
|
||||
<Android SDK path>/platform-tools/adb install <OpenCV4Android SDK path>/apk/OpenCV_2.4.7_Manager_2.14_armv7a-neon.apk
|
||||
<Android SDK path>/platform-tools/adb install <OpenCV4Android SDK path>/apk/OpenCV_2.4.8_Manager_2.16_armv7a-neon.apk
|
||||
|
||||
.. note:: ``armeabi``, ``armv7a-neon``, ``arm7a-neon-android8``, ``mips`` and ``x86`` stand for
|
||||
platform targets:
|
||||
|
@ -55,14 +55,14 @@ Manager to access OpenCV libraries externally installed in the target system.
|
||||
:guilabel:`File -> Import -> Existing project in your workspace`.
|
||||
|
||||
Press :guilabel:`Browse` button and locate OpenCV4Android SDK
|
||||
(:file:`OpenCV-2.4.7-android-sdk/sdk`).
|
||||
(:file:`OpenCV-2.4.8-android-sdk/sdk`).
|
||||
|
||||
.. image:: images/eclipse_opencv_dependency0.png
|
||||
:alt: Add dependency from OpenCV library
|
||||
:align: center
|
||||
|
||||
#. In application project add a reference to the OpenCV Java SDK in
|
||||
:guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.7``.
|
||||
:guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8``.
|
||||
|
||||
.. image:: images/eclipse_opencv_dependency1.png
|
||||
:alt: Add dependency from OpenCV library
|
||||
@ -128,27 +128,27 @@ described above.
|
||||
#. Add the OpenCV library project to your workspace the same way as for the async initialization
|
||||
above. Use menu :guilabel:`File -> Import -> Existing project in your workspace`,
|
||||
press :guilabel:`Browse` button and select OpenCV SDK path
|
||||
(:file:`OpenCV-2.4.7-android-sdk/sdk`).
|
||||
(:file:`OpenCV-2.4.8-android-sdk/sdk`).
|
||||
|
||||
.. image:: images/eclipse_opencv_dependency0.png
|
||||
:alt: Add dependency from OpenCV library
|
||||
:align: center
|
||||
|
||||
#. In the application project add a reference to the OpenCV4Android SDK in
|
||||
:guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.7``;
|
||||
:guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8``;
|
||||
|
||||
.. image:: images/eclipse_opencv_dependency1.png
|
||||
:alt: Add dependency from OpenCV library
|
||||
:align: center
|
||||
|
||||
#. If your application project **doesn't have a JNI part**, just copy the corresponding OpenCV
|
||||
native libs from :file:`<OpenCV-2.4.7-android-sdk>/sdk/native/libs/<target_arch>` to your
|
||||
native libs from :file:`<OpenCV-2.4.8-android-sdk>/sdk/native/libs/<target_arch>` to your
|
||||
project directory to folder :file:`libs/<target_arch>`.
|
||||
|
||||
In case of the application project **with a JNI part**, instead of manual libraries copying you
|
||||
need to modify your ``Android.mk`` file:
|
||||
add the following two code lines after the ``"include $(CLEAR_VARS)"`` and before
|
||||
``"include path_to_OpenCV-2.4.7-android-sdk/sdk/native/jni/OpenCV.mk"``
|
||||
``"include path_to_OpenCV-2.4.8-android-sdk/sdk/native/jni/OpenCV.mk"``
|
||||
|
||||
.. code-block:: make
|
||||
:linenos:
|
||||
@ -221,7 +221,7 @@ taken:
|
||||
|
||||
.. code-block:: make
|
||||
|
||||
include C:\Work\OpenCV4Android\OpenCV-2.4.7-android-sdk\sdk\native\jni\OpenCV.mk
|
||||
include C:\Work\OpenCV4Android\OpenCV-2.4.8-android-sdk\sdk\native\jni\OpenCV.mk
|
||||
|
||||
Should be inserted into the :file:`jni/Android.mk` file **after** this line:
|
||||
|
||||
@ -382,7 +382,7 @@ result.
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback);
|
||||
}
|
||||
|
||||
#. Defines that your activity implements ``CvViewFrameListener2`` interface and fix activity related
|
||||
#. Defines that your activity implements ``CvCameraViewListener2`` interface and fix activity related
|
||||
errors by defining missed methods. For this activity define ``onCreate``, ``onDestroy`` and
|
||||
``onPause`` and implement them according code snippet bellow. Fix errors by adding requited
|
||||
imports.
|
||||
@ -432,7 +432,7 @@ result.
|
||||
Lets discuss some most important steps. Every Android application with UI must implement Activity
|
||||
and View. By the first steps we create blank activity and default view layout. The simplest
|
||||
OpenCV-centric application must implement OpenCV initialization, create its own view to show
|
||||
preview from camera and implements ``CvViewFrameListener2`` interface to get frames from camera and
|
||||
preview from camera and implements ``CvCameraViewListener2`` interface to get frames from camera and
|
||||
process it.
|
||||
|
||||
First of all we create our application view using xml layout. Our layout consists of the only
|
||||
|
@ -106,8 +106,8 @@ Enable hardware optimizations
|
||||
-----------------------------
|
||||
|
||||
Depending on target platform architecture different instruction sets can be used. By default
|
||||
compiler generates code for armv5l without VFPv3 and NEON extensions. Add ``-DUSE_VFPV3=ON``
|
||||
to cmake command line to enable code generation for VFPv3 and ``-DUSE_NEON=ON`` for using
|
||||
compiler generates code for armv5l without VFPv3 and NEON extensions. Add ``-DENABLE_VFPV3=ON``
|
||||
to cmake command line to enable code generation for VFPv3 and ``-DENABLE_NEON=ON`` for using
|
||||
NEON SIMD extensions.
|
||||
|
||||
TBB is supported on multi core ARM SoCs also.
|
||||
|
@ -25,29 +25,34 @@ Let's use a simple program such as DisplayImage.cpp shown below.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include <stdio.h>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <stdio.h>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv;
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
Mat image;
|
||||
image = imread( argv[1], 1 );
|
||||
int main(int argc, char** argv )
|
||||
{
|
||||
if ( argc != 2 )
|
||||
{
|
||||
printf("usage: DisplayImage.out <Image_Path>\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( argc != 2 || !image.data )
|
||||
{
|
||||
printf( "No image data \n" );
|
||||
return -1;
|
||||
}
|
||||
Mat image;
|
||||
image = imread( argv[1], 1 );
|
||||
|
||||
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
|
||||
imshow( "Display Image", image );
|
||||
if ( !image.data )
|
||||
{
|
||||
printf("No image data \n");
|
||||
return -1;
|
||||
}
|
||||
namedWindow("Display Image", WINDOW_AUTOSIZE );
|
||||
imshow("Display Image", image);
|
||||
|
||||
waitKey(0);
|
||||
waitKey(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Create a CMake file
|
||||
---------------------
|
||||
|
@ -13,10 +13,10 @@ Required Packages
|
||||
|
||||
sudo apt-get install build-essential
|
||||
|
||||
* CMake 2.6 or higher;
|
||||
* CMake 2.8.7 or higher;
|
||||
* Git;
|
||||
* GTK+2.x or higher, including headers (libgtk2.0-dev);
|
||||
* pkgconfig;
|
||||
* pkg-config;
|
||||
* Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy);
|
||||
* ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev;
|
||||
* [optional] libdc1394 2.x;
|
||||
@ -74,7 +74,8 @@ Building OpenCV from Source Using CMake, Using the Command Line
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
make
|
||||
make -j8 # -j8 runs 8 jobs in parallel.
|
||||
# Change 8 to number of hardware threads available.
|
||||
sudo make install
|
||||
|
||||
.. note::
|
||||
|
@ -99,7 +99,7 @@ Explanation
|
||||
imshow( imageName, image );
|
||||
imshow( "Gray image", gray_image );
|
||||
|
||||
#. Add add the *waitKey(0)* function call for the program to wait forever for an user key press.
|
||||
#. Add the *waitKey(0)* function call for the program to wait forever for an user key press.
|
||||
|
||||
|
||||
Result
|
||||
|
@ -81,7 +81,7 @@ Building the OpenCV library from scratch requires a couple of tools installed be
|
||||
|
||||
+ An IDE of choice (preferably), or just a C\C++ compiler that will actually make the binary files. Here we will use the `Microsoft Visual Studio <https://www.microsoft.com/visualstudio/en-us>`_. However, you can use any other IDE that has a valid C\C++ compiler.
|
||||
|
||||
+ |CMake|_, which is a neat tool to make the project files (for your choosen IDE) from the OpenCV source files. It will also allow an easy configuration of the OpenCV build files, in order to make binary files that fits exactly to your needs.
|
||||
+ |CMake|_, which is a neat tool to make the project files (for your chosen IDE) from the OpenCV source files. It will also allow an easy configuration of the OpenCV build files, in order to make binary files that fits exactly to your needs.
|
||||
|
||||
+ Git to acquire the OpenCV source files. A good tool for this is |TortoiseGit|_. Alternatively, you can just download an archived version of the source files from our `page on Sourceforge <http://sourceforge.net/projects/opencvlibrary/files/opencv-win/>`_
|
||||
|
||||
@ -320,7 +320,7 @@ First we set an enviroment variable to make easier our work. This will hold the
|
||||
|
||||
Here the directory is where you have your OpenCV binaries (*extracted* or *built*). You can have different platform (e.g. x64 instead of x86) or compiler type, so substitute appropriate value. Inside this you should have two folders called *lib* and *bin*. The -m should be added if you wish to make the settings computer wise, instead of user wise.
|
||||
|
||||
If you built static libraries then you are done. Otherwise, you need to add the *bin* folders path to the systems path. This is cause you will use the OpenCV library in form of *\"Dynamic-link libraries\"* (also known as **DLL**). Inside these are stored all the algorithms and information the OpenCV library contains. The operating system will load them only on demand, during runtime. However, to do this he needs to know where they are. The systems **PATH** contains a list of folders where DLLs can be found. Add the OpenCV library path to this and the OS will know where to look if he ever needs the OpenCV binaries. Otherwise, you will need to copy the used DLLs right beside the applications executable file (*exe*) for the OS to find it, which is highly unpleasent if you work on many projects. To do this start up again the |PathEditor|_ and add the following new entry (right click in the application to bring up the menu):
|
||||
If you built static libraries then you are done. Otherwise, you need to add the *bin* folders path to the systems path. This is because you will use the OpenCV library in form of *\"Dynamic-link libraries\"* (also known as **DLL**). Inside these are stored all the algorithms and information the OpenCV library contains. The operating system will load them only on demand, during runtime. However, to do this the operating system needs to know where they are. The systems **PATH** contains a list of folders where DLLs can be found. Add the OpenCV library path to this and the OS will know where to look if he ever needs the OpenCV binaries. Otherwise, you will need to copy the used DLLs right beside the applications executable file (*exe*) for the OS to find it, which is highly unpleasent if you work on many projects. To do this start up again the |PathEditor|_ and add the following new entry (right click in the application to bring up the menu):
|
||||
|
||||
::
|
||||
|
||||
|
@ -171,21 +171,6 @@ As always, we would be happy to hear your comments and receive your contribution
|
||||
:width: 80pt
|
||||
:alt: gpu icon
|
||||
|
||||
* :ref:`Table-Of-Content-Bioinspired`
|
||||
|
||||
.. tabularcolumns:: m{100pt} m{300pt}
|
||||
.. cssclass:: toctableopencv
|
||||
|
||||
============= =======================================================
|
||||
|Bioinspired| Algorithms inspired from biological models.
|
||||
|
||||
============= =======================================================
|
||||
|
||||
.. |Bioinspired| image:: images/retina.jpg
|
||||
:height: 80pt
|
||||
:width: 80pt
|
||||
:alt: gpu icon
|
||||
|
||||
* :ref:`Table-Of-Content-iOS`
|
||||
|
||||
.. tabularcolumns:: m{100pt} m{300pt}
|
||||
@ -250,7 +235,6 @@ As always, we would be happy to hear your comments and receive your contribution
|
||||
ml/table_of_content_ml/table_of_content_ml
|
||||
photo/table_of_content_photo/table_of_content_photo
|
||||
gpu/table_of_content_gpu/table_of_content_gpu
|
||||
bioinspired/table_of_content_bioinspired/table_of_content_bioinspired
|
||||
ios/table_of_content_ios/table_of_content_ios
|
||||
viz/table_of_content_viz/table_of_content_viz
|
||||
general/table_of_content_general/table_of_content_general
|
||||
|
@ -43,7 +43,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
|
||||
cout << "First event loop is over" << endl;
|
||||
|
||||
/// Access window via its name
|
||||
viz::Viz3d sameWindow = viz::get("Viz Demo");
|
||||
viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo");
|
||||
|
||||
/// Start event loop
|
||||
sameWindow.spin();
|
||||
|
79
doc/user_guide/ug_intelperc.rst
Normal file
@ -0,0 +1,79 @@
|
||||
*******
|
||||
HighGUI
|
||||
*******
|
||||
|
||||
.. highlight:: cpp
|
||||
|
||||
Using Creative Senz3D and other Intel Perceptual Computing SDK compatible depth sensors
|
||||
=======================================================================================
|
||||
|
||||
Depth sensors compatible with Intel Perceptual Computing SDK are supported through ``VideoCapture`` class. Depth map, RGB image and some other formats of output can be retrieved by using familiar interface of ``VideoCapture``.
|
||||
|
||||
In order to use depth sensor with OpenCV you should do the following preliminary steps:
|
||||
|
||||
#.
|
||||
Install Intel Perceptual Computing SDK (from here http://www.intel.com/software/perceptual).
|
||||
|
||||
#.
|
||||
Configure OpenCV with Intel Perceptual Computing SDK support by setting ``WITH_INTELPERC`` flag in CMake. If Intel Perceptual Computing SDK is found in install folders OpenCV will be built with Intel Perceptual Computing SDK library (see a status ``INTELPERC`` in CMake log). If CMake process doesn't find Intel Perceptual Computing SDK installation folder automatically, the user should change corresponding CMake variables ``INTELPERC_LIB_DIR`` and ``INTELPERC_INCLUDE_DIR`` to the proper value.
|
||||
|
||||
#.
|
||||
Build OpenCV.
|
||||
|
||||
VideoCapture can retrieve the following data:
|
||||
|
||||
#.
|
||||
data given from depth generator:
|
||||
* ``CV_CAP_INTELPERC_DEPTH_MAP`` - each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth. (CV_16UC1)
|
||||
* ``CV_CAP_INTELPERC_UVDEPTH_MAP`` - each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of depth coordinates to the color coordinates. (CV_32FC2)
|
||||
* ``CV_CAP_INTELPERC_IR_MAP`` - each pixel is a 16-bit integer. The value indicates the intensity of the reflected laser beam. (CV_16UC1)
|
||||
#.
|
||||
data given from RGB image generator:
|
||||
* ``CV_CAP_INTELPERC_IMAGE`` - color image. (CV_8UC3)
|
||||
|
||||
In order to get depth map from depth sensor use ``VideoCapture::operator >>``, e. g. ::
|
||||
|
||||
VideoCapture capture( CV_CAP_INTELPERC );
|
||||
for(;;)
|
||||
{
|
||||
Mat depthMap;
|
||||
capture >> depthMap;
|
||||
|
||||
if( waitKey( 30 ) >= 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
For getting several data maps use ``VideoCapture::grab`` and ``VideoCapture::retrieve``, e.g. ::
|
||||
|
||||
VideoCapture capture(CV_CAP_INTELPERC);
|
||||
for(;;)
|
||||
{
|
||||
Mat depthMap;
|
||||
Mat image;
|
||||
Mat irImage;
|
||||
|
||||
capture.grab();
|
||||
|
||||
capture.retrieve( depthMap, CV_CAP_INTELPERC_DEPTH_MAP );
|
||||
capture.retrieve( image, CV_CAP_INTELPERC_IMAGE );
|
||||
capture.retrieve( irImage, CV_CAP_INTELPERC_IR_MAP);
|
||||
|
||||
if( waitKey( 30 ) >= 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
For setting and getting some property of sensor` data generators use ``VideoCapture::set`` and ``VideoCapture::get`` methods respectively, e.g. ::
|
||||
|
||||
VideoCapture capture( CV_CAP_INTELPERC );
|
||||
capture.set( CV_CAP_INTELPERC_DEPTH_GENERATOR | CV_CAP_PROP_INTELPERC_PROFILE_IDX, 0 );
|
||||
cout << "FPS " << capture.get( CV_CAP_INTELPERC_DEPTH_GENERATOR+CV_CAP_PROP_FPS ) << endl;
|
||||
|
||||
Since two types of sensor's data generators are supported (image generator and depth generator), there are two flags that should be used to set/get property of the needed generator:
|
||||
|
||||
* CV_CAP_INTELPERC_IMAGE_GENERATOR -- a flag for access to the image generator properties.
|
||||
|
||||
* CV_CAP_INTELPERC_DEPTH_GENERATOR -- a flag for access to the depth generator properties. This flag value is assumed by default if neither of the two possible values of the property is set.
|
||||
|
||||
For more information please refer to the example of usage intelperc_capture.cpp_ in ``opencv/samples/cpp`` folder.
|
||||
|
||||
.. _intelperc_capture.cpp: https://github.com/Itseez/opencv/tree/master/samples/cpp/intelperc_capture.cpp
|
@ -9,3 +9,4 @@ OpenCV User Guide
|
||||
ug_features2d.rst
|
||||
ug_highgui.rst
|
||||
ug_traincascade.rst
|
||||
ug_intelperc.rst
|
||||
|
@ -1,7 +1,7 @@
|
||||
file(GLOB old_hdrs "opencv/*.h*")
|
||||
install(FILES ${old_hdrs}
|
||||
DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv
|
||||
COMPONENT main)
|
||||
COMPONENT dev)
|
||||
install(FILES "opencv2/opencv.hpp"
|
||||
DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2
|
||||
COMPONENT main)
|
||||
COMPONENT dev)
|
||||
|
@ -52,7 +52,6 @@
|
||||
#include "opencv2/calib3d.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/contrib.hpp"
|
||||
#include "opencv2/bioinspired.hpp"
|
||||
#include "opencv2/ml.hpp"
|
||||
|
||||
#endif
|
||||
|
@ -40,6 +40,6 @@ else()
|
||||
get_filename_component(wrapper_name "${wrapper}" NAME)
|
||||
install(FILES "${LIBRARY_OUTPUT_PATH}/${wrapper_name}"
|
||||
DESTINATION ${OPENCV_LIB_INSTALL_PATH}
|
||||
COMPONENT main)
|
||||
COMPONENT libs)
|
||||
endforeach()
|
||||
endif()
|
||||
|
@ -63,4 +63,4 @@ if (NOT (CMAKE_BUILD_TYPE MATCHES "debug"))
|
||||
endif()
|
||||
|
||||
|
||||
install(TARGETS ${the_target} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main)
|
||||
install(TARGETS ${the_target} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs)
|
||||
|
@ -1,3 +0,0 @@
|
||||
set(the_description "Biologically inspired algorithms")
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef)
|
||||
ocv_define_module(bioinspired opencv_core OPTIONAL opencv_highgui opencv_ocl)
|
@ -1,10 +0,0 @@
|
||||
********************************************************************
|
||||
bioinspired. Biologically inspired vision models and derivated tools
|
||||
********************************************************************
|
||||
|
||||
The module provides biological visual systems models (human visual system and others). It also provides derivated objects that take advantage of those bio-inspired models.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
Human retina documentation <retina/index>
|
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 19 KiB |
@ -1,493 +0,0 @@
|
||||
Retina : a Bio mimetic human retina model
|
||||
*****************************************
|
||||
|
||||
.. highlight:: cpp
|
||||
|
||||
Retina
|
||||
======
|
||||
.. ocv:class:: Retina : public Algorithm
|
||||
|
||||
**Note** : do not forget that the retina model is included in the following namespace : *cv::bioinspired*.
|
||||
|
||||
Introduction
|
||||
++++++++++++
|
||||
|
||||
Class which provides the main controls to the Gipsa/Listic labs human retina model. This is a non separable spatio-temporal filter modelling the two main retina information channels :
|
||||
|
||||
* foveal vision for detailled color vision : the parvocellular pathway.
|
||||
|
||||
* peripheral vision for sensitive transient signals detection (motion and events) : the magnocellular pathway.
|
||||
|
||||
From a general point of view, this filter whitens the image spectrum and corrects luminance thanks to local adaptation. An other important property is its hability to filter out spatio-temporal noise while enhancing details.
|
||||
This model originates from Jeanny Herault work [Herault2010]_. It has been involved in Alexandre Benoit phd and his current research [Benoit2010]_, [Strat2013]_ (he currently maintains this module within OpenCV). It includes the work of other Jeanny's phd student such as [Chaix2007]_ and the log polar transformations of Barthelemy Durette described in Jeanny's book.
|
||||
|
||||
**NOTES :**
|
||||
|
||||
* For ease of use in computer vision applications, the two retina channels are applied homogeneously on all the input images. This does not follow the real retina topology but this can still be done using the log sampling capabilities proposed within the class.
|
||||
|
||||
* Extend the retina description and code use in the tutorial/contrib section for complementary explanations.
|
||||
|
||||
Preliminary illustration
|
||||
++++++++++++++++++++++++
|
||||
|
||||
As a preliminary presentation, let's start with a visual example. We propose to apply the filter on a low quality color jpeg image with backlight problems. Here is the considered input... *"Well, my eyes were able to see more that this strange black shadow..."*
|
||||
|
||||
.. image:: images/retinaInput.jpg
|
||||
:alt: a low quality color jpeg image with backlight problems.
|
||||
:align: center
|
||||
|
||||
Below, the retina foveal model applied on the entire image with default parameters. Here contours are enforced, halo effects are voluntary visible with this configuration. See parameters discussion below and increase horizontalCellsGain near 1 to remove them.
|
||||
|
||||
.. image:: images/retinaOutput_default.jpg
|
||||
:alt: the retina foveal model applied on the entire image with default parameters. Here contours are enforced, luminance is corrected and halo effects are voluntary visible with this configuration, increase horizontalCellsGain near 1 to remove them.
|
||||
:align: center
|
||||
|
||||
Below, a second retina foveal model output applied on the entire image with a parameters setup focused on naturalness perception. *"Hey, i now recognize my cat, looking at the mountains at the end of the day !"*. Here contours are enforced, luminance is corrected but halos are avoided with this configuration. The backlight effect is corrected and highlight details are still preserved. Then, even on a low quality jpeg image, if some luminance information remains, the retina is able to reconstruct a proper visual signal. Such configuration is also usefull for High Dynamic Range (*HDR*) images compression to 8bit images as discussed in [benoit2010]_ and in the demonstration codes discussed below.
|
||||
As shown at the end of the page, parameters change from defaults are :
|
||||
|
||||
* horizontalCellsGain=0.3
|
||||
|
||||
* photoreceptorsLocalAdaptationSensitivity=ganglioncellsSensitivity=0.89.
|
||||
|
||||
.. image:: images/retinaOutput_realistic.jpg
|
||||
:alt: the retina foveal model applied on the entire image with 'naturalness' parameters. Here contours are enforced but are avoided with this configuration, horizontalCellsGain is 0.3 and photoreceptorsLocalAdaptationSensitivity=ganglioncellsSensitivity=0.89.
|
||||
:align: center
|
||||
|
||||
As observed in this preliminary demo, the retina can be settled up with various parameters, by default, as shown on the figure above, the retina strongly reduces mean luminance energy and enforces all details of the visual scene. Luminance energy and halo effects can be modulated (exagerated to cancelled as shown on the two examples). In order to use your own parameters, you can use at least one time the *write(String fs)* method which will write a proper XML file with all default parameters. Then, tweak it on your own and reload them at any time using method *setup(String fs)*. These methods update a *Retina::RetinaParameters* member structure that is described hereafter. XML parameters file samples are shown at the end of the page.
|
||||
|
||||
Here is an overview of the abstract Retina interface, allocate one instance with the *createRetina* functions.::
|
||||
|
||||
namespace cv{namespace bioinspired{
|
||||
|
||||
class Retina : public Algorithm
|
||||
{
|
||||
public:
|
||||
// parameters setup instance
|
||||
struct RetinaParameters; // this class is detailled later
|
||||
|
||||
// main method for input frame processing (all use method, can also perform High Dynamic Range tone mapping)
|
||||
void run (InputArray inputImage);
|
||||
|
||||
// specific method aiming at correcting luminance only (faster High Dynamic Range tone mapping)
|
||||
void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)
|
||||
|
||||
// output buffers retreival methods
|
||||
// -> foveal color vision details channel with luminance and noise correction
|
||||
void getParvo (OutputArray retinaOutput_parvo);
|
||||
void getParvoRAW (OutputArray retinaOutput_parvo);// retreive original output buffers without any normalisation
|
||||
const Mat getParvoRAW () const;// retreive original output buffers without any normalisation
|
||||
// -> peripheral monochrome motion and events (transient information) channel
|
||||
void getMagno (OutputArray retinaOutput_magno);
|
||||
void getMagnoRAW (OutputArray retinaOutput_magno); // retreive original output buffers without any normalisation
|
||||
const Mat getMagnoRAW () const;// retreive original output buffers without any normalisation
|
||||
|
||||
// reset retina buffers... equivalent to closing your eyes for some seconds
|
||||
void clearBuffers ();
|
||||
|
||||
// retreive input and output buffers sizes
|
||||
Size getInputSize ();
|
||||
Size getOutputSize ();
|
||||
|
||||
// setup methods with specific parameters specification of global xml config file loading/write
|
||||
void setup (String retinaParameterFile="", const bool applyDefaultSetupOnFailure=true);
|
||||
void setup (FileStorage &fs, const bool applyDefaultSetupOnFailure=true);
|
||||
void setup (RetinaParameters newParameters);
|
||||
struct Retina::RetinaParameters getParameters ();
|
||||
const String printSetup ();
|
||||
virtual void write (String fs) const;
|
||||
virtual void write (FileStorage &fs) const;
|
||||
void setupOPLandIPLParvoChannel (const bool colorMode=true, const bool normaliseOutput=true, const float photoreceptorsLocalAdaptationSensitivity=0.7, const float photoreceptorsTemporalConstant=0.5, const float photoreceptorsSpatialConstant=0.53, const float horizontalCellsGain=0, const float HcellsTemporalConstant=1, const float HcellsSpatialConstant=7, const float ganglionCellsSensitivity=0.7);
|
||||
void setupIPLMagnoChannel (const bool normaliseOutput=true, const float parasolCells_beta=0, const float parasolCells_tau=0, const float parasolCells_k=7, const float amacrinCellsTemporalCutFrequency=1.2, const float V0CompressionParameter=0.95, const float localAdaptintegration_tau=0, const float localAdaptintegration_k=7);
|
||||
void setColorSaturation (const bool saturateColors=true, const float colorSaturationValue=4.0);
|
||||
void activateMovingContoursProcessing (const bool activate);
|
||||
void activateContoursProcessing (const bool activate);
|
||||
};
|
||||
|
||||
// Allocators
|
||||
cv::Ptr<Retina> createRetina (Size inputSize);
|
||||
cv::Ptr<Retina> createRetina (Size inputSize, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod=RETINA_COLOR_BAYER, const bool useRetinaLogSampling=false, const double reductionFactor=1.0, const double samplingStrenght=10.0);
|
||||
}} // cv and bioinspired namespaces end
|
||||
|
||||
.. Sample code::
|
||||
|
||||
* An example on retina tone mapping can be found at opencv_source_code/samples/cpp/OpenEXRimages_HDR_Retina_toneMapping.cpp
|
||||
* An example on retina tone mapping on video input can be found at opencv_source_code/samples/cpp/OpenEXRimages_HDR_Retina_toneMapping.cpp
|
||||
* A complete example illustrating the retina interface can be found at opencv_source_code/samples/cpp/retinaDemo.cpp
|
||||
|
||||
Description
|
||||
+++++++++++
|
||||
|
||||
Class which allows the `Gipsa <http://www.gipsa-lab.inpg.fr>`_ (preliminary work) / `Listic <http://www.listic.univ-savoie.fr>`_ (code maintainer and user) labs retina model to be used. This class allows human retina spatio-temporal image processing to be applied on still images, images sequences and video sequences. Briefly, here are the main human retina model properties:
|
||||
|
||||
* spectral whithening (mid-frequency details enhancement)
|
||||
|
||||
* high frequency spatio-temporal noise reduction (temporal noise and high frequency spatial noise are minimized)
|
||||
|
||||
* low frequency luminance reduction (luminance range compression) : high luminance regions do not hide details in darker regions anymore
|
||||
|
||||
* local logarithmic luminance compression allows details to be enhanced even in low light conditions
|
||||
|
||||
Use : this model can be used basically for spatio-temporal video effects but also in the aim of :
|
||||
|
||||
* performing texture analysis with enhanced signal to noise ratio and enhanced details robust against input images luminance ranges (check out the parvocellular retina channel output, by using the provided **getParvo** methods)
|
||||
|
||||
* performing motion analysis also taking benefit of the previously cited properties (check out the magnocellular retina channel output, by using the provided **getMagno** methods)
|
||||
|
||||
* general image/video sequence description using either one or both channels. An example of the use of Retina in a Bag of Words approach is given in [Strat2013]_.
|
||||
|
||||
Literature
|
||||
==========
|
||||
For more information, refer to the following papers :
|
||||
|
||||
* Model description :
|
||||
|
||||
.. [Benoit2010] Benoit A., Caplier A., Durette B., Herault, J., "Using Human Visual System Modeling For Bio-Inspired Low Level Image Processing", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773. DOI <http://dx.doi.org/10.1016/j.cviu.2010.01.011>
|
||||
|
||||
* Model use in a Bag of Words approach :
|
||||
|
||||
.. [Strat2013] Strat S., Benoit A., Lambert P., "Retina enhanced SIFT descriptors for video indexing", CBMI2013, Veszprém, Hungary, 2013.
|
||||
|
||||
* Please have a look at the reference work of Jeanny Herault that you can read in his book :
|
||||
|
||||
.. [Herault2010] Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
|
||||
This retina filter code includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
|
||||
* take a look at the *retinacolor.hpp* module to discover Brice Chaix de Lavarene phD color mosaicing/demosaicing and his reference paper:
|
||||
|
||||
.. [Chaix2007] B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
|
||||
* take a look at *imagelogpolprojection.hpp* to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions. More informations in the above cited Jeanny Heraults's book.
|
||||
|
||||
* Meylan&al work on HDR tone mapping that is implemented as a specific method within the model :
|
||||
|
||||
.. [Meylan2007] L. Meylan , D. Alleysson, S. Susstrunk, "A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images", Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816
|
||||
|
||||
Demos and experiments !
|
||||
=======================
|
||||
|
||||
**NOTE : Complementary to the following examples, have a look at the Retina tutorial in the tutorial/contrib section for complementary explanations.**
|
||||
|
||||
Take a look at the provided C++ examples provided with OpenCV :
|
||||
|
||||
* **samples/cpp/retinademo.cpp** shows how to use the retina module for details enhancement (Parvo channel output) and transient maps observation (Magno channel output). You can play with images, video sequences and webcam video.
|
||||
Typical uses are (provided your OpenCV installation is situated in folder *OpenCVReleaseFolder*)
|
||||
|
||||
* image processing : **OpenCVReleaseFolder/bin/retinademo -image myPicture.jpg**
|
||||
|
||||
* video processing : **OpenCVReleaseFolder/bin/retinademo -video myMovie.avi**
|
||||
|
||||
* webcam processing: **OpenCVReleaseFolder/bin/retinademo -video**
|
||||
|
||||
**Note :** This demo generates the file *RetinaDefaultParameters.xml* which contains the default parameters of the retina. Then, rename this as *RetinaSpecificParameters.xml*, adjust the parameters the way you want and reload the program to check the effect.
|
||||
|
||||
|
||||
* **samples/cpp/OpenEXRimages_HDR_Retina_toneMapping.cpp** shows how to use the retina to perform High Dynamic Range (HDR) luminance compression
|
||||
|
||||
Then, take a HDR image using bracketing with your camera and generate an OpenEXR image and then process it using the demo.
|
||||
|
||||
Typical use, supposing that you have the OpenEXR image such as *memorial.exr* (present in the samples/cpp/ folder)
|
||||
|
||||
**OpenCVReleaseFolder/bin/OpenEXRimages_HDR_Retina_toneMapping memorial.exr [optional: 'fast']**
|
||||
|
||||
Note that some sliders are made available to allow you to play with luminance compression.
|
||||
|
||||
If not using the 'fast' option, then, tone mapping is performed using the full retina model [Benoit2010]_. It includes spectral whitening that allows luminance energy to be reduced. When using the 'fast' option, then, a simpler method is used, it is an adaptation of the algorithm presented in [Meylan2007]_. This method gives also good results and is faster to process but it sometimes requires some more parameters adjustement.
|
||||
|
||||
|
||||
Methods description
|
||||
===================
|
||||
|
||||
Here are detailled the main methods to control the retina model
|
||||
|
||||
Ptr<Retina>::createRetina
|
||||
+++++++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: Ptr<cv::bioinspired::Retina> createRetina(Size inputSize)
|
||||
.. ocv:function:: Ptr<cv::bioinspired::Retina> createRetina(Size inputSize, const bool colorMode, cv::bioinspired::RETINA_COLORSAMPLINGMETHOD colorSamplingMethod = cv::bioinspired::RETINA_COLOR_BAYER, const bool useRetinaLogSampling = false, const double reductionFactor = 1.0, const double samplingStrenght = 10.0 )
|
||||
|
||||
Constructors from standardized interfaces : retreive a smart pointer to a Retina instance
|
||||
|
||||
:param inputSize: the input frame size
|
||||
:param colorMode: the chosen processing mode : with or without color processing
|
||||
:param colorSamplingMethod: specifies which kind of color sampling will be used :
|
||||
|
||||
* cv::bioinspired::RETINA_COLOR_RANDOM: each pixel position is either R, G or B in a random choice
|
||||
|
||||
* cv::bioinspired::RETINA_COLOR_DIAGONAL: color sampling is RGBRGBRGB..., line 2 BRGBRGBRG..., line 3, GBRGBRGBR...
|
||||
|
||||
* cv::bioinspired::RETINA_COLOR_BAYER: standard bayer sampling
|
||||
|
||||
:param useRetinaLogSampling: activate retina log sampling, if true, the 2 following parameters can be used
|
||||
:param reductionFactor: only usefull if param useRetinaLogSampling=true, specifies the reduction factor of the output frame (as the center (fovea) is high resolution and corners can be underscaled, then a reduction of the output is allowed without precision leak
|
||||
:param samplingStrenght: only usefull if param useRetinaLogSampling=true, specifies the strenght of the log scale that is applied
|
||||
|
||||
Retina::activateContoursProcessing
|
||||
++++++++++++++++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::activateContoursProcessing(const bool activate)
|
||||
|
||||
Activate/desactivate the Parvocellular pathway processing (contours information extraction), by default, it is activated
|
||||
|
||||
:param activate: true if Parvocellular (contours information extraction) output should be activated, false if not... if activated, the Parvocellular output can be retrieved using the **getParvo** methods
|
||||
|
||||
Retina::activateMovingContoursProcessing
|
||||
++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::activateMovingContoursProcessing(const bool activate)
|
||||
|
||||
Activate/desactivate the Magnocellular pathway processing (motion information extraction), by default, it is activated
|
||||
|
||||
:param activate: true if Magnocellular output should be activated, false if not... if activated, the Magnocellular output can be retrieved using the **getMagno** methods
|
||||
|
||||
Retina::clearBuffers
|
||||
++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::clearBuffers()
|
||||
|
||||
Clears all retina buffers (equivalent to opening the eyes after a long period of eye close ;o) whatchout the temporal transition occuring just after this method call.
|
||||
|
||||
Retina::getParvo
|
||||
++++++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::getParvo( OutputArray retinaOutput_parvo )
|
||||
.. ocv:function:: void Retina::getParvoRAW( OutputArray retinaOutput_parvo )
|
||||
.. ocv:function:: const Mat Retina::getParvoRAW() const
|
||||
|
||||
Accessor of the details channel of the retina (models foveal vision). Warning, getParvoRAW methods return buffers that are not rescaled within range [0;255] while the non RAW method allows a normalized matrix to be retrieved.
|
||||
|
||||
:param retinaOutput_parvo: the output buffer (reallocated if necessary), format can be :
|
||||
|
||||
* a Mat, this output is rescaled for standard 8bits image processing use in OpenCV
|
||||
|
||||
* RAW methods actually return a 1D matrix (encoding is R1, R2, ... Rn, G1, G2, ..., Gn, B1, B2, ...Bn), this output is the original retina filter model output, without any quantification or rescaling.
|
||||
|
||||
Retina::getMagno
|
||||
++++++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::getMagno( OutputArray retinaOutput_magno )
|
||||
.. ocv:function:: void Retina::getMagnoRAW( OutputArray retinaOutput_magno )
|
||||
.. ocv:function:: const Mat Retina::getMagnoRAW() const
|
||||
|
||||
Accessor of the motion channel of the retina (models peripheral vision). Warning, getMagnoRAW methods return buffers that are not rescaled within range [0;255] while the non RAW method allows a normalized matrix to be retrieved.
|
||||
|
||||
:param retinaOutput_magno: the output buffer (reallocated if necessary), format can be :
|
||||
|
||||
* a Mat, this output is rescaled for standard 8bits image processing use in OpenCV
|
||||
|
||||
* RAW methods actually return a 1D matrix (encoding is M1, M2,... Mn), this output is the original retina filter model output, without any quantification or rescaling.
|
||||
|
||||
Retina::getInputSize
|
||||
++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: Size Retina::getInputSize()
|
||||
|
||||
Retreive retina input buffer size
|
||||
|
||||
:return: the retina input buffer size
|
||||
|
||||
Retina::getOutputSize
|
||||
+++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: Size Retina::getOutputSize()
|
||||
|
||||
Retreive retina output buffer size that can be different from the input if a spatial log transformation is applied
|
||||
|
||||
:return: the retina output buffer size
|
||||
|
||||
Retina::printSetup
|
||||
++++++++++++++++++
|
||||
|
||||
.. ocv:function:: const String Retina::printSetup()
|
||||
|
||||
Outputs a string showing the used parameters setup
|
||||
|
||||
:return: a string which contains formated parameters information
|
||||
|
||||
Retina::run
|
||||
+++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::run(InputArray inputImage)
|
||||
|
||||
Method which allows retina to be applied on an input image, after run, encapsulated retina module is ready to deliver its outputs using dedicated acccessors, see getParvo and getMagno methods
|
||||
|
||||
:param inputImage: the input Mat image to be processed, can be gray level or BGR coded in any format (from 8bit to 16bits)
|
||||
|
||||
Retina::applyFastToneMapping
|
||||
++++++++++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)
|
||||
|
||||
Method which processes an image in the aim to correct its luminance : correct backlight problems, enhance details in shadows. This method is designed to perform High Dynamic Range image tone mapping (compress >8bit/pixel images to 8bit/pixel). This is a simplified version of the Retina Parvocellular model (simplified version of the run/getParvo methods call) since it does not include the spatio-temporal filter modelling the Outer Plexiform Layer of the retina that performs spectral whitening and many other stuff. However, it works great for tone mapping and in a faster way.
|
||||
|
||||
Check the demos and experiments section to see examples and the way to perform tone mapping using the original retina model and the method.
|
||||
|
||||
:param inputImage: the input image to process (should be coded in float format : CV_32F, CV_32FC1, CV_32F_C3, CV_32F_C4, the 4th channel won't be considered).
|
||||
:param outputToneMappedImage: the output 8bit/channel tone mapped image (CV_8U or CV_8UC3 format).
|
||||
|
||||
Retina::setColorSaturation
|
||||
++++++++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::setColorSaturation(const bool saturateColors = true, const float colorSaturationValue = 4.0 )
|
||||
|
||||
Activate color saturation as the final step of the color demultiplexing process -> this saturation is a sigmoide function applied to each channel of the demultiplexed image.
|
||||
|
||||
:param saturateColors: boolean that activates color saturation (if true) or desactivate (if false)
|
||||
:param colorSaturationValue: the saturation factor : a simple factor applied on the chrominance buffers
|
||||
|
||||
|
||||
Retina::setup
|
||||
+++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::setup(String retinaParameterFile = "", const bool applyDefaultSetupOnFailure = true )
|
||||
.. ocv:function:: void Retina::setup(FileStorage & fs, const bool applyDefaultSetupOnFailure = true )
|
||||
.. ocv:function:: void Retina::setup(RetinaParameters newParameters)
|
||||
|
||||
Try to open an XML retina parameters file to adjust current retina instance setup => if the xml file does not exist, then default setup is applied => warning, Exceptions are thrown if read XML file is not valid
|
||||
|
||||
:param retinaParameterFile: the parameters filename
|
||||
:param applyDefaultSetupOnFailure: set to true if an error must be thrown on error
|
||||
:param fs: the open Filestorage which contains retina parameters
|
||||
:param newParameters: a parameters structures updated with the new target configuration. You can retreive the current parameers structure using method *Retina::RetinaParameters Retina::getParameters()* and update it before running method *setup*.
|
||||
|
||||
Retina::write
|
||||
+++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::write( String fs ) const
|
||||
.. ocv:function:: void Retina::write( FileStorage& fs ) const
|
||||
|
||||
Write xml/yml formated parameters information
|
||||
|
||||
:param fs: the filename of the xml file that will be open and writen with formatted parameters information
|
||||
|
||||
Retina::setupIPLMagnoChannel
|
||||
++++++++++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::setupIPLMagnoChannel(const bool normaliseOutput = true, const float parasolCells_beta = 0, const float parasolCells_tau = 0, const float parasolCells_k = 7, const float amacrinCellsTemporalCutFrequency = 1.2, const float V0CompressionParameter = 0.95, const float localAdaptintegration_tau = 0, const float localAdaptintegration_k = 7 )
|
||||
|
||||
Set parameters values for the Inner Plexiform Layer (IPL) magnocellular channel this channel processes signals output from OPL processing stage in peripheral vision, it allows motion information enhancement. It is decorrelated from the details channel. See reference papers for more details.
|
||||
|
||||
:param normaliseOutput: specifies if (true) output is rescaled between 0 and 255 of not (false)
|
||||
:param parasolCells_beta: the low pass filter gain used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), typical value is 0
|
||||
:param parasolCells_tau: the low pass filter time constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical value is 0 (immediate response)
|
||||
:param parasolCells_k: the low pass filter spatial constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical value is 5
|
||||
:param amacrinCellsTemporalCutFrequency: the time constant of the first order high pass fiter of the magnocellular way (motion information channel), unit is frames, typical value is 1.2
|
||||
:param V0CompressionParameter: the compression strengh of the ganglion cells local adaptation output, set a value between 0.6 and 1 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 0.95
|
||||
:param localAdaptintegration_tau: specifies the temporal constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
:param localAdaptintegration_k: specifies the spatial constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
|
||||
Retina::setupOPLandIPLParvoChannel
|
||||
++++++++++++++++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::setupOPLandIPLParvoChannel(const bool colorMode = true, const bool normaliseOutput = true, const float photoreceptorsLocalAdaptationSensitivity = 0.7, const float photoreceptorsTemporalConstant = 0.5, const float photoreceptorsSpatialConstant = 0.53, const float horizontalCellsGain = 0, const float HcellsTemporalConstant = 1, const float HcellsSpatialConstant = 7, const float ganglionCellsSensitivity = 0.7 )
|
||||
|
||||
Setup the OPL and IPL parvo channels (see biologocal model) OPL is referred as Outer Plexiform Layer of the retina, it allows the spatio-temporal filtering which withens the spectrum and reduces spatio-temporal noise while attenuating global luminance (low frequency energy) IPL parvo is the OPL next processing stage, it refers to a part of the Inner Plexiform layer of the retina, it allows high contours sensitivity in foveal vision. See reference papers for more informations.
|
||||
|
||||
:param colorMode: specifies if (true) color is processed of not (false) to then processing gray level image
|
||||
:param normaliseOutput: specifies if (true) output is rescaled between 0 and 255 of not (false)
|
||||
:param photoreceptorsLocalAdaptationSensitivity: the photoreceptors sensitivity renage is 0-1 (more log compression effect when value increases)
|
||||
:param photoreceptorsTemporalConstant: the time constant of the first order low pass filter of the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 1 frame
|
||||
:param photoreceptorsSpatialConstant: the spatial constant of the first order low pass filter of the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 1 pixel
|
||||
:param horizontalCellsGain: gain of the horizontal cells network, if 0, then the mean value of the output is zero, if the parameter is near 1, then, the luminance is not filtered and is still reachable at the output, typicall value is 0
|
||||
:param HcellsTemporalConstant: the time constant of the first order low pass filter of the horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is frames, typical value is 1 frame, as the photoreceptors
|
||||
:param HcellsSpatialConstant: the spatial constant of the first order low pass filter of the horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, typical value is 5 pixel, this value is also used for local contrast computing when computing the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular channel model)
|
||||
:param ganglionCellsSensitivity: the compression strengh of the ganglion cells local adaptation output, set a value between 0.6 and 1 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 0.7
|
||||
|
||||
|
||||
Retina::RetinaParameters
|
||||
========================
|
||||
|
||||
.. ocv:struct:: Retina::RetinaParameters
|
||||
|
||||
This structure merges all the parameters that can be adjusted threw the **Retina::setup()**, **Retina::setupOPLandIPLParvoChannel** and **Retina::setupIPLMagnoChannel** setup methods
|
||||
Parameters structure for better clarity, check explenations on the comments of methods : setupOPLandIPLParvoChannel and setupIPLMagnoChannel. ::
|
||||
|
||||
class RetinaParameters{
|
||||
struct OPLandIplParvoParameters{ // Outer Plexiform Layer (OPL) and Inner Plexiform Layer Parvocellular (IplParvo) parameters
|
||||
OPLandIplParvoParameters():colorMode(true),
|
||||
normaliseOutput(true), // specifies if (true) output is rescaled between 0 and 255 of not (false)
|
||||
photoreceptorsLocalAdaptationSensitivity(0.7f), // the photoreceptors sensitivity renage is 0-1 (more log compression effect when value increases)
|
||||
photoreceptorsTemporalConstant(0.5f),// the time constant of the first order low pass filter of the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 1 frame
|
||||
photoreceptorsSpatialConstant(0.53f),// the spatial constant of the first order low pass filter of the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 1 pixel
|
||||
horizontalCellsGain(0.0f),//gain of the horizontal cells network, if 0, then the mean value of the output is zero, if the parameter is near 1, then, the luminance is not filtered and is still reachable at the output, typicall value is 0
|
||||
hcellsTemporalConstant(1.f),// the time constant of the first order low pass filter of the horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is frames, typical value is 1 frame, as the photoreceptors. Reduce to 0.5 to limit retina after effects.
|
||||
hcellsSpatialConstant(7.f),//the spatial constant of the first order low pass filter of the horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, typical value is 5 pixel, this value is also used for local contrast computing when computing the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular channel model)
|
||||
ganglionCellsSensitivity(0.7f)//the compression strengh of the ganglion cells local adaptation output, set a value between 0.6 and 1 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 0.7
|
||||
{};// default setup
|
||||
bool colorMode, normaliseOutput;
|
||||
float photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity;
|
||||
};
|
||||
struct IplMagnoParameters{ // Inner Plexiform Layer Magnocellular channel (IplMagno)
|
||||
IplMagnoParameters():
|
||||
normaliseOutput(true), //specifies if (true) output is rescaled between 0 and 255 of not (false)
|
||||
parasolCells_beta(0.f), // the low pass filter gain used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), typical value is 0
|
||||
parasolCells_tau(0.f), //the low pass filter time constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical value is 0 (immediate response)
|
||||
parasolCells_k(7.f), //the low pass filter spatial constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical value is 5
|
||||
amacrinCellsTemporalCutFrequency(1.2f), //the time constant of the first order high pass fiter of the magnocellular way (motion information channel), unit is frames, typical value is 1.2
|
||||
V0CompressionParameter(0.95f), the compression strengh of the ganglion cells local adaptation output, set a value between 0.6 and 1 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 0.95
|
||||
localAdaptintegration_tau(0.f), // specifies the temporal constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
localAdaptintegration_k(7.f) // specifies the spatial constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
{};// default setup
|
||||
bool normaliseOutput;
|
||||
float parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k;
|
||||
};
|
||||
struct OPLandIplParvoParameters OPLandIplParvo;
|
||||
struct IplMagnoParameters IplMagno;
|
||||
};
|
||||
|
||||
Retina parameters files examples
|
||||
++++++++++++++++++++++++++++++++
|
||||
|
||||
Here is the default configuration file of the retina module. It gives results such as the first retina output shown on the top of this page.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
<?xml version="1.0"?>
|
||||
<opencv_storage>
|
||||
<OPLandIPLparvo>
|
||||
<colorMode>1</colorMode>
|
||||
<normaliseOutput>1</normaliseOutput>
|
||||
<photoreceptorsLocalAdaptationSensitivity>7.5e-01</photoreceptorsLocalAdaptationSensitivity>
|
||||
<photoreceptorsTemporalConstant>9.0e-01</photoreceptorsTemporalConstant>
|
||||
<photoreceptorsSpatialConstant>5.3e-01</photoreceptorsSpatialConstant>
|
||||
<horizontalCellsGain>0.01</horizontalCellsGain>
|
||||
<hcellsTemporalConstant>0.5</hcellsTemporalConstant>
|
||||
<hcellsSpatialConstant>7.</hcellsSpatialConstant>
|
||||
<ganglionCellsSensitivity>7.5e-01</ganglionCellsSensitivity></OPLandIPLparvo>
|
||||
<IPLmagno>
|
||||
<normaliseOutput>1</normaliseOutput>
|
||||
<parasolCells_beta>0.</parasolCells_beta>
|
||||
<parasolCells_tau>0.</parasolCells_tau>
|
||||
<parasolCells_k>7.</parasolCells_k>
|
||||
<amacrinCellsTemporalCutFrequency>2.0e+00</amacrinCellsTemporalCutFrequency>
|
||||
<V0CompressionParameter>9.5e-01</V0CompressionParameter>
|
||||
<localAdaptintegration_tau>0.</localAdaptintegration_tau>
|
||||
<localAdaptintegration_k>7.</localAdaptintegration_k></IPLmagno>
|
||||
</opencv_storage>
|
||||
|
||||
Here is the 'realistic" setup used to obtain the second retina output shown on the top of this page.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
<?xml version="1.0"?>
|
||||
<opencv_storage>
|
||||
<OPLandIPLparvo>
|
||||
<colorMode>1</colorMode>
|
||||
<normaliseOutput>1</normaliseOutput>
|
||||
<photoreceptorsLocalAdaptationSensitivity>8.9e-01</photoreceptorsLocalAdaptationSensitivity>
|
||||
<photoreceptorsTemporalConstant>9.0e-01</photoreceptorsTemporalConstant>
|
||||
<photoreceptorsSpatialConstant>5.3e-01</photoreceptorsSpatialConstant>
|
||||
<horizontalCellsGain>0.3</horizontalCellsGain>
|
||||
<hcellsTemporalConstant>0.5</hcellsTemporalConstant>
|
||||
<hcellsSpatialConstant>7.</hcellsSpatialConstant>
|
||||
<ganglionCellsSensitivity>8.9e-01</ganglionCellsSensitivity></OPLandIPLparvo>
|
||||
<IPLmagno>
|
||||
<normaliseOutput>1</normaliseOutput>
|
||||
<parasolCells_beta>0.</parasolCells_beta>
|
||||
<parasolCells_tau>0.</parasolCells_tau>
|
||||
<parasolCells_k>7.</parasolCells_k>
|
||||
<amacrinCellsTemporalCutFrequency>2.0e+00</amacrinCellsTemporalCutFrequency>
|
||||
<V0CompressionParameter>9.5e-01</V0CompressionParameter>
|
||||
<localAdaptintegration_tau>0.</localAdaptintegration_tau>
|
||||
<localAdaptintegration_k>7.</localAdaptintegration_k></IPLmagno>
|
||||
</opencv_storage>
|
@ -1,50 +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) 2009, 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 __OPENCV_BIOINSPIRED_HPP__
|
||||
#define __OPENCV_BIOINSPIRED_HPP__
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/bioinspired/retina.hpp"
|
||||
#include "opencv2/bioinspired/retinafasttonemapping.hpp"
|
||||
|
||||
#endif
|
@ -1,311 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2013
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __OPENCV_BIOINSPIRED_RETINA_HPP__
|
||||
#define __OPENCV_BIOINSPIRED_RETINA_HPP__
|
||||
|
||||
/*
|
||||
* Retina.hpp
|
||||
*
|
||||
* Created on: Jul 19, 2011
|
||||
* Author: Alexandre Benoit
|
||||
*/
|
||||
|
||||
#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support
|
||||
|
||||
|
||||
namespace cv{
|
||||
namespace bioinspired{
|
||||
|
||||
enum {
|
||||
RETINA_COLOR_RANDOM, //!< each pixel position is either R, G or B in a random choice
|
||||
RETINA_COLOR_DIAGONAL,//!< color sampling is RGBRGBRGB..., line 2 BRGBRGBRG..., line 3, GBRGBRGBR...
|
||||
RETINA_COLOR_BAYER//!< standard bayer sampling
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Retina a wrapper class which allows the Gipsa/Listic Labs model to be used with OpenCV.
|
||||
* This retina model allows spatio-temporal image processing (applied on still images, video sequences).
|
||||
* As a summary, these are the retina model properties:
|
||||
* => It applies a spectral whithening (mid-frequency details enhancement)
|
||||
* => high frequency spatio-temporal noise reduction
|
||||
* => low frequency luminance to be reduced (luminance range compression)
|
||||
* => local logarithmic luminance compression allows details to be enhanced in low light conditions
|
||||
*
|
||||
* USE : this model can be used basically for spatio-temporal video effects but also for :
|
||||
* _using the getParvo method output matrix : texture analysiswith enhanced signal to noise ratio and enhanced details robust against input images luminance ranges
|
||||
* _using the getMagno method output matrix : motion analysis also with the previously cited properties
|
||||
*
|
||||
* for more information, reer to the following papers :
|
||||
* Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
* Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
*
|
||||
* The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
* _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
* ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
* _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
* ====> more informations in the above cited Jeanny Heraults's book.
|
||||
*/
|
||||
class CV_EXPORTS Retina : public Algorithm {
|
||||
|
||||
public:
|
||||
|
||||
// parameters structure for better clarity, check explenations on the comments of methods : setupOPLandIPLParvoChannel and setupIPLMagnoChannel
|
||||
struct RetinaParameters{
|
||||
struct OPLandIplParvoParameters{ // Outer Plexiform Layer (OPL) and Inner Plexiform Layer Parvocellular (IplParvo) parameters
|
||||
OPLandIplParvoParameters():colorMode(true),
|
||||
normaliseOutput(true),
|
||||
photoreceptorsLocalAdaptationSensitivity(0.75f),
|
||||
photoreceptorsTemporalConstant(0.9f),
|
||||
photoreceptorsSpatialConstant(0.53f),
|
||||
horizontalCellsGain(0.01f),
|
||||
hcellsTemporalConstant(0.5f),
|
||||
hcellsSpatialConstant(7.f),
|
||||
ganglionCellsSensitivity(0.75f){};// default setup
|
||||
bool colorMode, normaliseOutput;
|
||||
float photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity;
|
||||
};
|
||||
struct IplMagnoParameters{ // Inner Plexiform Layer Magnocellular channel (IplMagno)
|
||||
IplMagnoParameters():
|
||||
normaliseOutput(true),
|
||||
parasolCells_beta(0.f),
|
||||
parasolCells_tau(0.f),
|
||||
parasolCells_k(7.f),
|
||||
amacrinCellsTemporalCutFrequency(2.0f),
|
||||
V0CompressionParameter(0.95f),
|
||||
localAdaptintegration_tau(0.f),
|
||||
localAdaptintegration_k(7.f){};// default setup
|
||||
bool normaliseOutput;
|
||||
float parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k;
|
||||
};
|
||||
struct OPLandIplParvoParameters OPLandIplParvo;
|
||||
struct IplMagnoParameters IplMagno;
|
||||
};
|
||||
|
||||
/**
|
||||
* retreive retina input buffer size
|
||||
*/
|
||||
virtual Size getInputSize()=0;
|
||||
|
||||
/**
|
||||
* retreive retina output buffer size
|
||||
*/
|
||||
virtual Size getOutputSize()=0;
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
* => if the xml file does not exist, then default setup is applied
|
||||
* => warning, Exceptions are thrown if read XML file is not valid
|
||||
* @param retinaParameterFile : the parameters filename
|
||||
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
|
||||
*/
|
||||
virtual void setup(String retinaParameterFile="", const bool applyDefaultSetupOnFailure=true)=0;
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
* => if the xml file does not exist, then default setup is applied
|
||||
* => warning, Exceptions are thrown if read XML file is not valid
|
||||
* @param fs : the open Filestorage which contains retina parameters
|
||||
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
|
||||
*/
|
||||
virtual void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true)=0;
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
* => if the xml file does not exist, then default setup is applied
|
||||
* => warning, Exceptions are thrown if read XML file is not valid
|
||||
* @param newParameters : a parameters structures updated with the new target configuration
|
||||
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
|
||||
*/
|
||||
virtual void setup(RetinaParameters newParameters)=0;
|
||||
|
||||
/**
|
||||
* @return the current parameters setup
|
||||
*/
|
||||
virtual struct Retina::RetinaParameters getParameters()=0;
|
||||
|
||||
/**
|
||||
* parameters setup display method
|
||||
* @return a string which contains formatted parameters information
|
||||
*/
|
||||
virtual const String printSetup()=0;
|
||||
|
||||
/**
|
||||
* write xml/yml formated parameters information
|
||||
* @rparam fs : the filename of the xml file that will be open and writen with formatted parameters information
|
||||
*/
|
||||
virtual void write( String fs ) const=0;
|
||||
|
||||
/**
|
||||
* write xml/yml formated parameters information
|
||||
* @param fs : a cv::Filestorage object ready to be filled
|
||||
*/
|
||||
virtual void write( FileStorage& fs ) const=0;
|
||||
|
||||
/**
|
||||
* setup the OPL and IPL parvo channels (see biologocal model)
|
||||
* OPL is referred as Outer Plexiform Layer of the retina, it allows the spatio-temporal filtering which withens the spectrum and reduces spatio-temporal noise while attenuating global luminance (low frequency energy)
|
||||
* IPL parvo is the OPL next processing stage, it refers to Inner Plexiform layer of the retina, it allows high contours sensitivity in foveal vision.
|
||||
* for more informations, please have a look at the paper Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
* @param colorMode : specifies if (true) color is processed of not (false) to then processing gray level image
|
||||
* @param normaliseOutput : specifies if (true) output is rescaled between 0 and 255 of not (false)
|
||||
* @param photoreceptorsLocalAdaptationSensitivity: the photoreceptors sensitivity renage is 0-1 (more log compression effect when value increases)
|
||||
* @param photoreceptorsTemporalConstant: the time constant of the first order low pass filter of the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 1 frame
|
||||
* @param photoreceptorsSpatialConstant: the spatial constant of the first order low pass filter of the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 1 pixel
|
||||
* @param horizontalCellsGain: gain of the horizontal cells network, if 0, then the mean value of the output is zero, if the parameter is near 1, then, the luminance is not filtered and is still reachable at the output, typicall value is 0
|
||||
* @param HcellsTemporalConstant: the time constant of the first order low pass filter of the horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is frames, typical value is 1 frame, as the photoreceptors
|
||||
* @param HcellsSpatialConstant: the spatial constant of the first order low pass filter of the horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, typical value is 5 pixel, this value is also used for local contrast computing when computing the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular channel model)
|
||||
* @param ganglionCellsSensitivity: the compression strengh of the ganglion cells local adaptation output, set a value between 160 and 250 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 230
|
||||
*/
|
||||
virtual void setupOPLandIPLParvoChannel(const bool colorMode=true, const bool normaliseOutput = true, const float photoreceptorsLocalAdaptationSensitivity=0.7, const float photoreceptorsTemporalConstant=0.5, const float photoreceptorsSpatialConstant=0.53, const float horizontalCellsGain=0, const float HcellsTemporalConstant=1, const float HcellsSpatialConstant=7, const float ganglionCellsSensitivity=0.7)=0;
|
||||
|
||||
/**
|
||||
* set parameters values for the Inner Plexiform Layer (IPL) magnocellular channel
|
||||
* this channel processes signals outpint from OPL processing stage in peripheral vision, it allows motion information enhancement. It is decorrelated from the details channel. See reference paper for more details.
|
||||
* @param normaliseOutput : specifies if (true) output is rescaled between 0 and 255 of not (false)
|
||||
* @param parasolCells_beta: the low pass filter gain used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), typical value is 0
|
||||
* @param parasolCells_tau: the low pass filter time constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical value is 0 (immediate response)
|
||||
* @param parasolCells_k: the low pass filter spatial constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical value is 5
|
||||
* @param amacrinCellsTemporalCutFrequency: the time constant of the first order high pass fiter of the magnocellular way (motion information channel), unit is frames, tipicall value is 5
|
||||
* @param V0CompressionParameter: the compression strengh of the ganglion cells local adaptation output, set a value between 160 and 250 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 200
|
||||
* @param localAdaptintegration_tau: specifies the temporal constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
* @param localAdaptintegration_k: specifies the spatial constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
*/
|
||||
virtual void setupIPLMagnoChannel(const bool normaliseOutput = true, const float parasolCells_beta=0, const float parasolCells_tau=0, const float parasolCells_k=7, const float amacrinCellsTemporalCutFrequency=1.2, const float V0CompressionParameter=0.95, const float localAdaptintegration_tau=0, const float localAdaptintegration_k=7)=0;
|
||||
|
||||
/**
|
||||
* method which allows retina to be applied on an input image, after run, encapsulated retina module is ready to deliver its outputs using dedicated acccessors, see getParvo and getMagno methods
|
||||
* @param inputImage : the input cv::Mat image to be processed, can be gray level or BGR coded in any format (from 8bit to 16bits)
|
||||
*/
|
||||
virtual void run(InputArray inputImage)=0;
|
||||
|
||||
/**
|
||||
* method that applies a luminance correction (initially High Dynamic Range (HDR) tone mapping) using only the 2 local adaptation stages of the retina parvo channel : photoreceptors level and ganlion cells level. Spatio temporal filtering is applied but limited to temporal smoothing and eventually high frequencies attenuation. This is a lighter method than the one available using the regular run method. It is then faster but it does not include complete temporal filtering nor retina spectral whitening. Then, it can have a more limited effect on images with a very high dynamic range. This is an adptation of the original still image HDR tone mapping algorithm of David Alleyson, Sabine Susstruck and Laurence Meylan's work, please cite:
|
||||
* -> Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816
|
||||
@param inputImage the input image to process RGB or gray levels
|
||||
@param outputToneMappedImage the output tone mapped image
|
||||
*/
|
||||
virtual void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)=0;
|
||||
|
||||
/**
|
||||
* accessor of the details channel of the retina (models foveal vision)
|
||||
* @param retinaOutput_parvo : the output buffer (reallocated if necessary), this output is rescaled for standard 8bits image processing use in OpenCV
|
||||
*/
|
||||
virtual void getParvo(OutputArray retinaOutput_parvo)=0;
|
||||
|
||||
/**
|
||||
* accessor of the details channel of the retina (models foveal vision)
|
||||
* @param retinaOutput_parvo : a cv::Mat header filled with the internal parvo buffer of the retina module. This output is the original retina filter model output, without any quantification or rescaling
|
||||
*/
|
||||
virtual void getParvoRAW(OutputArray retinaOutput_parvo)=0;
|
||||
|
||||
/**
|
||||
* accessor of the motion channel of the retina (models peripheral vision)
|
||||
* @param retinaOutput_magno : the output buffer (reallocated if necessary), this output is rescaled for standard 8bits image processing use in OpenCV
|
||||
*/
|
||||
virtual void getMagno(OutputArray retinaOutput_magno)=0;
|
||||
|
||||
/**
|
||||
* accessor of the motion channel of the retina (models peripheral vision)
|
||||
* @param retinaOutput_magno : a cv::Mat header filled with the internal retina magno buffer of the retina module. This output is the original retina filter model output, without any quantification or rescaling
|
||||
*/
|
||||
virtual void getMagnoRAW(OutputArray retinaOutput_magno)=0;
|
||||
|
||||
// original API level data accessors : get buffers addresses from a Mat header, similar to getParvoRAW and getMagnoRAW...
|
||||
virtual const Mat getMagnoRAW() const=0;
|
||||
virtual const Mat getParvoRAW() const=0;
|
||||
|
||||
/**
|
||||
* activate color saturation as the final step of the color demultiplexing process
|
||||
* -> this saturation is a sigmoide function applied to each channel of the demultiplexed image.
|
||||
* @param saturateColors: boolean that activates color saturation (if true) or desactivate (if false)
|
||||
* @param colorSaturationValue: the saturation factor
|
||||
*/
|
||||
virtual void setColorSaturation(const bool saturateColors=true, const float colorSaturationValue=4.0)=0;
|
||||
|
||||
/**
|
||||
* clear all retina buffers (equivalent to opening the eyes after a long period of eye close ;o)
|
||||
*/
|
||||
virtual void clearBuffers()=0;
|
||||
|
||||
/**
|
||||
* Activate/desactivate the Magnocellular pathway processing (motion information extraction), by default, it is activated
|
||||
* @param activate: true if Magnocellular output should be activated, false if not
|
||||
*/
|
||||
virtual void activateMovingContoursProcessing(const bool activate)=0;
|
||||
|
||||
/**
|
||||
* Activate/desactivate the Parvocellular pathway processing (contours information extraction), by default, it is activated
|
||||
* @param activate: true if Parvocellular (contours information extraction) output should be activated, false if not
|
||||
*/
|
||||
virtual void activateContoursProcessing(const bool activate)=0;
|
||||
};
|
||||
CV_EXPORTS Ptr<Retina> createRetina(Size inputSize);
|
||||
CV_EXPORTS Ptr<Retina> createRetina(Size inputSize, const bool colorMode, int colorSamplingMethod=RETINA_COLOR_BAYER, const bool useRetinaLogSampling=false, const double reductionFactor=1.0, const double samplingStrenght=10.0);
|
||||
|
||||
CV_EXPORTS Ptr<Retina> createRetina_OCL(Size inputSize);
|
||||
CV_EXPORTS Ptr<Retina> createRetina_OCL(Size inputSize, const bool colorMode, int colorSamplingMethod=RETINA_COLOR_BAYER, const bool useRetinaLogSampling=false, const double reductionFactor=1.0, const double samplingStrenght=10.0);
|
||||
}
|
||||
}
|
||||
#endif /* __OPENCV_BIOINSPIRED_RETINA_HPP__ */
|
@ -1,121 +0,0 @@
|
||||
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2013
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** This class is based on image processing tools of the author and already used within the Retina class (this is the same code as method retina::applyFastToneMapping, but in an independent class, it is ligth from a memory requirement point of view). It implements an adaptation of the efficient tone mapping algorithm propose by David Alleyson, Sabine Susstruck and Laurence Meylan's work, please cite:
|
||||
** -> Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816
|
||||
**
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__
|
||||
#define __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__
|
||||
|
||||
/*
|
||||
* retinafasttonemapping.hpp
|
||||
*
|
||||
* Created on: May 26, 2013
|
||||
* Author: Alexandre Benoit
|
||||
*/
|
||||
|
||||
#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support
|
||||
|
||||
namespace cv{
|
||||
namespace bioinspired{
|
||||
|
||||
/**
|
||||
* @class RetinaFastToneMappingImpl a wrapper class which allows the tone mapping algorithm of Meylan&al(2007) to be used with OpenCV.
|
||||
* This algorithm is already implemented in thre Retina class (retina::applyFastToneMapping) but used it does not require all the retina model to be allocated. This allows a light memory use for low memory devices (smartphones, etc.
|
||||
* As a summary, these are the model properties:
|
||||
* => 2 stages of local luminance adaptation with a different local neighborhood for each.
|
||||
* => first stage models the retina photorecetors local luminance adaptation
|
||||
* => second stage models th ganglion cells local information adaptation
|
||||
* => compared to the initial publication, this class uses spatio-temporal low pass filters instead of spatial only filters.
|
||||
* ====> this can help noise robustness and temporal stability for video sequence use cases.
|
||||
* for more information, read to the following papers :
|
||||
* Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
* regarding spatio-temporal filter and the bigger retina model :
|
||||
* Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
*/
|
||||
class CV_EXPORTS RetinaFastToneMapping : public Algorithm
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* method that applies a luminance correction (initially High Dynamic Range (HDR) tone mapping) using only the 2 local adaptation stages of the retina parvocellular channel : photoreceptors level and ganlion cells level. Spatio temporal filtering is applied but limited to temporal smoothing and eventually high frequencies attenuation. This is a lighter method than the one available using the regular retina::run method. It is then faster but it does not include complete temporal filtering nor retina spectral whitening. Then, it can have a more limited effect on images with a very high dynamic range. This is an adptation of the original still image HDR tone mapping algorithm of David Alleyson, Sabine Susstruck and Laurence Meylan's work, please cite:
|
||||
* -> Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816
|
||||
@param inputImage the input image to process RGB or gray levels
|
||||
@param outputToneMappedImage the output tone mapped image
|
||||
*/
|
||||
virtual void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)=0;
|
||||
|
||||
/**
|
||||
* setup method that updates tone mapping behaviors by adjusing the local luminance computation area
|
||||
* @param photoreceptorsNeighborhoodRadius the first stage local adaptation area
|
||||
* @param ganglioncellsNeighborhoodRadius the second stage local adaptation area
|
||||
* @param meanLuminanceModulatorK the factor applied to modulate the meanLuminance information (default is 1, see reference paper)
|
||||
*/
|
||||
virtual void setup(const float photoreceptorsNeighborhoodRadius=3.f, const float ganglioncellsNeighborhoodRadius=1.f, const float meanLuminanceModulatorK=1.f)=0;
|
||||
};
|
||||
|
||||
CV_EXPORTS Ptr<RetinaFastToneMapping> createRetinaFastToneMapping(Size inputSize);
|
||||
|
||||
}
|
||||
}
|
||||
#endif /* __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__ */
|
@ -1,888 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2011
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include "basicretinafilter.hpp"
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
// @author Alexandre BENOIT, benoit.alexandre.vision@gmail.com, LISTIC : www.listic.univ-savoie.fr Gipsa-Lab, France: www.gipsa-lab.inpg.fr/
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
// BASIC RETINA FILTER
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
// Constructor and Desctructor of the basic retina filter
|
||||
BasicRetinaFilter::BasicRetinaFilter(const unsigned int NBrows, const unsigned int NBcolumns, const unsigned int parametersListSize, const bool useProgressiveFilter)
|
||||
:_filterOutput(NBrows, NBcolumns),
|
||||
_localBuffer(NBrows*NBcolumns),
|
||||
_filteringCoeficientsTable(3*parametersListSize),
|
||||
_progressiveSpatialConstant(0),// pointer to a local table containing local spatial constant (allocated with the object)
|
||||
_progressiveGain(0)
|
||||
{
|
||||
#ifdef T_BASIC_RETINA_ELEMENT_DEBUG
|
||||
std::cout<<"BasicRetinaFilter::BasicRetinaFilter: new filter, size="<<NBrows<<", "<<NBcolumns<<std::endl;
|
||||
#endif
|
||||
_halfNBrows=_filterOutput.getNBrows()/2;
|
||||
_halfNBcolumns=_filterOutput.getNBcolumns()/2;
|
||||
|
||||
if (useProgressiveFilter)
|
||||
{
|
||||
#ifdef T_BASIC_RETINA_ELEMENT_DEBUG
|
||||
std::cout<<"BasicRetinaFilter::BasicRetinaFilter: _progressiveSpatialConstant_Tbuffer"<<std::endl;
|
||||
#endif
|
||||
_progressiveSpatialConstant.resize(_filterOutput.size());
|
||||
#ifdef T_BASIC_RETINA_ELEMENT_DEBUG
|
||||
std::cout<<"BasicRetinaFilter::BasicRetinaFilter: new _progressiveGain_Tbuffer"<<NBrows<<", "<<NBcolumns<<std::endl;
|
||||
#endif
|
||||
_progressiveGain.resize(_filterOutput.size());
|
||||
}
|
||||
#ifdef T_BASIC_RETINA_ELEMENT_DEBUG
|
||||
std::cout<<"BasicRetinaFilter::BasicRetinaFilter: new filter, size="<<NBrows<<", "<<NBcolumns<<std::endl;
|
||||
#endif
|
||||
|
||||
// set default values
|
||||
_maxInputValue=256.0;
|
||||
|
||||
// reset all buffers
|
||||
clearAllBuffers();
|
||||
|
||||
#ifdef T_BASIC_RETINA_ELEMENT_DEBUG
|
||||
std::cout<<"BasicRetinaFilter::Init BasicRetinaElement at specified frame size OK, size="<<this->size()<<std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
BasicRetinaFilter::~BasicRetinaFilter()
|
||||
{
|
||||
|
||||
#ifdef BASIC_RETINA_ELEMENT_DEBUG
|
||||
std::cout<<"BasicRetinaFilter::BasicRetinaElement Deleted OK"<<std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// functions of the basic filter
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
// resize all allocated buffers
|
||||
void BasicRetinaFilter::resize(const unsigned int NBrows, const unsigned int NBcolumns)
|
||||
{
|
||||
|
||||
std::cout<<"BasicRetinaFilter::resize( "<<NBrows<<", "<<NBcolumns<<")"<<std::endl;
|
||||
|
||||
// resizing buffers
|
||||
_filterOutput.resizeBuffer(NBrows, NBcolumns);
|
||||
|
||||
// updating variables
|
||||
_halfNBrows=_filterOutput.getNBrows()/2;
|
||||
_halfNBcolumns=_filterOutput.getNBcolumns()/2;
|
||||
|
||||
_localBuffer.resize(_filterOutput.size());
|
||||
// in case of spatial adapted filter
|
||||
if (_progressiveSpatialConstant.size()>0)
|
||||
{
|
||||
_progressiveSpatialConstant.resize(_filterOutput.size());
|
||||
_progressiveGain.resize(_filterOutput.size());
|
||||
}
|
||||
// reset buffers
|
||||
clearAllBuffers();
|
||||
}
|
||||
|
||||
// Change coefficients table
|
||||
void BasicRetinaFilter::setLPfilterParameters(const float beta, const float tau, const float desired_k, const unsigned int filterIndex)
|
||||
{
|
||||
float _beta = beta+tau;
|
||||
float k=desired_k;
|
||||
// check if the spatial constant is correct (avoid 0 value to avoid division by 0)
|
||||
if (desired_k<=0)
|
||||
{
|
||||
k=0.001f;
|
||||
std::cerr<<"BasicRetinaFilter::spatial constant of the low pass filter must be superior to zero !!! correcting parameter setting to 0,001"<<std::endl;
|
||||
}
|
||||
|
||||
float _alpha = k*k;
|
||||
float _mu = 0.8f;
|
||||
unsigned int tableOffset=filterIndex*3;
|
||||
if (k<=0)
|
||||
{
|
||||
std::cerr<<"BasicRetinaFilter::spatial filtering coefficient must be superior to zero, correcting value to 0.01"<<std::endl;
|
||||
_alpha=0.0001f;
|
||||
}
|
||||
|
||||
float _temp = (1.0f+_beta)/(2.0f*_mu*_alpha);
|
||||
float a = _filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)std::sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[1+tableOffset]=(1.0f-a)*(1.0f-a)*(1.0f-a)*(1.0f-a)/(1.0f+_beta);
|
||||
_filteringCoeficientsTable[2+tableOffset] =tau;
|
||||
|
||||
//std::cout<<"BasicRetinaFilter::normal:"<<(1.0-a)*(1.0-a)*(1.0-a)*(1.0-a)/(1.0+_beta)<<" -> old:"<<(1-a)*(1-a)*(1-a)*(1-a)/(1+_beta)<<std::endl;
|
||||
|
||||
//std::cout<<"BasicRetinaFilter::a="<<a<<", gain="<<_filteringCoeficientsTable[1+tableOffset]<<", tau="<<tau<<std::endl;
|
||||
}
|
||||
|
||||
void BasicRetinaFilter::setProgressiveFilterConstants_CentredAccuracy(const float beta, const float tau, const float alpha0, const unsigned int filterIndex)
|
||||
{
|
||||
// check if dedicated buffers are already allocated, if not create them
|
||||
if (_progressiveSpatialConstant.size()!=_filterOutput.size())
|
||||
{
|
||||
_progressiveSpatialConstant.resize(_filterOutput.size());
|
||||
_progressiveGain.resize(_filterOutput.size());
|
||||
}
|
||||
|
||||
float _beta = beta+tau;
|
||||
float _mu=0.8f;
|
||||
if (alpha0<=0)
|
||||
{
|
||||
std::cerr<<"BasicRetinaFilter::spatial filtering coefficient must be superior to zero, correcting value to 0.01"<<std::endl;
|
||||
//alpha0=0.0001;
|
||||
}
|
||||
|
||||
unsigned int tableOffset=filterIndex*3;
|
||||
|
||||
float _alpha=0.8f;
|
||||
float _temp = (1.0f+_beta)/(2.0f*_mu*_alpha);
|
||||
float a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)std::sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[tableOffset+1]=(1.0f-a)*(1.0f-a)*(1.0f-a)*(1.0f-a)/(1.0f+_beta);
|
||||
_filteringCoeficientsTable[tableOffset+2] =tau;
|
||||
|
||||
float commonFactor=alpha0/(float)std::sqrt(_halfNBcolumns*_halfNBcolumns+_halfNBrows*_halfNBrows+1.0f);
|
||||
//memset(_progressiveSpatialConstant, 255, _filterOutput.getNBpixels());
|
||||
for (unsigned int idColumn=0;idColumn<_halfNBcolumns; ++idColumn)
|
||||
for (unsigned int idRow=0;idRow<_halfNBrows; ++idRow)
|
||||
{
|
||||
// computing local spatial constant
|
||||
float localSpatialConstantValue=commonFactor*std::sqrt((float)(idColumn*idColumn)+(float)(idRow*idRow));
|
||||
if (localSpatialConstantValue>1.0f)
|
||||
localSpatialConstantValue=1.0f;
|
||||
|
||||
_progressiveSpatialConstant[_halfNBcolumns-1+idColumn+_filterOutput.getNBcolumns()*(_halfNBrows-1+idRow)]=localSpatialConstantValue;
|
||||
_progressiveSpatialConstant[_halfNBcolumns-1-idColumn+_filterOutput.getNBcolumns()*(_halfNBrows-1+idRow)]=localSpatialConstantValue;
|
||||
_progressiveSpatialConstant[_halfNBcolumns-1+idColumn+_filterOutput.getNBcolumns()*(_halfNBrows-1-idRow)]=localSpatialConstantValue;
|
||||
_progressiveSpatialConstant[_halfNBcolumns-1-idColumn+_filterOutput.getNBcolumns()*(_halfNBrows-1-idRow)]=localSpatialConstantValue;
|
||||
|
||||
// computing local gain
|
||||
float localGain=(1-localSpatialConstantValue)*(1-localSpatialConstantValue)*(1-localSpatialConstantValue)*(1-localSpatialConstantValue)/(1+_beta);
|
||||
_progressiveGain[_halfNBcolumns-1+idColumn+_filterOutput.getNBcolumns()*(_halfNBrows-1+idRow)]=localGain;
|
||||
_progressiveGain[_halfNBcolumns-1-idColumn+_filterOutput.getNBcolumns()*(_halfNBrows-1+idRow)]=localGain;
|
||||
_progressiveGain[_halfNBcolumns-1+idColumn+_filterOutput.getNBcolumns()*(_halfNBrows-1-idRow)]=localGain;
|
||||
_progressiveGain[_halfNBcolumns-1-idColumn+_filterOutput.getNBcolumns()*(_halfNBrows-1-idRow)]=localGain;
|
||||
|
||||
//std::cout<<commonFactor<<", "<<std::sqrt((_halfNBcolumns-1-idColumn)+(_halfNBrows-idRow-1))<<", "<<(_halfNBcolumns-1-idColumn)<<", "<<(_halfNBrows-idRow-1)<<", "<<localSpatialConstantValue<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void BasicRetinaFilter::setProgressiveFilterConstants_CustomAccuracy(const float beta, const float tau, const float k, const std::valarray<float> &accuracyMap, const unsigned int filterIndex)
|
||||
{
|
||||
|
||||
if (accuracyMap.size()!=_filterOutput.size())
|
||||
{
|
||||
std::cerr<<"BasicRetinaFilter::setProgressiveFilterConstants_CustomAccuracy: error: input accuracy map does not match filter size, init skept"<<std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
// check if dedicated buffers are already allocated, if not create them
|
||||
if (_progressiveSpatialConstant.size()!=_filterOutput.size())
|
||||
{
|
||||
_progressiveSpatialConstant.resize(accuracyMap.size());
|
||||
_progressiveGain.resize(accuracyMap.size());
|
||||
}
|
||||
|
||||
float _beta = beta+tau;
|
||||
float _alpha=k*k;
|
||||
float _mu=0.8f;
|
||||
if (k<=0)
|
||||
{
|
||||
std::cerr<<"BasicRetinaFilter::spatial filtering coefficient must be superior to zero, correcting value to 0.01"<<std::endl;
|
||||
//alpha0=0.0001;
|
||||
}
|
||||
unsigned int tableOffset=filterIndex*3;
|
||||
float _temp = (1.0f+_beta)/(2.0f*_mu*_alpha);
|
||||
float a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)std::sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[tableOffset+1]=(1.0f-a)*(1.0f-a)*(1.0f-a)*(1.0f-a)/(1.0f+_beta);
|
||||
_filteringCoeficientsTable[tableOffset+2] =tau;
|
||||
|
||||
//memset(_progressiveSpatialConstant, 255, _filterOutput.getNBpixels());
|
||||
for (unsigned int idColumn=0;idColumn<_filterOutput.getNBcolumns(); ++idColumn)
|
||||
for (unsigned int idRow=0;idRow<_filterOutput.getNBrows(); ++idRow)
|
||||
{
|
||||
// computing local spatial constant
|
||||
unsigned int index=idColumn+idRow*_filterOutput.getNBcolumns();
|
||||
float localSpatialConstantValue=_a*accuracyMap[index];
|
||||
if (localSpatialConstantValue>1)
|
||||
localSpatialConstantValue=1;
|
||||
|
||||
_progressiveSpatialConstant[index]=localSpatialConstantValue;
|
||||
|
||||
// computing local gain
|
||||
float localGain=(1.0f-localSpatialConstantValue)*(1.0f-localSpatialConstantValue)*(1.0f-localSpatialConstantValue)*(1.0f-localSpatialConstantValue)/(1.0f+_beta);
|
||||
_progressiveGain[index]=localGain;
|
||||
|
||||
//std::cout<<commonFactor<<", "<<std::sqrt((_halfNBcolumns-1-idColumn)+(_halfNBrows-idRow-1))<<", "<<(_halfNBcolumns-1-idColumn)<<", "<<(_halfNBrows-idRow-1)<<", "<<localSpatialConstantValue<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
/// Local luminance adaptation functions
|
||||
// run local adaptation filter and save result in _filterOutput
|
||||
const std::valarray<float> &BasicRetinaFilter::runFilter_LocalAdapdation(const std::valarray<float> &inputFrame, const std::valarray<float> &localLuminance)
|
||||
{
|
||||
_localLuminanceAdaptation(get_data(inputFrame), get_data(localLuminance), &_filterOutput[0]);
|
||||
return _filterOutput;
|
||||
}
|
||||
// run local adaptation filter at a specific output adress
|
||||
void BasicRetinaFilter::runFilter_LocalAdapdation(const std::valarray<float> &inputFrame, const std::valarray<float> &localLuminance, std::valarray<float> &outputFrame)
|
||||
{
|
||||
_localLuminanceAdaptation(get_data(inputFrame), get_data(localLuminance), &outputFrame[0]);
|
||||
}
|
||||
// run local adaptation filter and save result in _filterOutput with autonomous low pass filtering before adaptation
|
||||
const std::valarray<float> &BasicRetinaFilter::runFilter_LocalAdapdation_autonomous(const std::valarray<float> &inputFrame)
|
||||
{
|
||||
_spatiotemporalLPfilter(get_data(inputFrame), &_filterOutput[0]);
|
||||
_localLuminanceAdaptation(get_data(inputFrame), &_filterOutput[0], &_filterOutput[0]);
|
||||
return _filterOutput;
|
||||
}
|
||||
// run local adaptation filter at a specific output adress with autonomous low pass filtering before adaptation
|
||||
void BasicRetinaFilter::runFilter_LocalAdapdation_autonomous(const std::valarray<float> &inputFrame, std::valarray<float> &outputFrame)
|
||||
{
|
||||
_spatiotemporalLPfilter(get_data(inputFrame), &_filterOutput[0]);
|
||||
_localLuminanceAdaptation(get_data(inputFrame), &_filterOutput[0], &outputFrame[0]);
|
||||
}
|
||||
|
||||
// local luminance adaptation of the input in regard of localLuminance buffer, the input is rewrited and becomes the output
|
||||
void BasicRetinaFilter::_localLuminanceAdaptation(float *inputOutputFrame, const float *localLuminance)
|
||||
{
|
||||
_localLuminanceAdaptation(inputOutputFrame, localLuminance, inputOutputFrame, false);
|
||||
|
||||
/* const float *localLuminancePTR=localLuminance;
|
||||
float *inputOutputFramePTR=inputOutputFrame;
|
||||
|
||||
for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel, ++inputOutputFramePTR)
|
||||
{
|
||||
float X0=*(localLuminancePTR++)*_localLuminanceFactor+_localLuminanceAddon;
|
||||
*(inputOutputFramePTR) = (_maxInputValue+X0)**inputOutputFramePTR/(*inputOutputFramePTR +X0+0.00000000001);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// local luminance adaptation of the input in regard of localLuminance buffer
|
||||
void BasicRetinaFilter::_localLuminanceAdaptation(const float *inputFrame, const float *localLuminance, float *outputFrame, const bool updateLuminanceMean)
|
||||
{
|
||||
if (updateLuminanceMean)
|
||||
{ float meanLuminance=0;
|
||||
const float *luminancePTR=inputFrame;
|
||||
for (unsigned int i=0;i<_filterOutput.getNBpixels();++i)
|
||||
meanLuminance+=*(luminancePTR++);
|
||||
meanLuminance/=_filterOutput.getNBpixels();
|
||||
//float tempMeanValue=meanLuminance+_meanInputValue*_tau;
|
||||
updateCompressionParameter(meanLuminance);
|
||||
}
|
||||
#ifdef MAKE_PARALLEL
|
||||
cv::parallel_for_(cv::Range(0,_filterOutput.getNBpixels()), Parallel_localAdaptation(localLuminance, inputFrame, outputFrame, _localLuminanceFactor, _localLuminanceAddon, _maxInputValue));
|
||||
#else
|
||||
//std::cout<<meanLuminance<<std::endl;
|
||||
const float *localLuminancePTR=localLuminance;
|
||||
const float *inputFramePTR=inputFrame;
|
||||
float *outputFramePTR=outputFrame;
|
||||
for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel, ++inputFramePTR, ++outputFramePTR)
|
||||
{
|
||||
float X0=*(localLuminancePTR++)*_localLuminanceFactor+_localLuminanceAddon;
|
||||
// TODO : the following line can lead to a divide by zero ! A small offset is added, take care if the offset is too large in case of High Dynamic Range images which can use very small values...
|
||||
*(outputFramePTR) = (_maxInputValue+X0)**inputFramePTR/(*inputFramePTR +X0+0.00000000001);
|
||||
//std::cout<<"BasicRetinaFilter::inputFrame[IDpixel]=%f, X0=%f, outputFrame[IDpixel]=%f\n", inputFrame[IDpixel], X0, outputFrame[IDpixel]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// local adaptation applied on a range of values which can be positive and negative
|
||||
void BasicRetinaFilter::_localLuminanceAdaptationPosNegValues(const float *inputFrame, const float *localLuminance, float *outputFrame)
|
||||
{
|
||||
const float *localLuminancePTR=localLuminance;
|
||||
const float *inputFramePTR=inputFrame;
|
||||
float *outputFramePTR=outputFrame;
|
||||
float factor=_maxInputValue*2.0f/(float)CV_PI;
|
||||
for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel, ++inputFramePTR)
|
||||
{
|
||||
float X0=*(localLuminancePTR++)*_localLuminanceFactor+_localLuminanceAddon;
|
||||
*(outputFramePTR++) = factor*atan(*inputFramePTR/X0);//(_maxInputValue+X0)**inputFramePTR/(*inputFramePTR +X0);
|
||||
//std::cout<<"BasicRetinaFilter::inputFrame[IDpixel]=%f, X0=%f, outputFrame[IDpixel]=%f\n", inputFrame[IDpixel], X0, outputFrame[IDpixel]);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
/// Spatio temporal Low Pass filter functions
|
||||
// run LP filter and save result in the basic retina element buffer
|
||||
const std::valarray<float> &BasicRetinaFilter::runFilter_LPfilter(const std::valarray<float> &inputFrame, const unsigned int filterIndex)
|
||||
{
|
||||
_spatiotemporalLPfilter(get_data(inputFrame), &_filterOutput[0], filterIndex);
|
||||
return _filterOutput;
|
||||
}
|
||||
|
||||
// run LP filter for a new frame input and save result at a specific output adress
|
||||
void BasicRetinaFilter::runFilter_LPfilter(const std::valarray<float> &inputFrame, std::valarray<float> &outputFrame, const unsigned int filterIndex)
|
||||
{
|
||||
_spatiotemporalLPfilter(get_data(inputFrame), &outputFrame[0], filterIndex);
|
||||
}
|
||||
|
||||
// run LP filter on the input data and rewrite it
|
||||
void BasicRetinaFilter::runFilter_LPfilter_Autonomous(std::valarray<float> &inputOutputFrame, const unsigned int filterIndex)
|
||||
{
|
||||
unsigned int coefTableOffset=filterIndex*3;
|
||||
|
||||
/**********/
|
||||
_a=_filteringCoeficientsTable[coefTableOffset];
|
||||
_gain=_filteringCoeficientsTable[1+coefTableOffset];
|
||||
_tau=_filteringCoeficientsTable[2+coefTableOffset];
|
||||
|
||||
// launch the serie of 1D directional filters in order to compute the 2D low pass filter
|
||||
_horizontalCausalFilter(&inputOutputFrame[0], 0, _filterOutput.getNBrows());
|
||||
_horizontalAnticausalFilter(&inputOutputFrame[0], 0, _filterOutput.getNBrows());
|
||||
_verticalCausalFilter(&inputOutputFrame[0], 0, _filterOutput.getNBcolumns());
|
||||
_verticalAnticausalFilter_multGain(&inputOutputFrame[0], 0, _filterOutput.getNBcolumns());
|
||||
|
||||
}
|
||||
// run LP filter for a new frame input and save result at a specific output adress
|
||||
void BasicRetinaFilter::_spatiotemporalLPfilter(const float *inputFrame, float *outputFrame, const unsigned int filterIndex)
|
||||
{
|
||||
unsigned int coefTableOffset=filterIndex*3;
|
||||
/**********/
|
||||
_a=_filteringCoeficientsTable[coefTableOffset];
|
||||
_gain=_filteringCoeficientsTable[1+coefTableOffset];
|
||||
_tau=_filteringCoeficientsTable[2+coefTableOffset];
|
||||
|
||||
// launch the serie of 1D directional filters in order to compute the 2D low pass filter
|
||||
_horizontalCausalFilter_addInput(inputFrame, outputFrame, 0,_filterOutput.getNBrows());
|
||||
_horizontalAnticausalFilter(outputFrame, 0, _filterOutput.getNBrows());
|
||||
_verticalCausalFilter(outputFrame, 0, _filterOutput.getNBcolumns());
|
||||
_verticalAnticausalFilter_multGain(outputFrame, 0, _filterOutput.getNBcolumns());
|
||||
|
||||
}
|
||||
|
||||
// run SQUARING LP filter for a new frame input and save result at a specific output adress
|
||||
float BasicRetinaFilter::_squaringSpatiotemporalLPfilter(const float *inputFrame, float *outputFrame, const unsigned int filterIndex)
|
||||
{
|
||||
unsigned int coefTableOffset=filterIndex*3;
|
||||
/**********/
|
||||
_a=_filteringCoeficientsTable[coefTableOffset];
|
||||
_gain=_filteringCoeficientsTable[1+coefTableOffset];
|
||||
_tau=_filteringCoeficientsTable[2+coefTableOffset];
|
||||
|
||||
// launch the serie of 1D directional filters in order to compute the 2D low pass filter
|
||||
|
||||
_squaringHorizontalCausalFilter(inputFrame, outputFrame, 0, _filterOutput.getNBrows());
|
||||
_horizontalAnticausalFilter(outputFrame, 0, _filterOutput.getNBrows());
|
||||
_verticalCausalFilter(outputFrame, 0, _filterOutput.getNBcolumns());
|
||||
return _verticalAnticausalFilter_returnMeanValue(outputFrame, 0, _filterOutput.getNBcolumns());
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// standard version of the 1D low pass filters
|
||||
|
||||
// horizontal causal filter which adds the input inside
|
||||
void BasicRetinaFilter::_horizontalCausalFilter(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd)
|
||||
{
|
||||
|
||||
|
||||
//#pragma omp parallel for
|
||||
for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow)
|
||||
{
|
||||
register float* outputPTR=outputFrame+(IDrowStart+IDrow)*_filterOutput.getNBcolumns();
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index)
|
||||
{
|
||||
result = *(outputPTR)+ _a* result;
|
||||
*(outputPTR++) = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
// horizontal causal filter which adds the input inside
|
||||
void BasicRetinaFilter::_horizontalCausalFilter_addInput(const float *inputFrame, float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd)
|
||||
{
|
||||
#ifdef MAKE_PARALLEL
|
||||
cv::parallel_for_(cv::Range(IDrowStart,IDrowEnd), Parallel_horizontalCausalFilter_addInput(inputFrame, outputFrame, IDrowStart, _filterOutput.getNBcolumns(), _a, _tau));
|
||||
#else
|
||||
for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow)
|
||||
{
|
||||
register float* outputPTR=outputFrame+(IDrowStart+IDrow)*_filterOutput.getNBcolumns();
|
||||
register const float* inputPTR=inputFrame+(IDrowStart+IDrow)*_filterOutput.getNBcolumns();
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index)
|
||||
{
|
||||
result = *(inputPTR++) + _tau**(outputPTR)+ _a* result;
|
||||
*(outputPTR++) = result;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// horizontal anticausal filter (basic way, no add on)
|
||||
void BasicRetinaFilter::_horizontalAnticausalFilter(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd)
|
||||
{
|
||||
|
||||
#ifdef MAKE_PARALLEL
|
||||
cv::parallel_for_(cv::Range(IDrowStart,IDrowEnd), Parallel_horizontalAnticausalFilter(outputFrame, IDrowEnd, _filterOutput.getNBcolumns(), _a ));
|
||||
#else
|
||||
for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow)
|
||||
{
|
||||
register float* outputPTR=outputFrame+(IDrowEnd-IDrow)*(_filterOutput.getNBcolumns())-1;
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index)
|
||||
{
|
||||
result = *(outputPTR)+ _a* result;
|
||||
*(outputPTR--) = result;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// horizontal anticausal filter which multiplies the output by _gain
|
||||
void BasicRetinaFilter::_horizontalAnticausalFilter_multGain(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd)
|
||||
{
|
||||
|
||||
//#pragma omp parallel for
|
||||
for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow)
|
||||
{
|
||||
register float* outputPTR=outputFrame+(IDrowEnd-IDrow)*(_filterOutput.getNBcolumns())-1;
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index)
|
||||
{
|
||||
result = *(outputPTR)+ _a* result;
|
||||
*(outputPTR--) = _gain*result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vertical anticausal filter
|
||||
void BasicRetinaFilter::_verticalCausalFilter(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd)
|
||||
{
|
||||
#ifdef MAKE_PARALLEL
|
||||
cv::parallel_for_(cv::Range(IDcolumnStart,IDcolumnEnd), Parallel_verticalCausalFilter(outputFrame, _filterOutput.getNBrows(), _filterOutput.getNBcolumns(), _a ));
|
||||
#else
|
||||
for (unsigned int IDcolumn=IDcolumnStart; IDcolumn<IDcolumnEnd; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=outputFrame+IDcolumn;
|
||||
|
||||
for (unsigned int index=0; index<_filterOutput.getNBrows(); ++index)
|
||||
{
|
||||
result = *(outputPTR) + _a * result;
|
||||
*(outputPTR) = result;
|
||||
outputPTR+=_filterOutput.getNBcolumns();
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// vertical anticausal filter (basic way, no add on)
|
||||
void BasicRetinaFilter::_verticalAnticausalFilter(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd)
|
||||
{
|
||||
float* offset=outputFrame+_filterOutput.getNBpixels()-_filterOutput.getNBcolumns();
|
||||
//#pragma omp parallel for
|
||||
for (unsigned int IDcolumn=IDcolumnStart; IDcolumn<IDcolumnEnd; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=offset+IDcolumn;
|
||||
|
||||
for (unsigned int index=0; index<_filterOutput.getNBrows(); ++index)
|
||||
{
|
||||
result = *(outputPTR) + _a * result;
|
||||
*(outputPTR) = result;
|
||||
outputPTR-=_filterOutput.getNBcolumns();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vertical anticausal filter which multiplies the output by _gain
|
||||
void BasicRetinaFilter::_verticalAnticausalFilter_multGain(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd)
|
||||
{
|
||||
#ifdef MAKE_PARALLEL
|
||||
cv::parallel_for_(cv::Range(IDcolumnStart,IDcolumnEnd), Parallel_verticalAnticausalFilter_multGain(outputFrame, _filterOutput.getNBrows(), _filterOutput.getNBcolumns(), _a, _gain ));
|
||||
#else
|
||||
float* offset=outputFrame+_filterOutput.getNBpixels()-_filterOutput.getNBcolumns();
|
||||
//#pragma omp parallel for
|
||||
for (unsigned int IDcolumn=IDcolumnStart; IDcolumn<IDcolumnEnd; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=offset+IDcolumn;
|
||||
|
||||
for (unsigned int index=0; index<_filterOutput.getNBrows(); ++index)
|
||||
{
|
||||
result = *(outputPTR) + _a * result;
|
||||
*(outputPTR) = _gain*result;
|
||||
outputPTR-=_filterOutput.getNBcolumns();
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
// specific modifications of 1D filters
|
||||
|
||||
// -> squaring horizontal causal filter
|
||||
void BasicRetinaFilter::_squaringHorizontalCausalFilter(const float *inputFrame, float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd)
|
||||
{
|
||||
register float* outputPTR=outputFrame+IDrowStart*_filterOutput.getNBcolumns();
|
||||
register const float* inputPTR=inputFrame+IDrowStart*_filterOutput.getNBcolumns();
|
||||
for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow)
|
||||
{
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index)
|
||||
{
|
||||
result = *(inputPTR)**(inputPTR) + _tau**(outputPTR)+ _a* result;
|
||||
*(outputPTR++) = result;
|
||||
++inputPTR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vertical anticausal filter that returns the mean value of its result
|
||||
float BasicRetinaFilter::_verticalAnticausalFilter_returnMeanValue(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd)
|
||||
{
|
||||
register float meanValue=0;
|
||||
float* offset=outputFrame+_filterOutput.getNBpixels()-_filterOutput.getNBcolumns();
|
||||
for (unsigned int IDcolumn=IDcolumnStart; IDcolumn<IDcolumnEnd; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=offset+IDcolumn;
|
||||
|
||||
for (unsigned int index=0; index<_filterOutput.getNBrows(); ++index)
|
||||
{
|
||||
result = *(outputPTR) + _a * result;
|
||||
*(outputPTR) = _gain*result;
|
||||
meanValue+=*(outputPTR);
|
||||
outputPTR-=_filterOutput.getNBcolumns();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return meanValue/(float)_filterOutput.getNBpixels();
|
||||
}
|
||||
|
||||
// LP filter with integration in specific areas (regarding true values of a binary parameters image)
|
||||
void BasicRetinaFilter::_localSquaringSpatioTemporalLPfilter(const float *inputFrame, float *LPfilterOutput, const unsigned int *integrationAreas, const unsigned int filterIndex)
|
||||
{
|
||||
unsigned int coefTableOffset=filterIndex*3;
|
||||
_a=_filteringCoeficientsTable[coefTableOffset+0];
|
||||
_gain=_filteringCoeficientsTable[coefTableOffset+1];
|
||||
_tau=_filteringCoeficientsTable[coefTableOffset+2];
|
||||
// launch the serie of 1D directional filters in order to compute the 2D low pass filter
|
||||
|
||||
_local_squaringHorizontalCausalFilter(inputFrame, LPfilterOutput, 0, _filterOutput.getNBrows(), integrationAreas);
|
||||
_local_horizontalAnticausalFilter(LPfilterOutput, 0, _filterOutput.getNBrows(), integrationAreas);
|
||||
_local_verticalCausalFilter(LPfilterOutput, 0, _filterOutput.getNBcolumns(), integrationAreas);
|
||||
_local_verticalAnticausalFilter_multGain(LPfilterOutput, 0, _filterOutput.getNBcolumns(), integrationAreas);
|
||||
|
||||
}
|
||||
|
||||
// LP filter on specific parts of the picture instead of all the image
|
||||
// same functions (some of them) but take a binary flag to allow integration, false flag means, no data change at the output...
|
||||
|
||||
// this function take an image in input and squares it befor computing
|
||||
void BasicRetinaFilter::_local_squaringHorizontalCausalFilter(const float *inputFrame, float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd, const unsigned int *integrationAreas)
|
||||
{
|
||||
register float* outputPTR=outputFrame+IDrowStart*_filterOutput.getNBcolumns();
|
||||
register const float* inputPTR=inputFrame+IDrowStart*_filterOutput.getNBcolumns();
|
||||
const unsigned int *integrationAreasPTR=integrationAreas;
|
||||
for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow)
|
||||
{
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index)
|
||||
{
|
||||
if (*(integrationAreasPTR++))
|
||||
result = *(inputPTR)**(inputPTR) + _tau**(outputPTR)+ _a* result;
|
||||
else
|
||||
result=0;
|
||||
*(outputPTR++) = result;
|
||||
++inputPTR;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BasicRetinaFilter::_local_horizontalAnticausalFilter(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd, const unsigned int *integrationAreas)
|
||||
{
|
||||
|
||||
register float* outputPTR=outputFrame+IDrowEnd*(_filterOutput.getNBcolumns())-1;
|
||||
const unsigned int *integrationAreasPTR=integrationAreas;
|
||||
|
||||
for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow)
|
||||
{
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index)
|
||||
{
|
||||
if (*(integrationAreasPTR++))
|
||||
result = *(outputPTR)+ _a* result;
|
||||
else
|
||||
result=0;
|
||||
*(outputPTR--) = result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BasicRetinaFilter::_local_verticalCausalFilter(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd, const unsigned int *integrationAreas)
|
||||
{
|
||||
const unsigned int *integrationAreasPTR=integrationAreas;
|
||||
|
||||
for (unsigned int IDcolumn=IDcolumnStart; IDcolumn<IDcolumnEnd; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=outputFrame+IDcolumn;
|
||||
|
||||
for (unsigned int index=0; index<_filterOutput.getNBrows(); ++index)
|
||||
{
|
||||
if (*(integrationAreasPTR++))
|
||||
result = *(outputPTR)+ _a* result;
|
||||
else
|
||||
result=0;
|
||||
*(outputPTR) = result;
|
||||
outputPTR+=_filterOutput.getNBcolumns();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// this functions affects _gain at the output
|
||||
void BasicRetinaFilter::_local_verticalAnticausalFilter_multGain(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd, const unsigned int *integrationAreas)
|
||||
{
|
||||
const unsigned int *integrationAreasPTR=integrationAreas;
|
||||
float* offset=outputFrame+_filterOutput.getNBpixels()-_filterOutput.getNBcolumns();
|
||||
|
||||
for (unsigned int IDcolumn=IDcolumnStart; IDcolumn<IDcolumnEnd; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=offset+IDcolumn;
|
||||
|
||||
for (unsigned int index=0; index<_filterOutput.getNBrows(); ++index)
|
||||
{
|
||||
if (*(integrationAreasPTR++))
|
||||
result = *(outputPTR)+ _a* result;
|
||||
else
|
||||
result=0;
|
||||
*(outputPTR) = _gain*result;
|
||||
outputPTR-=_filterOutput.getNBcolumns();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// run LP filter for a new frame input and save result at a specific output adress
|
||||
// -> USE IRREGULAR SPATIAL CONSTANT
|
||||
|
||||
// irregular filter computed from a buffer and rewrites it
|
||||
void BasicRetinaFilter::_spatiotemporalLPfilter_Irregular(float *inputOutputFrame, const unsigned int filterIndex)
|
||||
{
|
||||
if (_progressiveGain.size()==0)
|
||||
{
|
||||
std::cerr<<"BasicRetinaFilter::runProgressiveFilter: cannot perform filtering, no progressive filter settled up"<<std::endl;
|
||||
return;
|
||||
}
|
||||
unsigned int coefTableOffset=filterIndex*3;
|
||||
/**********/
|
||||
//_a=_filteringCoeficientsTable[coefTableOffset];
|
||||
_tau=_filteringCoeficientsTable[2+coefTableOffset];
|
||||
|
||||
// launch the serie of 1D directional filters in order to compute the 2D low pass filter
|
||||
_horizontalCausalFilter_Irregular(inputOutputFrame, 0, (int)_filterOutput.getNBrows());
|
||||
_horizontalAnticausalFilter_Irregular(inputOutputFrame, 0, (int)_filterOutput.getNBrows(), &_progressiveSpatialConstant[0]);
|
||||
_verticalCausalFilter_Irregular(inputOutputFrame, 0, (int)_filterOutput.getNBcolumns(), &_progressiveSpatialConstant[0]);
|
||||
_verticalAnticausalFilter_Irregular_multGain(inputOutputFrame, 0, (int)_filterOutput.getNBcolumns());
|
||||
|
||||
}
|
||||
// irregular filter computed from a buffer and puts result on another
|
||||
void BasicRetinaFilter::_spatiotemporalLPfilter_Irregular(const float *inputFrame, float *outputFrame, const unsigned int filterIndex)
|
||||
{
|
||||
if (_progressiveGain.size()==0)
|
||||
{
|
||||
std::cerr<<"BasicRetinaFilter::runProgressiveFilter: cannot perform filtering, no progressive filter settled up"<<std::endl;
|
||||
return;
|
||||
}
|
||||
unsigned int coefTableOffset=filterIndex*3;
|
||||
/**********/
|
||||
//_a=_filteringCoeficientsTable[coefTableOffset];
|
||||
_tau=_filteringCoeficientsTable[2+coefTableOffset];
|
||||
|
||||
// launch the serie of 1D directional filters in order to compute the 2D low pass filter
|
||||
_horizontalCausalFilter_Irregular_addInput(inputFrame, outputFrame, 0, (int)_filterOutput.getNBrows());
|
||||
_horizontalAnticausalFilter_Irregular(outputFrame, 0, (int)_filterOutput.getNBrows(), &_progressiveSpatialConstant[0]);
|
||||
_verticalCausalFilter_Irregular(outputFrame, 0, (int)_filterOutput.getNBcolumns(), &_progressiveSpatialConstant[0]);
|
||||
_verticalAnticausalFilter_Irregular_multGain(outputFrame, 0, (int)_filterOutput.getNBcolumns());
|
||||
|
||||
}
|
||||
// 1D filters with irregular spatial constant
|
||||
// horizontal causal filter wich runs on its input buffer
|
||||
void BasicRetinaFilter::_horizontalCausalFilter_Irregular(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd)
|
||||
{
|
||||
register float* outputPTR=outputFrame+IDrowStart*_filterOutput.getNBcolumns();
|
||||
register const float* spatialConstantPTR=&_progressiveSpatialConstant[0]+IDrowStart*_filterOutput.getNBcolumns();
|
||||
for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow)
|
||||
{
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index)
|
||||
{
|
||||
result = *(outputPTR)+ *(spatialConstantPTR++)* result;
|
||||
*(outputPTR++) = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// horizontal causal filter with add input
|
||||
void BasicRetinaFilter::_horizontalCausalFilter_Irregular_addInput(const float *inputFrame, float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd)
|
||||
{
|
||||
register float* outputPTR=outputFrame+IDrowStart*_filterOutput.getNBcolumns();
|
||||
register const float* inputPTR=inputFrame+IDrowStart*_filterOutput.getNBcolumns();
|
||||
register const float* spatialConstantPTR=&_progressiveSpatialConstant[0]+IDrowStart*_filterOutput.getNBcolumns();
|
||||
for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow)
|
||||
{
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index)
|
||||
{
|
||||
result = *(inputPTR++) + _tau**(outputPTR)+ *(spatialConstantPTR++)* result;
|
||||
*(outputPTR++) = result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// horizontal anticausal filter (basic way, no add on)
|
||||
void BasicRetinaFilter::_horizontalAnticausalFilter_Irregular(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd, const float *spatialConstantBuffer)
|
||||
{
|
||||
#ifdef MAKE_PARALLEL
|
||||
cv::parallel_for_(cv::Range(IDrowStart,IDrowEnd), Parallel_horizontalAnticausalFilter_Irregular(outputFrame, spatialConstantBuffer, IDrowEnd, _filterOutput.getNBcolumns()));
|
||||
#else
|
||||
register float* outputPTR=outputFrame+IDrowEnd*(_filterOutput.getNBcolumns())-1;
|
||||
register const float* spatialConstantPTR=spatialConstantBuffer+IDrowEnd*(_filterOutput.getNBcolumns())-1;
|
||||
|
||||
for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow)
|
||||
{
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index)
|
||||
{
|
||||
result = *(outputPTR)+ *(spatialConstantPTR--)* result;
|
||||
*(outputPTR--) = result;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
// vertical anticausal filter
|
||||
void BasicRetinaFilter::_verticalCausalFilter_Irregular(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd, const float *spatialConstantBuffer)
|
||||
{
|
||||
#ifdef MAKE_PARALLEL
|
||||
cv::parallel_for_(cv::Range(IDcolumnStart,IDcolumnEnd), Parallel_verticalCausalFilter_Irregular(outputFrame, spatialConstantBuffer, _filterOutput.getNBrows(), _filterOutput.getNBcolumns()));
|
||||
#else
|
||||
for (unsigned int IDcolumn=IDcolumnStart; IDcolumn<IDcolumnEnd; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=outputFrame+IDcolumn;
|
||||
register const float *spatialConstantPTR=spatialConstantBuffer+IDcolumn;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBrows(); ++index)
|
||||
{
|
||||
result = *(outputPTR) + *(spatialConstantPTR) * result;
|
||||
*(outputPTR) = result;
|
||||
outputPTR+=_filterOutput.getNBcolumns();
|
||||
spatialConstantPTR+=_filterOutput.getNBcolumns();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// vertical anticausal filter which multiplies the output by _gain
|
||||
void BasicRetinaFilter::_verticalAnticausalFilter_Irregular_multGain(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd)
|
||||
{
|
||||
float* outputOffset=outputFrame+_filterOutput.getNBpixels()-_filterOutput.getNBcolumns();
|
||||
const float* constantOffset=&_progressiveSpatialConstant[0]+_filterOutput.getNBpixels()-_filterOutput.getNBcolumns();
|
||||
const float* gainOffset=&_progressiveGain[0]+_filterOutput.getNBpixels()-_filterOutput.getNBcolumns();
|
||||
for (unsigned int IDcolumn=IDcolumnStart; IDcolumn<IDcolumnEnd; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=outputOffset+IDcolumn;
|
||||
register const float *spatialConstantPTR=constantOffset+IDcolumn;
|
||||
register const float *progressiveGainPTR=gainOffset+IDcolumn;
|
||||
for (unsigned int index=0; index<_filterOutput.getNBrows(); ++index)
|
||||
{
|
||||
result = *(outputPTR) + *(spatialConstantPTR) * result;
|
||||
*(outputPTR) = *(progressiveGainPTR)*result;
|
||||
outputPTR-=_filterOutput.getNBcolumns();
|
||||
spatialConstantPTR-=_filterOutput.getNBcolumns();
|
||||
progressiveGainPTR-=_filterOutput.getNBcolumns();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
@ -1,657 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2011
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef BASICRETINAELEMENT_HPP_
|
||||
#define BASICRETINAELEMENT_HPP_
|
||||
|
||||
#include <cstring>
|
||||
|
||||
|
||||
/**
|
||||
* @class BasicRetinaFilter
|
||||
* @brief Brief overview, this class provides tools for low level image processing:
|
||||
* --> this class is able to perform:
|
||||
* -> first order Low pass optimized filtering
|
||||
* -> local luminance adaptation (able to correct back light problems and contrast enhancement)
|
||||
* -> progressive low pass filter filtering (higher filtering on the borders than on the center)
|
||||
* -> image data between 0 and 255 resampling with different options, linear rescaling, sigmoide)
|
||||
*
|
||||
* NOTE : initially the retina model was based on double format scalar values but
|
||||
* a good memory/precision compromise is float...
|
||||
* also the double format precision does not make so much sense from a biological point of view (neurons value coding is not so precise)
|
||||
*
|
||||
* TYPICAL USE:
|
||||
*
|
||||
* // create object at a specified picture size
|
||||
* BasicRetinaFilter *_photoreceptorsPrefilter;
|
||||
* _photoreceptorsPrefilter =new BasicRetinaFilter(sizeRows, sizeWindows);
|
||||
*
|
||||
* // init gain, spatial and temporal parameters:
|
||||
* _photoreceptorsPrefilter->setCoefficientsTable(gain,temporalConstant, spatialConstant);
|
||||
*
|
||||
* // during program execution, call the filter for local luminance correction or low pass filtering for an input picture called "FrameBuffer":
|
||||
* _photoreceptorsPrefilter->runFilter_LocalAdapdation(FrameBuffer);
|
||||
* // or (Low pass first order filter)
|
||||
* _photoreceptorsPrefilter->runFilter_LPfilter(FrameBuffer);
|
||||
* // get output frame and its size:
|
||||
* const unsigned int output_nbRows=_photoreceptorsPrefilter->getNBrows();
|
||||
* const unsigned int output_nbColumns=_photoreceptorsPrefilter->getNBcolumns();
|
||||
* const double *outputFrame=_photoreceptorsPrefilter->getOutput();
|
||||
*
|
||||
* // at the end of the program, destroy object:
|
||||
* delete _photoreceptorsPrefilter;
|
||||
|
||||
* @author Alexandre BENOIT, benoit.alexandre.vision@gmail.com, LISTIC : www.listic.univ-savoie.fr, Gipsa-Lab, France: www.gipsa-lab.inpg.fr/
|
||||
* Creation date 2007
|
||||
* synthesis of the work described in Alexandre BENOIT thesis: "Le systeme visuel humain au secours de la vision par ordinateur"
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "templatebuffer.hpp"
|
||||
|
||||
//#define __BASIC_RETINA_ELEMENT_DEBUG
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
class BasicRetinaFilter
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* constructor of the base bio-inspired toolbox, parameters are only linked to imae input size and number of filtering capabilities of the object
|
||||
* @param NBrows: number of rows of the input image
|
||||
* @param NBcolumns: number of columns of the input image
|
||||
* @param parametersListSize: specifies the number of parameters set (each parameters set represents a specific low pass spatio-temporal filter)
|
||||
* @param useProgressiveFilter: specifies if the filter has irreguar (progressive) filtering capabilities (this can be activated later using setProgressiveFilterConstants_xxx methods)
|
||||
*/
|
||||
BasicRetinaFilter(const unsigned int NBrows, const unsigned int NBcolumns, const unsigned int parametersListSize=1, const bool useProgressiveFilter=false);
|
||||
|
||||
/**
|
||||
* standrad destructore
|
||||
*/
|
||||
~BasicRetinaFilter();
|
||||
|
||||
/**
|
||||
* function which clears the output buffer of the object
|
||||
*/
|
||||
inline void clearOutputBuffer(){_filterOutput=0;};
|
||||
|
||||
/**
|
||||
* function which clears the secondary buffer of the object
|
||||
*/
|
||||
inline void clearSecondaryBuffer(){_localBuffer=0;};
|
||||
|
||||
/**
|
||||
* function which clears the output and the secondary buffer of the object
|
||||
*/
|
||||
inline void clearAllBuffers(){clearOutputBuffer();clearSecondaryBuffer();};
|
||||
|
||||
/**
|
||||
* resize basic retina filter object (resize all allocated buffers
|
||||
* @param NBrows: the new height size
|
||||
* @param NBcolumns: the new width size
|
||||
*/
|
||||
void resize(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
|
||||
/**
|
||||
* forbiden method inherited from parent std::valarray
|
||||
* prefer not to use this method since the filter matrix become vectors
|
||||
*/
|
||||
void resize(const unsigned int){std::cerr<<"error, not accessible method"<<std::endl;};
|
||||
|
||||
/**
|
||||
* low pass filter call and run (models the homogeneous cells network at the retina level, for example horizontal cells or photoreceptors)
|
||||
* @param inputFrame: the input image to be processed
|
||||
* @param filterIndex: the offset which specifies the parameter set that should be used for the filtering
|
||||
* @return the processed image, the output is reachable later by using function getOutput()
|
||||
*/
|
||||
const std::valarray<float> &runFilter_LPfilter(const std::valarray<float> &inputFrame, const unsigned int filterIndex=0); // run the LP filter for a new frame input and save result in _filterOutput
|
||||
|
||||
/**
|
||||
* low pass filter call and run (models the homogeneous cells network at the retina level, for example horizontal cells or photoreceptors)
|
||||
* @param inputFrame: the input image to be processed
|
||||
* @param outputFrame: the output buffer in which the result is writed
|
||||
* @param filterIndex: the offset which specifies the parameter set that should be used for the filtering
|
||||
*/
|
||||
void runFilter_LPfilter(const std::valarray<float> &inputFrame, std::valarray<float> &outputFrame, const unsigned int filterIndex=0); // run LP filter on a specific output adress
|
||||
|
||||
/**
|
||||
* low pass filter call and run (models the homogeneous cells network at the retina level, for example horizontal cells or photoreceptors)
|
||||
* @param inputOutputFrame: the input image to be processed on which the result is rewrited
|
||||
* @param filterIndex: the offset which specifies the parameter set that should be used for the filtering
|
||||
*/
|
||||
void runFilter_LPfilter_Autonomous(std::valarray<float> &inputOutputFrame, const unsigned int filterIndex=0);// run LP filter on the input data and rewrite it
|
||||
|
||||
/**
|
||||
* local luminance adaptation call and run (contrast enhancement property of the photoreceptors)
|
||||
* @param inputOutputFrame: the input image to be processed
|
||||
* @param localLuminance: an image which represents the local luminance of the inputFrame parameter, in general, it is its low pass spatial filtering
|
||||
* @return the processed image, the output is reachable later by using function getOutput()
|
||||
*/
|
||||
const std::valarray<float> &runFilter_LocalAdapdation(const std::valarray<float> &inputOutputFrame, const std::valarray<float> &localLuminance);// run local adaptation filter and save result in _filterOutput
|
||||
|
||||
/**
|
||||
* local luminance adaptation call and run (contrast enhancement property of the photoreceptors)
|
||||
* @param inputFrame: the input image to be processed
|
||||
* @param localLuminance: an image which represents the local luminance of the inputFrame parameter, in general, it is its low pass spatial filtering
|
||||
* @param outputFrame: the output buffer in which the result is writed
|
||||
*/
|
||||
void runFilter_LocalAdapdation(const std::valarray<float> &inputFrame, const std::valarray<float> &localLuminance, std::valarray<float> &outputFrame); // run local adaptation filter on a specific output adress
|
||||
|
||||
/**
|
||||
* local luminance adaptation call and run (contrast enhancement property of the photoreceptors)
|
||||
* @param inputFrame: the input image to be processed
|
||||
* @return the processed image, the output is reachable later by using function getOutput()
|
||||
*/
|
||||
const std::valarray<float> &runFilter_LocalAdapdation_autonomous(const std::valarray<float> &inputFrame);// run local adaptation filter and save result in _filterOutput
|
||||
|
||||
/**
|
||||
* local luminance adaptation call and run (contrast enhancement property of the photoreceptors)
|
||||
* @param inputFrame: the input image to be processed
|
||||
* @param outputFrame: the output buffer in which the result is writen
|
||||
*/
|
||||
void runFilter_LocalAdapdation_autonomous(const std::valarray<float> &inputFrame, std::valarray<float> &outputFrame); // run local adaptation filter on a specific output adress
|
||||
|
||||
/**
|
||||
* run low pass filtering with progressive parameters (models the retina log sampling of the photoreceptors and its low pass filtering effect consequence: more powerfull low pass filtering effect on the corners)
|
||||
* @param inputFrame: the input image to be processed
|
||||
* @param filterIndex: the index which specifies the parameter set that should be used for the filtering
|
||||
* @return the processed image, the output is reachable later by using function getOutput() if outputFrame is NULL
|
||||
*/
|
||||
inline void runProgressiveFilter(std::valarray<float> &inputFrame, const unsigned int filterIndex=0){_spatiotemporalLPfilter_Irregular(&inputFrame[0], filterIndex);};
|
||||
|
||||
/**
|
||||
* run low pass filtering with progressive parameters (models the retina log sampling of the photoreceptors and its low pass filtering effect consequence: more powerfull low pass filtering effect on the corners)
|
||||
* @param inputFrame: the input image to be processed
|
||||
* @param outputFrame: the output buffer in which the result is writen
|
||||
* @param filterIndex: the index which specifies the parameter set that should be used for the filtering
|
||||
*/
|
||||
inline void runProgressiveFilter(const std::valarray<float> &inputFrame,
|
||||
std::valarray<float> &outputFrame,
|
||||
const unsigned int filterIndex=0)
|
||||
{_spatiotemporalLPfilter_Irregular(get_data(inputFrame), &outputFrame[0], filterIndex);};
|
||||
|
||||
/**
|
||||
* first order spatio-temporal low pass filter setup function
|
||||
* @param beta: gain of the filter (generally set to zero)
|
||||
* @param tau: time constant of the filter (unit is frame for video processing)
|
||||
* @param k: spatial constant of the filter (unit is pixels)
|
||||
* @param filterIndex: the index which specifies the parameter set that should be used for the filtering
|
||||
*/
|
||||
void setLPfilterParameters(const float beta, const float tau, const float k, const unsigned int filterIndex=0); // change the parameters of the filter
|
||||
|
||||
/**
|
||||
* first order spatio-temporal low pass filter setup function
|
||||
* @param beta: gain of the filter (generally set to zero)
|
||||
* @param tau: time constant of the filter (unit is frame for video processing)
|
||||
* @param alpha0: spatial constant of the filter (unit is pixels) on the border of the image
|
||||
* @param filterIndex: the index which specifies the parameter set that should be used for the filtering
|
||||
*/
|
||||
void setProgressiveFilterConstants_CentredAccuracy(const float beta, const float tau, const float alpha0, const unsigned int filterIndex=0);
|
||||
|
||||
/**
|
||||
* first order spatio-temporal low pass filter setup function
|
||||
* @param beta: gain of the filter (generally set to zero)
|
||||
* @param tau: time constant of the filter (unit is frame for video processing)
|
||||
* @param alpha0: spatial constant of the filter (unit is pixels) on the border of the image
|
||||
* @param accuracyMap an image (float format) which values range is between 0 and 1, where 0 means, apply no filtering and 1 means apply the filtering as specified in the parameters set, intermediate values allow to smooth variations of the filtering strenght
|
||||
* @param filterIndex: the index which specifies the parameter set that should be used for the filtering
|
||||
*/
|
||||
void setProgressiveFilterConstants_CustomAccuracy(const float beta, const float tau, const float alpha0, const std::valarray<float> &accuracyMap, const unsigned int filterIndex=0);
|
||||
|
||||
/**
|
||||
* local luminance adaptation setup, this function should be applied for normal local adaptation (not for tone mapping operation)
|
||||
* @param v0: compression effect for the local luminance adaptation processing, set a value between 0.6 and 0.9 for best results, a high value yields to a high compression effect
|
||||
* @param maxInputValue: the maximum amplitude value measured after local adaptation processing (c.f. function runFilter_LocalAdapdation & runFilter_LocalAdapdation_autonomous)
|
||||
* @param meanLuminance: the a priori meann luminance of the input data (should be 128 for 8bits images but can vary greatly in case of High Dynamic Range Images (HDRI)
|
||||
*/
|
||||
void setV0CompressionParameter(const float v0, const float maxInputValue, const float){ _v0=v0*maxInputValue; _localLuminanceFactor=v0; _localLuminanceAddon=maxInputValue*(1.0f-v0); _maxInputValue=maxInputValue;};
|
||||
|
||||
/**
|
||||
* update local luminance adaptation setup, initial maxInputValue is kept. This function should be applied for normal local adaptation (not for tone mapping operation)
|
||||
* @param v0: compression effect for the local luminance adaptation processing, set a value between 0.6 and 0.9 for best results, a high value yields to a high compression effect
|
||||
* @param meanLuminance: the a priori meann luminance of the input data (should be 128 for 8bits images but can vary greatly in case of High Dynamic Range Images (HDRI)
|
||||
*/
|
||||
void setV0CompressionParameter(const float v0, const float meanLuminance){ this->setV0CompressionParameter(v0, _maxInputValue, meanLuminance);};
|
||||
|
||||
/**
|
||||
* local luminance adaptation setup, this function should be applied for normal local adaptation (not for tone mapping operation)
|
||||
* @param v0: compression effect for the local luminance adaptation processing, set a value between 0.6 and 0.9 for best results, a high value yields to a high compression effect
|
||||
*/
|
||||
void setV0CompressionParameter(const float v0){ _v0=v0*_maxInputValue; _localLuminanceFactor=v0; _localLuminanceAddon=_maxInputValue*(1.0f-v0);};
|
||||
|
||||
/**
|
||||
* local luminance adaptation setup, this function should be applied for local adaptation applied to tone mapping operation
|
||||
* @param v0: compression effect for the local luminance adaptation processing, set a value between 0.6 and 0.9 for best results, a high value yields to a high compression effect
|
||||
* @param maxInputValue: the maximum amplitude value measured after local adaptation processing (c.f. function runFilter_LocalAdapdation & runFilter_LocalAdapdation_autonomous)
|
||||
* @param meanLuminance: the a priori meann luminance of the input data (should be 128 for 8bits images but can vary greatly in case of High Dynamic Range Images (HDRI)
|
||||
*/
|
||||
void setV0CompressionParameterToneMapping(const float v0, const float maxInputValue, const float meanLuminance=128.0f){ _v0=v0*maxInputValue; _localLuminanceFactor=1.0f; _localLuminanceAddon=meanLuminance*v0; _maxInputValue=maxInputValue;};
|
||||
|
||||
/**
|
||||
* update compression parameters while keeping v0 parameter value
|
||||
* @param meanLuminance the input frame mean luminance
|
||||
*/
|
||||
inline void updateCompressionParameter(const float meanLuminance){_localLuminanceFactor=1; _localLuminanceAddon=meanLuminance*_v0;};
|
||||
|
||||
/**
|
||||
* @return the v0 compression parameter used to compute the local adaptation
|
||||
*/
|
||||
float getV0CompressionParameter(){ return _v0/_maxInputValue;};
|
||||
|
||||
/**
|
||||
* @return the output result of the object
|
||||
*/
|
||||
inline const std::valarray<float> &getOutput() const {return _filterOutput;};
|
||||
|
||||
/**
|
||||
* @return number of rows of the filter
|
||||
*/
|
||||
inline unsigned int getNBrows(){return _filterOutput.getNBrows();};
|
||||
|
||||
/**
|
||||
* @return number of columns of the filter
|
||||
*/
|
||||
inline unsigned int getNBcolumns(){return _filterOutput.getNBcolumns();};
|
||||
|
||||
/**
|
||||
* @return number of pixels of the filter
|
||||
*/
|
||||
inline unsigned int getNBpixels(){return _filterOutput.getNBpixels();};
|
||||
|
||||
/**
|
||||
* force filter output to be normalized between 0 and maxValue
|
||||
* @param maxValue: the maximum output value that is required
|
||||
*/
|
||||
inline void normalizeGrayOutput_0_maxOutputValue(const float maxValue){_filterOutput.normalizeGrayOutput_0_maxOutputValue(maxValue);};
|
||||
|
||||
/**
|
||||
* force filter output to be normalized around 0 and rescaled with a sigmoide effect (extrem values saturation)
|
||||
* @param maxValue: the maximum output value that is required
|
||||
*/
|
||||
inline void normalizeGrayOutputCentredSigmoide(){_filterOutput.normalizeGrayOutputCentredSigmoide();};
|
||||
|
||||
/**
|
||||
* force filter output to be normalized : data centering and std normalisation
|
||||
* @param maxValue: the maximum output value that is required
|
||||
*/
|
||||
inline void centerReductImageLuminance(){_filterOutput.centerReductImageLuminance();};
|
||||
|
||||
/**
|
||||
* @return the maximum input buffer value
|
||||
*/
|
||||
inline float getMaxInputValue(){return this->_maxInputValue;};
|
||||
|
||||
/**
|
||||
* @return the maximum input buffer value
|
||||
*/
|
||||
inline void setMaxInputValue(const float newMaxInputValue){this->_maxInputValue=newMaxInputValue;};
|
||||
|
||||
protected:
|
||||
|
||||
/////////////////////////
|
||||
// data buffers
|
||||
TemplateBuffer<float> _filterOutput; // primary buffer (contains processing outputs)
|
||||
std::valarray<float> _localBuffer; // local secondary buffer
|
||||
/////////////////////////
|
||||
// PARAMETERS
|
||||
unsigned int _halfNBrows;
|
||||
unsigned int _halfNBcolumns;
|
||||
|
||||
// parameters buffers
|
||||
std::valarray <float>_filteringCoeficientsTable;
|
||||
std::valarray <float>_progressiveSpatialConstant;// pointer to a local table containing local spatial constant (allocated with the object)
|
||||
std::valarray <float>_progressiveGain;// pointer to a local table containing local spatial constant (allocated with the object)
|
||||
|
||||
// local adaptation filtering parameters
|
||||
float _v0; //value used for local luminance adaptation function
|
||||
float _maxInputValue;
|
||||
float _meanInputValue;
|
||||
float _localLuminanceFactor;
|
||||
float _localLuminanceAddon;
|
||||
|
||||
// protected data related to standard low pass filters parameters
|
||||
float _a;
|
||||
float _tau;
|
||||
float _gain;
|
||||
|
||||
/////////////////////////
|
||||
// FILTERS METHODS
|
||||
|
||||
// Basic low pass spation temporal low pass filter used by each retina filters
|
||||
void _spatiotemporalLPfilter(const float *inputFrame, float *LPfilterOutput, const unsigned int coefTableOffset=0);
|
||||
float _squaringSpatiotemporalLPfilter(const float *inputFrame, float *outputFrame, const unsigned int filterIndex=0);
|
||||
|
||||
// LP filter with an irregular spatial filtering
|
||||
|
||||
// -> rewrites the input buffer
|
||||
void _spatiotemporalLPfilter_Irregular(float *inputOutputFrame, const unsigned int filterIndex=0);
|
||||
// writes the output on another buffer
|
||||
void _spatiotemporalLPfilter_Irregular(const float *inputFrame, float *outputFrame, const unsigned int filterIndex=0);
|
||||
// LP filter that squares the input and computes the output ONLY on the areas where the integrationAreas map are TRUE
|
||||
void _localSquaringSpatioTemporalLPfilter(const float *inputFrame, float *LPfilterOutput, const unsigned int *integrationAreas, const unsigned int filterIndex=0);
|
||||
|
||||
// local luminance adaptation of the input in regard of localLuminance buffer
|
||||
void _localLuminanceAdaptation(const float *inputFrame, const float *localLuminance, float *outputFrame, const bool updateLuminanceMean=true);
|
||||
// local luminance adaptation of the input in regard of localLuminance buffer, the input is rewrited and becomes the output
|
||||
void _localLuminanceAdaptation(float *inputOutputFrame, const float *localLuminance);
|
||||
// local adaptation applied on a range of values which can be positive and negative
|
||||
void _localLuminanceAdaptationPosNegValues(const float *inputFrame, const float *localLuminance, float *outputFrame);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// 1D directional filters used for the 2D low pass filtering
|
||||
|
||||
// 1D filters with image input
|
||||
void _horizontalCausalFilter_addInput(const float *inputFrame, float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd);
|
||||
// 1D filters with image input that is squared in the function // parallelized with TBB
|
||||
void _squaringHorizontalCausalFilter(const float *inputFrame, float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd);
|
||||
// vertical anticausal filter that returns the mean value of its result
|
||||
float _verticalAnticausalFilter_returnMeanValue(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd);
|
||||
|
||||
// most simple functions: only perform 1D filtering with output=input (no add on)
|
||||
void _horizontalCausalFilter(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd);
|
||||
void _horizontalAnticausalFilter(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd); // parallelized with TBB
|
||||
void _verticalCausalFilter(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd); // parallelized with TBB
|
||||
void _verticalAnticausalFilter(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd);
|
||||
|
||||
// perform 1D filtering with output with varrying spatial coefficient
|
||||
void _horizontalCausalFilter_Irregular(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd);
|
||||
void _horizontalCausalFilter_Irregular_addInput(const float *inputFrame, float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd);
|
||||
void _horizontalAnticausalFilter_Irregular(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd, const float *spatialConstantBuffer); // parallelized with TBB
|
||||
void _verticalCausalFilter_Irregular(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd, const float *spatialConstantBuffer); // parallelized with TBB
|
||||
void _verticalAnticausalFilter_Irregular_multGain(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd);
|
||||
|
||||
|
||||
// 1D filters in which the output is multiplied by _gain
|
||||
void _verticalAnticausalFilter_multGain(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd); // this functions affects _gain at the output // parallelized with TBB
|
||||
void _horizontalAnticausalFilter_multGain(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd); // this functions affects _gain at the output
|
||||
|
||||
// LP filter on specific parts of the picture instead of all the image
|
||||
// same functions (some of them) but take a binary flag to allow integration, false flag means, 0 at the output...
|
||||
void _local_squaringHorizontalCausalFilter(const float *inputFrame, float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd, const unsigned int *integrationAreas);
|
||||
void _local_horizontalAnticausalFilter(float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd, const unsigned int *integrationAreas);
|
||||
void _local_verticalCausalFilter(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd, const unsigned int *integrationAreas);
|
||||
void _local_verticalAnticausalFilter_multGain(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd, const unsigned int *integrationAreas); // this functions affects _gain at the output
|
||||
|
||||
#ifdef MAKE_PARALLEL
|
||||
/******************************************************
|
||||
** IF some parallelizing thread methods are available, then, main loops are parallelized using these functors
|
||||
** ==> main idea paralellise main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelised methods as necessary
|
||||
** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelised
|
||||
** ==> functors constructors can differ from the parameters used with their related serial functions
|
||||
*/
|
||||
|
||||
#define _DEBUG_TBB // define DEBUG_TBB in order to display additionnal data on stdout
|
||||
class Parallel_horizontalAnticausalFilter: public cv::ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
float *outputFrame;
|
||||
unsigned int IDrowEnd, nbColumns;
|
||||
float filterParam_a;
|
||||
public:
|
||||
// constructor which takes the input image pointer reference reference and limits
|
||||
Parallel_horizontalAnticausalFilter(float *bufferToProcess, const unsigned int idEnd, const unsigned int nbCols, const float a )
|
||||
:outputFrame(bufferToProcess), IDrowEnd(idEnd), nbColumns(nbCols), filterParam_a(a)
|
||||
{
|
||||
#ifdef DEBUG_TBB
|
||||
std::cout<<"Parallel_horizontalAnticausalFilter::Parallel_horizontalAnticausalFilter :"
|
||||
<<"\n\t idEnd="<<IDrowEnd
|
||||
<<"\n\t nbCols="<<nbColumns
|
||||
<<"\n\t filterParam="<<filterParam_a
|
||||
<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void operator()( const Range& r ) const {
|
||||
|
||||
#ifdef DEBUG_TBB
|
||||
std::cout<<"Parallel_horizontalAnticausalFilter::operator() :"
|
||||
<<"\n\t range size="<<r.size()
|
||||
<<"\n\t first index="<<r.start
|
||||
//<<"\n\t last index="<<filterParam
|
||||
<<std::endl;
|
||||
#endif
|
||||
for (int IDrow=r.start; IDrow!=r.end; ++IDrow)
|
||||
{
|
||||
register float* outputPTR=outputFrame+(IDrowEnd-IDrow)*(nbColumns)-1;
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<nbColumns; ++index)
|
||||
{
|
||||
result = *(outputPTR)+ filterParam_a* result;
|
||||
*(outputPTR--) = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Parallel_horizontalCausalFilter_addInput: public cv::ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
const float *inputFrame;
|
||||
float *outputFrame;
|
||||
unsigned int IDrowStart, nbColumns;
|
||||
float filterParam_a, filterParam_tau;
|
||||
public:
|
||||
Parallel_horizontalCausalFilter_addInput(const float *bufferToAddAsInputProcess, float *bufferToProcess, const unsigned int idStart, const unsigned int nbCols, const float a, const float tau)
|
||||
:inputFrame(bufferToAddAsInputProcess), outputFrame(bufferToProcess), IDrowStart(idStart), nbColumns(nbCols), filterParam_a(a), filterParam_tau(tau){}
|
||||
|
||||
virtual void operator()( const Range& r ) const {
|
||||
for (int IDrow=r.start; IDrow!=r.end; ++IDrow)
|
||||
{
|
||||
register float* outputPTR=outputFrame+(IDrowStart+IDrow)*nbColumns;
|
||||
register const float* inputPTR=inputFrame+(IDrowStart+IDrow)*nbColumns;
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<nbColumns; ++index)
|
||||
{
|
||||
result = *(inputPTR++) + filterParam_tau**(outputPTR)+ filterParam_a* result;
|
||||
*(outputPTR++) = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Parallel_verticalCausalFilter: public cv::ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
float *outputFrame;
|
||||
unsigned int nbRows, nbColumns;
|
||||
float filterParam_a;
|
||||
public:
|
||||
Parallel_verticalCausalFilter(float *bufferToProcess, const unsigned int nbRws, const unsigned int nbCols, const float a )
|
||||
:outputFrame(bufferToProcess), nbRows(nbRws), nbColumns(nbCols), filterParam_a(a){}
|
||||
|
||||
virtual void operator()( const Range& r ) const {
|
||||
for (int IDcolumn=r.start; IDcolumn!=r.end; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=outputFrame+IDcolumn;
|
||||
|
||||
for (unsigned int index=0; index<nbRows; ++index)
|
||||
{
|
||||
result = *(outputPTR) + filterParam_a * result;
|
||||
*(outputPTR) = result;
|
||||
outputPTR+=nbColumns;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Parallel_verticalAnticausalFilter_multGain: public cv::ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
float *outputFrame;
|
||||
unsigned int nbRows, nbColumns;
|
||||
float filterParam_a, filterParam_gain;
|
||||
public:
|
||||
Parallel_verticalAnticausalFilter_multGain(float *bufferToProcess, const unsigned int nbRws, const unsigned int nbCols, const float a, const float gain)
|
||||
:outputFrame(bufferToProcess), nbRows(nbRws), nbColumns(nbCols), filterParam_a(a), filterParam_gain(gain){}
|
||||
|
||||
virtual void operator()( const Range& r ) const {
|
||||
float* offset=outputFrame+nbColumns*nbRows-nbColumns;
|
||||
for (int IDcolumn=r.start; IDcolumn!=r.end; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=offset+IDcolumn;
|
||||
|
||||
for (unsigned int index=0; index<nbRows; ++index)
|
||||
{
|
||||
result = *(outputPTR) + filterParam_a * result;
|
||||
*(outputPTR) = filterParam_gain*result;
|
||||
outputPTR-=nbColumns;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Parallel_localAdaptation: public cv::ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
const float *localLuminance, *inputFrame;
|
||||
float *outputFrame;
|
||||
float localLuminanceFactor, localLuminanceAddon, maxInputValue;
|
||||
public:
|
||||
Parallel_localAdaptation(const float *localLum, const float *inputImg, float *bufferToProcess, const float localLuminanceFact, const float localLuminanceAdd, const float maxInputVal)
|
||||
:localLuminance(localLum), inputFrame(inputImg),outputFrame(bufferToProcess), localLuminanceFactor(localLuminanceFact), localLuminanceAddon(localLuminanceAdd), maxInputValue(maxInputVal) {};
|
||||
|
||||
virtual void operator()( const Range& r ) const {
|
||||
const float *localLuminancePTR=localLuminance+r.start;
|
||||
const float *inputFramePTR=inputFrame+r.start;
|
||||
float *outputFramePTR=outputFrame+r.start;
|
||||
for (register int IDpixel=r.start ; IDpixel!=r.end ; ++IDpixel, ++inputFramePTR, ++outputFramePTR)
|
||||
{
|
||||
float X0=*(localLuminancePTR++)*localLuminanceFactor+localLuminanceAddon;
|
||||
// TODO : the following line can lead to a divide by zero ! A small offset is added, take care if the offset is too large in case of High Dynamic Range images which can use very small values...
|
||||
*(outputFramePTR) = (maxInputValue+X0)**inputFramePTR/(*inputFramePTR +X0+0.00000000001f);
|
||||
//std::cout<<"BasicRetinaFilter::inputFrame[IDpixel]=%f, X0=%f, outputFrame[IDpixel]=%f\n", inputFrame[IDpixel], X0, outputFrame[IDpixel]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////
|
||||
/// Specific filtering methods which manage non const spatial filtering parameter (used By retinacolor and LogProjectors)
|
||||
class Parallel_horizontalAnticausalFilter_Irregular: public cv::ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
float *outputFrame;
|
||||
const float *spatialConstantBuffer;
|
||||
unsigned int IDrowEnd, nbColumns;
|
||||
public:
|
||||
Parallel_horizontalAnticausalFilter_Irregular(float *bufferToProcess, const float *spatialConst, const unsigned int idEnd, const unsigned int nbCols)
|
||||
:outputFrame(bufferToProcess), spatialConstantBuffer(spatialConst), IDrowEnd(idEnd), nbColumns(nbCols){}
|
||||
|
||||
virtual void operator()( const Range& r ) const {
|
||||
|
||||
for (int IDrow=r.start; IDrow!=r.end; ++IDrow)
|
||||
{
|
||||
register float* outputPTR=outputFrame+(IDrowEnd-IDrow)*(nbColumns)-1;
|
||||
register const float* spatialConstantPTR=spatialConstantBuffer+(IDrowEnd-IDrow)*(nbColumns)-1;
|
||||
register float result=0;
|
||||
for (unsigned int index=0; index<nbColumns; ++index)
|
||||
{
|
||||
result = *(outputPTR)+ *(spatialConstantPTR--)* result;
|
||||
*(outputPTR--) = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Parallel_verticalCausalFilter_Irregular: public cv::ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
float *outputFrame;
|
||||
const float *spatialConstantBuffer;
|
||||
unsigned int nbRows, nbColumns;
|
||||
public:
|
||||
Parallel_verticalCausalFilter_Irregular(float *bufferToProcess, const float *spatialConst, const unsigned int nbRws, const unsigned int nbCols)
|
||||
:outputFrame(bufferToProcess), spatialConstantBuffer(spatialConst), nbRows(nbRws), nbColumns(nbCols){}
|
||||
|
||||
virtual void operator()( const Range& r ) const {
|
||||
for (int IDcolumn=r.start; IDcolumn!=r.end; ++IDcolumn)
|
||||
{
|
||||
register float result=0;
|
||||
register float *outputPTR=outputFrame+IDcolumn;
|
||||
register const float* spatialConstantPTR=spatialConstantBuffer+IDcolumn;
|
||||
for (unsigned int index=0; index<nbRows; ++index)
|
||||
{
|
||||
result = *(outputPTR) + *(spatialConstantPTR) * result;
|
||||
*(outputPTR) = result;
|
||||
outputPTR+=nbColumns;
|
||||
spatialConstantPTR+=nbColumns;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
#endif
|
@ -1,451 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2011
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "imagelogpolprojection.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
// @author Alexandre BENOIT, benoit.alexandre.vision@gmail.com, LISTIC : www.listic.univ-savoie.fr, Gipsa-Lab, France: www.gipsa-lab.inpg.fr/
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
// constructor
|
||||
ImageLogPolProjection::ImageLogPolProjection(const unsigned int nbRows, const unsigned int nbColumns, const PROJECTIONTYPE projection, const bool colorModeCapable)
|
||||
:BasicRetinaFilter(nbRows, nbColumns),
|
||||
_sampledFrame(0),
|
||||
_tempBuffer(_localBuffer),
|
||||
_transformTable(0),
|
||||
_irregularLPfilteredFrame(_filterOutput)
|
||||
{
|
||||
_inputDoubleNBpixels=nbRows*nbColumns*2;
|
||||
_selectedProjection = projection;
|
||||
_reductionFactor=0;
|
||||
_initOK=false;
|
||||
_usefullpixelIndex=0;
|
||||
_colorModeCapable=colorModeCapable;
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::allocating"<<std::endl;
|
||||
#endif
|
||||
if (_colorModeCapable)
|
||||
{
|
||||
_tempBuffer.resize(nbRows*nbColumns*3);
|
||||
}
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::done"<<std::endl;
|
||||
#endif
|
||||
|
||||
clearAllBuffers();
|
||||
}
|
||||
|
||||
// destructor
|
||||
ImageLogPolProjection::~ImageLogPolProjection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// reset buffers method
|
||||
void ImageLogPolProjection::clearAllBuffers()
|
||||
{
|
||||
_sampledFrame=0;
|
||||
_tempBuffer=0;
|
||||
BasicRetinaFilter::clearAllBuffers();
|
||||
}
|
||||
|
||||
/**
|
||||
* resize retina color filter object (resize all allocated buffers)
|
||||
* @param NBrows: the new height size
|
||||
* @param NBcolumns: the new width size
|
||||
*/
|
||||
void ImageLogPolProjection::resize(const unsigned int NBrows, const unsigned int NBcolumns)
|
||||
{
|
||||
BasicRetinaFilter::resize(NBrows, NBcolumns);
|
||||
initProjection(_reductionFactor, _samplingStrenght);
|
||||
|
||||
// reset buffers method
|
||||
clearAllBuffers();
|
||||
|
||||
}
|
||||
|
||||
// init functions depending on the projection type
|
||||
bool ImageLogPolProjection::initProjection(const double reductionFactor, const double samplingStrenght)
|
||||
{
|
||||
switch(_selectedProjection)
|
||||
{
|
||||
case RETINALOGPROJECTION:
|
||||
return _initLogRetinaSampling(reductionFactor, samplingStrenght);
|
||||
break;
|
||||
case CORTEXLOGPOLARPROJECTION:
|
||||
return _initLogPolarCortexSampling(reductionFactor, samplingStrenght);
|
||||
break;
|
||||
default:
|
||||
std::cout<<"ImageLogPolProjection::no projection setted up... performing default retina projection... take care"<<std::endl;
|
||||
return _initLogRetinaSampling(reductionFactor, samplingStrenght);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// -> private init functions dedicated to each projection
|
||||
bool ImageLogPolProjection::_initLogRetinaSampling(const double reductionFactor, const double samplingStrenght)
|
||||
{
|
||||
_initOK=false;
|
||||
|
||||
if (_selectedProjection!=RETINALOGPROJECTION)
|
||||
{
|
||||
std::cerr<<"ImageLogPolProjection::initLogRetinaSampling: could not initialize logPolar projection for a log projection system\n -> you probably chose the wrong init function, use initLogPolarCortexSampling() instead"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
if (reductionFactor<1.0)
|
||||
{
|
||||
std::cerr<<"ImageLogPolProjection::initLogRetinaSampling: reduction factor must be superior to 0, skeeping initialisation..."<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// compute image output size
|
||||
_outputNBrows=predictOutputSize(this->getNBrows(), reductionFactor);
|
||||
_outputNBcolumns=predictOutputSize(this->getNBcolumns(), reductionFactor);
|
||||
_outputNBpixels=_outputNBrows*_outputNBcolumns;
|
||||
_outputDoubleNBpixels=_outputNBrows*_outputNBcolumns*2;
|
||||
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::initLogRetinaSampling: Log resampled image resampling factor: "<<reductionFactor<<", strenght:"<<samplingStrenght<<std::endl;
|
||||
std::cout<<"ImageLogPolProjection::initLogRetinaSampling: Log resampled image size: "<<_outputNBrows<<"*"<<_outputNBcolumns<<std::endl;
|
||||
#endif
|
||||
|
||||
// setup progressive prefilter that will be applied BEFORE log sampling
|
||||
setProgressiveFilterConstants_CentredAccuracy(0.f, 0.f, 0.99f);
|
||||
|
||||
// (re)create the image output buffer and transform table if the reduction factor changed
|
||||
_sampledFrame.resize(_outputNBpixels*(1+(unsigned int)_colorModeCapable*2));
|
||||
|
||||
// specifiying new reduction factor after preliminar checks
|
||||
_reductionFactor=reductionFactor;
|
||||
_samplingStrenght=samplingStrenght;
|
||||
|
||||
// compute the rlim for symetric rows/columns sampling, then, the rlim is based on the smallest dimension
|
||||
_minDimension=(double)(_filterOutput.getNBrows() < _filterOutput.getNBcolumns() ? _filterOutput.getNBrows() : _filterOutput.getNBcolumns());
|
||||
|
||||
// input frame dimensions dependent log sampling:
|
||||
//double rlim=1.0/reductionFactor*(minDimension/2.0+samplingStrenght);
|
||||
|
||||
// input frame dimensions INdependent log sampling:
|
||||
_azero=(1.0+reductionFactor*std::sqrt(samplingStrenght))/(reductionFactor*reductionFactor*samplingStrenght-1.0);
|
||||
_alim=(1.0+_azero)/reductionFactor;
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::initLogRetinaSampling: rlim= "<<rlim<<std::endl;
|
||||
std::cout<<"ImageLogPolProjection::initLogRetinaSampling: alim= "<<alim<<std::endl;
|
||||
#endif
|
||||
|
||||
// get half frame size
|
||||
unsigned int halfOutputRows = _outputNBrows/2-1;
|
||||
unsigned int halfOutputColumns = _outputNBcolumns/2-1;
|
||||
unsigned int halfInputRows = _filterOutput.getNBrows()/2-1;
|
||||
unsigned int halfInputColumns = _filterOutput.getNBcolumns()/2-1;
|
||||
|
||||
// computing log sampling matrix by computing quarters of images
|
||||
// the original new image center (_filterOutput.getNBrows()/2, _filterOutput.getNBcolumns()/2) being at coordinate (_filterOutput.getNBrows()/(2*_reductionFactor), _filterOutput.getNBcolumns()/(2*_reductionFactor))
|
||||
|
||||
// -> use a temporary transform table which is bigger than the final one, we only report pixels coordinates that are included in the sampled picture
|
||||
std::valarray<unsigned int> tempTransformTable(2*_outputNBpixels); // the structure would be: (pixelInputCoordinate n)(pixelOutputCoordinate n)(pixelInputCoordinate n+1)(pixelOutputCoordinate n+1)
|
||||
_usefullpixelIndex=0;
|
||||
|
||||
double rMax=0;
|
||||
halfInputRows<halfInputColumns ? rMax=(double)(halfInputRows*halfInputRows):rMax=(double)(halfInputColumns*halfInputColumns);
|
||||
|
||||
for (unsigned int idRow=0;idRow<halfOutputRows; ++idRow)
|
||||
{
|
||||
for (unsigned int idColumn=0;idColumn<halfOutputColumns; ++idColumn)
|
||||
{
|
||||
// get the pixel position in the original picture
|
||||
|
||||
// -> input frame dimensions dependent log sampling:
|
||||
//double scale = samplingStrenght/(rlim-(double)std::sqrt(idRow*idRow+idColumn*idColumn));
|
||||
|
||||
// -> input frame dimensions INdependent log sampling:
|
||||
double scale=getOriginalRadiusLength((double)std::sqrt((double)(idRow*idRow+idColumn*idColumn)));
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::initLogRetinaSampling: scale= "<<scale<<std::endl;
|
||||
std::cout<<"ImageLogPolProjection::initLogRetinaSampling: scale2= "<<scale2<<std::endl;
|
||||
#endif
|
||||
if (scale < 0) ///check it later
|
||||
scale = 10000;
|
||||
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
// std::cout<<"ImageLogPolProjection::initLogRetinaSampling: scale= "<<scale<<std::endl;
|
||||
#endif
|
||||
|
||||
unsigned int u=(unsigned int)floor((double)idRow*scale);
|
||||
unsigned int v=(unsigned int)floor((double)idColumn*scale);
|
||||
|
||||
// manage border effects
|
||||
double length=u*u+v*v;
|
||||
double radiusRatio=std::sqrt(rMax/length);
|
||||
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::(inputH, inputW)="<<halfInputRows<<", "<<halfInputColumns<<", Rmax2="<<rMax<<std::endl;
|
||||
std::cout<<"before ==> ImageLogPolProjection::(u, v)="<<u<<", "<<v<<", r="<<u*u+v*v<<std::endl;
|
||||
std::cout<<"ratio ="<<radiusRatio<<std::endl;
|
||||
#endif
|
||||
|
||||
if (radiusRatio < 1.0)
|
||||
{
|
||||
u=(unsigned int)floor(radiusRatio*double(u));
|
||||
v=(unsigned int)floor(radiusRatio*double(v));
|
||||
}
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"after ==> ImageLogPolProjection::(u, v)="<<u<<", "<<v<<", r="<<u*u+v*v<<std::endl;
|
||||
std::cout<<"ImageLogPolProjection::("<<(halfOutputRows-idRow)<<", "<<idColumn+halfOutputColumns<<") <- ("<<halfInputRows-u<<", "<<v+halfInputColumns<<")"<<std::endl;
|
||||
std::cout<<(halfOutputRows-idRow)+(halfOutputColumns+idColumn)*_outputNBrows<<" -> "<<(halfInputRows-u)+_filterOutput.getNBrows()*(halfInputColumns+v)<<std::endl;
|
||||
#endif
|
||||
|
||||
if ((u<halfInputRows)&&(v<halfInputColumns))
|
||||
{
|
||||
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"*** VALID ***"<<std::endl;
|
||||
#endif
|
||||
|
||||
// set pixel coordinate of the input picture in the transform table at the current log sampled pixel
|
||||
// 1st quadrant
|
||||
tempTransformTable[_usefullpixelIndex++]=(halfOutputColumns+idColumn)+(halfOutputRows-idRow)*_outputNBcolumns;
|
||||
tempTransformTable[_usefullpixelIndex++]=_filterOutput.getNBcolumns()*(halfInputRows-u)+(halfInputColumns+v);
|
||||
// 2nd quadrant
|
||||
tempTransformTable[_usefullpixelIndex++]=(halfOutputColumns+idColumn)+(halfOutputRows+idRow)*_outputNBcolumns;
|
||||
tempTransformTable[_usefullpixelIndex++]=_filterOutput.getNBcolumns()*(halfInputRows+u)+(halfInputColumns+v);
|
||||
// 3rd quadrant
|
||||
tempTransformTable[_usefullpixelIndex++]=(halfOutputColumns-idColumn)+(halfOutputRows-idRow)*_outputNBcolumns;
|
||||
tempTransformTable[_usefullpixelIndex++]=_filterOutput.getNBcolumns()*(halfInputRows-u)+(halfInputColumns-v);
|
||||
// 4td quadrant
|
||||
tempTransformTable[_usefullpixelIndex++]=(halfOutputColumns-idColumn)+(halfOutputRows+idRow)*_outputNBcolumns;
|
||||
tempTransformTable[_usefullpixelIndex++]=_filterOutput.getNBcolumns()*(halfInputRows+u)+(halfInputColumns-v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// (re)creating and filling the transform table
|
||||
_transformTable.resize(_usefullpixelIndex);
|
||||
memcpy(&_transformTable[0], &tempTransformTable[0], sizeof(unsigned int)*_usefullpixelIndex);
|
||||
|
||||
// reset all buffers
|
||||
clearAllBuffers();
|
||||
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::initLogRetinaSampling: init done successfully"<<std::endl;
|
||||
#endif
|
||||
_initOK=true;
|
||||
return _initOK;
|
||||
}
|
||||
|
||||
bool ImageLogPolProjection::_initLogPolarCortexSampling(const double reductionFactor, const double)
|
||||
{
|
||||
_initOK=false;
|
||||
|
||||
if (_selectedProjection!=CORTEXLOGPOLARPROJECTION)
|
||||
{
|
||||
std::cerr<<"ImageLogPolProjection::could not initialize log projection for a logPolar projection system\n -> you probably chose the wrong init function, use initLogRetinaSampling() instead"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (reductionFactor<1.0)
|
||||
{
|
||||
std::cerr<<"ImageLogPolProjection::reduction factor must be superior to 0, skeeping initialisation..."<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// compute the smallest image size
|
||||
unsigned int minDimension=(_filterOutput.getNBrows() < _filterOutput.getNBcolumns() ? _filterOutput.getNBrows() : _filterOutput.getNBcolumns());
|
||||
// specifiying new reduction factor after preliminar checks
|
||||
_reductionFactor=reductionFactor;
|
||||
// compute image output size
|
||||
_outputNBrows=(unsigned int)((double)minDimension/reductionFactor);
|
||||
_outputNBcolumns=(unsigned int)((double)minDimension/reductionFactor);
|
||||
_outputNBpixels=_outputNBrows*_outputNBcolumns;
|
||||
_outputDoubleNBpixels=_outputNBrows*_outputNBcolumns*2;
|
||||
|
||||
// get half frame size
|
||||
//unsigned int halfOutputRows = _outputNBrows/2-1;
|
||||
//unsigned int halfOutputColumns = _outputNBcolumns/2-1;
|
||||
unsigned int halfInputRows = _filterOutput.getNBrows()/2-1;
|
||||
unsigned int halfInputColumns = _filterOutput.getNBcolumns()/2-1;
|
||||
|
||||
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::Log resampled image size: "<<_outputNBrows<<"*"<<_outputNBcolumns<<std::endl;
|
||||
#endif
|
||||
|
||||
// setup progressive prefilter that will be applied BEFORE log sampling
|
||||
setProgressiveFilterConstants_CentredAccuracy(0.f, 0.f, 0.99f);
|
||||
|
||||
// (re)create the image output buffer and transform table if the reduction factor changed
|
||||
_sampledFrame.resize(_outputNBpixels*(1+(unsigned int)_colorModeCapable*2));
|
||||
|
||||
// create the radius and orientation axis and fill them, radius E [0;1], orientation E[-pi, pi]
|
||||
std::valarray<double> radiusAxis(_outputNBcolumns);
|
||||
double radiusStep=2.30/(double)_outputNBcolumns;
|
||||
for (unsigned int i=0;i<_outputNBcolumns;++i)
|
||||
{
|
||||
radiusAxis[i]=i*radiusStep;
|
||||
}
|
||||
std::valarray<double> orientationAxis(_outputNBrows);
|
||||
double orientationStep=-2.0*CV_PI/(double)_outputNBrows;
|
||||
for (unsigned int io=0;io<_outputNBrows;++io)
|
||||
{
|
||||
orientationAxis[io]=io*orientationStep;
|
||||
}
|
||||
// -> use a temporay transform table which is bigger than the final one, we only report pixels coordinates that are included in the sampled picture
|
||||
std::valarray<unsigned int> tempTransformTable(2*_outputNBpixels); // the structure would be: (pixelInputCoordinate n)(pixelOutputCoordinate n)(pixelInputCoordinate n+1)(pixelOutputCoordinate n+1)
|
||||
_usefullpixelIndex=0;
|
||||
|
||||
//std::cout<<"ImageLogPolProjection::Starting cortex projection"<<std::endl;
|
||||
// compute transformation, get theta and Radius in reagrd of the output sampled pixel
|
||||
double diagonalLenght=std::sqrt((double)(_outputNBcolumns*_outputNBcolumns+_outputNBrows*_outputNBrows));
|
||||
for (unsigned int radiusIndex=0;radiusIndex<_outputNBcolumns;++radiusIndex)
|
||||
for(unsigned int orientationIndex=0;orientationIndex<_outputNBrows;++orientationIndex)
|
||||
{
|
||||
double x=1.0+sinh(radiusAxis[radiusIndex])*cos(orientationAxis[orientationIndex]);
|
||||
double y=sinh(radiusAxis[radiusIndex])*sin(orientationAxis[orientationIndex]);
|
||||
// get the input picture coordinate
|
||||
double R=diagonalLenght*std::sqrt(x*x+y*y)/(5.0+std::sqrt(x*x+y*y));
|
||||
double theta=atan2(y,x);
|
||||
// convert input polar coord into cartesian/C compatble coordinate
|
||||
unsigned int columnIndex=(unsigned int)(cos(theta)*R)+halfInputColumns;
|
||||
unsigned int rowIndex=(unsigned int)(sin(theta)*R)+halfInputRows;
|
||||
//std::cout<<"ImageLogPolProjection::R="<<R<<" / Theta="<<theta<<" / (x, y)="<<columnIndex<<", "<<rowIndex<<std::endl;
|
||||
if ((columnIndex<_filterOutput.getNBcolumns())&&(columnIndex>0)&&(rowIndex<_filterOutput.getNBrows())&&(rowIndex>0))
|
||||
{
|
||||
// set coordinate
|
||||
tempTransformTable[_usefullpixelIndex++]=radiusIndex+orientationIndex*_outputNBcolumns;
|
||||
tempTransformTable[_usefullpixelIndex++]= columnIndex+rowIndex*_filterOutput.getNBcolumns();
|
||||
}
|
||||
}
|
||||
|
||||
// (re)creating and filling the transform table
|
||||
_transformTable.resize(_usefullpixelIndex);
|
||||
memcpy(&_transformTable[0], &tempTransformTable[0], sizeof(unsigned int)*_usefullpixelIndex);
|
||||
|
||||
// reset all buffers
|
||||
clearAllBuffers();
|
||||
_initOK=true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// action function
|
||||
std::valarray<float> &ImageLogPolProjection::runProjection(const std::valarray<float> &inputFrame, const bool colorMode)
|
||||
{
|
||||
if (_colorModeCapable&&colorMode)
|
||||
{
|
||||
// progressive filtering and storage of the result in _tempBuffer
|
||||
_spatiotemporalLPfilter_Irregular(get_data(inputFrame), &_irregularLPfilteredFrame[0]);
|
||||
_spatiotemporalLPfilter_Irregular(&_irregularLPfilteredFrame[0], &_tempBuffer[0]); // warning, temporal issue may occur, if the temporal constant is not NULL !!!
|
||||
|
||||
_spatiotemporalLPfilter_Irregular(get_data(inputFrame)+_filterOutput.getNBpixels(), &_irregularLPfilteredFrame[0]);
|
||||
_spatiotemporalLPfilter_Irregular(&_irregularLPfilteredFrame[0], &_tempBuffer[0]+_filterOutput.getNBpixels());
|
||||
|
||||
_spatiotemporalLPfilter_Irregular(get_data(inputFrame)+_filterOutput.getNBpixels()*2, &_irregularLPfilteredFrame[0]);
|
||||
_spatiotemporalLPfilter_Irregular(&_irregularLPfilteredFrame[0], &_tempBuffer[0]+_filterOutput.getNBpixels()*2);
|
||||
|
||||
// applying image projection/resampling
|
||||
register unsigned int *transformTablePTR=&_transformTable[0];
|
||||
for (unsigned int i=0 ; i<_usefullpixelIndex ; i+=2, transformTablePTR+=2)
|
||||
{
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::i:"<<i<<"output(max="<<_outputNBpixels<<")="<<_transformTable[i]<<" / intput(max="<<_filterOutput.getNBpixels()<<")="<<_transformTable[i+1]<<std::endl;
|
||||
#endif
|
||||
_sampledFrame[*(transformTablePTR)]=_tempBuffer[*(transformTablePTR+1)];
|
||||
_sampledFrame[*(transformTablePTR)+_outputNBpixels]=_tempBuffer[*(transformTablePTR+1)+_filterOutput.getNBpixels()];
|
||||
_sampledFrame[*(transformTablePTR)+_outputDoubleNBpixels]=_tempBuffer[*(transformTablePTR+1)+_inputDoubleNBpixels];
|
||||
}
|
||||
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::runProjection: color image projection OK"<<std::endl;
|
||||
#endif
|
||||
//normalizeGrayOutput_0_maxOutputValue(_sampledFrame, _outputNBpixels);
|
||||
}else
|
||||
{
|
||||
_spatiotemporalLPfilter_Irregular(get_data(inputFrame), &_irregularLPfilteredFrame[0]);
|
||||
_spatiotemporalLPfilter_Irregular(&_irregularLPfilteredFrame[0], &_irregularLPfilteredFrame[0]);
|
||||
// applying image projection/resampling
|
||||
register unsigned int *transformTablePTR=&_transformTable[0];
|
||||
for (unsigned int i=0 ; i<_usefullpixelIndex ; i+=2, transformTablePTR+=2)
|
||||
{
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"i:"<<i<<"output(max="<<_outputNBpixels<<")="<<_transformTable[i]<<" / intput(max="<<_filterOutput.getNBpixels()<<")="<<_transformTable[i+1]<<std::endl;
|
||||
#endif
|
||||
_sampledFrame[*(transformTablePTR)]=_irregularLPfilteredFrame[*(transformTablePTR+1)];
|
||||
}
|
||||
//normalizeGrayOutput_0_maxOutputValue(_sampledFrame, _outputNBpixels);
|
||||
#ifdef IMAGELOGPOLPROJECTION_DEBUG
|
||||
std::cout<<"ImageLogPolProjection::runProjection: gray level image projection OK"<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return _sampledFrame;
|
||||
}
|
||||
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
@ -1,243 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2011
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef IMAGELOGPOLPROJECTION_H_
|
||||
#define IMAGELOGPOLPROJECTION_H_
|
||||
|
||||
/**
|
||||
* @class ImageLogPolProjection
|
||||
* @brief class able to perform a log sampling of an image input (models the log sampling of the photoreceptors of the retina)
|
||||
* or a log polar projection which models the retina information projection on the primary visual cortex: a linear projection in the center for detail analysis and a log projection of the borders (low spatial frequency motion information in general)
|
||||
*
|
||||
* collaboration: Barthelemy DURETTE who experimented the retina log projection
|
||||
-> "Traitement visuels Bio mimtiques pour la supplance perceptive", internal technical report, May 2005, Gipsa-lab/DIS, Grenoble, FRANCE
|
||||
*
|
||||
* * TYPICAL USE:
|
||||
*
|
||||
* // create object, here for a log sampling (keyword:RETINALOGPROJECTION): (dynamic object allocation sample)
|
||||
* ImageLogPolProjection *imageSamplingTool;
|
||||
* imageSamplingTool = new ImageLogPolProjection(frameSizeRows, frameSizeColumns, RETINALOGPROJECTION);
|
||||
*
|
||||
* // init log projection:
|
||||
* imageSamplingTool->initProjection(1.0, 15.0);
|
||||
*
|
||||
* // during program execution, call the log transform applied to a frame called "FrameBuffer" :
|
||||
* imageSamplingTool->runProjection(FrameBuffer);
|
||||
* // get output frame and its size:
|
||||
* const unsigned int logSampledFrame_nbRows=imageSamplingTool->getOutputNBrows();
|
||||
* const unsigned int logSampledFrame_nbColumns=imageSamplingTool->getOutputNBcolumns();
|
||||
* const double *logSampledFrame=imageSamplingTool->getSampledFrame();
|
||||
*
|
||||
* // at the end of the program, destroy object:
|
||||
* delete imageSamplingTool;
|
||||
*
|
||||
* @author Alexandre BENOIT, benoit.alexandre.vision@gmail.com, LISTIC : www.listic.univ-savoie.fr, Gipsa-Lab, France: www.gipsa-lab.inpg.fr/
|
||||
* Creation date 2007
|
||||
*/
|
||||
|
||||
//#define __IMAGELOGPOLPROJECTION_DEBUG // used for std output debug information
|
||||
|
||||
#include "basicretinafilter.hpp"
|
||||
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
|
||||
class ImageLogPolProjection:public BasicRetinaFilter
|
||||
{
|
||||
public:
|
||||
|
||||
enum PROJECTIONTYPE{RETINALOGPROJECTION, CORTEXLOGPOLARPROJECTION};
|
||||
|
||||
/**
|
||||
* constructor, just specifies the image input size and the projection type, no projection initialisation is done
|
||||
* -> use initLogRetinaSampling() or initLogPolarCortexSampling() for that
|
||||
* @param nbRows: number of rows of the input image
|
||||
* @param nbColumns: number of columns of the input image
|
||||
* @param projection: the type of projection, RETINALOGPROJECTION or CORTEXLOGPOLARPROJECTION
|
||||
* @param colorMode: specifies if the projection is applied on a grayscale image (false) or color images (3 layers) (true)
|
||||
*/
|
||||
ImageLogPolProjection(const unsigned int nbRows, const unsigned int nbColumns, const PROJECTIONTYPE projection, const bool colorMode=false);
|
||||
|
||||
/**
|
||||
* standard destructor
|
||||
*/
|
||||
virtual ~ImageLogPolProjection();
|
||||
|
||||
/**
|
||||
* function that clears all buffers of the object
|
||||
*/
|
||||
void clearAllBuffers();
|
||||
|
||||
/**
|
||||
* resize retina color filter object (resize all allocated buffers)
|
||||
* @param NBrows: the new height size
|
||||
* @param NBcolumns: the new width size
|
||||
*/
|
||||
void resize(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
|
||||
/**
|
||||
* init function depending on the projection type
|
||||
* @param reductionFactor: the size reduction factor of the ouptup image in regard of the size of the input image, must be superior to 1
|
||||
* @param samplingStrenght: specifies the strenght of the log compression effect (magnifying coefficient)
|
||||
* @return true if the init was performed without any errors
|
||||
*/
|
||||
bool initProjection(const double reductionFactor, const double samplingStrenght);
|
||||
|
||||
/**
|
||||
* main funtion of the class: run projection function
|
||||
* @param inputFrame: the input frame to be processed
|
||||
* @param colorMode: the input buffer color mode: false=gray levels, true = 3 color channels mode
|
||||
* @return the output frame
|
||||
*/
|
||||
std::valarray<float> &runProjection(const std::valarray<float> &inputFrame, const bool colorMode=false);
|
||||
|
||||
/**
|
||||
* @return the numbers of rows (height) of the images OUTPUTS of the object
|
||||
*/
|
||||
inline unsigned int getOutputNBrows(){return _outputNBrows;};
|
||||
|
||||
/**
|
||||
* @return the numbers of columns (width) of the images OUTPUTS of the object
|
||||
*/
|
||||
inline unsigned int getOutputNBcolumns(){return _outputNBcolumns;};
|
||||
|
||||
/**
|
||||
* main funtion of the class: run projection function
|
||||
* @param size: one of the input frame initial dimensions to be processed
|
||||
* @return the output frame dimension
|
||||
*/
|
||||
inline static unsigned int predictOutputSize(const unsigned int size, const double reductionFactor){return (unsigned int)((double)size/reductionFactor);};
|
||||
|
||||
/**
|
||||
* @return the output of the filter which applies an irregular Low Pass spatial filter to the imag input (see function
|
||||
*/
|
||||
inline const std::valarray<float> &getIrregularLPfilteredInputFrame() const {return _irregularLPfilteredFrame;};
|
||||
|
||||
/**
|
||||
* function which allows to retrieve the output frame which was updated after the "runProjection(...) function BasicRetinaFilter::runProgressiveFilter(...)
|
||||
* @return the projection result
|
||||
*/
|
||||
inline const std::valarray<float> &getSampledFrame() const {return _sampledFrame;};
|
||||
|
||||
/**
|
||||
* function which allows gives the tranformation table, its size is (getNBrows()*getNBcolumns()*2)
|
||||
* @return the transformation matrix [outputPixIndex_i, inputPixIndex_i, outputPixIndex_i+1, inputPixIndex_i+1....]
|
||||
*/
|
||||
inline const std::valarray<unsigned int> &getSamplingMap() const {return _transformTable;};
|
||||
|
||||
inline double getOriginalRadiusLength(const double projectedRadiusLength){return _azero/(_alim-projectedRadiusLength*2.0/_minDimension);};
|
||||
|
||||
// unsigned int getInputPixelIndex(const unsigned int ){ return _transformTable[index*2+1]};
|
||||
|
||||
private:
|
||||
PROJECTIONTYPE _selectedProjection;
|
||||
|
||||
// size of the image output
|
||||
unsigned int _outputNBrows;
|
||||
unsigned int _outputNBcolumns;
|
||||
unsigned int _outputNBpixels;
|
||||
unsigned int _outputDoubleNBpixels;
|
||||
unsigned int _inputDoubleNBpixels;
|
||||
|
||||
// is the object able to manage color flag
|
||||
bool _colorModeCapable;
|
||||
// sampling strenght factor
|
||||
double _samplingStrenght;
|
||||
// sampling reduction factor
|
||||
double _reductionFactor;
|
||||
|
||||
// log sampling parameters
|
||||
double _azero;
|
||||
double _alim;
|
||||
double _minDimension;
|
||||
|
||||
// template buffers
|
||||
std::valarray<float>_sampledFrame;
|
||||
std::valarray<float>&_tempBuffer;
|
||||
std::valarray<unsigned int>_transformTable;
|
||||
|
||||
std::valarray<float> &_irregularLPfilteredFrame; // just a reference for easier understanding
|
||||
unsigned int _usefullpixelIndex;
|
||||
|
||||
// init transformation tables
|
||||
bool _computeLogProjection();
|
||||
bool _computeLogPolarProjection();
|
||||
|
||||
// specifies if init was done correctly
|
||||
bool _initOK;
|
||||
// private init projections functions called by "initProjection(...)" function
|
||||
bool _initLogRetinaSampling(const double reductionFactor, const double samplingStrenght);
|
||||
bool _initLogPolarCortexSampling(const double reductionFactor, const double samplingStrenght);
|
||||
|
||||
ImageLogPolProjection(const ImageLogPolProjection&);
|
||||
ImageLogPolProjection& operator=(const ImageLogPolProjection&);
|
||||
|
||||
};
|
||||
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
#endif /*IMAGELOGPOLPROJECTION_H_*/
|
@ -1,212 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2011
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "magnoretinafilter.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
// Constructor and Desctructor of the OPL retina filter
|
||||
MagnoRetinaFilter::MagnoRetinaFilter(const unsigned int NBrows, const unsigned int NBcolumns)
|
||||
:BasicRetinaFilter(NBrows, NBcolumns, 2),
|
||||
_previousInput_ON(NBrows*NBcolumns),
|
||||
_previousInput_OFF(NBrows*NBcolumns),
|
||||
_amacrinCellsTempOutput_ON(NBrows*NBcolumns),
|
||||
_amacrinCellsTempOutput_OFF(NBrows*NBcolumns),
|
||||
_magnoXOutputON(NBrows*NBcolumns),
|
||||
_magnoXOutputOFF(NBrows*NBcolumns),
|
||||
_localProcessBufferON(NBrows*NBcolumns),
|
||||
_localProcessBufferOFF(NBrows*NBcolumns)
|
||||
{
|
||||
_magnoYOutput=&_filterOutput;
|
||||
_magnoYsaturated=&_localBuffer;
|
||||
|
||||
|
||||
clearAllBuffers();
|
||||
|
||||
#ifdef IPL_RETINA_ELEMENT_DEBUG
|
||||
std::cout<<"MagnoRetinaFilter::Init IPL retina filter at specified frame size OK"<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
MagnoRetinaFilter::~MagnoRetinaFilter()
|
||||
{
|
||||
#ifdef IPL_RETINA_ELEMENT_DEBUG
|
||||
std::cout<<"MagnoRetinaFilter::Delete IPL retina filter OK"<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// function that clears all buffers of the object
|
||||
void MagnoRetinaFilter::clearAllBuffers()
|
||||
{
|
||||
BasicRetinaFilter::clearAllBuffers();
|
||||
_previousInput_ON=0;
|
||||
_previousInput_OFF=0;
|
||||
_amacrinCellsTempOutput_ON=0;
|
||||
_amacrinCellsTempOutput_OFF=0;
|
||||
_magnoXOutputON=0;
|
||||
_magnoXOutputOFF=0;
|
||||
_localProcessBufferON=0;
|
||||
_localProcessBufferOFF=0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* resize retina magno filter object (resize all allocated buffers
|
||||
* @param NBrows: the new height size
|
||||
* @param NBcolumns: the new width size
|
||||
*/
|
||||
void MagnoRetinaFilter::resize(const unsigned int NBrows, const unsigned int NBcolumns)
|
||||
{
|
||||
BasicRetinaFilter::resize(NBrows, NBcolumns);
|
||||
_previousInput_ON.resize(NBrows*NBcolumns);
|
||||
_previousInput_OFF.resize(NBrows*NBcolumns);
|
||||
_amacrinCellsTempOutput_ON.resize(NBrows*NBcolumns);
|
||||
_amacrinCellsTempOutput_OFF.resize(NBrows*NBcolumns);
|
||||
_magnoXOutputON.resize(NBrows*NBcolumns);
|
||||
_magnoXOutputOFF.resize(NBrows*NBcolumns);
|
||||
_localProcessBufferON.resize(NBrows*NBcolumns);
|
||||
_localProcessBufferOFF.resize(NBrows*NBcolumns);
|
||||
|
||||
// to be sure, relink buffers
|
||||
_magnoYOutput=&_filterOutput;
|
||||
_magnoYsaturated=&_localBuffer;
|
||||
|
||||
// reset all buffers
|
||||
clearAllBuffers();
|
||||
}
|
||||
|
||||
void MagnoRetinaFilter::setCoefficientsTable(const float parasolCells_beta, const float parasolCells_tau, const float parasolCells_k, const float amacrinCellsTemporalCutFrequency, const float localAdaptIntegration_tau, const float localAdaptIntegration_k )
|
||||
{
|
||||
_temporalCoefficient=(float)std::exp(-1.0f/amacrinCellsTemporalCutFrequency);
|
||||
// the first set of parameters is dedicated to the low pass filtering property of the ganglion cells
|
||||
BasicRetinaFilter::setLPfilterParameters(parasolCells_beta, parasolCells_tau, parasolCells_k, 0);
|
||||
// the second set of parameters is dedicated to the ganglion cells output intergartion for their local adaptation property
|
||||
BasicRetinaFilter::setLPfilterParameters(0, localAdaptIntegration_tau, localAdaptIntegration_k, 1);
|
||||
}
|
||||
|
||||
void MagnoRetinaFilter::_amacrineCellsComputing(const float *OPL_ON, const float *OPL_OFF)
|
||||
{
|
||||
#ifdef MAKE_PARALLEL
|
||||
cv::parallel_for_(cv::Range(0,_filterOutput.getNBpixels()), Parallel_amacrineCellsComputing(OPL_ON, OPL_OFF, &_previousInput_ON[0], &_previousInput_OFF[0], &_amacrinCellsTempOutput_ON[0], &_amacrinCellsTempOutput_OFF[0], _temporalCoefficient));
|
||||
#else
|
||||
register const float *OPL_ON_PTR=OPL_ON;
|
||||
register const float *OPL_OFF_PTR=OPL_OFF;
|
||||
register float *previousInput_ON_PTR= &_previousInput_ON[0];
|
||||
register float *previousInput_OFF_PTR= &_previousInput_OFF[0];
|
||||
register float *amacrinCellsTempOutput_ON_PTR= &_amacrinCellsTempOutput_ON[0];
|
||||
register float *amacrinCellsTempOutput_OFF_PTR= &_amacrinCellsTempOutput_OFF[0];
|
||||
|
||||
for (unsigned int IDpixel=0 ; IDpixel<this->getNBpixels(); ++IDpixel)
|
||||
{
|
||||
|
||||
/* Compute ON and OFF amacrin cells high pass temporal filter */
|
||||
float magnoXonPixelResult = _temporalCoefficient*(*amacrinCellsTempOutput_ON_PTR+ *OPL_ON_PTR-*previousInput_ON_PTR);
|
||||
*(amacrinCellsTempOutput_ON_PTR++)=((float)(magnoXonPixelResult>0))*magnoXonPixelResult;
|
||||
|
||||
float magnoXoffPixelResult = _temporalCoefficient*(*amacrinCellsTempOutput_OFF_PTR+ *OPL_OFF_PTR-*previousInput_OFF_PTR);
|
||||
*(amacrinCellsTempOutput_OFF_PTR++)=((float)(magnoXoffPixelResult>0))*magnoXoffPixelResult;
|
||||
|
||||
/* prepare next loop */
|
||||
*(previousInput_ON_PTR++)=*(OPL_ON_PTR++);
|
||||
*(previousInput_OFF_PTR++)=*(OPL_OFF_PTR++);
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// launch filter that runs all the IPL filter
|
||||
const std::valarray<float> &MagnoRetinaFilter::runFilter(const std::valarray<float> &OPL_ON, const std::valarray<float> &OPL_OFF)
|
||||
{
|
||||
// Compute the high pass temporal filter
|
||||
_amacrineCellsComputing(get_data(OPL_ON), get_data(OPL_OFF));
|
||||
|
||||
// apply low pass filtering on ON and OFF ways after temporal high pass filtering
|
||||
_spatiotemporalLPfilter(&_amacrinCellsTempOutput_ON[0], &_magnoXOutputON[0], 0);
|
||||
_spatiotemporalLPfilter(&_amacrinCellsTempOutput_OFF[0], &_magnoXOutputOFF[0], 0);
|
||||
|
||||
// local adaptation of the ganglion cells to the local contrast of the moving contours
|
||||
_spatiotemporalLPfilter(&_magnoXOutputON[0], &_localProcessBufferON[0], 1);
|
||||
_localLuminanceAdaptation(&_magnoXOutputON[0], &_localProcessBufferON[0]);
|
||||
_spatiotemporalLPfilter(&_magnoXOutputOFF[0], &_localProcessBufferOFF[0], 1);
|
||||
_localLuminanceAdaptation(&_magnoXOutputOFF[0], &_localProcessBufferOFF[0]);
|
||||
|
||||
/* Compute MagnoY */
|
||||
register float *magnoYOutput= &(*_magnoYOutput)[0];
|
||||
register float *magnoXOutputON_PTR= &_magnoXOutputON[0];
|
||||
register float *magnoXOutputOFF_PTR= &_magnoXOutputOFF[0];
|
||||
for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel)
|
||||
*(magnoYOutput++)=*(magnoXOutputON_PTR++)+*(magnoXOutputOFF_PTR++);
|
||||
|
||||
return (*_magnoYOutput);
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
@ -1,245 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2011
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef MagnoRetinaFilter_H_
|
||||
#define MagnoRetinaFilter_H_
|
||||
|
||||
/**
|
||||
* @class MagnoRetinaFilter
|
||||
* @brief class which describes the magnocellular channel of the retina:
|
||||
* -> performs a moving contours extraction with powerfull local data enhancement
|
||||
*
|
||||
* TYPICAL USE:
|
||||
*
|
||||
* // create object at a specified picture size
|
||||
* MagnoRetinaFilter *movingContoursExtractor;
|
||||
* movingContoursExtractor =new MagnoRetinaFilter(frameSizeRows, frameSizeColumns);
|
||||
*
|
||||
* // init gain, spatial and temporal parameters:
|
||||
* movingContoursExtractor->setCoefficientsTable(0, 0.7, 5, 3);
|
||||
*
|
||||
* // during program execution, call the filter for contours extraction for an input picture called "FrameBuffer":
|
||||
* movingContoursExtractor->runfilter(FrameBuffer);
|
||||
*
|
||||
* // get the output frame, check in the class description below for more outputs:
|
||||
* const float *movingContours=movingContoursExtractor->getMagnoYsaturated();
|
||||
*
|
||||
* // at the end of the program, destroy object:
|
||||
* delete movingContoursExtractor;
|
||||
|
||||
* @author Alexandre BENOIT, benoit.alexandre.vision@gmail.com, LISTIC : www.listic.univ-savoie.fr, Gipsa-Lab, France: www.gipsa-lab.inpg.fr/
|
||||
* Creation date 2007
|
||||
* Based on Alexandre BENOIT thesis: "Le système visuel humain au secours de la vision par ordinateur"
|
||||
*/
|
||||
|
||||
#include "basicretinafilter.hpp"
|
||||
|
||||
//#define _IPL_RETINA_ELEMENT_DEBUG
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
class MagnoRetinaFilter: public BasicRetinaFilter
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* constructor parameters are only linked to image input size
|
||||
* @param NBrows: number of rows of the input image
|
||||
* @param NBcolumns: number of columns of the input image
|
||||
*/
|
||||
MagnoRetinaFilter(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
|
||||
|
||||
/**
|
||||
* destructor
|
||||
*/
|
||||
virtual ~MagnoRetinaFilter();
|
||||
|
||||
/**
|
||||
* function that clears all buffers of the object
|
||||
*/
|
||||
void clearAllBuffers();
|
||||
|
||||
/**
|
||||
* resize retina magno filter object (resize all allocated buffers)
|
||||
* @param NBrows: the new height size
|
||||
* @param NBcolumns: the new width size
|
||||
*/
|
||||
void resize(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
|
||||
/**
|
||||
* set parameters values
|
||||
* @param parasolCells_beta: the low pass filter gain used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), typical value is 0
|
||||
* @param parasolCells_tau: the low pass filter time constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical value is 0 (immediate response)
|
||||
* @param parasolCells_k: the low pass filter spatial constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical value is 5
|
||||
* @param amacrinCellsTemporalCutFrequency: the time constant of the first order high pass fiter of the magnocellular way (motion information channel), unit is frames, tipicall value is 5
|
||||
* @param localAdaptIntegration_tau: specifies the temporal constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
* @param localAdaptIntegration_k: specifies the spatial constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
*/
|
||||
void setCoefficientsTable(const float parasolCells_beta, const float parasolCells_tau, const float parasolCells_k, const float amacrinCellsTemporalCutFrequency, const float localAdaptIntegration_tau, const float localAdaptIntegration_k);
|
||||
|
||||
/**
|
||||
* launch filter that runs all the IPL magno filter (model of the magnocellular channel of the Inner Plexiform Layer of the retina)
|
||||
* @param OPL_ON: the output of the bipolar ON cells of the retina (available from the ParvoRetinaFilter class (getBipolarCellsON() function)
|
||||
* @param OPL_OFF: the output of the bipolar OFF cells of the retina (available from the ParvoRetinaFilter class (getBipolarCellsOFF() function)
|
||||
* @return the processed result without post-processing
|
||||
*/
|
||||
const std::valarray<float> &runFilter(const std::valarray<float> &OPL_ON, const std::valarray<float> &OPL_OFF);
|
||||
|
||||
/**
|
||||
* @return the Magnocellular ON channel filtering output
|
||||
*/
|
||||
inline const std::valarray<float> &getMagnoON() const {return _magnoXOutputON;};
|
||||
|
||||
/**
|
||||
* @return the Magnocellular OFF channel filtering output
|
||||
*/
|
||||
inline const std::valarray<float> &getMagnoOFF() const {return _magnoXOutputOFF;};
|
||||
|
||||
/**
|
||||
* @return the Magnocellular Y (sum of the ON and OFF magno channels) filtering output
|
||||
*/
|
||||
inline const std::valarray<float> &getMagnoYsaturated() const {return *_magnoYsaturated;};
|
||||
|
||||
/**
|
||||
* applies an image normalization which saturates the high output values by the use of an assymetric sigmoide
|
||||
*/
|
||||
inline void normalizeGrayOutputNearZeroCentreredSigmoide(){_filterOutput.normalizeGrayOutputNearZeroCentreredSigmoide(&(*_magnoYOutput)[0], &(*_magnoYsaturated)[0]);};
|
||||
|
||||
/**
|
||||
* @return the horizontal cells' temporal constant
|
||||
*/
|
||||
inline float getTemporalConstant(){return this->_filteringCoeficientsTable[2];};
|
||||
|
||||
private:
|
||||
|
||||
// related pointers to these buffers
|
||||
std::valarray<float> _previousInput_ON;
|
||||
std::valarray<float> _previousInput_OFF;
|
||||
std::valarray<float> _amacrinCellsTempOutput_ON;
|
||||
std::valarray<float> _amacrinCellsTempOutput_OFF;
|
||||
std::valarray<float> _magnoXOutputON;
|
||||
std::valarray<float> _magnoXOutputOFF;
|
||||
std::valarray<float> _localProcessBufferON;
|
||||
std::valarray<float> _localProcessBufferOFF;
|
||||
// reference to parent buffers and allow better readability
|
||||
TemplateBuffer<float> *_magnoYOutput;
|
||||
std::valarray<float> *_magnoYsaturated;
|
||||
|
||||
// varialbles
|
||||
float _temporalCoefficient;
|
||||
|
||||
// amacrine cells filter : high pass temporal filter
|
||||
void _amacrineCellsComputing(const float *ONinput, const float *OFFinput);
|
||||
#ifdef MAKE_PARALLEL
|
||||
/******************************************************
|
||||
** IF some parallelizing thread methods are available, then, main loops are parallelized using these functors
|
||||
** ==> main idea paralellise main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelised methods as necessary
|
||||
** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelised
|
||||
** ==> functors constructors can differ from the parameters used with their related serial functions
|
||||
*/
|
||||
class Parallel_amacrineCellsComputing: public cv::ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
const float *OPL_ON, *OPL_OFF;
|
||||
float *previousInput_ON, *previousInput_OFF, *amacrinCellsTempOutput_ON, *amacrinCellsTempOutput_OFF;
|
||||
float temporalCoefficient;
|
||||
public:
|
||||
Parallel_amacrineCellsComputing(const float *OPL_ON_PTR, const float *OPL_OFF_PTR, float *previousInput_ON_PTR, float *previousInput_OFF_PTR, float *amacrinCellsTempOutput_ON_PTR, float *amacrinCellsTempOutput_OFF_PTR, float temporalCoefficientVal)
|
||||
:OPL_ON(OPL_ON_PTR), OPL_OFF(OPL_OFF_PTR), previousInput_ON(previousInput_ON_PTR), previousInput_OFF(previousInput_OFF_PTR), amacrinCellsTempOutput_ON(amacrinCellsTempOutput_ON_PTR), amacrinCellsTempOutput_OFF(amacrinCellsTempOutput_OFF_PTR), temporalCoefficient(temporalCoefficientVal) {}
|
||||
|
||||
virtual void operator()( const Range& r ) const {
|
||||
register const float *OPL_ON_PTR=OPL_ON+r.start;
|
||||
register const float *OPL_OFF_PTR=OPL_OFF+r.start;
|
||||
register float *previousInput_ON_PTR= previousInput_ON+r.start;
|
||||
register float *previousInput_OFF_PTR= previousInput_OFF+r.start;
|
||||
register float *amacrinCellsTempOutput_ON_PTR= amacrinCellsTempOutput_ON+r.start;
|
||||
register float *amacrinCellsTempOutput_OFF_PTR= amacrinCellsTempOutput_OFF+r.start;
|
||||
|
||||
for (int IDpixel=r.start ; IDpixel!=r.end; ++IDpixel)
|
||||
{
|
||||
|
||||
/* Compute ON and OFF amacrin cells high pass temporal filter */
|
||||
float magnoXonPixelResult = temporalCoefficient*(*amacrinCellsTempOutput_ON_PTR+ *OPL_ON_PTR-*previousInput_ON_PTR);
|
||||
*(amacrinCellsTempOutput_ON_PTR++)=((float)(magnoXonPixelResult>0))*magnoXonPixelResult;
|
||||
|
||||
float magnoXoffPixelResult = temporalCoefficient*(*amacrinCellsTempOutput_OFF_PTR+ *OPL_OFF_PTR-*previousInput_OFF_PTR);
|
||||
*(amacrinCellsTempOutput_OFF_PTR++)=((float)(magnoXoffPixelResult>0))*magnoXoffPixelResult;
|
||||
|
||||
/* prepare next loop */
|
||||
*(previousInput_ON_PTR++)=*(OPL_ON_PTR++);
|
||||
*(previousInput_OFF_PTR++)=*(OPL_OFF_PTR++);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
};
|
||||
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
|
||||
#endif /*MagnoRetinaFilter_H_*/
|
@ -1,779 +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) 2010-2013, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Peng Xiao, pengxiao@multicorewareinc.com
|
||||
//
|
||||
// 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 oclMaterials 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*/
|
||||
|
||||
//data (which is float) is aligend in 32 bytes
|
||||
#define WIDTH_MULTIPLE (32 >> 2)
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
//*******************************************************
|
||||
// basicretinafilter
|
||||
//////////////// _spatiotemporalLPfilter ////////////////
|
||||
//_horizontalCausalFilter_addInput
|
||||
kernel void horizontalCausalFilter_addInput(
|
||||
global const float * input,
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const int in_offset,
|
||||
const int out_offset,
|
||||
const float _tau,
|
||||
const float _a
|
||||
)
|
||||
{
|
||||
int gid = get_global_id(0);
|
||||
if(gid >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
global const float * iptr =
|
||||
input + mad24(gid, elements_per_row, in_offset / 4);
|
||||
global float * optr =
|
||||
output + mad24(gid, elements_per_row, out_offset / 4);
|
||||
|
||||
float res;
|
||||
float4 in_v4, out_v4, res_v4 = (float4)(0);
|
||||
//vectorize to increase throughput
|
||||
for(int i = 0; i < cols / 4; ++i, iptr += 4, optr += 4)
|
||||
{
|
||||
in_v4 = vload4(0, iptr);
|
||||
out_v4 = vload4(0, optr);
|
||||
|
||||
res_v4.x = in_v4.x + _tau * out_v4.x + _a * res_v4.w;
|
||||
res_v4.y = in_v4.y + _tau * out_v4.y + _a * res_v4.x;
|
||||
res_v4.z = in_v4.z + _tau * out_v4.z + _a * res_v4.y;
|
||||
res_v4.w = in_v4.w + _tau * out_v4.w + _a * res_v4.z;
|
||||
|
||||
vstore4(res_v4, 0, optr);
|
||||
}
|
||||
res = res_v4.w;
|
||||
// there may be left some
|
||||
for(int i = 0; i < cols % 4; ++i, ++iptr, ++optr)
|
||||
{
|
||||
res = *iptr + _tau * *optr + _a * res;
|
||||
*optr = res;
|
||||
}
|
||||
}
|
||||
|
||||
//_horizontalAnticausalFilter
|
||||
kernel void horizontalAnticausalFilter(
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const int out_offset,
|
||||
const float _a
|
||||
)
|
||||
{
|
||||
int gid = get_global_id(0);
|
||||
if(gid >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
global float * optr = output +
|
||||
mad24(gid + 1, elements_per_row, - 1 + out_offset / 4);
|
||||
|
||||
float4 result_v4 = (float4)(0), out_v4;
|
||||
float result = 0;
|
||||
// we assume elements_per_row is multple of WIDTH_MULTIPLE
|
||||
for(int i = 0; i < WIDTH_MULTIPLE; ++ i, -- optr)
|
||||
{
|
||||
if(i >= elements_per_row - cols)
|
||||
{
|
||||
result = *optr + _a * result;
|
||||
}
|
||||
*optr = result;
|
||||
}
|
||||
result_v4.x = result;
|
||||
optr -= 3;
|
||||
for(int i = WIDTH_MULTIPLE / 4; i < elements_per_row / 4; ++i, optr -= 4)
|
||||
{
|
||||
// shift left, `offset` is type `size_t` so it cannot be negative
|
||||
out_v4 = vload4(0, optr);
|
||||
|
||||
result_v4.w = out_v4.w + _a * result_v4.x;
|
||||
result_v4.z = out_v4.z + _a * result_v4.w;
|
||||
result_v4.y = out_v4.y + _a * result_v4.z;
|
||||
result_v4.x = out_v4.x + _a * result_v4.y;
|
||||
|
||||
vstore4(result_v4, 0, optr);
|
||||
}
|
||||
}
|
||||
|
||||
//_verticalCausalFilter
|
||||
kernel void verticalCausalFilter(
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const int out_offset,
|
||||
const float _a
|
||||
)
|
||||
{
|
||||
int gid = get_global_id(0);
|
||||
if(gid >= cols)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
global float * optr = output + gid + out_offset / 4;
|
||||
float result = 0;
|
||||
for(int i = 0; i < rows; ++i, optr += elements_per_row)
|
||||
{
|
||||
result = *optr + _a * result;
|
||||
*optr = result;
|
||||
}
|
||||
}
|
||||
|
||||
//_verticalCausalFilter
|
||||
kernel void verticalAnticausalFilter_multGain(
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const int out_offset,
|
||||
const float _a,
|
||||
const float _gain
|
||||
)
|
||||
{
|
||||
int gid = get_global_id(0);
|
||||
if(gid >= cols)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
global float * optr = output + (rows - 1) * elements_per_row + gid + out_offset / 4;
|
||||
float result = 0;
|
||||
for(int i = 0; i < rows; ++i, optr -= elements_per_row)
|
||||
{
|
||||
result = *optr + _a * result;
|
||||
*optr = _gain * result;
|
||||
}
|
||||
}
|
||||
//
|
||||
// end of _spatiotemporalLPfilter
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////// horizontalAnticausalFilter_Irregular ////////////////
|
||||
kernel void horizontalAnticausalFilter_Irregular(
|
||||
global float * output,
|
||||
global float * buffer,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const int out_offset,
|
||||
const int buffer_offset
|
||||
)
|
||||
{
|
||||
int gid = get_global_id(0);
|
||||
if(gid >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
global float * optr =
|
||||
output + mad24(rows - gid, elements_per_row, -1 + out_offset / 4);
|
||||
global float * bptr =
|
||||
buffer + mad24(rows - gid, elements_per_row, -1 + buffer_offset / 4);
|
||||
|
||||
float4 buf_v4, out_v4, res_v4 = (float4)(0);
|
||||
float result = 0;
|
||||
// we assume elements_per_row is multple of WIDTH_MULTIPLE
|
||||
for(int i = 0; i < WIDTH_MULTIPLE; ++ i, -- optr, -- bptr)
|
||||
{
|
||||
if(i >= elements_per_row - cols)
|
||||
{
|
||||
result = *optr + *bptr * result;
|
||||
}
|
||||
*optr = result;
|
||||
}
|
||||
res_v4.x = result;
|
||||
optr -= 3;
|
||||
bptr -= 3;
|
||||
for(int i = WIDTH_MULTIPLE / 4; i < elements_per_row / 4; ++i, optr -= 4, bptr -= 4)
|
||||
{
|
||||
buf_v4 = vload4(0, bptr);
|
||||
out_v4 = vload4(0, optr);
|
||||
|
||||
res_v4.w = out_v4.w + buf_v4.w * res_v4.x;
|
||||
res_v4.z = out_v4.z + buf_v4.z * res_v4.w;
|
||||
res_v4.y = out_v4.y + buf_v4.y * res_v4.z;
|
||||
res_v4.x = out_v4.x + buf_v4.x * res_v4.y;
|
||||
|
||||
vstore4(res_v4, 0, optr);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////// verticalCausalFilter_Irregular ////////////////
|
||||
kernel void verticalCausalFilter_Irregular(
|
||||
global float * output,
|
||||
global float * buffer,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const int out_offset,
|
||||
const int buffer_offset
|
||||
)
|
||||
{
|
||||
int gid = get_global_id(0);
|
||||
if(gid >= cols)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
global float * optr = output + gid + out_offset / 4;
|
||||
global float * bptr = buffer + gid + buffer_offset / 4;
|
||||
float result = 0;
|
||||
for(int i = 0; i < rows; ++i, optr += elements_per_row, bptr += elements_per_row)
|
||||
{
|
||||
result = *optr + *bptr * result;
|
||||
*optr = result;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////// _adaptiveHorizontalCausalFilter_addInput ////////////////
|
||||
kernel void adaptiveHorizontalCausalFilter_addInput(
|
||||
global const float * input,
|
||||
global const float * gradient,
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const int in_offset,
|
||||
const int grad_offset,
|
||||
const int out_offset
|
||||
)
|
||||
{
|
||||
int gid = get_global_id(0);
|
||||
if(gid >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
global const float * iptr =
|
||||
input + mad24(gid, elements_per_row, in_offset / 4);
|
||||
global const float * gptr =
|
||||
gradient + mad24(gid, elements_per_row, grad_offset / 4);
|
||||
global float * optr =
|
||||
output + mad24(gid, elements_per_row, out_offset / 4);
|
||||
|
||||
float4 in_v4, grad_v4, out_v4, res_v4 = (float4)(0);
|
||||
for(int i = 0; i < cols / 4; ++i, iptr += 4, gptr += 4, optr += 4)
|
||||
{
|
||||
in_v4 = vload4(0, iptr);
|
||||
grad_v4 = vload4(0, gptr);
|
||||
|
||||
res_v4.x = in_v4.x + grad_v4.x * res_v4.w;
|
||||
res_v4.y = in_v4.y + grad_v4.y * res_v4.x;
|
||||
res_v4.z = in_v4.z + grad_v4.z * res_v4.y;
|
||||
res_v4.w = in_v4.w + grad_v4.w * res_v4.z;
|
||||
|
||||
vstore4(res_v4, 0, optr);
|
||||
}
|
||||
for(int i = 0; i < cols % 4; ++i, ++iptr, ++gptr, ++optr)
|
||||
{
|
||||
res_v4.w = *iptr + *gptr * res_v4.w;
|
||||
*optr = res_v4.w;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////// _adaptiveVerticalAnticausalFilter_multGain ////////////////
|
||||
kernel void adaptiveVerticalAnticausalFilter_multGain(
|
||||
global const float * gradient,
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const int grad_offset,
|
||||
const int out_offset,
|
||||
const float gain
|
||||
)
|
||||
{
|
||||
int gid = get_global_id(0);
|
||||
if(gid >= cols)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int start_idx = mad24(rows - 1, elements_per_row, gid);
|
||||
|
||||
global const float * gptr = gradient + start_idx + grad_offset / 4;
|
||||
global float * optr = output + start_idx + out_offset / 4;
|
||||
|
||||
float result = 0;
|
||||
for(int i = 0; i < rows; ++i, gptr -= elements_per_row, optr -= elements_per_row)
|
||||
{
|
||||
result = *optr + *gptr * result;
|
||||
*optr = gain * result;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////// _localLuminanceAdaptation ////////////////
|
||||
// FIXME:
|
||||
// This kernel seems to have precision problem on GPU
|
||||
kernel void localLuminanceAdaptation(
|
||||
global const float * luma,
|
||||
global const float * input,
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const float _localLuminanceAddon,
|
||||
const float _localLuminanceFactor,
|
||||
const float _maxInputValue
|
||||
)
|
||||
{
|
||||
int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int offset = mad24(gidy, elements_per_row, gidx);
|
||||
|
||||
float X0 = luma[offset] * _localLuminanceFactor + _localLuminanceAddon;
|
||||
float input_val = input[offset];
|
||||
// output of the following line may be different between GPU and CPU
|
||||
output[offset] = (_maxInputValue + X0) * input_val / (input_val + X0 + 0.00000000001f);
|
||||
}
|
||||
// end of basicretinafilter
|
||||
//*******************************************************
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
//******************************************************
|
||||
// magno
|
||||
// TODO: this kernel has too many buffer accesses, better to make it
|
||||
// vector read/write for fetch efficiency
|
||||
kernel void amacrineCellsComputing(
|
||||
global const float * opl_on,
|
||||
global const float * opl_off,
|
||||
global float * prev_in_on,
|
||||
global float * prev_in_off,
|
||||
global float * out_on,
|
||||
global float * out_off,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const float coeff
|
||||
)
|
||||
{
|
||||
int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int offset = mad24(gidy, elements_per_row, gidx);
|
||||
opl_on += offset;
|
||||
opl_off += offset;
|
||||
prev_in_on += offset;
|
||||
prev_in_off += offset;
|
||||
out_on += offset;
|
||||
out_off += offset;
|
||||
|
||||
float magnoXonPixelResult = coeff * (*out_on + *opl_on - *prev_in_on);
|
||||
*out_on = fmax(magnoXonPixelResult, 0);
|
||||
float magnoXoffPixelResult = coeff * (*out_off + *opl_off - *prev_in_off);
|
||||
*out_off = fmax(magnoXoffPixelResult, 0);
|
||||
|
||||
*prev_in_on = *opl_on;
|
||||
*prev_in_off = *opl_off;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
//******************************************************
|
||||
// parvo
|
||||
// TODO: this kernel has too many buffer accesses, needs optimization
|
||||
kernel void OPL_OnOffWaysComputing(
|
||||
global float4 * photo_out,
|
||||
global float4 * horiz_out,
|
||||
global float4 * bipol_on,
|
||||
global float4 * bipol_off,
|
||||
global float4 * parvo_on,
|
||||
global float4 * parvo_off,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row
|
||||
)
|
||||
{
|
||||
int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx * 4 >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// we assume elements_per_row must be multiples of 4
|
||||
int offset = mad24(gidy, elements_per_row >> 2, gidx);
|
||||
photo_out += offset;
|
||||
horiz_out += offset;
|
||||
bipol_on += offset;
|
||||
bipol_off += offset;
|
||||
parvo_on += offset;
|
||||
parvo_off += offset;
|
||||
|
||||
float4 diff = *photo_out - *horiz_out;
|
||||
float4 isPositive;// = convert_float4(diff > (float4)(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
isPositive.x = diff.x > 0.0f;
|
||||
isPositive.y = diff.y > 0.0f;
|
||||
isPositive.z = diff.z > 0.0f;
|
||||
isPositive.w = diff.w > 0.0f;
|
||||
float4 res_on = isPositive * diff;
|
||||
float4 res_off = (isPositive - (float4)(1.0f)) * diff;
|
||||
|
||||
*bipol_on = res_on;
|
||||
*parvo_on = res_on;
|
||||
|
||||
*bipol_off = res_off;
|
||||
*parvo_off = res_off;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
//******************************************************
|
||||
// retinacolor
|
||||
inline int bayerSampleOffset(int step, int rows, int x, int y)
|
||||
{
|
||||
return mad24(y, step, x) +
|
||||
((y % 2) + (x % 2)) * rows * step;
|
||||
}
|
||||
|
||||
|
||||
/////// colorMultiplexing //////
|
||||
kernel void runColorMultiplexingBayer(
|
||||
global const float * input,
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row
|
||||
)
|
||||
{
|
||||
int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int offset = mad24(gidy, elements_per_row, gidx);
|
||||
output[offset] = input[bayerSampleOffset(elements_per_row, rows, gidx, gidy)];
|
||||
}
|
||||
|
||||
kernel void runColorDemultiplexingBayer(
|
||||
global const float * input,
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row
|
||||
)
|
||||
{
|
||||
int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int offset = mad24(gidy, elements_per_row, gidx);
|
||||
output[bayerSampleOffset(elements_per_row, rows, gidx, gidy)] = input[offset];
|
||||
}
|
||||
|
||||
kernel void demultiplexAssign(
|
||||
global const float * input,
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row
|
||||
)
|
||||
{
|
||||
int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int offset = bayerSampleOffset(elements_per_row, rows, gidx, gidy);
|
||||
output[offset] = input[offset];
|
||||
}
|
||||
|
||||
|
||||
//// normalizeGrayOutputCentredSigmoide
|
||||
kernel void normalizeGrayOutputCentredSigmoide(
|
||||
global const float * input,
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const float meanval,
|
||||
const float X0
|
||||
)
|
||||
|
||||
{
|
||||
int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int offset = mad24(gidy, elements_per_row, gidx);
|
||||
|
||||
float input_val = input[offset];
|
||||
output[offset] = meanval +
|
||||
(meanval + X0) * (input_val - meanval) / (fabs(input_val - meanval) + X0);
|
||||
}
|
||||
|
||||
//// normalize by photoreceptors density
|
||||
kernel void normalizePhotoDensity(
|
||||
global const float * chroma,
|
||||
global const float * colorDensity,
|
||||
global const float * multiplex,
|
||||
global float * luma,
|
||||
global float * demultiplex,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const float pG
|
||||
)
|
||||
{
|
||||
const int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const int offset = mad24(gidy, elements_per_row, gidx);
|
||||
int index = offset;
|
||||
|
||||
float Cr = chroma[index] * colorDensity[index];
|
||||
index += elements_per_row * rows;
|
||||
float Cg = chroma[index] * colorDensity[index];
|
||||
index += elements_per_row * rows;
|
||||
float Cb = chroma[index] * colorDensity[index];
|
||||
|
||||
const float luma_res = (Cr + Cg + Cb) * pG;
|
||||
luma[offset] = luma_res;
|
||||
demultiplex[bayerSampleOffset(elements_per_row, rows, gidx, gidy)] =
|
||||
multiplex[offset] - luma_res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////// computeGradient ///////
|
||||
// TODO:
|
||||
// this function maybe accelerated by image2d_t or lds
|
||||
kernel void computeGradient(
|
||||
global const float * luma,
|
||||
global float * gradient,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row
|
||||
)
|
||||
{
|
||||
int gidx = get_global_id(0) + 2, gidy = get_global_id(1) + 2;
|
||||
if(gidx >= cols - 2 || gidy >= rows - 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int offset = mad24(gidy, elements_per_row, gidx);
|
||||
luma += offset;
|
||||
|
||||
// horizontal and vertical local gradients
|
||||
const float v_grad = fabs(luma[elements_per_row] - luma[- elements_per_row]);
|
||||
const float h_grad = fabs(luma[1] - luma[-1]);
|
||||
|
||||
// neighborhood horizontal and vertical gradients
|
||||
const float cur_val = luma[0];
|
||||
const float v_grad_p = fabs(cur_val - luma[- 2 * elements_per_row]);
|
||||
const float h_grad_p = fabs(cur_val - luma[- 2]);
|
||||
const float v_grad_n = fabs(cur_val - luma[2 * elements_per_row]);
|
||||
const float h_grad_n = fabs(cur_val - luma[2]);
|
||||
|
||||
const float horiz_grad = 0.5f * h_grad + 0.25f * (h_grad_p + h_grad_n);
|
||||
const float verti_grad = 0.5f * v_grad + 0.25f * (v_grad_p + v_grad_n);
|
||||
const bool is_vertical_greater = horiz_grad < verti_grad;
|
||||
|
||||
gradient[offset + elements_per_row * rows] = is_vertical_greater ? 0.06f : 0.57f;
|
||||
gradient[offset ] = is_vertical_greater ? 0.57f : 0.06f;
|
||||
}
|
||||
|
||||
|
||||
/////// substractResidual ///////
|
||||
kernel void substractResidual(
|
||||
global float * input,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const float pR,
|
||||
const float pG,
|
||||
const float pB
|
||||
)
|
||||
{
|
||||
const int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int indices [3] =
|
||||
{
|
||||
mad24(gidy, elements_per_row, gidx),
|
||||
mad24(gidy + rows, elements_per_row, gidx),
|
||||
mad24(gidy + 2 * rows, elements_per_row, gidx)
|
||||
};
|
||||
float vals[3] = {input[indices[0]], input[indices[1]], input[indices[2]]};
|
||||
float residu = pR * vals[0] + pG * vals[1] + pB * vals[2];
|
||||
|
||||
input[indices[0]] = vals[0] - residu;
|
||||
input[indices[1]] = vals[1] - residu;
|
||||
input[indices[2]] = vals[2] - residu;
|
||||
}
|
||||
|
||||
///// clipRGBOutput_0_maxInputValue /////
|
||||
kernel void clipRGBOutput_0_maxInputValue(
|
||||
global float * input,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const float maxVal
|
||||
)
|
||||
{
|
||||
const int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const int offset = mad24(gidy, elements_per_row, gidx);
|
||||
float val = input[offset];
|
||||
val = clamp(val, 0.0f, maxVal);
|
||||
input[offset] = val;
|
||||
}
|
||||
|
||||
//// normalizeGrayOutputNearZeroCentreredSigmoide ////
|
||||
kernel void normalizeGrayOutputNearZeroCentreredSigmoide(
|
||||
global float * input,
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const float maxVal,
|
||||
const float X0cube
|
||||
)
|
||||
{
|
||||
const int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const int offset = mad24(gidy, elements_per_row, gidx);
|
||||
float currentCubeLuminance = input[offset];
|
||||
currentCubeLuminance = currentCubeLuminance * currentCubeLuminance * currentCubeLuminance;
|
||||
output[offset] = currentCubeLuminance * X0cube / (X0cube + currentCubeLuminance);
|
||||
}
|
||||
|
||||
//// centerReductImageLuminance ////
|
||||
kernel void centerReductImageLuminance(
|
||||
global float * input,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row,
|
||||
const float mean,
|
||||
const float std_dev
|
||||
)
|
||||
{
|
||||
const int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const int offset = mad24(gidy, elements_per_row, gidx);
|
||||
|
||||
float val = input[offset];
|
||||
input[offset] = (val - mean) / std_dev;
|
||||
}
|
||||
|
||||
//// inverseValue ////
|
||||
kernel void inverseValue(
|
||||
global float * input,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int elements_per_row
|
||||
)
|
||||
{
|
||||
const int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const int offset = mad24(gidy, elements_per_row, gidx);
|
||||
input[offset] = 1.f / input[offset];
|
||||
}
|
||||
|
||||
#define CV_PI 3.1415926535897932384626433832795
|
||||
|
||||
//// _processRetinaParvoMagnoMapping ////
|
||||
kernel void processRetinaParvoMagnoMapping(
|
||||
global float * parvo,
|
||||
global float * magno,
|
||||
global float * output,
|
||||
const int cols,
|
||||
const int rows,
|
||||
const int halfCols,
|
||||
const int halfRows,
|
||||
const int elements_per_row,
|
||||
const float minDistance
|
||||
)
|
||||
{
|
||||
const int gidx = get_global_id(0), gidy = get_global_id(1);
|
||||
if(gidx >= cols || gidy >= rows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const int offset = mad24(gidy, elements_per_row, gidx);
|
||||
|
||||
float distanceToCenter =
|
||||
sqrt(((float)(gidy - halfRows) * (gidy - halfRows) + (gidx - halfCols) * (gidx - halfCols)));
|
||||
|
||||
float a = distanceToCenter < minDistance ?
|
||||
(0.5f + 0.5f * (float)cos(CV_PI * distanceToCenter / minDistance)) : 0;
|
||||
float b = 1.f - a;
|
||||
|
||||
output[offset] = parvo[offset] * a + magno[offset] * b;
|
||||
}
|
@ -1,233 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2011
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
#include "parvoretinafilter.hpp"
|
||||
|
||||
// @author Alexandre BENOIT, benoit.alexandre.vision@gmail.com, LISTIC : www.listic.univ-savoie.fr, Gipsa-Lab, France: www.gipsa-lab.inpg.fr/
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
//////////////////////////////////////////////////////////
|
||||
// OPL RETINA FILTER
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
// Constructor and Desctructor of the OPL retina filter
|
||||
|
||||
ParvoRetinaFilter::ParvoRetinaFilter(const unsigned int NBrows, const unsigned int NBcolumns)
|
||||
:BasicRetinaFilter(NBrows, NBcolumns, 3),
|
||||
_photoreceptorsOutput(NBrows*NBcolumns),
|
||||
_horizontalCellsOutput(NBrows*NBcolumns),
|
||||
_parvocellularOutputON(NBrows*NBcolumns),
|
||||
_parvocellularOutputOFF(NBrows*NBcolumns),
|
||||
_bipolarCellsOutputON(NBrows*NBcolumns),
|
||||
_bipolarCellsOutputOFF(NBrows*NBcolumns),
|
||||
_localAdaptationOFF(NBrows*NBcolumns)
|
||||
{
|
||||
// link to the required local parent adaptation buffers
|
||||
_localAdaptationON=&_localBuffer;
|
||||
_parvocellularOutputONminusOFF=&_filterOutput;
|
||||
// (*_localAdaptationON)=&_localBuffer;
|
||||
// (*_parvocellularOutputONminusOFF)=&(BasicRetinaFilter::TemplateBuffer);
|
||||
|
||||
// init: set all the values to 0
|
||||
clearAllBuffers();
|
||||
|
||||
|
||||
#ifdef OPL_RETINA_ELEMENT_DEBUG
|
||||
std::cout<<"ParvoRetinaFilter::Init OPL retina filter at specified frame size OK\n"<<std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
ParvoRetinaFilter::~ParvoRetinaFilter()
|
||||
{
|
||||
|
||||
#ifdef OPL_RETINA_ELEMENT_DEBUG
|
||||
std::cout<<"ParvoRetinaFilter::Delete OPL retina filter OK"<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// functions of the PARVO filter
|
||||
////////////////////////////////////
|
||||
|
||||
// function that clears all buffers of the object
|
||||
void ParvoRetinaFilter::clearAllBuffers()
|
||||
{
|
||||
BasicRetinaFilter::clearAllBuffers();
|
||||
_photoreceptorsOutput=0;
|
||||
_horizontalCellsOutput=0;
|
||||
_parvocellularOutputON=0;
|
||||
_parvocellularOutputOFF=0;
|
||||
_bipolarCellsOutputON=0;
|
||||
_bipolarCellsOutputOFF=0;
|
||||
_localAdaptationOFF=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* resize parvo retina filter object (resize all allocated buffers
|
||||
* @param NBrows: the new height size
|
||||
* @param NBcolumns: the new width size
|
||||
*/
|
||||
void ParvoRetinaFilter::resize(const unsigned int NBrows, const unsigned int NBcolumns)
|
||||
{
|
||||
BasicRetinaFilter::resize(NBrows, NBcolumns);
|
||||
_photoreceptorsOutput.resize(NBrows*NBcolumns);
|
||||
_horizontalCellsOutput.resize(NBrows*NBcolumns);
|
||||
_parvocellularOutputON.resize(NBrows*NBcolumns);
|
||||
_parvocellularOutputOFF.resize(NBrows*NBcolumns);
|
||||
_bipolarCellsOutputON.resize(NBrows*NBcolumns);
|
||||
_bipolarCellsOutputOFF.resize(NBrows*NBcolumns);
|
||||
_localAdaptationOFF.resize(NBrows*NBcolumns);
|
||||
|
||||
// link to the required local parent adaptation buffers
|
||||
_localAdaptationON=&_localBuffer;
|
||||
_parvocellularOutputONminusOFF=&_filterOutput;
|
||||
|
||||
// clean buffers
|
||||
clearAllBuffers();
|
||||
}
|
||||
|
||||
// change the parameters of the filter
|
||||
void ParvoRetinaFilter::setOPLandParvoFiltersParameters(const float beta1, const float tau1, const float k1, const float beta2, const float tau2, const float k2)
|
||||
{
|
||||
// init photoreceptors low pass filter
|
||||
setLPfilterParameters(beta1, tau1, k1);
|
||||
// init horizontal cells low pass filter
|
||||
setLPfilterParameters(beta2, tau2, k2, 1);
|
||||
// init parasol ganglion cells low pass filter (default parameters)
|
||||
setLPfilterParameters(0, tau1, k1, 2);
|
||||
|
||||
}
|
||||
|
||||
// update/set size of the frames
|
||||
|
||||
// run filter for a new frame input
|
||||
// output return is (*_parvocellularOutputONminusOFF)
|
||||
const std::valarray<float> &ParvoRetinaFilter::runFilter(const std::valarray<float> &inputFrame, const bool useParvoOutput)
|
||||
{
|
||||
_spatiotemporalLPfilter(get_data(inputFrame), &_photoreceptorsOutput[0]);
|
||||
_spatiotemporalLPfilter(&_photoreceptorsOutput[0], &_horizontalCellsOutput[0], 1);
|
||||
_OPL_OnOffWaysComputing();
|
||||
|
||||
if (useParvoOutput)
|
||||
{
|
||||
// local adaptation processes on ON and OFF ways
|
||||
_spatiotemporalLPfilter(&_bipolarCellsOutputON[0], &(*_localAdaptationON)[0], 2);
|
||||
_localLuminanceAdaptation(&_parvocellularOutputON[0], &(*_localAdaptationON)[0]);
|
||||
|
||||
_spatiotemporalLPfilter(&_bipolarCellsOutputOFF[0], &_localAdaptationOFF[0], 2);
|
||||
_localLuminanceAdaptation(&_parvocellularOutputOFF[0], &_localAdaptationOFF[0]);
|
||||
|
||||
//// Final loop that computes the main output of this filter
|
||||
//
|
||||
//// loop that makes the difference between photoreceptor cells output and horizontal cells
|
||||
//// positive part goes on the ON way, negative pat goes on the OFF way
|
||||
register float *parvocellularOutputONminusOFF_PTR=&(*_parvocellularOutputONminusOFF)[0];
|
||||
register float *parvocellularOutputON_PTR=&_parvocellularOutputON[0];
|
||||
register float *parvocellularOutputOFF_PTR=&_parvocellularOutputOFF[0];
|
||||
|
||||
for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel)
|
||||
*(parvocellularOutputONminusOFF_PTR++)= (*(parvocellularOutputON_PTR++)-*(parvocellularOutputOFF_PTR++));
|
||||
}
|
||||
return (*_parvocellularOutputONminusOFF);
|
||||
}
|
||||
|
||||
void ParvoRetinaFilter::_OPL_OnOffWaysComputing() // WARNING : this method requires many buffer accesses, parallelizing can increase bandwith & core efficacy
|
||||
{
|
||||
// loop that makes the difference between photoreceptor cells output and horizontal cells
|
||||
// positive part goes on the ON way, negative pat goes on the OFF way
|
||||
|
||||
#ifdef MAKE_PARALLEL
|
||||
cv::parallel_for_(cv::Range(0,_filterOutput.getNBpixels()), Parallel_OPL_OnOffWaysComputing(&_photoreceptorsOutput[0], &_horizontalCellsOutput[0], &_bipolarCellsOutputON[0], &_bipolarCellsOutputOFF[0], &_parvocellularOutputON[0], &_parvocellularOutputOFF[0]));
|
||||
#else
|
||||
float *photoreceptorsOutput_PTR= &_photoreceptorsOutput[0];
|
||||
float *horizontalCellsOutput_PTR= &_horizontalCellsOutput[0];
|
||||
float *bipolarCellsON_PTR = &_bipolarCellsOutputON[0];
|
||||
float *bipolarCellsOFF_PTR = &_bipolarCellsOutputOFF[0];
|
||||
float *parvocellularOutputON_PTR= &_parvocellularOutputON[0];
|
||||
float *parvocellularOutputOFF_PTR= &_parvocellularOutputOFF[0];
|
||||
// compute bipolar cells response equal to photoreceptors minus horizontal cells response
|
||||
// and copy the result on parvo cellular outputs... keeping time before their local contrast adaptation for final result
|
||||
for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel)
|
||||
{
|
||||
float pixelDifference = *(photoreceptorsOutput_PTR++) -*(horizontalCellsOutput_PTR++);
|
||||
// test condition to allow write pixelDifference in ON or OFF buffer and 0 in the over
|
||||
float isPositive=(float) (pixelDifference>0.0f);
|
||||
|
||||
// ON and OFF channels writing step
|
||||
*(parvocellularOutputON_PTR++)=*(bipolarCellsON_PTR++) = isPositive*pixelDifference;
|
||||
*(parvocellularOutputOFF_PTR++)=*(bipolarCellsOFF_PTR++)= (isPositive-1.0f)*pixelDifference;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
@ -1,263 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2011
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ParvoRetinaFilter_H_
|
||||
#define ParvoRetinaFilter_H_
|
||||
|
||||
/**
|
||||
* @class ParvoRetinaFilter
|
||||
* @brief class which describes the OPL retina model and the Inner Plexiform Layer parvocellular channel of the retina:
|
||||
* -> performs a contours extraction with powerfull local data enhancement as at the retina level
|
||||
* -> spectrum whitening occurs at the OPL (Outer Plexiform Layer) of the retina: corrects the 1/f spectrum tendancy of natural images
|
||||
* ---> enhances details with mid spatial frequencies, attenuates low spatial frequencies (luminance), attenuates high temporal frequencies and high spatial frequencies, etc.
|
||||
*
|
||||
* TYPICAL USE:
|
||||
*
|
||||
* // create object at a specified picture size
|
||||
* ParvoRetinaFilter *contoursExtractor;
|
||||
* contoursExtractor =new ParvoRetinaFilter(frameSizeRows, frameSizeColumns);
|
||||
*
|
||||
* // init gain, spatial and temporal parameters:
|
||||
* contoursExtractor->setCoefficientsTable(0, 0.7, 1, 0, 7, 1);
|
||||
*
|
||||
* // during program execution, call the filter for contours extraction for an input picture called "FrameBuffer":
|
||||
* contoursExtractor->runfilter(FrameBuffer);
|
||||
*
|
||||
* // get the output frame, check in the class description below for more outputs:
|
||||
* const float *contours=contoursExtractor->getParvoONminusOFF();
|
||||
*
|
||||
* // at the end of the program, destroy object:
|
||||
* delete contoursExtractor;
|
||||
|
||||
* @author Alexandre BENOIT, benoit.alexandre.vision@gmail.com, LISTIC : www.listic.univ-savoie.fr, Gipsa-Lab, France: www.gipsa-lab.inpg.fr/
|
||||
* Creation date 2007
|
||||
* Based on Alexandre BENOIT thesis: "Le système visuel humain au secours de la vision par ordinateur"
|
||||
*
|
||||
*/
|
||||
|
||||
#include "basicretinafilter.hpp"
|
||||
|
||||
|
||||
//#define _OPL_RETINA_ELEMENT_DEBUG
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
//retina classes that derivate from the Basic Retrina class
|
||||
class ParvoRetinaFilter: public BasicRetinaFilter
|
||||
{
|
||||
|
||||
public:
|
||||
/**
|
||||
* constructor parameters are only linked to image input size
|
||||
* @param NBrows: number of rows of the input image
|
||||
* @param NBcolumns: number of columns of the input image
|
||||
*/
|
||||
ParvoRetinaFilter(const unsigned int NBrows=480, const unsigned int NBcolumns=640);
|
||||
|
||||
/**
|
||||
* standard desctructor
|
||||
*/
|
||||
virtual ~ParvoRetinaFilter();
|
||||
|
||||
/**
|
||||
* resize method, keeps initial parameters, all buffers are flushed
|
||||
* @param NBrows: number of rows of the input image
|
||||
* @param NBcolumns: number of columns of the input image
|
||||
*/
|
||||
void resize(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
|
||||
/**
|
||||
* function that clears all buffers of the object
|
||||
*/
|
||||
void clearAllBuffers();
|
||||
|
||||
/**
|
||||
* setup the OPL and IPL parvo channels
|
||||
* @param beta1: gain of the horizontal cells network, if 0, then the mean value of the output is zero, if the parameter is near 1, the amplitude is boosted but it should only be used for values rescaling... if needed
|
||||
* @param tau1: the time constant of the first order low pass filter of the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 1 frame
|
||||
* @param k1: the spatial constant of the first order low pass filter of the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 1 pixel
|
||||
* @param beta2: gain of the horizontal cells network, if 0, then the mean value of the output is zero, if the parameter is near 1, then, the luminance is not filtered and is still reachable at the output, typicall value is 0
|
||||
* @param tau2: the time constant of the first order low pass filter of the horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is frames, typical value is 1 frame, as the photoreceptors
|
||||
* @param k2: the spatial constant of the first order low pass filter of the horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, typical value is 5 pixel, this value is also used for local contrast computing when computing the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular channel model)
|
||||
*/
|
||||
void setOPLandParvoFiltersParameters(const float beta1, const float tau1, const float k1, const float beta2, const float tau2, const float k2);
|
||||
|
||||
/**
|
||||
* setup more precisely the low pass filter used for the ganglion cells low pass filtering (used for local luminance adaptation)
|
||||
* @param tau: time constant of the filter (unit is frame for video processing)
|
||||
* @param k: spatial constant of the filter (unit is pixels)
|
||||
*/
|
||||
void setGanglionCellsLocalAdaptationLPfilterParameters(const float tau, const float k){BasicRetinaFilter::setLPfilterParameters(0, tau, k, 2);}; // change the parameters of the filter
|
||||
|
||||
|
||||
/**
|
||||
* launch filter that runs the OPL spatiotemporal filtering and optionally finalizes IPL Pagno filter (model of the Parvocellular channel of the Inner Plexiform Layer of the retina)
|
||||
* @param inputFrame: the input image to be processed, this can be the direct gray level input frame, but a better efficacy is expected if the input is preliminary processed by the photoreceptors local adaptation possible to acheive with the help of a BasicRetinaFilter object
|
||||
* @param useParvoOutput: set true if the final IPL filtering step has to be computed (local contrast enhancement)
|
||||
* @return the processed Parvocellular channel output (updated only if useParvoOutput is true)
|
||||
* @details: in any case, after this function call, photoreceptors and horizontal cells output are updated, use getPhotoreceptorsLPfilteringOutput() and getHorizontalCellsOutput() to get them
|
||||
* also, bipolar cells output are accessible (difference between photoreceptors and horizontal cells, ON output has positive values, OFF ouput has negative values), use the following access methods: getBipolarCellsON() and getBipolarCellsOFF()if useParvoOutput is true,
|
||||
* if useParvoOutput is true, the complete Parvocellular channel is computed, more outputs are updated and can be accessed threw: getParvoON(), getParvoOFF() and their difference with getOutput()
|
||||
*/
|
||||
const std::valarray<float> &runFilter(const std::valarray<float> &inputFrame, const bool useParvoOutput=true); // output return is _parvocellularOutputONminusOFF
|
||||
|
||||
/**
|
||||
* @return the output of the photoreceptors filtering step (high cut frequency spatio-temporal low pass filter)
|
||||
*/
|
||||
inline const std::valarray<float> &getPhotoreceptorsLPfilteringOutput() const {return _photoreceptorsOutput;};
|
||||
|
||||
/**
|
||||
* @return the output of the photoreceptors filtering step (low cut frequency spatio-temporal low pass filter)
|
||||
*/
|
||||
inline const std::valarray<float> &getHorizontalCellsOutput() const { return _horizontalCellsOutput;};
|
||||
|
||||
/**
|
||||
* @return the output Parvocellular ON channel of the retina model
|
||||
*/
|
||||
inline const std::valarray<float> &getParvoON() const {return _parvocellularOutputON;};
|
||||
|
||||
/**
|
||||
* @return the output Parvocellular OFF channel of the retina model
|
||||
*/
|
||||
inline const std::valarray<float> &getParvoOFF() const {return _parvocellularOutputOFF;};
|
||||
|
||||
/**
|
||||
* @return the output of the Bipolar cells of the ON channel of the retina model same as function getParvoON() but without luminance local adaptation
|
||||
*/
|
||||
inline const std::valarray<float> &getBipolarCellsON() const {return _bipolarCellsOutputON;};
|
||||
|
||||
/**
|
||||
* @return the output of the Bipolar cells of the OFF channel of the retina model same as function getParvoON() but without luminance local adaptation
|
||||
*/
|
||||
inline const std::valarray<float> &getBipolarCellsOFF() const {return _bipolarCellsOutputOFF;};
|
||||
|
||||
/**
|
||||
* @return the photoreceptors's temporal constant
|
||||
*/
|
||||
inline float getPhotoreceptorsTemporalConstant(){return this->_filteringCoeficientsTable[2];};
|
||||
|
||||
/**
|
||||
* @return the horizontal cells' temporal constant
|
||||
*/
|
||||
inline float getHcellsTemporalConstant(){return this->_filteringCoeficientsTable[5];};
|
||||
|
||||
private:
|
||||
// template buffers
|
||||
std::valarray <float>_photoreceptorsOutput;
|
||||
std::valarray <float>_horizontalCellsOutput;
|
||||
std::valarray <float>_parvocellularOutputON;
|
||||
std::valarray <float>_parvocellularOutputOFF;
|
||||
std::valarray <float>_bipolarCellsOutputON;
|
||||
std::valarray <float>_bipolarCellsOutputOFF;
|
||||
std::valarray <float>_localAdaptationOFF;
|
||||
std::valarray <float> *_localAdaptationON;
|
||||
TemplateBuffer<float> *_parvocellularOutputONminusOFF;
|
||||
// private functions
|
||||
void _OPL_OnOffWaysComputing();
|
||||
|
||||
#ifdef MAKE_PARALLEL
|
||||
/******************************************************
|
||||
** IF some parallelizing thread methods are available, then, main loops are parallelized using these functors
|
||||
** ==> main idea paralellise main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelised methods as necessary
|
||||
** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelised
|
||||
** ==> functors constructors can differ from the parameters used with their related serial functions
|
||||
*/
|
||||
class Parallel_OPL_OnOffWaysComputing: public cv::ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
float *photoreceptorsOutput, *horizontalCellsOutput, *bipolarCellsON, *bipolarCellsOFF, *parvocellularOutputON, *parvocellularOutputOFF;
|
||||
public:
|
||||
Parallel_OPL_OnOffWaysComputing(float *photoreceptorsOutput_PTR, float *horizontalCellsOutput_PTR, float *bipolarCellsON_PTR, float *bipolarCellsOFF_PTR, float *parvocellularOutputON_PTR, float *parvocellularOutputOFF_PTR)
|
||||
:photoreceptorsOutput(photoreceptorsOutput_PTR), horizontalCellsOutput(horizontalCellsOutput_PTR), bipolarCellsON(bipolarCellsON_PTR), bipolarCellsOFF(bipolarCellsOFF_PTR), parvocellularOutputON(parvocellularOutputON_PTR), parvocellularOutputOFF(parvocellularOutputOFF_PTR) {}
|
||||
|
||||
virtual void operator()( const Range& r ) const {
|
||||
// compute bipolar cells response equal to photoreceptors minus horizontal cells response
|
||||
// and copy the result on parvo cellular outputs... keeping time before their local contrast adaptation for final result
|
||||
float *photoreceptorsOutput_PTR= photoreceptorsOutput+r.start;
|
||||
float *horizontalCellsOutput_PTR= horizontalCellsOutput+r.start;
|
||||
float *bipolarCellsON_PTR = bipolarCellsON+r.start;
|
||||
float *bipolarCellsOFF_PTR = bipolarCellsOFF+r.start;
|
||||
float *parvocellularOutputON_PTR= parvocellularOutputON+r.start;
|
||||
float *parvocellularOutputOFF_PTR= parvocellularOutputOFF+r.start;
|
||||
|
||||
for (register int IDpixel=r.start ; IDpixel!=r.end ; ++IDpixel)
|
||||
{
|
||||
float pixelDifference = *(photoreceptorsOutput_PTR++) -*(horizontalCellsOutput_PTR++);
|
||||
// test condition to allow write pixelDifference in ON or OFF buffer and 0 in the over
|
||||
float isPositive=(float) (pixelDifference>0.0f);
|
||||
|
||||
// ON and OFF channels writing step
|
||||
*(parvocellularOutputON_PTR++)=*(bipolarCellsON_PTR++) = isPositive*pixelDifference;
|
||||
*(parvocellularOutputOFF_PTR++)=*(bipolarCellsOFF_PTR++)= (isPositive-1.0f)*pixelDifference;
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
};
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
#endif
|
@ -1,68 +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) 2009, 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 __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#include "opencv2/bioinspired.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
#include "opencv2/core/private.hpp"
|
||||
#include "opencv2/core/ocl.hpp"
|
||||
|
||||
#include <valarray>
|
||||
|
||||
#ifdef HAVE_OPENCV_OCL
|
||||
#include "opencv2/ocl/private/util.hpp"
|
||||
#endif
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
// special function to get pointer to constant valarray elements, since
|
||||
// simple &arr[0] does not compile on VS2005/VS2008.
|
||||
template<typename T> inline const T* get_data(const std::valarray<T>& arr)
|
||||
{ return &((std::valarray<T>&)arr)[0]; }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,743 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
**
|
||||
**
|
||||
** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2011
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** For Human Visual System tools (bioinspired)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Retina.cpp
|
||||
*
|
||||
* Created on: Jul 19, 2011
|
||||
* Author: Alexandre Benoit
|
||||
*/
|
||||
#include "precomp.hpp"
|
||||
#include "retinafilter.hpp"
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
#include <valarray>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
|
||||
class RetinaImpl : public Retina
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Main constructor with most commun use setup : create an instance of color ready retina model
|
||||
* @param inputSize : the input frame size
|
||||
*/
|
||||
RetinaImpl(Size inputSize);
|
||||
|
||||
/**
|
||||
* Complete Retina filter constructor which allows all basic structural parameters definition
|
||||
* @param inputSize : the input frame size
|
||||
* @param colorMode : the chosen processing mode : with or without color processing
|
||||
* @param colorSamplingMethod: specifies which kind of color sampling will be used
|
||||
* @param useRetinaLogSampling: activate retina log sampling, if true, the 2 following parameters can be used
|
||||
* @param reductionFactor: only usefull if param useRetinaLogSampling=true, specifies the reduction factor of the output frame (as the center (fovea) is high resolution and corners can be underscaled, then a reduction of the output is allowed without precision leak
|
||||
* @param samplingStrenght: only usefull if param useRetinaLogSampling=true, specifies the strenght of the log scale that is applied
|
||||
*/
|
||||
RetinaImpl(Size inputSize, const bool colorMode, int colorSamplingMethod=RETINA_COLOR_BAYER, const bool useRetinaLogSampling=false, const double reductionFactor=1.0, const double samplingStrenght=10.0);
|
||||
|
||||
virtual ~RetinaImpl();
|
||||
/**
|
||||
* retreive retina input buffer size
|
||||
*/
|
||||
Size getInputSize();
|
||||
|
||||
/**
|
||||
* retreive retina output buffer size
|
||||
*/
|
||||
Size getOutputSize();
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
* => if the xml file does not exist, then default setup is applied
|
||||
* => warning, Exceptions are thrown if read XML file is not valid
|
||||
* @param retinaParameterFile : the parameters filename
|
||||
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
|
||||
*/
|
||||
void setup(String retinaParameterFile="", const bool applyDefaultSetupOnFailure=true);
|
||||
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
* => if the xml file does not exist, then default setup is applied
|
||||
* => warning, Exceptions are thrown if read XML file is not valid
|
||||
* @param fs : the open Filestorage which contains retina parameters
|
||||
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
|
||||
*/
|
||||
void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true);
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
* => if the xml file does not exist, then default setup is applied
|
||||
* => warning, Exceptions are thrown if read XML file is not valid
|
||||
* @param newParameters : a parameters structures updated with the new target configuration
|
||||
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
|
||||
*/
|
||||
void setup(Retina::RetinaParameters newParameters);
|
||||
|
||||
/**
|
||||
* @return the current parameters setup
|
||||
*/
|
||||
struct Retina::RetinaParameters getParameters();
|
||||
|
||||
/**
|
||||
* parameters setup display method
|
||||
* @return a string which contains formatted parameters information
|
||||
*/
|
||||
const String printSetup();
|
||||
|
||||
/**
|
||||
* write xml/yml formated parameters information
|
||||
* @rparam fs : the filename of the xml file that will be open and writen with formatted parameters information
|
||||
*/
|
||||
virtual void write( String fs ) const;
|
||||
|
||||
|
||||
/**
|
||||
* write xml/yml formated parameters information
|
||||
* @param fs : a cv::Filestorage object ready to be filled
|
||||
*/
|
||||
virtual void write( FileStorage& fs ) const;
|
||||
|
||||
/**
|
||||
* setup the OPL and IPL parvo channels (see biologocal model)
|
||||
* OPL is referred as Outer Plexiform Layer of the retina, it allows the spatio-temporal filtering which withens the spectrum and reduces spatio-temporal noise while attenuating global luminance (low frequency energy)
|
||||
* IPL parvo is the OPL next processing stage, it refers to Inner Plexiform layer of the retina, it allows high contours sensitivity in foveal vision.
|
||||
* for more informations, please have a look at the paper Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
* @param colorMode : specifies if (true) color is processed of not (false) to then processing gray level image
|
||||
* @param normaliseOutput : specifies if (true) output is rescaled between 0 and 255 of not (false)
|
||||
* @param photoreceptorsLocalAdaptationSensitivity: the photoreceptors sensitivity renage is 0-1 (more log compression effect when value increases)
|
||||
* @param photoreceptorsTemporalConstant: the time constant of the first order low pass filter of the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 1 frame
|
||||
* @param photoreceptorsSpatialConstant: the spatial constant of the first order low pass filter of the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 1 pixel
|
||||
* @param horizontalCellsGain: gain of the horizontal cells network, if 0, then the mean value of the output is zero, if the parameter is near 1, then, the luminance is not filtered and is still reachable at the output, typicall value is 0
|
||||
* @param HcellsTemporalConstant: the time constant of the first order low pass filter of the horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is frames, typical value is 1 frame, as the photoreceptors
|
||||
* @param HcellsSpatialConstant: the spatial constant of the first order low pass filter of the horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, typical value is 5 pixel, this value is also used for local contrast computing when computing the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular channel model)
|
||||
* @param ganglionCellsSensitivity: the compression strengh of the ganglion cells local adaptation output, set a value between 160 and 250 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 230
|
||||
*/
|
||||
void setupOPLandIPLParvoChannel(const bool colorMode=true, const bool normaliseOutput = true, const float photoreceptorsLocalAdaptationSensitivity=0.7, const float photoreceptorsTemporalConstant=0.5, const float photoreceptorsSpatialConstant=0.53, const float horizontalCellsGain=0, const float HcellsTemporalConstant=1, const float HcellsSpatialConstant=7, const float ganglionCellsSensitivity=0.7);
|
||||
|
||||
/**
|
||||
* set parameters values for the Inner Plexiform Layer (IPL) magnocellular channel
|
||||
* this channel processes signals outpint from OPL processing stage in peripheral vision, it allows motion information enhancement. It is decorrelated from the details channel. See reference paper for more details.
|
||||
* @param normaliseOutput : specifies if (true) output is rescaled between 0 and 255 of not (false)
|
||||
* @param parasolCells_beta: the low pass filter gain used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), typical value is 0
|
||||
* @param parasolCells_tau: the low pass filter time constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical value is 0 (immediate response)
|
||||
* @param parasolCells_k: the low pass filter spatial constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical value is 5
|
||||
* @param amacrinCellsTemporalCutFrequency: the time constant of the first order high pass fiter of the magnocellular way (motion information channel), unit is frames, tipicall value is 5
|
||||
* @param V0CompressionParameter: the compression strengh of the ganglion cells local adaptation output, set a value between 160 and 250 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 200
|
||||
* @param localAdaptintegration_tau: specifies the temporal constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
* @param localAdaptintegration_k: specifies the spatial constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
*/
|
||||
void setupIPLMagnoChannel(const bool normaliseOutput = true, const float parasolCells_beta=0, const float parasolCells_tau=0, const float parasolCells_k=7, const float amacrinCellsTemporalCutFrequency=1.2, const float V0CompressionParameter=0.95, const float localAdaptintegration_tau=0, const float localAdaptintegration_k=7);
|
||||
|
||||
/**
|
||||
* method which allows retina to be applied on an input image, after run, encapsulated retina module is ready to deliver its outputs using dedicated acccessors, see getParvo and getMagno methods
|
||||
* @param inputImage : the input cv::Mat image to be processed, can be gray level or BGR coded in any format (from 8bit to 16bits)
|
||||
*/
|
||||
void run(InputArray inputImage);
|
||||
|
||||
/**
|
||||
* method that applies a luminance correction (initially High Dynamic Range (HDR) tone mapping) using only the 2 local adaptation stages of the retina parvo channel : photoreceptors level and ganlion cells level. Spatio temporal filtering is applied but limited to temporal smoothing and eventually high frequencies attenuation. This is a lighter method than the one available using the regular run method. It is then faster but it does not include complete temporal filtering nor retina spectral whitening. This is an adptation of the original still image HDR tone mapping algorithm of David Alleyson, Sabine Susstruck and Laurence Meylan's work, please cite:
|
||||
* -> Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816
|
||||
@param inputImage the input image to process RGB or gray levels
|
||||
@param outputToneMappedImage the output tone mapped image
|
||||
*/
|
||||
void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage);
|
||||
|
||||
/**
|
||||
* accessor of the details channel of the retina (models foveal vision)
|
||||
* @param retinaOutput_parvo : the output buffer (reallocated if necessary), this output is rescaled for standard 8bits image processing use in OpenCV
|
||||
*/
|
||||
void getParvo(OutputArray retinaOutput_parvo);
|
||||
|
||||
/**
|
||||
* accessor of the details channel of the retina (models foveal vision)
|
||||
* @param retinaOutput_parvo : a cv::Mat header filled with the internal parvo buffer of the retina module. This output is the original retina filter model output, without any quantification or rescaling
|
||||
*/
|
||||
void getParvoRAW(OutputArray retinaOutput_parvo);
|
||||
|
||||
/**
|
||||
* accessor of the motion channel of the retina (models peripheral vision)
|
||||
* @param retinaOutput_magno : the output buffer (reallocated if necessary), this output is rescaled for standard 8bits image processing use in OpenCV
|
||||
*/
|
||||
void getMagno(OutputArray retinaOutput_magno);
|
||||
|
||||
/**
|
||||
* accessor of the motion channel of the retina (models peripheral vision)
|
||||
* @param retinaOutput_magno : a cv::Mat header filled with the internal retina magno buffer of the retina module. This output is the original retina filter model output, without any quantification or rescaling
|
||||
*/
|
||||
void getMagnoRAW(OutputArray retinaOutput_magno);
|
||||
|
||||
// original API level data accessors : get buffers addresses from a Mat header, similar to getParvoRAW and getMagnoRAW...
|
||||
const Mat getMagnoRAW() const;
|
||||
const Mat getParvoRAW() const;
|
||||
|
||||
/**
|
||||
* activate color saturation as the final step of the color demultiplexing process
|
||||
* -> this saturation is a sigmoide function applied to each channel of the demultiplexed image.
|
||||
* @param saturateColors: boolean that activates color saturation (if true) or desactivate (if false)
|
||||
* @param colorSaturationValue: the saturation factor
|
||||
*/
|
||||
void setColorSaturation(const bool saturateColors=true, const float colorSaturationValue=4.0);
|
||||
|
||||
/**
|
||||
* clear all retina buffers (equivalent to opening the eyes after a long period of eye close ;o)
|
||||
*/
|
||||
void clearBuffers();
|
||||
|
||||
/**
|
||||
* Activate/desactivate the Magnocellular pathway processing (motion information extraction), by default, it is activated
|
||||
* @param activate: true if Magnocellular output should be activated, false if not
|
||||
*/
|
||||
void activateMovingContoursProcessing(const bool activate);
|
||||
|
||||
/**
|
||||
* Activate/desactivate the Parvocellular pathway processing (contours information extraction), by default, it is activated
|
||||
* @param activate: true if Parvocellular (contours information extraction) output should be activated, false if not
|
||||
*/
|
||||
void activateContoursProcessing(const bool activate);
|
||||
private:
|
||||
|
||||
// Parameteres setup members
|
||||
RetinaParameters _retinaParameters; // structure of parameters
|
||||
|
||||
// Retina model related modules
|
||||
std::valarray<float> _inputBuffer; //!< buffer used to convert input cv::Mat to internal retina buffers format (valarrays)
|
||||
|
||||
// pointer to retina model
|
||||
RetinaFilter* _retinaFilter; //!< the pointer to the retina module, allocated with instance construction
|
||||
|
||||
//! private method called by constructors, gathers their parameters and use them in a unified way
|
||||
void _init(const Size inputSize, const bool colorMode, int colorSamplingMethod=RETINA_COLOR_BAYER, const bool useRetinaLogSampling=false, const double reductionFactor=1.0, const double samplingStrenght=10.0);
|
||||
|
||||
/**
|
||||
* exports a valarray buffer outing from bioinspired objects to a cv::Mat in CV_8UC1 (gray level picture) or CV_8UC3 (color) format
|
||||
* @param grayMatrixToConvert the valarray to export to OpenCV
|
||||
* @param nbRows : the number of rows of the valarray flatten matrix
|
||||
* @param nbColumns : the number of rows of the valarray flatten matrix
|
||||
* @param colorMode : a flag which mentions if matrix is color (true) or graylevel (false)
|
||||
* @param outBuffer : the output matrix which is reallocated to satisfy Retina output buffer dimensions
|
||||
*/
|
||||
void _convertValarrayBuffer2cvMat(const std::valarray<float> &grayMatrixToConvert, const unsigned int nbRows, const unsigned int nbColumns, const bool colorMode, OutputArray outBuffer);
|
||||
|
||||
/**
|
||||
* convert a cv::Mat to a valarray buffer in float format
|
||||
* @param inputMatToConvert : the OpenCV cv::Mat that has to be converted to gray or RGB valarray buffer that will be processed by the retina model
|
||||
* @param outputValarrayMatrix : the output valarray
|
||||
* @return the input image color mode (color=true, gray levels=false)
|
||||
*/
|
||||
bool _convertCvMat2ValarrayBuffer(InputArray inputMatToConvert, std::valarray<float> &outputValarrayMatrix);
|
||||
|
||||
|
||||
};
|
||||
|
||||
// smart pointers allocation :
|
||||
Ptr<Retina> createRetina(Size inputSize){ return makePtr<RetinaImpl>(inputSize); }
|
||||
Ptr<Retina> createRetina(Size inputSize, const bool colorMode, int colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght){
|
||||
return makePtr<RetinaImpl>(inputSize, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
}
|
||||
|
||||
|
||||
// RetinaImpl code
|
||||
RetinaImpl::RetinaImpl(const cv::Size inputSz)
|
||||
{
|
||||
_retinaFilter = 0;
|
||||
_init(inputSz, true, RETINA_COLOR_BAYER, false);
|
||||
}
|
||||
|
||||
RetinaImpl::RetinaImpl(const cv::Size inputSz, const bool colorMode, int colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
{
|
||||
_retinaFilter = 0;
|
||||
_init(inputSz, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
};
|
||||
|
||||
RetinaImpl::~RetinaImpl()
|
||||
{
|
||||
if (_retinaFilter)
|
||||
delete _retinaFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* retreive retina input buffer size
|
||||
*/
|
||||
Size RetinaImpl::getInputSize(){return cv::Size(_retinaFilter->getInputNBcolumns(), _retinaFilter->getInputNBrows());}
|
||||
|
||||
/**
|
||||
* retreive retina output buffer size
|
||||
*/
|
||||
Size RetinaImpl::getOutputSize(){return cv::Size(_retinaFilter->getOutputNBcolumns(), _retinaFilter->getOutputNBrows());}
|
||||
|
||||
|
||||
void RetinaImpl::setColorSaturation(const bool saturateColors, const float colorSaturationValue)
|
||||
{
|
||||
_retinaFilter->setColorSaturation(saturateColors, colorSaturationValue);
|
||||
}
|
||||
|
||||
struct Retina::RetinaParameters RetinaImpl::getParameters(){return _retinaParameters;}
|
||||
|
||||
void RetinaImpl::setup(String retinaParameterFile, const bool applyDefaultSetupOnFailure)
|
||||
{
|
||||
try
|
||||
{
|
||||
// opening retinaParameterFile in read mode
|
||||
cv::FileStorage fs(retinaParameterFile, cv::FileStorage::READ);
|
||||
setup(fs, applyDefaultSetupOnFailure);
|
||||
}
|
||||
catch(Exception &e)
|
||||
{
|
||||
printf("Retina::setup: wrong/unappropriate xml parameter file : error report :`n=>%s\n", e.what());
|
||||
if (applyDefaultSetupOnFailure)
|
||||
{
|
||||
printf("Retina::setup: resetting retina with default parameters\n");
|
||||
setupOPLandIPLParvoChannel();
|
||||
setupIPLMagnoChannel();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("=> keeping current parameters\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RetinaImpl::setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure)
|
||||
{
|
||||
try
|
||||
{
|
||||
// read parameters file if it exists or apply default setup if asked for
|
||||
if (!fs.isOpened())
|
||||
{
|
||||
printf("Retina::setup: provided parameters file could not be open... skeeping configuration\n");
|
||||
return;
|
||||
// implicit else case : retinaParameterFile could be open (it exists at least)
|
||||
}
|
||||
// OPL and Parvo init first... update at the same time the parameters structure and the retina core
|
||||
cv::FileNode rootFn = fs.root(), currFn=rootFn["OPLandIPLparvo"];
|
||||
currFn["colorMode"]>>_retinaParameters.OPLandIplParvo.colorMode;
|
||||
currFn["normaliseOutput"]>>_retinaParameters.OPLandIplParvo.normaliseOutput;
|
||||
currFn["photoreceptorsLocalAdaptationSensitivity"]>>_retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity;
|
||||
currFn["photoreceptorsTemporalConstant"]>>_retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant;
|
||||
currFn["photoreceptorsSpatialConstant"]>>_retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant;
|
||||
currFn["horizontalCellsGain"]>>_retinaParameters.OPLandIplParvo.horizontalCellsGain;
|
||||
currFn["hcellsTemporalConstant"]>>_retinaParameters.OPLandIplParvo.hcellsTemporalConstant;
|
||||
currFn["hcellsSpatialConstant"]>>_retinaParameters.OPLandIplParvo.hcellsSpatialConstant;
|
||||
currFn["ganglionCellsSensitivity"]>>_retinaParameters.OPLandIplParvo.ganglionCellsSensitivity;
|
||||
setupOPLandIPLParvoChannel(_retinaParameters.OPLandIplParvo.colorMode, _retinaParameters.OPLandIplParvo.normaliseOutput, _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity, _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant, _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant, _retinaParameters.OPLandIplParvo.horizontalCellsGain, _retinaParameters.OPLandIplParvo.hcellsTemporalConstant, _retinaParameters.OPLandIplParvo.hcellsSpatialConstant, _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity);
|
||||
|
||||
// init retina IPL magno setup... update at the same time the parameters structure and the retina core
|
||||
currFn=rootFn["IPLmagno"];
|
||||
currFn["normaliseOutput"]>>_retinaParameters.IplMagno.normaliseOutput;
|
||||
currFn["parasolCells_beta"]>>_retinaParameters.IplMagno.parasolCells_beta;
|
||||
currFn["parasolCells_tau"]>>_retinaParameters.IplMagno.parasolCells_tau;
|
||||
currFn["parasolCells_k"]>>_retinaParameters.IplMagno.parasolCells_k;
|
||||
currFn["amacrinCellsTemporalCutFrequency"]>>_retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency;
|
||||
currFn["V0CompressionParameter"]>>_retinaParameters.IplMagno.V0CompressionParameter;
|
||||
currFn["localAdaptintegration_tau"]>>_retinaParameters.IplMagno.localAdaptintegration_tau;
|
||||
currFn["localAdaptintegration_k"]>>_retinaParameters.IplMagno.localAdaptintegration_k;
|
||||
|
||||
setupIPLMagnoChannel(_retinaParameters.IplMagno.normaliseOutput, _retinaParameters.IplMagno.parasolCells_beta, _retinaParameters.IplMagno.parasolCells_tau, _retinaParameters.IplMagno.parasolCells_k, _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency,_retinaParameters.IplMagno.V0CompressionParameter, _retinaParameters.IplMagno.localAdaptintegration_tau, _retinaParameters.IplMagno.localAdaptintegration_k);
|
||||
|
||||
}catch(Exception &e)
|
||||
{
|
||||
printf("RetinaImpl::setup: resetting retina with default parameters\n");
|
||||
if (applyDefaultSetupOnFailure)
|
||||
{
|
||||
setupOPLandIPLParvoChannel();
|
||||
setupIPLMagnoChannel();
|
||||
}
|
||||
printf("Retina::setup: wrong/unappropriate xml parameter file : error report :`n=>%s\n", e.what());
|
||||
printf("=> keeping current parameters\n");
|
||||
}
|
||||
|
||||
// report current configuration
|
||||
printf("%s\n", printSetup().c_str());
|
||||
}
|
||||
|
||||
void RetinaImpl::setup(Retina::RetinaParameters newConfiguration)
|
||||
{
|
||||
// simply copy structures
|
||||
memcpy(&_retinaParameters, &newConfiguration, sizeof(Retina::RetinaParameters));
|
||||
// apply setup
|
||||
setupOPLandIPLParvoChannel(_retinaParameters.OPLandIplParvo.colorMode, _retinaParameters.OPLandIplParvo.normaliseOutput, _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity, _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant, _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant, _retinaParameters.OPLandIplParvo.horizontalCellsGain, _retinaParameters.OPLandIplParvo.hcellsTemporalConstant, _retinaParameters.OPLandIplParvo.hcellsSpatialConstant, _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity);
|
||||
setupIPLMagnoChannel(_retinaParameters.IplMagno.normaliseOutput, _retinaParameters.IplMagno.parasolCells_beta, _retinaParameters.IplMagno.parasolCells_tau, _retinaParameters.IplMagno.parasolCells_k, _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency,_retinaParameters.IplMagno.V0CompressionParameter, _retinaParameters.IplMagno.localAdaptintegration_tau, _retinaParameters.IplMagno.localAdaptintegration_k);
|
||||
|
||||
}
|
||||
|
||||
const String RetinaImpl::printSetup()
|
||||
{
|
||||
std::stringstream outmessage;
|
||||
|
||||
// displaying OPL and IPL parvo setup
|
||||
outmessage<<"Current Retina instance setup :"
|
||||
<<"\nOPLandIPLparvo"<<"{"
|
||||
<< "\n\t colorMode : " << _retinaParameters.OPLandIplParvo.colorMode
|
||||
<< "\n\t normalizeParvoOutput :" << _retinaParameters.OPLandIplParvo.normaliseOutput
|
||||
<< "\n\t photoreceptorsLocalAdaptationSensitivity : " << _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity
|
||||
<< "\n\t photoreceptorsTemporalConstant : " << _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant
|
||||
<< "\n\t photoreceptorsSpatialConstant : " << _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant
|
||||
<< "\n\t horizontalCellsGain : " << _retinaParameters.OPLandIplParvo.horizontalCellsGain
|
||||
<< "\n\t hcellsTemporalConstant : " << _retinaParameters.OPLandIplParvo.hcellsTemporalConstant
|
||||
<< "\n\t hcellsSpatialConstant : " << _retinaParameters.OPLandIplParvo.hcellsSpatialConstant
|
||||
<< "\n\t parvoGanglionCellsSensitivity : " << _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity
|
||||
<<"}\n";
|
||||
|
||||
// displaying IPL magno setup
|
||||
outmessage<<"Current Retina instance setup :"
|
||||
<<"\nIPLmagno"<<"{"
|
||||
<< "\n\t normaliseOutput : " << _retinaParameters.IplMagno.normaliseOutput
|
||||
<< "\n\t parasolCells_beta : " << _retinaParameters.IplMagno.parasolCells_beta
|
||||
<< "\n\t parasolCells_tau : " << _retinaParameters.IplMagno.parasolCells_tau
|
||||
<< "\n\t parasolCells_k : " << _retinaParameters.IplMagno.parasolCells_k
|
||||
<< "\n\t amacrinCellsTemporalCutFrequency : " << _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency
|
||||
<< "\n\t V0CompressionParameter : " << _retinaParameters.IplMagno.V0CompressionParameter
|
||||
<< "\n\t localAdaptintegration_tau : " << _retinaParameters.IplMagno.localAdaptintegration_tau
|
||||
<< "\n\t localAdaptintegration_k : " << _retinaParameters.IplMagno.localAdaptintegration_k
|
||||
<<"}";
|
||||
return outmessage.str().c_str();
|
||||
}
|
||||
|
||||
void RetinaImpl::write( String fs ) const
|
||||
{
|
||||
FileStorage parametersSaveFile(fs, cv::FileStorage::WRITE );
|
||||
write(parametersSaveFile);
|
||||
}
|
||||
|
||||
void RetinaImpl::write( FileStorage& fs ) const
|
||||
{
|
||||
if (!fs.isOpened())
|
||||
return; // basic error case
|
||||
fs<<"OPLandIPLparvo"<<"{";
|
||||
fs << "colorMode" << _retinaParameters.OPLandIplParvo.colorMode;
|
||||
fs << "normaliseOutput" << _retinaParameters.OPLandIplParvo.normaliseOutput;
|
||||
fs << "photoreceptorsLocalAdaptationSensitivity" << _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity;
|
||||
fs << "photoreceptorsTemporalConstant" << _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant;
|
||||
fs << "photoreceptorsSpatialConstant" << _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant;
|
||||
fs << "horizontalCellsGain" << _retinaParameters.OPLandIplParvo.horizontalCellsGain;
|
||||
fs << "hcellsTemporalConstant" << _retinaParameters.OPLandIplParvo.hcellsTemporalConstant;
|
||||
fs << "hcellsSpatialConstant" << _retinaParameters.OPLandIplParvo.hcellsSpatialConstant;
|
||||
fs << "ganglionCellsSensitivity" << _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity;
|
||||
fs << "}";
|
||||
fs<<"IPLmagno"<<"{";
|
||||
fs << "normaliseOutput" << _retinaParameters.IplMagno.normaliseOutput;
|
||||
fs << "parasolCells_beta" << _retinaParameters.IplMagno.parasolCells_beta;
|
||||
fs << "parasolCells_tau" << _retinaParameters.IplMagno.parasolCells_tau;
|
||||
fs << "parasolCells_k" << _retinaParameters.IplMagno.parasolCells_k;
|
||||
fs << "amacrinCellsTemporalCutFrequency" << _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency;
|
||||
fs << "V0CompressionParameter" << _retinaParameters.IplMagno.V0CompressionParameter;
|
||||
fs << "localAdaptintegration_tau" << _retinaParameters.IplMagno.localAdaptintegration_tau;
|
||||
fs << "localAdaptintegration_k" << _retinaParameters.IplMagno.localAdaptintegration_k;
|
||||
fs<<"}";
|
||||
}
|
||||
|
||||
void RetinaImpl::setupOPLandIPLParvoChannel(const bool colorMode, const bool normaliseOutput, const float photoreceptorsLocalAdaptationSensitivity, const float photoreceptorsTemporalConstant, const float photoreceptorsSpatialConstant, const float horizontalCellsGain, const float HcellsTemporalConstant, const float HcellsSpatialConstant, const float ganglionCellsSensitivity)
|
||||
{
|
||||
// retina core parameters setup
|
||||
_retinaFilter->setColorMode(colorMode);
|
||||
_retinaFilter->setPhotoreceptorsLocalAdaptationSensitivity(photoreceptorsLocalAdaptationSensitivity);
|
||||
_retinaFilter->setOPLandParvoParameters(0, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, HcellsTemporalConstant, HcellsSpatialConstant, ganglionCellsSensitivity);
|
||||
_retinaFilter->setParvoGanglionCellsLocalAdaptationSensitivity(ganglionCellsSensitivity);
|
||||
_retinaFilter->activateNormalizeParvoOutput_0_maxOutputValue(normaliseOutput);
|
||||
|
||||
// update parameters struture
|
||||
|
||||
_retinaParameters.OPLandIplParvo.colorMode = colorMode;
|
||||
_retinaParameters.OPLandIplParvo.normaliseOutput = normaliseOutput;
|
||||
_retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity = photoreceptorsLocalAdaptationSensitivity;
|
||||
_retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant = photoreceptorsTemporalConstant;
|
||||
_retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant = photoreceptorsSpatialConstant;
|
||||
_retinaParameters.OPLandIplParvo.horizontalCellsGain = horizontalCellsGain;
|
||||
_retinaParameters.OPLandIplParvo.hcellsTemporalConstant = HcellsTemporalConstant;
|
||||
_retinaParameters.OPLandIplParvo.hcellsSpatialConstant = HcellsSpatialConstant;
|
||||
_retinaParameters.OPLandIplParvo.ganglionCellsSensitivity = ganglionCellsSensitivity;
|
||||
|
||||
}
|
||||
|
||||
void RetinaImpl::setupIPLMagnoChannel(const bool normaliseOutput, const float parasolCells_beta, const float parasolCells_tau, const float parasolCells_k, const float amacrinCellsTemporalCutFrequency, const float V0CompressionParameter, const float localAdaptintegration_tau, const float localAdaptintegration_k)
|
||||
{
|
||||
|
||||
_retinaFilter->setMagnoCoefficientsTable(parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k);
|
||||
_retinaFilter->activateNormalizeMagnoOutput_0_maxOutputValue(normaliseOutput);
|
||||
|
||||
// update parameters struture
|
||||
_retinaParameters.IplMagno.normaliseOutput = normaliseOutput;
|
||||
_retinaParameters.IplMagno.parasolCells_beta = parasolCells_beta;
|
||||
_retinaParameters.IplMagno.parasolCells_tau = parasolCells_tau;
|
||||
_retinaParameters.IplMagno.parasolCells_k = parasolCells_k;
|
||||
_retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency = amacrinCellsTemporalCutFrequency;
|
||||
_retinaParameters.IplMagno.V0CompressionParameter = V0CompressionParameter;
|
||||
_retinaParameters.IplMagno.localAdaptintegration_tau = localAdaptintegration_tau;
|
||||
_retinaParameters.IplMagno.localAdaptintegration_k = localAdaptintegration_k;
|
||||
}
|
||||
|
||||
void RetinaImpl::run(InputArray inputMatToConvert)
|
||||
{
|
||||
// first convert input image to the compatible format : std::valarray<float>
|
||||
const bool colorMode = _convertCvMat2ValarrayBuffer(inputMatToConvert.getMat(), _inputBuffer);
|
||||
// process the retina
|
||||
if (!_retinaFilter->runFilter(_inputBuffer, colorMode, false, _retinaParameters.OPLandIplParvo.colorMode && colorMode, false))
|
||||
throw cv::Exception(-1, "RetinaImpl cannot be applied, wrong input buffer size", "RetinaImpl::run", "RetinaImpl.h", 0);
|
||||
}
|
||||
|
||||
void RetinaImpl::applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)
|
||||
{
|
||||
// first convert input image to the compatible format :
|
||||
const bool colorMode = _convertCvMat2ValarrayBuffer(inputImage.getMat(), _inputBuffer);
|
||||
const unsigned int nbPixels=_retinaFilter->getOutputNBrows()*_retinaFilter->getOutputNBcolumns();
|
||||
|
||||
// process tone mapping
|
||||
if (colorMode)
|
||||
{
|
||||
std::valarray<float> imageOutput(nbPixels*3);
|
||||
_retinaFilter->runRGBToneMapping(_inputBuffer, imageOutput, true, _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity, _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity);
|
||||
_convertValarrayBuffer2cvMat(imageOutput, _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), true, outputToneMappedImage);
|
||||
}else
|
||||
{
|
||||
std::valarray<float> imageOutput(nbPixels);
|
||||
_retinaFilter->runGrayToneMapping(_inputBuffer, imageOutput, _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity, _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity);
|
||||
_convertValarrayBuffer2cvMat(imageOutput, _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), false, outputToneMappedImage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RetinaImpl::getParvo(OutputArray retinaOutput_parvo)
|
||||
{
|
||||
if (_retinaFilter->getColorMode())
|
||||
{
|
||||
// reallocate output buffer (if necessary)
|
||||
_convertValarrayBuffer2cvMat(_retinaFilter->getColorOutput(), _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), true, retinaOutput_parvo);
|
||||
}else
|
||||
{
|
||||
// reallocate output buffer (if necessary)
|
||||
_convertValarrayBuffer2cvMat(_retinaFilter->getContours(), _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), false, retinaOutput_parvo);
|
||||
}
|
||||
//retinaOutput_parvo/=255.0;
|
||||
}
|
||||
void RetinaImpl::getMagno(OutputArray retinaOutput_magno)
|
||||
{
|
||||
// reallocate output buffer (if necessary)
|
||||
_convertValarrayBuffer2cvMat(_retinaFilter->getMovingContours(), _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), false, retinaOutput_magno);
|
||||
//retinaOutput_magno/=255.0;
|
||||
}
|
||||
|
||||
// original API level data accessors : copy buffers if size matches, reallocate if required
|
||||
void RetinaImpl::getMagnoRAW(OutputArray magnoOutputBufferCopy){
|
||||
// get magno channel header
|
||||
const cv::Mat magnoChannel=cv::Mat(getMagnoRAW());
|
||||
// copy data
|
||||
magnoChannel.copyTo(magnoOutputBufferCopy);
|
||||
}
|
||||
|
||||
void RetinaImpl::getParvoRAW(OutputArray parvoOutputBufferCopy){
|
||||
// get parvo channel header
|
||||
const cv::Mat parvoChannel=cv::Mat(getMagnoRAW());
|
||||
// copy data
|
||||
parvoChannel.copyTo(parvoOutputBufferCopy);
|
||||
}
|
||||
|
||||
// original API level data accessors : get buffers addresses...
|
||||
const Mat RetinaImpl::getMagnoRAW() const {
|
||||
// create a cv::Mat header for the valarray
|
||||
return Mat((int)_retinaFilter->getMovingContours().size(),1, CV_32F, (void*)get_data(_retinaFilter->getMovingContours()));
|
||||
|
||||
}
|
||||
|
||||
const Mat RetinaImpl::getParvoRAW() const {
|
||||
if (_retinaFilter->getColorMode()) // check if color mode is enabled
|
||||
{
|
||||
// create a cv::Mat table (for RGB planes as a single vector)
|
||||
return Mat((int)_retinaFilter->getColorOutput().size(), 1, CV_32F, (void*)get_data(_retinaFilter->getColorOutput()));
|
||||
}
|
||||
// otherwise, output is gray level
|
||||
// create a cv::Mat header for the valarray
|
||||
return Mat((int)_retinaFilter->getContours().size(), 1, CV_32F, (void*)get_data(_retinaFilter->getContours()));
|
||||
}
|
||||
|
||||
// private method called by constructirs
|
||||
void RetinaImpl::_init(const cv::Size inputSz, const bool colorMode, int colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
{
|
||||
// basic error check
|
||||
if (inputSz.height*inputSz.width <= 0)
|
||||
throw cv::Exception(-1, "Bad retina size setup : size height and with must be superior to zero", "RetinaImpl::setup", "Retina.cpp", 0);
|
||||
|
||||
unsigned int nbPixels=inputSz.height*inputSz.width;
|
||||
// resize buffers if size does not match
|
||||
_inputBuffer.resize(nbPixels*3); // buffer supports gray images but also 3 channels color buffers... (larger is better...)
|
||||
|
||||
// allocate the retina model
|
||||
if (_retinaFilter)
|
||||
delete _retinaFilter;
|
||||
_retinaFilter = new RetinaFilter(inputSz.height, inputSz.width, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
|
||||
_retinaParameters.OPLandIplParvo.colorMode = colorMode;
|
||||
// prepare the default parameter XML file with default setup
|
||||
setup(_retinaParameters);
|
||||
|
||||
// init retina
|
||||
_retinaFilter->clearAllBuffers();
|
||||
|
||||
// report current configuration
|
||||
printf("%s\n", printSetup().c_str());
|
||||
}
|
||||
|
||||
void RetinaImpl::_convertValarrayBuffer2cvMat(const std::valarray<float> &grayMatrixToConvert, const unsigned int nbRows, const unsigned int nbColumns, const bool colorMode, OutputArray outBuffer)
|
||||
{
|
||||
// fill output buffer with the valarray buffer
|
||||
const float *valarrayPTR=get_data(grayMatrixToConvert);
|
||||
if (!colorMode)
|
||||
{
|
||||
outBuffer.create(cv::Size(nbColumns, nbRows), CV_8U);
|
||||
Mat outMat = outBuffer.getMat();
|
||||
for (unsigned int i=0;i<nbRows;++i)
|
||||
{
|
||||
for (unsigned int j=0;j<nbColumns;++j)
|
||||
{
|
||||
cv::Point2d pixel(j,i);
|
||||
outMat.at<unsigned char>(pixel)=(unsigned char)*(valarrayPTR++);
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
const unsigned int nbPixels=nbColumns*nbRows;
|
||||
const unsigned int doubleNBpixels=nbColumns*nbRows*2;
|
||||
outBuffer.create(cv::Size(nbColumns, nbRows), CV_8UC3);
|
||||
Mat outMat = outBuffer.getMat();
|
||||
for (unsigned int i=0;i<nbRows;++i)
|
||||
{
|
||||
for (unsigned int j=0;j<nbColumns;++j,++valarrayPTR)
|
||||
{
|
||||
cv::Point2d pixel(j,i);
|
||||
cv::Vec3b pixelValues;
|
||||
pixelValues[2]=(unsigned char)*(valarrayPTR);
|
||||
pixelValues[1]=(unsigned char)*(valarrayPTR+nbPixels);
|
||||
pixelValues[0]=(unsigned char)*(valarrayPTR+doubleNBpixels);
|
||||
|
||||
outMat.at<cv::Vec3b>(pixel)=pixelValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RetinaImpl::_convertCvMat2ValarrayBuffer(InputArray inputMat, std::valarray<float> &outputValarrayMatrix)
|
||||
{
|
||||
const Mat inputMatToConvert=inputMat.getMat();
|
||||
// first check input consistency
|
||||
if (inputMatToConvert.empty())
|
||||
throw cv::Exception(-1, "RetinaImpl cannot be applied, input buffer is empty", "RetinaImpl::run", "RetinaImpl.h", 0);
|
||||
|
||||
// retreive color mode from image input
|
||||
int imageNumberOfChannels = inputMatToConvert.channels();
|
||||
|
||||
// convert to float AND fill the valarray buffer
|
||||
typedef float T; // define here the target pixel format, here, float
|
||||
const int dsttype = DataType<T>::depth; // output buffer is float format
|
||||
|
||||
const unsigned int nbPixels=inputMat.getMat().rows*inputMat.getMat().cols;
|
||||
const unsigned int doubleNBpixels=inputMat.getMat().rows*inputMat.getMat().cols*2;
|
||||
|
||||
if(imageNumberOfChannels==4)
|
||||
{
|
||||
// create a cv::Mat table (for RGBA planes)
|
||||
cv::Mat planes[4] =
|
||||
{
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[doubleNBpixels]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[nbPixels]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0])
|
||||
};
|
||||
planes[3] = cv::Mat(inputMatToConvert.size(), dsttype); // last channel (alpha) does not point on the valarray (not usefull in our case)
|
||||
// split color cv::Mat in 4 planes... it fills valarray directely
|
||||
cv::split(Mat_<Vec<T, 4> >(inputMatToConvert), planes);
|
||||
}
|
||||
else if (imageNumberOfChannels==3)
|
||||
{
|
||||
// create a cv::Mat table (for RGB planes)
|
||||
cv::Mat planes[] =
|
||||
{
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[doubleNBpixels]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[nbPixels]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0])
|
||||
};
|
||||
// split color cv::Mat in 3 planes... it fills valarray directely
|
||||
cv::split(cv::Mat_<Vec<T, 3> >(inputMatToConvert), planes);
|
||||
}
|
||||
else if(imageNumberOfChannels==1)
|
||||
{
|
||||
// create a cv::Mat header for the valarray
|
||||
cv::Mat dst(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0]);
|
||||
inputMatToConvert.convertTo(dst, dsttype);
|
||||
}
|
||||
else
|
||||
CV_Error(Error::StsUnsupportedFormat, "input image must be single channel (gray levels), bgr format (color) or bgra (color with transparency which won't be considered");
|
||||
|
||||
return imageNumberOfChannels>1; // return bool : false for gray level image processing, true for color mode
|
||||
}
|
||||
|
||||
void RetinaImpl::clearBuffers() {_retinaFilter->clearAllBuffers();}
|
||||
|
||||
void RetinaImpl::activateMovingContoursProcessing(const bool activate){_retinaFilter->activateMovingContoursProcessing(activate);}
|
||||
|
||||
void RetinaImpl::activateContoursProcessing(const bool activate){_retinaFilter->activateContoursProcessing(activate);}
|
||||
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
@ -1,634 +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) 2010-2013, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Peng Xiao, pengxiao@multicorewareinc.com
|
||||
//
|
||||
// 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 oclMaterials 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 __OCL_RETINA_HPP__
|
||||
#define __OCL_RETINA_HPP__
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCV_OCL
|
||||
|
||||
// please refer to c++ headers for API comments
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
namespace ocl
|
||||
{
|
||||
void normalizeGrayOutputCentredSigmoide(const float meanValue, const float sensitivity, cv::ocl::oclMat &in, cv::ocl::oclMat &out, const float maxValue = 255.f);
|
||||
void normalizeGrayOutput_0_maxOutputValue(cv::ocl::oclMat &inputOutputBuffer, const float maxOutputValue = 255.0);
|
||||
void normalizeGrayOutputNearZeroCentreredSigmoide(cv::ocl::oclMat &inputPicture, cv::ocl::oclMat &outputBuffer, const float sensitivity = 40, const float maxOutputValue = 255.0f);
|
||||
void centerReductImageLuminance(cv::ocl::oclMat &inputOutputBuffer);
|
||||
|
||||
class BasicRetinaFilter
|
||||
{
|
||||
public:
|
||||
BasicRetinaFilter(const unsigned int NBrows, const unsigned int NBcolumns, const unsigned int parametersListSize = 1, const bool useProgressiveFilter = false);
|
||||
~BasicRetinaFilter();
|
||||
inline void clearOutputBuffer()
|
||||
{
|
||||
_filterOutput = 0;
|
||||
};
|
||||
inline void clearSecondaryBuffer()
|
||||
{
|
||||
_localBuffer = 0;
|
||||
};
|
||||
inline void clearAllBuffers()
|
||||
{
|
||||
clearOutputBuffer();
|
||||
clearSecondaryBuffer();
|
||||
};
|
||||
void resize(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
const cv::ocl::oclMat &runFilter_LPfilter(const cv::ocl::oclMat &inputFrame, const unsigned int filterIndex = 0);
|
||||
void runFilter_LPfilter(const cv::ocl::oclMat &inputFrame, cv::ocl::oclMat &outputFrame, const unsigned int filterIndex = 0);
|
||||
void runFilter_LPfilter_Autonomous(cv::ocl::oclMat &inputOutputFrame, const unsigned int filterIndex = 0);
|
||||
const cv::ocl::oclMat &runFilter_LocalAdapdation(const cv::ocl::oclMat &inputOutputFrame, const cv::ocl::oclMat &localLuminance);
|
||||
void runFilter_LocalAdapdation(const cv::ocl::oclMat &inputFrame, const cv::ocl::oclMat &localLuminance, cv::ocl::oclMat &outputFrame);
|
||||
const cv::ocl::oclMat &runFilter_LocalAdapdation_autonomous(const cv::ocl::oclMat &inputFrame);
|
||||
void runFilter_LocalAdapdation_autonomous(const cv::ocl::oclMat &inputFrame, cv::ocl::oclMat &outputFrame);
|
||||
void setLPfilterParameters(const float beta, const float tau, const float k, const unsigned int filterIndex = 0);
|
||||
inline void setV0CompressionParameter(const float v0, const float maxInputValue, const float)
|
||||
{
|
||||
_v0 = v0 * maxInputValue;
|
||||
_localLuminanceFactor = v0;
|
||||
_localLuminanceAddon = maxInputValue * (1.0f - v0);
|
||||
_maxInputValue = maxInputValue;
|
||||
};
|
||||
inline void setV0CompressionParameter(const float v0, const float meanLuminance)
|
||||
{
|
||||
this->setV0CompressionParameter(v0, _maxInputValue, meanLuminance);
|
||||
};
|
||||
inline void setV0CompressionParameter(const float v0)
|
||||
{
|
||||
_v0 = v0 * _maxInputValue;
|
||||
_localLuminanceFactor = v0;
|
||||
_localLuminanceAddon = _maxInputValue * (1.0f - v0);
|
||||
};
|
||||
inline void setV0CompressionParameterToneMapping(const float v0, const float maxInputValue, const float meanLuminance = 128.0f)
|
||||
{
|
||||
_v0 = v0 * maxInputValue;
|
||||
_localLuminanceFactor = 1.0f;
|
||||
_localLuminanceAddon = meanLuminance * _v0;
|
||||
_maxInputValue = maxInputValue;
|
||||
};
|
||||
inline void updateCompressionParameter(const float meanLuminance)
|
||||
{
|
||||
_localLuminanceFactor = 1;
|
||||
_localLuminanceAddon = meanLuminance * _v0;
|
||||
};
|
||||
inline float getV0CompressionParameter()
|
||||
{
|
||||
return _v0 / _maxInputValue;
|
||||
};
|
||||
inline const cv::ocl::oclMat &getOutput() const
|
||||
{
|
||||
return _filterOutput;
|
||||
};
|
||||
inline unsigned int getNBrows()
|
||||
{
|
||||
return _filterOutput.rows;
|
||||
};
|
||||
inline unsigned int getNBcolumns()
|
||||
{
|
||||
return _filterOutput.cols;
|
||||
};
|
||||
inline unsigned int getNBpixels()
|
||||
{
|
||||
return _filterOutput.size().area();
|
||||
};
|
||||
inline void normalizeGrayOutput_0_maxOutputValue(const float maxValue)
|
||||
{
|
||||
ocl::normalizeGrayOutput_0_maxOutputValue(_filterOutput, maxValue);
|
||||
};
|
||||
inline void normalizeGrayOutputCentredSigmoide()
|
||||
{
|
||||
ocl::normalizeGrayOutputCentredSigmoide(0.0, 2.0, _filterOutput, _filterOutput);
|
||||
};
|
||||
inline void centerReductImageLuminance()
|
||||
{
|
||||
ocl::centerReductImageLuminance(_filterOutput);
|
||||
};
|
||||
inline float getMaxInputValue()
|
||||
{
|
||||
return this->_maxInputValue;
|
||||
};
|
||||
inline void setMaxInputValue(const float newMaxInputValue)
|
||||
{
|
||||
this->_maxInputValue = newMaxInputValue;
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
int _NBrows;
|
||||
int _NBcols;
|
||||
unsigned int _halfNBrows;
|
||||
unsigned int _halfNBcolumns;
|
||||
|
||||
cv::ocl::oclMat _filterOutput;
|
||||
cv::ocl::oclMat _localBuffer;
|
||||
|
||||
std::valarray <float>_filteringCoeficientsTable;
|
||||
float _v0;
|
||||
float _maxInputValue;
|
||||
float _meanInputValue;
|
||||
float _localLuminanceFactor;
|
||||
float _localLuminanceAddon;
|
||||
|
||||
float _a;
|
||||
float _tau;
|
||||
float _gain;
|
||||
|
||||
void _spatiotemporalLPfilter(const cv::ocl::oclMat &inputFrame, cv::ocl::oclMat &LPfilterOutput, const unsigned int coefTableOffset = 0);
|
||||
float _squaringSpatiotemporalLPfilter(const cv::ocl::oclMat &inputFrame, cv::ocl::oclMat &outputFrame, const unsigned int filterIndex = 0);
|
||||
void _spatiotemporalLPfilter_Irregular(const cv::ocl::oclMat &inputFrame, cv::ocl::oclMat &outputFrame, const unsigned int filterIndex = 0);
|
||||
void _localSquaringSpatioTemporalLPfilter(const cv::ocl::oclMat &inputFrame, cv::ocl::oclMat &LPfilterOutput, const unsigned int *integrationAreas, const unsigned int filterIndex = 0);
|
||||
void _localLuminanceAdaptation(const cv::ocl::oclMat &inputFrame, const cv::ocl::oclMat &localLuminance, cv::ocl::oclMat &outputFrame, const bool updateLuminanceMean = true);
|
||||
void _localLuminanceAdaptation(cv::ocl::oclMat &inputOutputFrame, const cv::ocl::oclMat &localLuminance);
|
||||
void _localLuminanceAdaptationPosNegValues(const cv::ocl::oclMat &inputFrame, const cv::ocl::oclMat &localLuminance, float *outputFrame);
|
||||
void _horizontalCausalFilter_addInput(const cv::ocl::oclMat &inputFrame, cv::ocl::oclMat &outputFrame);
|
||||
void _horizontalAnticausalFilter(cv::ocl::oclMat &outputFrame);
|
||||
void _verticalCausalFilter(cv::ocl::oclMat &outputFrame);
|
||||
void _horizontalAnticausalFilter_Irregular(cv::ocl::oclMat &outputFrame, const cv::ocl::oclMat &spatialConstantBuffer);
|
||||
void _verticalCausalFilter_Irregular(cv::ocl::oclMat &outputFrame, const cv::ocl::oclMat &spatialConstantBuffer);
|
||||
void _verticalAnticausalFilter_multGain(cv::ocl::oclMat &outputFrame);
|
||||
};
|
||||
|
||||
class MagnoRetinaFilter: public BasicRetinaFilter
|
||||
{
|
||||
public:
|
||||
MagnoRetinaFilter(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
virtual ~MagnoRetinaFilter();
|
||||
void clearAllBuffers();
|
||||
void resize(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
void setCoefficientsTable(const float parasolCells_beta, const float parasolCells_tau, const float parasolCells_k, const float amacrinCellsTemporalCutFrequency, const float localAdaptIntegration_tau, const float localAdaptIntegration_k);
|
||||
|
||||
const cv::ocl::oclMat &runFilter(const cv::ocl::oclMat &OPL_ON, const cv::ocl::oclMat &OPL_OFF);
|
||||
|
||||
inline const cv::ocl::oclMat &getMagnoON() const
|
||||
{
|
||||
return _magnoXOutputON;
|
||||
};
|
||||
inline const cv::ocl::oclMat &getMagnoOFF() const
|
||||
{
|
||||
return _magnoXOutputOFF;
|
||||
};
|
||||
inline const cv::ocl::oclMat &getMagnoYsaturated() const
|
||||
{
|
||||
return _magnoYsaturated;
|
||||
};
|
||||
inline void normalizeGrayOutputNearZeroCentreredSigmoide()
|
||||
{
|
||||
ocl::normalizeGrayOutputNearZeroCentreredSigmoide(_magnoYOutput, _magnoYsaturated);
|
||||
};
|
||||
inline float getTemporalConstant()
|
||||
{
|
||||
return this->_filteringCoeficientsTable[2];
|
||||
};
|
||||
private:
|
||||
cv::ocl::oclMat _previousInput_ON;
|
||||
cv::ocl::oclMat _previousInput_OFF;
|
||||
cv::ocl::oclMat _amacrinCellsTempOutput_ON;
|
||||
cv::ocl::oclMat _amacrinCellsTempOutput_OFF;
|
||||
cv::ocl::oclMat _magnoXOutputON;
|
||||
cv::ocl::oclMat _magnoXOutputOFF;
|
||||
cv::ocl::oclMat _localProcessBufferON;
|
||||
cv::ocl::oclMat _localProcessBufferOFF;
|
||||
cv::ocl::oclMat _magnoYOutput;
|
||||
cv::ocl::oclMat _magnoYsaturated;
|
||||
|
||||
float _temporalCoefficient;
|
||||
void _amacrineCellsComputing(const cv::ocl::oclMat &OPL_ON, const cv::ocl::oclMat &OPL_OFF);
|
||||
};
|
||||
|
||||
class ParvoRetinaFilter: public BasicRetinaFilter
|
||||
{
|
||||
public:
|
||||
ParvoRetinaFilter(const unsigned int NBrows = 480, const unsigned int NBcolumns = 640);
|
||||
virtual ~ParvoRetinaFilter();
|
||||
void resize(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
void clearAllBuffers();
|
||||
void setOPLandParvoFiltersParameters(const float beta1, const float tau1, const float k1, const float beta2, const float tau2, const float k2);
|
||||
|
||||
inline void setGanglionCellsLocalAdaptationLPfilterParameters(const float tau, const float k)
|
||||
{
|
||||
BasicRetinaFilter::setLPfilterParameters(0, tau, k, 2);
|
||||
};
|
||||
const cv::ocl::oclMat &runFilter(const cv::ocl::oclMat &inputFrame, const bool useParvoOutput = true);
|
||||
|
||||
inline const cv::ocl::oclMat &getPhotoreceptorsLPfilteringOutput() const
|
||||
{
|
||||
return _photoreceptorsOutput;
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getHorizontalCellsOutput() const
|
||||
{
|
||||
return _horizontalCellsOutput;
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getParvoON() const
|
||||
{
|
||||
return _parvocellularOutputON;
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getParvoOFF() const
|
||||
{
|
||||
return _parvocellularOutputOFF;
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getBipolarCellsON() const
|
||||
{
|
||||
return _bipolarCellsOutputON;
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getBipolarCellsOFF() const
|
||||
{
|
||||
return _bipolarCellsOutputOFF;
|
||||
};
|
||||
|
||||
inline float getPhotoreceptorsTemporalConstant()
|
||||
{
|
||||
return this->_filteringCoeficientsTable[2];
|
||||
};
|
||||
|
||||
inline float getHcellsTemporalConstant()
|
||||
{
|
||||
return this->_filteringCoeficientsTable[5];
|
||||
};
|
||||
private:
|
||||
cv::ocl::oclMat _photoreceptorsOutput;
|
||||
cv::ocl::oclMat _horizontalCellsOutput;
|
||||
cv::ocl::oclMat _parvocellularOutputON;
|
||||
cv::ocl::oclMat _parvocellularOutputOFF;
|
||||
cv::ocl::oclMat _bipolarCellsOutputON;
|
||||
cv::ocl::oclMat _bipolarCellsOutputOFF;
|
||||
cv::ocl::oclMat _localAdaptationOFF;
|
||||
cv::ocl::oclMat _localAdaptationON;
|
||||
cv::ocl::oclMat _parvocellularOutputONminusOFF;
|
||||
void _OPL_OnOffWaysComputing();
|
||||
};
|
||||
class RetinaColor: public BasicRetinaFilter
|
||||
{
|
||||
public:
|
||||
RetinaColor(const unsigned int NBrows, const unsigned int NBcolumns, const int samplingMethod = RETINA_COLOR_DIAGONAL);
|
||||
virtual ~RetinaColor();
|
||||
|
||||
void clearAllBuffers();
|
||||
void resize(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
inline void runColorMultiplexing(const cv::ocl::oclMat &inputRGBFrame)
|
||||
{
|
||||
runColorMultiplexing(inputRGBFrame, _multiplexedFrame);
|
||||
};
|
||||
void runColorMultiplexing(const cv::ocl::oclMat &demultiplexedInputFrame, cv::ocl::oclMat &multiplexedFrame);
|
||||
void runColorDemultiplexing(const cv::ocl::oclMat &multiplexedColorFrame, const bool adaptiveFiltering = false, const float maxInputValue = 255.0);
|
||||
|
||||
void setColorSaturation(const bool saturateColors = true, const float colorSaturationValue = 4.0)
|
||||
{
|
||||
_saturateColors = saturateColors;
|
||||
_colorSaturationValue = colorSaturationValue;
|
||||
};
|
||||
|
||||
void setChrominanceLPfilterParameters(const float beta, const float tau, const float k)
|
||||
{
|
||||
setLPfilterParameters(beta, tau, k);
|
||||
};
|
||||
|
||||
bool applyKrauskopfLMS2Acr1cr2Transform(cv::ocl::oclMat &result);
|
||||
bool applyLMS2LabTransform(cv::ocl::oclMat &result);
|
||||
inline const cv::ocl::oclMat &getMultiplexedFrame() const
|
||||
{
|
||||
return _multiplexedFrame;
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getDemultiplexedColorFrame() const
|
||||
{
|
||||
return _demultiplexedColorFrame;
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getLuminance() const
|
||||
{
|
||||
return _luminance;
|
||||
};
|
||||
inline const cv::ocl::oclMat &getChrominance() const
|
||||
{
|
||||
return _chrominance;
|
||||
};
|
||||
void clipRGBOutput_0_maxInputValue(cv::ocl::oclMat &inputOutputBuffer, const float maxOutputValue = 255.0);
|
||||
void normalizeRGBOutput_0_maxOutputValue(const float maxOutputValue = 255.0);
|
||||
inline void setDemultiplexedColorFrame(const cv::ocl::oclMat &demultiplexedImage)
|
||||
{
|
||||
_demultiplexedColorFrame = demultiplexedImage;
|
||||
};
|
||||
protected:
|
||||
inline unsigned int bayerSampleOffset(unsigned int index)
|
||||
{
|
||||
return index + ((index / getNBcolumns()) % 2) * getNBpixels() + ((index % getNBcolumns()) % 2) * getNBpixels();
|
||||
}
|
||||
inline Rect getROI(int idx)
|
||||
{
|
||||
return Rect(0, idx * _NBrows, _NBcols, _NBrows);
|
||||
}
|
||||
int _samplingMethod;
|
||||
bool _saturateColors;
|
||||
float _colorSaturationValue;
|
||||
cv::ocl::oclMat _luminance;
|
||||
cv::ocl::oclMat _multiplexedFrame;
|
||||
cv::ocl::oclMat _RGBmosaic;
|
||||
cv::ocl::oclMat _tempMultiplexedFrame;
|
||||
cv::ocl::oclMat _demultiplexedTempBuffer;
|
||||
cv::ocl::oclMat _demultiplexedColorFrame;
|
||||
cv::ocl::oclMat _chrominance;
|
||||
cv::ocl::oclMat _colorLocalDensity;
|
||||
cv::ocl::oclMat _imageGradient;
|
||||
|
||||
float _pR, _pG, _pB;
|
||||
bool _objectInit;
|
||||
|
||||
void _initColorSampling();
|
||||
void _adaptiveSpatialLPfilter(const cv::ocl::oclMat &inputFrame, const cv::ocl::oclMat &gradient, cv::ocl::oclMat &outputFrame);
|
||||
void _adaptiveHorizontalCausalFilter_addInput(const cv::ocl::oclMat &inputFrame, const cv::ocl::oclMat &gradient, cv::ocl::oclMat &outputFrame);
|
||||
void _adaptiveVerticalAnticausalFilter_multGain(const cv::ocl::oclMat &gradient, cv::ocl::oclMat &outputFrame);
|
||||
void _computeGradient(const cv::ocl::oclMat &luminance, cv::ocl::oclMat &gradient);
|
||||
void _normalizeOutputs_0_maxOutputValue(void);
|
||||
void _applyImageColorSpaceConversion(const cv::ocl::oclMat &inputFrame, cv::ocl::oclMat &outputFrame, const float *transformTable);
|
||||
};
|
||||
class RetinaFilter
|
||||
{
|
||||
public:
|
||||
RetinaFilter(const unsigned int sizeRows, const unsigned int sizeColumns, const bool colorMode = false, const int samplingMethod = RETINA_COLOR_BAYER, const bool useRetinaLogSampling = false, const double reductionFactor = 1.0, const double samplingStrenght = 10.0);
|
||||
~RetinaFilter();
|
||||
|
||||
void clearAllBuffers();
|
||||
void resize(const unsigned int NBrows, const unsigned int NBcolumns);
|
||||
bool checkInput(const cv::ocl::oclMat &input, const bool colorMode);
|
||||
bool runFilter(const cv::ocl::oclMat &imageInput, const bool useAdaptiveFiltering = true, const bool processRetinaParvoMagnoMapping = false, const bool useColorMode = false, const bool inputIsColorMultiplexed = false);
|
||||
|
||||
void setGlobalParameters(const float OPLspatialResponse1 = 0.7, const float OPLtemporalresponse1 = 1, const float OPLassymetryGain = 0, const float OPLspatialResponse2 = 5, const float OPLtemporalresponse2 = 1, const float LPfilterSpatialResponse = 5, const float LPfilterGain = 0, const float LPfilterTemporalresponse = 0, const float MovingContoursExtractorCoefficient = 5, const bool normalizeParvoOutput_0_maxOutputValue = false, const bool normalizeMagnoOutput_0_maxOutputValue = false, const float maxOutputValue = 255.0, const float maxInputValue = 255.0, const float meanValue = 128.0);
|
||||
|
||||
inline void setPhotoreceptorsLocalAdaptationSensitivity(const float V0CompressionParameter)
|
||||
{
|
||||
_photoreceptorsPrefilter.setV0CompressionParameter(1 - V0CompressionParameter);
|
||||
_setInitPeriodCount();
|
||||
};
|
||||
|
||||
inline void setParvoGanglionCellsLocalAdaptationSensitivity(const float V0CompressionParameter)
|
||||
{
|
||||
_ParvoRetinaFilter.setV0CompressionParameter(V0CompressionParameter);
|
||||
_setInitPeriodCount();
|
||||
};
|
||||
|
||||
inline void setGanglionCellsLocalAdaptationLPfilterParameters(const float spatialResponse, const float temporalResponse)
|
||||
{
|
||||
_ParvoRetinaFilter.setGanglionCellsLocalAdaptationLPfilterParameters(temporalResponse, spatialResponse);
|
||||
_setInitPeriodCount();
|
||||
};
|
||||
|
||||
inline void setMagnoGanglionCellsLocalAdaptationSensitivity(const float V0CompressionParameter)
|
||||
{
|
||||
_MagnoRetinaFilter.setV0CompressionParameter(V0CompressionParameter);
|
||||
_setInitPeriodCount();
|
||||
};
|
||||
|
||||
void setOPLandParvoParameters(const float beta1, const float tau1, const float k1, const float beta2, const float tau2, const float k2, const float V0CompressionParameter)
|
||||
{
|
||||
_ParvoRetinaFilter.setOPLandParvoFiltersParameters(beta1, tau1, k1, beta2, tau2, k2);
|
||||
_ParvoRetinaFilter.setV0CompressionParameter(V0CompressionParameter);
|
||||
_setInitPeriodCount();
|
||||
};
|
||||
|
||||
void setMagnoCoefficientsTable(const float parasolCells_beta, const float parasolCells_tau, const float parasolCells_k, const float amacrinCellsTemporalCutFrequency, const float V0CompressionParameter, const float localAdaptintegration_tau, const float localAdaptintegration_k)
|
||||
{
|
||||
_MagnoRetinaFilter.setCoefficientsTable(parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, localAdaptintegration_tau, localAdaptintegration_k);
|
||||
_MagnoRetinaFilter.setV0CompressionParameter(V0CompressionParameter);
|
||||
_setInitPeriodCount();
|
||||
};
|
||||
|
||||
inline void activateNormalizeParvoOutput_0_maxOutputValue(const bool normalizeParvoOutput_0_maxOutputValue)
|
||||
{
|
||||
_normalizeParvoOutput_0_maxOutputValue = normalizeParvoOutput_0_maxOutputValue;
|
||||
};
|
||||
|
||||
inline void activateNormalizeMagnoOutput_0_maxOutputValue(const bool normalizeMagnoOutput_0_maxOutputValue)
|
||||
{
|
||||
_normalizeMagnoOutput_0_maxOutputValue = normalizeMagnoOutput_0_maxOutputValue;
|
||||
};
|
||||
|
||||
inline void setMaxOutputValue(const float maxOutputValue)
|
||||
{
|
||||
_maxOutputValue = maxOutputValue;
|
||||
};
|
||||
|
||||
void setColorMode(const bool desiredColorMode)
|
||||
{
|
||||
_useColorMode = desiredColorMode;
|
||||
};
|
||||
inline void setColorSaturation(const bool saturateColors = true, const float colorSaturationValue = 4.0)
|
||||
{
|
||||
_colorEngine.setColorSaturation(saturateColors, colorSaturationValue);
|
||||
};
|
||||
inline const cv::ocl::oclMat &getLocalAdaptation() const
|
||||
{
|
||||
return _photoreceptorsPrefilter.getOutput();
|
||||
};
|
||||
inline const cv::ocl::oclMat &getPhotoreceptors() const
|
||||
{
|
||||
return _ParvoRetinaFilter.getPhotoreceptorsLPfilteringOutput();
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getHorizontalCells() const
|
||||
{
|
||||
return _ParvoRetinaFilter.getHorizontalCellsOutput();
|
||||
};
|
||||
inline bool areContoursProcessed()
|
||||
{
|
||||
return _useParvoOutput;
|
||||
};
|
||||
bool getParvoFoveaResponse(cv::ocl::oclMat &parvoFovealResponse);
|
||||
inline void activateContoursProcessing(const bool useParvoOutput)
|
||||
{
|
||||
_useParvoOutput = useParvoOutput;
|
||||
};
|
||||
|
||||
const cv::ocl::oclMat &getContours();
|
||||
|
||||
inline const cv::ocl::oclMat &getContoursON() const
|
||||
{
|
||||
return _ParvoRetinaFilter.getParvoON();
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getContoursOFF() const
|
||||
{
|
||||
return _ParvoRetinaFilter.getParvoOFF();
|
||||
};
|
||||
|
||||
inline bool areMovingContoursProcessed()
|
||||
{
|
||||
return _useMagnoOutput;
|
||||
};
|
||||
|
||||
inline void activateMovingContoursProcessing(const bool useMagnoOutput)
|
||||
{
|
||||
_useMagnoOutput = useMagnoOutput;
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getMovingContours() const
|
||||
{
|
||||
return _MagnoRetinaFilter.getOutput();
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getMovingContoursSaturated() const
|
||||
{
|
||||
return _MagnoRetinaFilter.getMagnoYsaturated();
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getMovingContoursON() const
|
||||
{
|
||||
return _MagnoRetinaFilter.getMagnoON();
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getMovingContoursOFF() const
|
||||
{
|
||||
return _MagnoRetinaFilter.getMagnoOFF();
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getRetinaParvoMagnoMappedOutput() const
|
||||
{
|
||||
return _retinaParvoMagnoMappedFrame;
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getParvoContoursChannel() const
|
||||
{
|
||||
return _colorEngine.getLuminance();
|
||||
};
|
||||
|
||||
inline const cv::ocl::oclMat &getParvoChrominance() const
|
||||
{
|
||||
return _colorEngine.getChrominance();
|
||||
};
|
||||
inline const cv::ocl::oclMat &getColorOutput() const
|
||||
{
|
||||
return _colorEngine.getDemultiplexedColorFrame();
|
||||
};
|
||||
|
||||
inline bool isColorMode()
|
||||
{
|
||||
return _useColorMode;
|
||||
};
|
||||
bool getColorMode()
|
||||
{
|
||||
return _useColorMode;
|
||||
};
|
||||
|
||||
inline bool isInitTransitionDone()
|
||||
{
|
||||
if (_ellapsedFramesSinceLastReset < _globalTemporalConstant)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
inline float getRetinaSamplingBackProjection(const float projectedRadiusLength)
|
||||
{
|
||||
return projectedRadiusLength;
|
||||
};
|
||||
|
||||
inline unsigned int getInputNBrows()
|
||||
{
|
||||
return _photoreceptorsPrefilter.getNBrows();
|
||||
};
|
||||
|
||||
inline unsigned int getInputNBcolumns()
|
||||
{
|
||||
return _photoreceptorsPrefilter.getNBcolumns();
|
||||
};
|
||||
|
||||
inline unsigned int getInputNBpixels()
|
||||
{
|
||||
return _photoreceptorsPrefilter.getNBpixels();
|
||||
};
|
||||
|
||||
inline unsigned int getOutputNBrows()
|
||||
{
|
||||
return _photoreceptorsPrefilter.getNBrows();
|
||||
};
|
||||
|
||||
inline unsigned int getOutputNBcolumns()
|
||||
{
|
||||
return _photoreceptorsPrefilter.getNBcolumns();
|
||||
};
|
||||
|
||||
inline unsigned int getOutputNBpixels()
|
||||
{
|
||||
return _photoreceptorsPrefilter.getNBpixels();
|
||||
};
|
||||
private:
|
||||
bool _useParvoOutput;
|
||||
bool _useMagnoOutput;
|
||||
|
||||
unsigned int _ellapsedFramesSinceLastReset;
|
||||
unsigned int _globalTemporalConstant;
|
||||
|
||||
cv::ocl::oclMat _retinaParvoMagnoMappedFrame;
|
||||
BasicRetinaFilter _photoreceptorsPrefilter;
|
||||
ParvoRetinaFilter _ParvoRetinaFilter;
|
||||
MagnoRetinaFilter _MagnoRetinaFilter;
|
||||
RetinaColor _colorEngine;
|
||||
|
||||
bool _useMinimalMemoryForToneMappingONLY;
|
||||
bool _normalizeParvoOutput_0_maxOutputValue;
|
||||
bool _normalizeMagnoOutput_0_maxOutputValue;
|
||||
float _maxOutputValue;
|
||||
bool _useColorMode;
|
||||
|
||||
void _setInitPeriodCount();
|
||||
void _processRetinaParvoMagnoMapping();
|
||||
void _runGrayToneMapping(const cv::ocl::oclMat &grayImageInput, cv::ocl::oclMat &grayImageOutput , const float PhotoreceptorsCompression = 0.6, const float ganglionCellsCompression = 0.6);
|
||||
};
|
||||
|
||||
} /* namespace ocl */
|
||||
} /* namespace bioinspired */
|
||||
} /* namespace cv */
|
||||
|
||||
#endif /* HAVE_OPENCV_OCL */
|
||||
#endif /* __OCL_RETINA_HPP__ */
|