mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
merge with Itseez/opencv
This commit is contained in:
@@ -4,4 +4,4 @@ if(NOT OPENCV_MODULES_PATH)
|
||||
set(OPENCV_MODULES_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
endif()
|
||||
|
||||
ocv_glob_modules(${OPENCV_MODULES_PATH})
|
||||
ocv_glob_modules(${OPENCV_MODULES_PATH} ${OPENCV_EXTRA_MODULES_PATH})
|
||||
|
||||
@@ -6,7 +6,7 @@ set(the_description "Auxiliary module for Android native camera support")
|
||||
set(OPENCV_MODULE_TYPE STATIC)
|
||||
|
||||
ocv_define_module(androidcamera INTERNAL opencv_core log dl)
|
||||
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/camera_wrapper" "${OpenCV_SOURCE_DIR}/android/service/engine/jni/include")
|
||||
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/camera_wrapper" "${OpenCV_SOURCE_DIR}/platforms/android/service/engine/jni/include")
|
||||
|
||||
# Android source tree for native camera
|
||||
SET (ANDROID_SOURCE_TREE "ANDROID_SOURCE_TREE-NOTFOUND" CACHE PATH
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1) && !defined(ANDROID_r4_0_0) && !defined(ANDROID_r4_0_3) && !defined(ANDROID_r4_1_1) && !defined(ANDROID_r4_2_0)
|
||||
# error Building camera wrapper for your version of Android is not supported by OpenCV. You need to modify OpenCV sources in order to compile camera wrapper for your version of Android.
|
||||
#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1) && \
|
||||
!defined(ANDROID_r4_0_0) && !defined(ANDROID_r4_0_3) && !defined(ANDROID_r4_1_1) && \
|
||||
!defined(ANDROID_r4_2_0) && !defined(ANDROID_r4_3_0)
|
||||
# error Building camera wrapper for your version of Android is not supported by OpenCV.\
|
||||
You need to modify OpenCV sources in order to compile camera wrapper for your version of Android.
|
||||
#endif
|
||||
|
||||
#include <camera/Camera.h>
|
||||
@@ -16,17 +19,18 @@
|
||||
//Include SurfaceTexture.h file with the SurfaceTexture class
|
||||
# include <gui/SurfaceTexture.h>
|
||||
# define MAGIC_OPENCV_TEXTURE_ID (0x10)
|
||||
#else // defined(ANDROID_r3_0_1) || defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3)
|
||||
//TODO: This is either 2.2 or 2.3. Include the headers for ISurface.h access
|
||||
#if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0)
|
||||
#include <gui/ISurface.h>
|
||||
#include <gui/BufferQueue.h>
|
||||
#elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0)
|
||||
# include <gui/ISurface.h>
|
||||
# include <gui/BufferQueue.h>
|
||||
#elif defined(ANDROID_r4_3_0)
|
||||
# include <gui/IGraphicBufferProducer.h>
|
||||
# include <gui/BufferQueue.h>
|
||||
#else
|
||||
# include <surfaceflinger/ISurface.h>
|
||||
#endif // defined(ANDROID_r4_1_1)
|
||||
#endif // defined(ANDROID_r3_0_1) || defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3)
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
//undef logging macro from /system/core/libcutils/loghack.h
|
||||
#ifdef LOGD
|
||||
@@ -45,7 +49,6 @@
|
||||
# undef LOGE
|
||||
#endif
|
||||
|
||||
|
||||
// LOGGING
|
||||
#include <android/log.h>
|
||||
#define CAMERA_LOG_TAG "OpenCV_NativeCamera"
|
||||
@@ -60,7 +63,7 @@ using namespace android;
|
||||
|
||||
void debugShowFPS();
|
||||
|
||||
#if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0)
|
||||
#if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
|
||||
class ConsumerListenerStub: public BufferQueue::ConsumerListener
|
||||
{
|
||||
public:
|
||||
@@ -73,6 +76,29 @@ public:
|
||||
};
|
||||
#endif
|
||||
|
||||
std::string getProcessName()
|
||||
{
|
||||
std::string result;
|
||||
std::ifstream f;
|
||||
|
||||
f.open("/proc/self/cmdline");
|
||||
if (f.is_open())
|
||||
{
|
||||
std::string fullPath;
|
||||
std::getline(f, fullPath, '\0');
|
||||
if (!fullPath.empty())
|
||||
{
|
||||
int i = fullPath.size()-1;
|
||||
while ((i >= 0) && (fullPath[i] != '/')) i--;
|
||||
result = fullPath.substr(i+1, std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void debugShowFPS()
|
||||
{
|
||||
static int mFrameCount = 0;
|
||||
@@ -280,7 +306,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr
|
||||
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0)
|
||||
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
|
||||
,camera_frame_metadata_t*
|
||||
#endif
|
||||
)
|
||||
@@ -361,6 +387,11 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
typedef sp<Camera> (*Android22ConnectFuncType)();
|
||||
typedef sp<Camera> (*Android23ConnectFuncType)(int);
|
||||
typedef sp<Camera> (*Android3DConnectFuncType)(int, int);
|
||||
typedef sp<Camera> (*Android43ConnectFuncType)(int, const String16&, int);
|
||||
|
||||
const int ANY_CAMERA_INDEX = -1;
|
||||
const int BACK_CAMERA_INDEX = 99;
|
||||
const int FRONT_CAMERA_INDEX = 98;
|
||||
|
||||
enum {
|
||||
CAMERA_SUPPORT_MODE_2D = 0x01, /* Camera Sensor supports 2D mode. */
|
||||
@@ -369,11 +400,65 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
CAMERA_SUPPORT_MODE_ZSL = 0x08 /* Camera Sensor supports ZSL mode. */
|
||||
};
|
||||
|
||||
// used for Android 4.3
|
||||
enum {
|
||||
USE_CALLING_UID = -1
|
||||
};
|
||||
|
||||
const char Android22ConnectName[] = "_ZN7android6Camera7connectEv";
|
||||
const char Android23ConnectName[] = "_ZN7android6Camera7connectEi";
|
||||
const char Android3DConnectName[] = "_ZN7android6Camera7connectEii";
|
||||
const char Android43ConnectName[] = "_ZN7android6Camera7connectEiRKNS_8String16Ei";
|
||||
|
||||
LOGD("CameraHandler::initCameraConnect(%p, %d, %p, %p)", callback, cameraId, userData, prevCameraParameters);
|
||||
int localCameraIndex = cameraId;
|
||||
|
||||
if (cameraId == ANY_CAMERA_INDEX)
|
||||
{
|
||||
localCameraIndex = 0;
|
||||
}
|
||||
#if !defined(ANDROID_r2_2_0)
|
||||
else if (cameraId == BACK_CAMERA_INDEX)
|
||||
{
|
||||
LOGD("Back camera selected");
|
||||
for (int i = 0; i < Camera::getNumberOfCameras(); i++)
|
||||
{
|
||||
CameraInfo info;
|
||||
Camera::getCameraInfo(i, &info);
|
||||
if (info.facing == CAMERA_FACING_BACK)
|
||||
{
|
||||
localCameraIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (cameraId == FRONT_CAMERA_INDEX)
|
||||
{
|
||||
LOGD("Front camera selected");
|
||||
for (int i = 0; i < Camera::getNumberOfCameras(); i++)
|
||||
{
|
||||
CameraInfo info;
|
||||
Camera::getCameraInfo(i, &info);
|
||||
if (info.facing == CAMERA_FACING_FRONT)
|
||||
{
|
||||
localCameraIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (localCameraIndex == BACK_CAMERA_INDEX)
|
||||
{
|
||||
LOGE("Back camera not found!");
|
||||
return NULL;
|
||||
}
|
||||
else if (localCameraIndex == FRONT_CAMERA_INDEX)
|
||||
{
|
||||
LOGE("Front camera not found!");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
LOGD("CameraHandler::initCameraConnect(%p, %d, %p, %p)", callback, localCameraIndex, userData, prevCameraParameters);
|
||||
|
||||
sp<Camera> camera = 0;
|
||||
|
||||
@@ -381,8 +466,8 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
|
||||
if (!CameraHALHandle)
|
||||
{
|
||||
LOGE("Cannot link to \"libcamera_client.so\"");
|
||||
return NULL;
|
||||
LOGE("Cannot link to \"libcamera_client.so\"");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// reset errors
|
||||
@@ -390,24 +475,30 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
|
||||
if (Android22ConnectFuncType Android22Connect = (Android22ConnectFuncType)dlsym(CameraHALHandle, Android22ConnectName))
|
||||
{
|
||||
LOGD("Connecting to CameraService v 2.2");
|
||||
camera = Android22Connect();
|
||||
LOGD("Connecting to CameraService v 2.2");
|
||||
camera = Android22Connect();
|
||||
}
|
||||
else if (Android23ConnectFuncType Android23Connect = (Android23ConnectFuncType)dlsym(CameraHALHandle, Android23ConnectName))
|
||||
{
|
||||
LOGD("Connecting to CameraService v 2.3");
|
||||
camera = Android23Connect(cameraId);
|
||||
LOGD("Connecting to CameraService v 2.3");
|
||||
camera = Android23Connect(localCameraIndex);
|
||||
}
|
||||
else if (Android3DConnectFuncType Android3DConnect = (Android3DConnectFuncType)dlsym(CameraHALHandle, Android3DConnectName))
|
||||
{
|
||||
LOGD("Connecting to CameraService v 3D");
|
||||
camera = Android3DConnect(cameraId, CAMERA_SUPPORT_MODE_2D);
|
||||
LOGD("Connecting to CameraService v 3D");
|
||||
camera = Android3DConnect(localCameraIndex, CAMERA_SUPPORT_MODE_2D);
|
||||
}
|
||||
else if (Android43ConnectFuncType Android43Connect = (Android43ConnectFuncType)dlsym(CameraHALHandle, Android43ConnectName))
|
||||
{
|
||||
std::string currentProcName = getProcessName();
|
||||
LOGD("Current process name for camera init: %s", currentProcName.c_str());
|
||||
camera = Android43Connect(localCameraIndex, String16(currentProcName.c_str()), USE_CALLING_UID);
|
||||
}
|
||||
else
|
||||
{
|
||||
dlclose(CameraHALHandle);
|
||||
LOGE("Cannot connect to CameraService. Connect method was not found!");
|
||||
return NULL;
|
||||
dlclose(CameraHALHandle);
|
||||
LOGE("Cannot connect to CameraService. Connect method was not found!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dlclose(CameraHALHandle);
|
||||
@@ -422,9 +513,9 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
camera->setListener(handler);
|
||||
|
||||
handler->camera = camera;
|
||||
handler->cameraId = cameraId;
|
||||
handler->cameraId = localCameraIndex;
|
||||
|
||||
if (prevCameraParameters != 0)
|
||||
if (prevCameraParameters != NULL)
|
||||
{
|
||||
LOGI("initCameraConnect: Setting paramers from previous camera handler");
|
||||
camera->setParameters(prevCameraParameters->flatten());
|
||||
@@ -456,11 +547,11 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
const char* available_focus_modes = handler->params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES);
|
||||
if (available_focus_modes != 0)
|
||||
{
|
||||
if (strstr(available_focus_modes, "continuous-video") != NULL)
|
||||
{
|
||||
handler->params.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO);
|
||||
if (strstr(available_focus_modes, "continuous-video") != NULL)
|
||||
{
|
||||
handler->params.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO);
|
||||
|
||||
status_t resParams = handler->camera->setParameters(handler->params.flatten());
|
||||
status_t resParams = handler->camera->setParameters(handler->params.flatten());
|
||||
|
||||
if (resParams != 0)
|
||||
{
|
||||
@@ -470,8 +561,8 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
{
|
||||
LOGD("initCameraConnect: autofocus is set to mode \"continuous-video\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//check if yuv420sp format available. Set this format as preview format.
|
||||
@@ -513,26 +604,25 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
}
|
||||
}
|
||||
|
||||
status_t pdstatus;
|
||||
status_t bufferStatus;
|
||||
#if defined(ANDROID_r2_2_0)
|
||||
pdstatus = camera->setPreviewDisplay(sp<ISurface>(0 /*new DummySurface*/));
|
||||
if (pdstatus != 0)
|
||||
LOGE("initCameraConnect: failed setPreviewDisplay(0) call; camera migth not work correctly on some devices");
|
||||
bufferStatus = camera->setPreviewDisplay(sp<ISurface>(0 /*new DummySurface*/));
|
||||
if (bufferStatus != 0)
|
||||
LOGE("initCameraConnect: failed setPreviewDisplay(0) call (status %d); camera might not work correctly on some devices", bufferStatus);
|
||||
#elif defined(ANDROID_r2_3_3)
|
||||
/* Do nothing in case of 2.3 for now */
|
||||
|
||||
#elif defined(ANDROID_r3_0_1) || defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3)
|
||||
sp<SurfaceTexture> surfaceTexture = new SurfaceTexture(MAGIC_OPENCV_TEXTURE_ID);
|
||||
pdstatus = camera->setPreviewTexture(surfaceTexture);
|
||||
if (pdstatus != 0)
|
||||
LOGE("initCameraConnect: failed setPreviewTexture call; camera migth not work correctly");
|
||||
#elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0)
|
||||
bufferStatus = camera->setPreviewTexture(surfaceTexture);
|
||||
if (bufferStatus != 0)
|
||||
LOGE("initCameraConnect: failed setPreviewTexture call (status %d); camera might not work correctly", bufferStatus);
|
||||
#elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
|
||||
sp<BufferQueue> bufferQueue = new BufferQueue();
|
||||
sp<BufferQueue::ConsumerListener> queueListener = new ConsumerListenerStub();
|
||||
bufferQueue->consumerConnect(queueListener);
|
||||
pdstatus = camera->setPreviewTexture(bufferQueue);
|
||||
if (pdstatus != 0)
|
||||
LOGE("initCameraConnect: failed setPreviewTexture call; camera migth not work correctly");
|
||||
bufferStatus = camera->setPreviewTexture(bufferQueue);
|
||||
if (bufferStatus != 0)
|
||||
LOGE("initCameraConnect: failed setPreviewTexture call; camera might not work correctly");
|
||||
#endif
|
||||
|
||||
#if (defined(ANDROID_r2_2_0) || defined(ANDROID_r2_3_3) || defined(ANDROID_r3_0_1))
|
||||
@@ -548,9 +638,9 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
#endif //!(defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3))
|
||||
|
||||
LOGD("Starting preview");
|
||||
status_t resStart = camera->startPreview();
|
||||
status_t previewStatus = camera->startPreview();
|
||||
|
||||
if (resStart != 0)
|
||||
if (previewStatus != 0)
|
||||
{
|
||||
LOGE("initCameraConnect: startPreview() fails. Closing camera connection...");
|
||||
handler->closeCameraConnect();
|
||||
@@ -558,7 +648,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGD("Preview started successfully");
|
||||
LOGD("Preview started successfully");
|
||||
}
|
||||
|
||||
return handler;
|
||||
@@ -573,9 +663,11 @@ void CameraHandler::closeCameraConnect()
|
||||
}
|
||||
|
||||
camera->stopPreview();
|
||||
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
|
||||
camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
|
||||
#endif
|
||||
camera->disconnect();
|
||||
camera.clear();
|
||||
|
||||
camera=NULL;
|
||||
// ATTENTION!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// When we set
|
||||
@@ -816,14 +908,60 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
|
||||
|
||||
if (*ppcameraHandler == 0)
|
||||
{
|
||||
LOGE("applyProperties: Passed null *ppcameraHandler");
|
||||
LOGE("applyProperties: Passed NULL *ppcameraHandler");
|
||||
return;
|
||||
}
|
||||
|
||||
LOGD("CameraHandler::applyProperties()");
|
||||
CameraHandler* previousCameraHandler=*ppcameraHandler;
|
||||
CameraParameters curCameraParameters(previousCameraHandler->params.flatten());
|
||||
CameraParameters curCameraParameters((*ppcameraHandler)->params.flatten());
|
||||
|
||||
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
|
||||
CameraHandler* handler=*ppcameraHandler;
|
||||
|
||||
handler->camera->stopPreview();
|
||||
handler->camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
|
||||
|
||||
status_t reconnectStatus = handler->camera->reconnect();
|
||||
if (reconnectStatus != 0)
|
||||
{
|
||||
LOGE("applyProperties: failed to reconnect camera (status %d)", reconnectStatus);
|
||||
return;
|
||||
}
|
||||
|
||||
handler->camera->setParameters(curCameraParameters.flatten());
|
||||
handler->params.unflatten(curCameraParameters.flatten());
|
||||
|
||||
status_t bufferStatus;
|
||||
# if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3)
|
||||
sp<SurfaceTexture> surfaceTexture = new SurfaceTexture(MAGIC_OPENCV_TEXTURE_ID);
|
||||
bufferStatus = handler->camera->setPreviewTexture(surfaceTexture);
|
||||
if (bufferStatus != 0)
|
||||
LOGE("applyProperties: failed setPreviewTexture call (status %d); camera might not work correctly", bufferStatus);
|
||||
# elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
|
||||
sp<BufferQueue> bufferQueue = new BufferQueue();
|
||||
sp<BufferQueue::ConsumerListener> queueListener = new ConsumerListenerStub();
|
||||
bufferQueue->consumerConnect(queueListener);
|
||||
bufferStatus = handler->camera->setPreviewTexture(bufferQueue);
|
||||
if (bufferStatus != 0)
|
||||
LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
|
||||
# endif
|
||||
|
||||
handler->camera->setPreviewCallbackFlags( CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK | CAMERA_FRAME_CALLBACK_FLAG_COPY_OUT_MASK);//with copy
|
||||
|
||||
LOGD("Starting preview");
|
||||
status_t previewStatus = handler->camera->startPreview();
|
||||
|
||||
if (previewStatus != 0)
|
||||
{
|
||||
LOGE("initCameraConnect: startPreview() fails. Closing camera connection...");
|
||||
handler->closeCameraConnect();
|
||||
handler = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGD("Preview started successfully");
|
||||
}
|
||||
#else
|
||||
CameraHandler* previousCameraHandler=*ppcameraHandler;
|
||||
CameraCallback cameraCallback=previousCameraHandler->cameraCallback;
|
||||
void* userData=previousCameraHandler->userData;
|
||||
int cameraId=previousCameraHandler->cameraId;
|
||||
@@ -832,7 +970,6 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
|
||||
previousCameraHandler->closeCameraConnect();
|
||||
LOGD("CameraHandler::applyProperties(): after previousCameraHandler->closeCameraConnect");
|
||||
|
||||
|
||||
LOGD("CameraHandler::applyProperties(): before initCameraConnect");
|
||||
CameraHandler* handler=initCameraConnect(cameraCallback, cameraId, userData, &curCameraParameters);
|
||||
LOGD("CameraHandler::applyProperties(): after initCameraConnect, handler=0x%x", (int)handler);
|
||||
@@ -845,6 +982,7 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
|
||||
}
|
||||
}
|
||||
(*ppcameraHandler)=handler;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,4 +14,3 @@ double getCameraPropertyC(void* camera, int propIdx);
|
||||
void setCameraPropertyC(void* camera, int propIdx, double value);
|
||||
void applyCameraPropertiesC(void** camera);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,4 +44,4 @@ private:
|
||||
int frameHeight;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <dirent.h>
|
||||
#include <android/log.h>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <opencv2/core/version.hpp>
|
||||
@@ -12,6 +11,8 @@
|
||||
#include "camera_wrapper.h"
|
||||
#include "EngineCommon.h"
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
#undef LOG_TAG
|
||||
#undef LOGE
|
||||
#undef LOGD
|
||||
@@ -28,6 +29,11 @@
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
struct str_greater
|
||||
{
|
||||
bool operator() (const cv::String& a, const cv::String& b) { return a > b; }
|
||||
};
|
||||
|
||||
class CameraWrapperConnector
|
||||
{
|
||||
public:
|
||||
@@ -37,17 +43,17 @@ public:
|
||||
static CameraActivity::ErrorCode getProperty(void* camera, int propIdx, double* value);
|
||||
static CameraActivity::ErrorCode applyProperties(void** ppcamera);
|
||||
|
||||
static void setPathLibFolder(const std::string& path);
|
||||
static void setPathLibFolder(const cv::String& path);
|
||||
|
||||
private:
|
||||
static std::string pathLibFolder;
|
||||
static cv::String pathLibFolder;
|
||||
static bool isConnectedToLib;
|
||||
|
||||
static std::string getPathLibFolder();
|
||||
static std::string getDefaultPathLibFolder();
|
||||
static cv::String getPathLibFolder();
|
||||
static cv::String getDefaultPathLibFolder();
|
||||
static CameraActivity::ErrorCode connectToLib();
|
||||
static CameraActivity::ErrorCode getSymbolFromLib(void * libHandle, const char* symbolName, void** ppSymbol);
|
||||
static void fillListWrapperLibs(const std::string& folderPath, std::vector<std::string>& listLibs);
|
||||
static void fillListWrapperLibs(const cv::String& folderPath, std::vector<cv::String>& listLibs);
|
||||
|
||||
static InitCameraConnectC pInitCameraC;
|
||||
static CloseCameraConnectC pCloseCameraC;
|
||||
@@ -58,7 +64,7 @@ private:
|
||||
friend bool nextFrame(void* buffer, size_t bufferSize, void* userData);
|
||||
};
|
||||
|
||||
std::string CameraWrapperConnector::pathLibFolder;
|
||||
cv::String CameraWrapperConnector::pathLibFolder;
|
||||
|
||||
bool CameraWrapperConnector::isConnectedToLib = false;
|
||||
InitCameraConnectC CameraWrapperConnector::pInitCameraC = 0;
|
||||
@@ -165,7 +171,7 @@ CameraActivity::ErrorCode CameraWrapperConnector::connectToLib()
|
||||
}
|
||||
|
||||
dlerror();
|
||||
std::string folderPath = getPathLibFolder();
|
||||
cv::String folderPath = getPathLibFolder();
|
||||
if (folderPath.empty())
|
||||
{
|
||||
LOGD("Trying to find native camera in default OpenCV packages");
|
||||
@@ -174,12 +180,12 @@ CameraActivity::ErrorCode CameraWrapperConnector::connectToLib()
|
||||
|
||||
LOGD("CameraWrapperConnector::connectToLib: folderPath=%s", folderPath.c_str());
|
||||
|
||||
std::vector<std::string> listLibs;
|
||||
std::vector<cv::String> listLibs;
|
||||
fillListWrapperLibs(folderPath, listLibs);
|
||||
std::sort(listLibs.begin(), listLibs.end(), std::greater<std::string>());
|
||||
std::sort(listLibs.begin(), listLibs.end(), str_greater());
|
||||
|
||||
void * libHandle=0;
|
||||
std::string cur_path;
|
||||
cv::String cur_path;
|
||||
for(size_t i = 0; i < listLibs.size(); i++) {
|
||||
cur_path=folderPath + listLibs[i];
|
||||
LOGD("try to load library '%s'", listLibs[i].c_str());
|
||||
@@ -245,7 +251,7 @@ CameraActivity::ErrorCode CameraWrapperConnector::getSymbolFromLib(void* libHand
|
||||
return CameraActivity::NO_ERROR;
|
||||
}
|
||||
|
||||
void CameraWrapperConnector::fillListWrapperLibs(const std::string& folderPath, std::vector<std::string>& listLibs)
|
||||
void CameraWrapperConnector::fillListWrapperLibs(const cv::String& folderPath, std::vector<cv::String>& listLibs)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
@@ -264,7 +270,7 @@ void CameraWrapperConnector::fillListWrapperLibs(const std::string& folderPath,
|
||||
}
|
||||
}
|
||||
|
||||
std::string CameraWrapperConnector::getDefaultPathLibFolder()
|
||||
cv::String CameraWrapperConnector::getDefaultPathLibFolder()
|
||||
{
|
||||
#define BIN_PACKAGE_NAME(x) "org.opencv.lib_v" CVAUX_STR(CV_VERSION_EPOCH) CVAUX_STR(CV_VERSION_MAJOR) "_" x
|
||||
const char* const packageList[] = {BIN_PACKAGE_NAME("armv7a"), OPENCV_ENGINE_PACKAGE};
|
||||
@@ -287,10 +293,10 @@ std::string CameraWrapperConnector::getDefaultPathLibFolder()
|
||||
}
|
||||
}
|
||||
|
||||
return std::string();
|
||||
return cv::String();
|
||||
}
|
||||
|
||||
std::string CameraWrapperConnector::getPathLibFolder()
|
||||
cv::String CameraWrapperConnector::getPathLibFolder()
|
||||
{
|
||||
if (!pathLibFolder.empty())
|
||||
return pathLibFolder;
|
||||
@@ -358,10 +364,10 @@ std::string CameraWrapperConnector::getPathLibFolder()
|
||||
LOGE("Could not get library name and base address");
|
||||
}
|
||||
|
||||
return std::string();
|
||||
return cv::String();
|
||||
}
|
||||
|
||||
void CameraWrapperConnector::setPathLibFolder(const std::string& path)
|
||||
void CameraWrapperConnector::setPathLibFolder(const cv::String& path)
|
||||
{
|
||||
pathLibFolder=path;
|
||||
}
|
||||
@@ -428,14 +434,14 @@ void CameraActivity::applyProperties()
|
||||
int CameraActivity::getFrameWidth()
|
||||
{
|
||||
if (frameWidth <= 0)
|
||||
frameWidth = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEWIDTH);
|
||||
frameWidth = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEWIDTH);
|
||||
return frameWidth;
|
||||
}
|
||||
|
||||
int CameraActivity::getFrameHeight()
|
||||
{
|
||||
if (frameHeight <= 0)
|
||||
frameHeight = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT);
|
||||
frameHeight = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT);
|
||||
return frameHeight;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
set(the_description "Biologically inspired algorithms")
|
||||
ocv_define_module(bioinspired opencv_core OPTIONAL opencv_highgui opencv_ocl)
|
||||
@@ -0,0 +1,10 @@
|
||||
********************************************************************
|
||||
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>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -5,56 +5,96 @@ Retina : a Bio mimetic human retina model
|
||||
|
||||
Retina
|
||||
======
|
||||
.. ocv:class:: Retina : public Algorithm
|
||||
|
||||
.. ocv:class:: Retina
|
||||
**Note** : do not forget that the retina model is included in the following namespace : *cv::bioinspired*.
|
||||
|
||||
Class which provides the main controls to the Gipsa/Listic labs human retina model. Spatio-temporal filtering modelling the two main retina information channels :
|
||||
Introduction
|
||||
++++++++++++
|
||||
|
||||
* foveal vision for detailled color vision : the parvocellular pathway).
|
||||
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 :
|
||||
|
||||
* periphearal vision for sensitive transient signals detection (motion and events) : the magnocellular pathway.
|
||||
* foveal vision for detailled color vision : the parvocellular pathway.
|
||||
|
||||
**NOTE : See the Retina tutorial in the tutorial/contrib section for complementary explanations.**
|
||||
* peripheral vision for sensitive transient signals detection (motion and events) : the magnocellular pathway.
|
||||
|
||||
The retina can be settled up with various parameters, by default, the retina cancels mean luminance and enforces all details of the visual scene. In order to use your own parameters, you can use at least one time the *write(std::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(std::string fs)*. These methods update a *Retina::RetinaParameters* member structure that is described hereafter. ::
|
||||
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.
|
||||
|
||||
class Retina
|
||||
**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
|
||||
|
||||
// constructors
|
||||
Retina (Size inputSize);
|
||||
Retina (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);
|
||||
// main method for input frame processing (all use method, can also perform High Dynamic Range tone mapping)
|
||||
void run (InputArray inputImage);
|
||||
|
||||
// main method for input frame processing
|
||||
void run (const Mat &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 (Mat &retinaOutput_parvo);
|
||||
void getParvo (std::valarray< float > &retinaOutput_parvo);
|
||||
const std::valarray< float > & getParvo () const;
|
||||
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 (Mat &retinaOutput_magno);
|
||||
void getMagno (std::valarray< float > &retinaOutput_magno);
|
||||
const std::valarray< float > & getMagno () const;
|
||||
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 inputSize ();
|
||||
Size outputSize ();
|
||||
Size getInputSize ();
|
||||
Size getOutputSize ();
|
||||
|
||||
// setup methods with specific parameters specification of global xml config file loading/write
|
||||
void setup (std::string retinaParameterFile="", const bool applyDefaultSetupOnFailure=true);
|
||||
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 std::string printSetup ();
|
||||
virtual void write (std::string fs) const;
|
||||
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);
|
||||
@@ -63,11 +103,21 @@ The retina can be settled up with various parameters, by default, the retina can
|
||||
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_HighDynamicRange_Retina_toneMapping.cpp
|
||||
* An example on retina tone mapping on video input can be found at opencv_source_code/samples/cpp/OpenEXRimages_HighDynamicRange_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) 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:
|
||||
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)
|
||||
|
||||
@@ -83,19 +133,35 @@ Use : this model can be used basically for spatio-temporal video effects but als
|
||||
|
||||
* 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 :
|
||||
|
||||
* 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 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 :
|
||||
|
||||
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.
|
||||
.. [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: 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 the *retinacolor.hpp* module to discover Brice Chaix de Lavarene phD color mosaicing/demosaicing and his reference paper:
|
||||
|
||||
* 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.
|
||||
.. [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 !
|
||||
=======================
|
||||
@@ -120,32 +186,38 @@ Take a look at the provided C++ examples provided with OpenCV :
|
||||
|
||||
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 *memorial.exr* (present in the samples/cpp/ folder)
|
||||
Typical use, supposing that you have the OpenEXR image such as *memorial.exr* (present in the samples/cpp/ folder)
|
||||
|
||||
**OpenCVReleaseFolder/bin/OpenEXRimages_HighDynamicRange_Retina_toneMapping memorial.exr**
|
||||
**OpenCVReleaseFolder/bin/OpenEXRimages_HighDynamicRange_Retina_toneMapping memorial.exr [optionnal: '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
|
||||
|
||||
Retina::Retina
|
||||
++++++++++++++
|
||||
Ptr<Retina>::createRetina
|
||||
+++++++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: Retina::Retina(Size inputSize)
|
||||
.. ocv:function:: Retina::Retina(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 )
|
||||
.. 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
|
||||
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
|
||||
* 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
|
||||
: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
|
||||
@@ -178,55 +250,46 @@ Retina::clearBuffers
|
||||
Retina::getParvo
|
||||
++++++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::getParvo( Mat & retinaOutput_parvo )
|
||||
.. ocv:function:: void Retina::getParvo( std::valarray<float> & retinaOutput_parvo )
|
||||
.. ocv:function:: const std::valarray<float> & Retina::getParvo() const
|
||||
.. 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)
|
||||
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
|
||||
|
||||
* a 1D std::valarray Buffer (encoding is R1, R2, ... Rn), this output is the original retina filter model output, without any quantification or rescaling
|
||||
* 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( Mat & retinaOutput_magno )
|
||||
.. ocv:function:: void Retina::getMagno( std::valarray<float> & retinaOutput_magno )
|
||||
.. ocv:function:: const std::valarray<float> & Retina::getMagno() const
|
||||
.. 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)
|
||||
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
|
||||
|
||||
* a 1D std::valarray Buffer (encoding is R1, R2, ... Rn), this output is the original retina filter model output, without any quantification or rescaling
|
||||
* 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::getParameters
|
||||
+++++++++++++++++++++
|
||||
Retina::getInputSize
|
||||
++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: Retina::RetinaParameters Retina::getParameters()
|
||||
|
||||
Retrieve the current parameters values in a *Retina::RetinaParameters* structure
|
||||
|
||||
:return: the current parameters setup
|
||||
|
||||
Retina::inputSize
|
||||
+++++++++++++++++
|
||||
|
||||
.. ocv:function:: Size Retina::inputSize()
|
||||
.. ocv:function:: Size Retina::getInputSize()
|
||||
|
||||
Retreive retina input buffer size
|
||||
|
||||
:return: the retina input buffer size
|
||||
|
||||
Retina::outputSize
|
||||
++++++++++++++++++
|
||||
Retina::getOutputSize
|
||||
+++++++++++++++++++++
|
||||
|
||||
.. ocv:function:: Size Retina::outputSize()
|
||||
.. ocv:function:: Size Retina::getOutputSize()
|
||||
|
||||
Retreive retina output buffer size that can be different from the input if a spatial log transformation is applied
|
||||
|
||||
@@ -235,21 +298,33 @@ Retina::outputSize
|
||||
Retina::printSetup
|
||||
++++++++++++++++++
|
||||
|
||||
.. ocv:function:: const std::string Retina::printSetup()
|
||||
.. ocv:function:: const String Retina::printSetup()
|
||||
|
||||
Outputs a string showing the used parameters setup
|
||||
|
||||
:return: a string which contains formatted parameters information
|
||||
:return: a string which contains formated parameters information
|
||||
|
||||
Retina::run
|
||||
+++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::run(const Mat & inputImage)
|
||||
.. 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
|
||||
++++++++++++++++++++++++++
|
||||
|
||||
@@ -264,7 +339,7 @@ Retina::setColorSaturation
|
||||
Retina::setup
|
||||
+++++++++++++
|
||||
|
||||
.. ocv:function:: void Retina::setup(std::string retinaParameterFile = "", const bool applyDefaultSetupOnFailure = true )
|
||||
.. 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)
|
||||
|
||||
@@ -273,12 +348,12 @@ Retina::setup
|
||||
: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
|
||||
: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( std::string fs ) const
|
||||
.. ocv:function:: void Retina::write( String fs ) const
|
||||
.. ocv:function:: void Retina::write( FileStorage& fs ) const
|
||||
|
||||
Write xml/yml formated parameters information
|
||||
@@ -335,7 +410,7 @@ Retina::RetinaParameters
|
||||
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
|
||||
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
|
||||
@@ -359,3 +434,60 @@ Retina::RetinaParameters
|
||||
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>
|
||||
@@ -0,0 +1,50 @@
|
||||
/*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
|
||||
@@ -0,0 +1,48 @@
|
||||
/*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.
|
||||
// Copyright (C) 2013, OpenCV Foundation, 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*/
|
||||
|
||||
#ifdef __OPENCV_BUILD
|
||||
#error this is a compatibility header which should not be used inside the OpenCV library
|
||||
#endif
|
||||
|
||||
#include "opencv2/bioinspired.hpp"
|
||||
+58
-103
@@ -6,12 +6,12 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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
|
||||
** 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).
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -62,8 +62,8 @@
|
||||
** the use of this software, even if advised of the possibility of such damage.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __OPENCV_CONTRIB_RETINA_HPP__
|
||||
#define __OPENCV_CONTRIB_RETINA_HPP__
|
||||
#ifndef __OPENCV_BIOINSPIRED_RETINA_HPP__
|
||||
#define __OPENCV_BIOINSPIRED_RETINA_HPP__
|
||||
|
||||
/*
|
||||
* Retina.hpp
|
||||
@@ -73,22 +73,19 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support
|
||||
#include <valarray>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
enum RETINA_COLORSAMPLINGMETHOD
|
||||
{
|
||||
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 RetinaFilter;
|
||||
|
||||
/**
|
||||
* @class Retina a wrapper class which allows the Gipsa/Listic Labs model to be used.
|
||||
* @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)
|
||||
@@ -110,7 +107,7 @@ class RetinaFilter;
|
||||
* _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 {
|
||||
class CV_EXPORTS Retina : public Algorithm {
|
||||
|
||||
public:
|
||||
|
||||
@@ -119,13 +116,13 @@ public:
|
||||
struct OPLandIplParvoParameters{ // Outer Plexiform Layer (OPL) and Inner Plexiform Layer Parvocellular (IplParvo) parameters
|
||||
OPLandIplParvoParameters():colorMode(true),
|
||||
normaliseOutput(true),
|
||||
photoreceptorsLocalAdaptationSensitivity(0.7f),
|
||||
photoreceptorsTemporalConstant(0.5f),
|
||||
photoreceptorsLocalAdaptationSensitivity(0.75f),
|
||||
photoreceptorsTemporalConstant(0.9f),
|
||||
photoreceptorsSpatialConstant(0.53f),
|
||||
horizontalCellsGain(0.0f),
|
||||
hcellsTemporalConstant(1.f),
|
||||
horizontalCellsGain(0.01f),
|
||||
hcellsTemporalConstant(0.5f),
|
||||
hcellsSpatialConstant(7.f),
|
||||
ganglionCellsSensitivity(0.7f){};// default setup
|
||||
ganglionCellsSensitivity(0.75f){};// default setup
|
||||
bool colorMode, normaliseOutput;
|
||||
float photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity;
|
||||
};
|
||||
@@ -135,7 +132,7 @@ public:
|
||||
parasolCells_beta(0.f),
|
||||
parasolCells_tau(0.f),
|
||||
parasolCells_k(7.f),
|
||||
amacrinCellsTemporalCutFrequency(1.2f),
|
||||
amacrinCellsTemporalCutFrequency(2.0f),
|
||||
V0CompressionParameter(0.95f),
|
||||
localAdaptintegration_tau(0.f),
|
||||
localAdaptintegration_k(7.f){};// default setup
|
||||
@@ -146,34 +143,15 @@ public:
|
||||
struct IplMagnoParameters IplMagno;
|
||||
};
|
||||
|
||||
/**
|
||||
* Main constructor with most commun use setup : create an instance of color ready retina model
|
||||
* @param inputSize : the input frame size
|
||||
*/
|
||||
Retina(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
|
||||
*/
|
||||
Retina(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);
|
||||
|
||||
virtual ~Retina();
|
||||
|
||||
/**
|
||||
* retreive retina input buffer size
|
||||
*/
|
||||
Size inputSize();
|
||||
virtual Size getInputSize()=0;
|
||||
|
||||
/**
|
||||
* retreive retina output buffer size
|
||||
*/
|
||||
Size outputSize();
|
||||
virtual Size getOutputSize()=0;
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
@@ -182,8 +160,7 @@ public:
|
||||
* @param retinaParameterFile : the parameters filename
|
||||
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
|
||||
*/
|
||||
void setup(std::string retinaParameterFile="", const bool applyDefaultSetupOnFailure=true);
|
||||
|
||||
virtual void setup(String retinaParameterFile="", const bool applyDefaultSetupOnFailure=true)=0;
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
@@ -192,7 +169,7 @@ public:
|
||||
* @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);
|
||||
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
|
||||
@@ -201,31 +178,30 @@ public:
|
||||
* @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(RetinaParameters newParameters);
|
||||
virtual void setup(RetinaParameters newParameters)=0;
|
||||
|
||||
/**
|
||||
* @return the current parameters setup
|
||||
*/
|
||||
Retina::RetinaParameters getParameters();
|
||||
* @return the current parameters setup
|
||||
*/
|
||||
virtual struct Retina::RetinaParameters getParameters()=0;
|
||||
|
||||
/**
|
||||
* parameters setup display method
|
||||
* @return a string which contains formatted parameters information
|
||||
*/
|
||||
const std::string printSetup();
|
||||
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( std::string fs ) const;
|
||||
|
||||
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;
|
||||
virtual void write( FileStorage& fs ) const=0;
|
||||
|
||||
/**
|
||||
* setup the OPL and IPL parvo channels (see biologocal model)
|
||||
@@ -242,7 +218,7 @@ public:
|
||||
* @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);
|
||||
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
|
||||
@@ -256,41 +232,49 @@ public:
|
||||
* @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);
|
||||
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)
|
||||
*/
|
||||
void run(const Mat &inputImage);
|
||||
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
|
||||
*/
|
||||
void getParvo(Mat &retinaOutput_parvo);
|
||||
virtual void getParvo(OutputArray retinaOutput_parvo)=0;
|
||||
|
||||
/**
|
||||
* accessor of the details channel of the retina (models foveal vision)
|
||||
* @param retinaOutput_parvo : the output buffer (reallocated if necessary), this output is the original retina filter model output, without any quantification or rescaling
|
||||
* @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 getParvo(std::valarray<float> &retinaOutput_parvo);
|
||||
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
|
||||
*/
|
||||
void getMagno(Mat &retinaOutput_magno);
|
||||
virtual void getMagno(OutputArray retinaOutput_magno)=0;
|
||||
|
||||
/**
|
||||
* accessor of the motion channel of the retina (models peripheral vision)
|
||||
* @param retinaOutput_magno : the output buffer (reallocated if necessary), this output is the original retina filter model output, without any quantification or rescaling
|
||||
* @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 getMagno(std::valarray<float> &retinaOutput_magno);
|
||||
virtual void getMagnoRAW(OutputArray retinaOutput_magno)=0;
|
||||
|
||||
// original API level data accessors : get buffers addresses...
|
||||
const std::valarray<float> & getMagno() const;
|
||||
const std::valarray<float> & getParvo() const;
|
||||
// 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
|
||||
@@ -298,59 +282,30 @@ public:
|
||||
* @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);
|
||||
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)
|
||||
*/
|
||||
void clearBuffers();
|
||||
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
|
||||
*/
|
||||
void activateMovingContoursProcessing(const bool activate);
|
||||
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
|
||||
*/
|
||||
void activateContoursProcessing(const bool activate);
|
||||
|
||||
protected:
|
||||
// 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
|
||||
|
||||
/**
|
||||
* exports a valarray buffer outing from HVStools 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, Mat &outBuffer);
|
||||
|
||||
/**
|
||||
*
|
||||
* @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(const cv::Mat inputMatToConvert, std::valarray<float> &outputValarrayMatrix);
|
||||
|
||||
//! private method called by constructors, gathers their parameters and use them in a unified way
|
||||
void _init(const 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);
|
||||
|
||||
|
||||
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_CONTRIB_RETINA_HPP__ */
|
||||
|
||||
}
|
||||
#endif /* __OPENCV_BIOINSPIRED_RETINA_HPP__ */
|
||||
@@ -0,0 +1,121 @@
|
||||
|
||||
/*#******************************************************************************
|
||||
** 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__ */
|
||||
+6
-4
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -72,7 +72,8 @@
|
||||
|
||||
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/
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
@@ -883,4 +884,5 @@ void BasicRetinaFilter::_verticalAnticausalFilter_Irregular_multGain(float *outp
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
+7
-6
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -113,6 +113,8 @@
|
||||
//#define __BASIC_RETINA_ELEMENT_DEBUG
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
class BasicRetinaFilter
|
||||
{
|
||||
@@ -287,7 +289,7 @@ namespace cv
|
||||
* @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;};
|
||||
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
|
||||
@@ -650,7 +652,6 @@ namespace cv
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
#endif
|
||||
|
||||
|
||||
+6
-4
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -72,7 +72,8 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
namespace bioinspired
|
||||
{
|
||||
// constructor
|
||||
ImageLogPolProjection::ImageLogPolProjection(const unsigned int nbRows, const unsigned int nbColumns, const PROJECTIONTYPE projection, const bool colorModeCapable)
|
||||
:BasicRetinaFilter(nbRows, nbColumns),
|
||||
@@ -446,4 +447,5 @@ std::valarray<float> &ImageLogPolProjection::runProjection(const std::valarray<f
|
||||
return _sampledFrame;
|
||||
}
|
||||
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
+6
-3
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -103,6 +103,8 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
|
||||
class ImageLogPolProjection:public BasicRetinaFilter
|
||||
{
|
||||
@@ -236,5 +238,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
#endif /*IMAGELOGPOLPROJECTION_H_*/
|
||||
+6
-5
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -72,6 +72,8 @@
|
||||
|
||||
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),
|
||||
@@ -206,6 +208,5 @@ const std::valarray<float> &MagnoRetinaFilter::runFilter(const std::valarray<flo
|
||||
|
||||
return (*_magnoYOutput);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
+6
-6
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -99,7 +99,8 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
namespace bioinspired
|
||||
{
|
||||
class MagnoRetinaFilter: public BasicRetinaFilter
|
||||
{
|
||||
public:
|
||||
@@ -238,8 +239,7 @@ namespace cv
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
|
||||
#endif /*MagnoRetinaFilter_H_*/
|
||||
|
||||
|
||||
@@ -0,0 +1,779 @@
|
||||
/*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;
|
||||
}
|
||||
+6
-4
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -73,6 +73,8 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
//////////////////////////////////////////////////////////
|
||||
// OPL RETINA FILTER
|
||||
//////////////////////////////////////////////////////////
|
||||
@@ -227,5 +229,5 @@ void ParvoRetinaFilter::_OPL_OnOffWaysComputing() // WARNING : this method requi
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
+6
-4
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -103,6 +103,8 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
//retina classes that derivate from the Basic Retrina class
|
||||
class ParvoRetinaFilter: public BasicRetinaFilter
|
||||
{
|
||||
@@ -256,6 +258,6 @@ private:
|
||||
#endif
|
||||
|
||||
};
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*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 <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
|
||||
@@ -0,0 +1,743 @@
|
||||
/*#******************************************************************************
|
||||
** 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(_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(_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( _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
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,634 @@
|
||||
/*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__ */
|
||||
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -73,14 +73,15 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
namespace bioinspired
|
||||
{
|
||||
// init static values
|
||||
static float _LMStoACr1Cr2[]={1.0, 1.0, 0.0, 1.0, -1.0, 0.0, -0.5, -0.5, 1.0};
|
||||
//static double _ACr1Cr2toLMS[]={0.5, 0.5, 0.0, 0.5, -0.5, 0.0, 0.5, 0.0, 1.0};
|
||||
static float _LMStoLab[]={0.5774f, 0.5774f, 0.5774f, 0.4082f, 0.4082f, -0.8165f, 0.7071f, -0.7071f, 0.f};
|
||||
|
||||
// constructor/desctructor
|
||||
RetinaColor::RetinaColor(const unsigned int NBrows, const unsigned int NBcolumns, const RETINA_COLORSAMPLINGMETHOD samplingMethod)
|
||||
RetinaColor::RetinaColor(const unsigned int NBrows, const unsigned int NBcolumns, const int samplingMethod)
|
||||
:BasicRetinaFilter(NBrows, NBcolumns, 3),
|
||||
_colorSampling(NBrows*NBcolumns),
|
||||
_RGBmosaic(NBrows*NBcolumns*3),
|
||||
@@ -338,8 +339,11 @@ void RetinaColor::runColorDemultiplexing(const std::valarray<float> &multiplexed
|
||||
}
|
||||
|
||||
// compute the gradient of the luminance
|
||||
#ifdef MAKE_PARALLEL // call the TemplateBuffer TBB clipping method
|
||||
cv::parallel_for_(cv::Range(2,_filterOutput.getNBrows()-2), Parallel_computeGradient(_filterOutput.getNBcolumns(), _filterOutput.getNBrows(), &(*_luminance)[0], &_imageGradient[0]));
|
||||
#else
|
||||
_computeGradient(&(*_luminance)[0]);
|
||||
|
||||
#endif
|
||||
// adaptively filter the submosaics to get the adaptive densities, here the buffer _chrominance is used as a temp buffer
|
||||
_adaptiveSpatialLPfilter(&_RGBmosaic[0], &_chrominance[0]);
|
||||
_adaptiveSpatialLPfilter(&_RGBmosaic[0]+_filterOutput.getNBpixels(), &_chrominance[0]+_filterOutput.getNBpixels());
|
||||
@@ -717,4 +721,5 @@ void RetinaColor::_applyImageColorSpaceConversion(const std::valarray<float> &in
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -85,7 +85,8 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
namespace bioinspired
|
||||
{
|
||||
class RetinaColor: public BasicRetinaFilter
|
||||
{
|
||||
public:
|
||||
@@ -99,7 +100,7 @@ namespace cv
|
||||
* @param NBcolumns: number of columns of the input image
|
||||
* @param samplingMethod: the chosen color sampling method
|
||||
*/
|
||||
RetinaColor(const unsigned int NBrows, const unsigned int NBcolumns, const RETINA_COLORSAMPLINGMETHOD samplingMethod=RETINA_COLOR_DIAGONAL);
|
||||
RetinaColor(const unsigned int NBrows, const unsigned int NBcolumns, const int samplingMethod=RETINA_COLOR_BAYER);
|
||||
|
||||
/**
|
||||
* standard destructor
|
||||
@@ -219,7 +220,7 @@ namespace cv
|
||||
protected:
|
||||
|
||||
// private functions
|
||||
RETINA_COLORSAMPLINGMETHOD _samplingMethod;
|
||||
int _samplingMethod;
|
||||
bool _saturateColors;
|
||||
float _colorSaturationValue;
|
||||
// links to parent buffers (more convienient names
|
||||
@@ -333,10 +334,56 @@ namespace cv
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Parallel_computeGradient: public cv::ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
float *imageGradient;
|
||||
const float *luminance;
|
||||
unsigned int nbColumns, doubleNbColumns, nbRows, nbPixels;
|
||||
public:
|
||||
Parallel_computeGradient(const unsigned int nbCols, const unsigned int nbRws, const float *lum, float *imageGrad)
|
||||
:imageGradient(imageGrad), luminance(lum), nbColumns(nbCols), doubleNbColumns(2*nbCols), nbRows(nbRws), nbPixels(nbRws*nbCols){};
|
||||
|
||||
virtual void operator()( const Range& r ) const {
|
||||
for (int idLine=r.start;idLine!=r.end;++idLine)
|
||||
{
|
||||
for (unsigned int idColumn=2;idColumn<nbColumns-2;++idColumn)
|
||||
{
|
||||
const unsigned int pixelIndex=idColumn+nbColumns*idLine;
|
||||
|
||||
// horizontal and vertical local gradients
|
||||
const float verticalGrad=fabs(luminance[pixelIndex+nbColumns]-luminance[pixelIndex-nbColumns]);
|
||||
const float horizontalGrad=fabs(luminance[pixelIndex+1]-luminance[pixelIndex-1]);
|
||||
|
||||
// neighborhood horizontal and vertical gradients
|
||||
const float verticalGrad_p=fabs(luminance[pixelIndex]-luminance[pixelIndex-doubleNbColumns]);
|
||||
const float horizontalGrad_p=fabs(luminance[pixelIndex]-luminance[pixelIndex-2]);
|
||||
const float verticalGrad_n=fabs(luminance[pixelIndex+doubleNbColumns]-luminance[pixelIndex]);
|
||||
const float horizontalGrad_n=fabs(luminance[pixelIndex+2]-luminance[pixelIndex]);
|
||||
|
||||
const float horizontalGradient=0.5f*horizontalGrad+0.25f*(horizontalGrad_p+horizontalGrad_n);
|
||||
const float verticalGradient=0.5f*verticalGrad+0.25f*(verticalGrad_p+verticalGrad_n);
|
||||
|
||||
// compare local gradient means and fill the appropriate filtering coefficient value that will be used in adaptative filters
|
||||
if (horizontalGradient<verticalGradient)
|
||||
{
|
||||
imageGradient[pixelIndex+nbPixels]=0.06f;
|
||||
imageGradient[pixelIndex]=0.57f;
|
||||
}
|
||||
else
|
||||
{
|
||||
imageGradient[pixelIndex+nbPixels]=0.57f;
|
||||
imageGradient[pixelIndex]=0.06f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
};
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
|
||||
#endif /*RETINACOLOR_HPP_*/
|
||||
|
||||
|
||||
@@ -0,0 +1,316 @@
|
||||
|
||||
/*#******************************************************************************
|
||||
** 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* retinafasttonemapping.cpp
|
||||
*
|
||||
* Created on: May 26, 2013
|
||||
* Author: Alexandre Benoit
|
||||
*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "basicretinafilter.hpp"
|
||||
#include "retinacolor.hpp"
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
#include <valarray>
|
||||
|
||||
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 RetinaFastToneMappingImpl : public RetinaFastToneMapping
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* constructor
|
||||
* @param imageInput: the size of the images to process
|
||||
*/
|
||||
RetinaFastToneMappingImpl(Size imageInput)
|
||||
{
|
||||
unsigned int nbPixels=imageInput.height*imageInput.width;
|
||||
|
||||
// basic error check
|
||||
if (nbPixels <= 0)
|
||||
throw cv::Exception(-1, "Bad retina size setup : size height and with must be superior to zero", "RetinaImpl::setup", "retinafasttonemapping.cpp", 0);
|
||||
|
||||
// resize buffers
|
||||
_inputBuffer.resize(nbPixels*3); // buffer supports gray images but also 3 channels color buffers... (larger is better...)
|
||||
_imageOutput.resize(nbPixels*3);
|
||||
_temp2.resize(nbPixels);
|
||||
// allocate the main filter with 2 setup sets properties (one for each low pass filter
|
||||
_multiuseFilter = makePtr<BasicRetinaFilter>(imageInput.height, imageInput.width, 2);
|
||||
// allocate the color manager (multiplexer/demultiplexer
|
||||
_colorEngine = makePtr<RetinaColor>(imageInput.height, imageInput.width);
|
||||
// setup filter behaviors with default values
|
||||
setup();
|
||||
}
|
||||
|
||||
/**
|
||||
* basic destructor
|
||||
*/
|
||||
virtual ~RetinaFastToneMappingImpl(){};
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// first convert input image to the compatible format :
|
||||
const bool colorMode = _convertCvMat2ValarrayBuffer(inputImage.getMat(), _inputBuffer);
|
||||
|
||||
// process tone mapping
|
||||
if (colorMode)
|
||||
{
|
||||
_runRGBToneMapping(_inputBuffer, _imageOutput, true);
|
||||
_convertValarrayBuffer2cvMat(_imageOutput, _multiuseFilter->getNBrows(), _multiuseFilter->getNBcolumns(), true, outputToneMappedImage);
|
||||
}else
|
||||
{
|
||||
_runGrayToneMapping(_inputBuffer, _imageOutput);
|
||||
_convertValarrayBuffer2cvMat(_imageOutput, _multiuseFilter->getNBrows(), _multiuseFilter->getNBcolumns(), false, outputToneMappedImage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// setup the spatio-temporal properties of each filter
|
||||
_meanLuminanceModulatorK = meanLuminanceModulatorK;
|
||||
_multiuseFilter->setV0CompressionParameter(1.f, 255.f, 128.f);
|
||||
_multiuseFilter->setLPfilterParameters(0.f, 0.f, photoreceptorsNeighborhoodRadius, 1);
|
||||
_multiuseFilter->setLPfilterParameters(0.f, 0.f, ganglioncellsNeighborhoodRadius, 2);
|
||||
}
|
||||
|
||||
private:
|
||||
// a filter able to perform local adaptation and low pass spatio-temporal filtering
|
||||
cv::Ptr <BasicRetinaFilter> _multiuseFilter;
|
||||
cv::Ptr <RetinaColor> _colorEngine;
|
||||
|
||||
//!< buffer used to convert input cv::Mat to internal retina buffers format (valarrays)
|
||||
std::valarray<float> _inputBuffer;
|
||||
std::valarray<float> _imageOutput;
|
||||
std::valarray<float> _temp2;
|
||||
float _meanLuminanceModulatorK;
|
||||
|
||||
|
||||
void _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 _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
|
||||
}
|
||||
|
||||
|
||||
// run the initilized retina filter in order to perform gray image tone mapping, after this call all retina outputs are updated
|
||||
void _runGrayToneMapping(const std::valarray<float> &grayImageInput, std::valarray<float> &grayImageOutput)
|
||||
{
|
||||
// apply tone mapping on the multiplexed image
|
||||
// -> photoreceptors local adaptation (large area adaptation)
|
||||
_multiuseFilter->runFilter_LPfilter(grayImageInput, grayImageOutput, 0); // compute low pass filtering modeling the horizontal cells filtering to acess local luminance
|
||||
_multiuseFilter->setV0CompressionParameterToneMapping(1.f, grayImageOutput.max(), _meanLuminanceModulatorK*grayImageOutput.sum()/(float)_multiuseFilter->getNBpixels());
|
||||
_multiuseFilter->runFilter_LocalAdapdation(grayImageInput, grayImageOutput, _temp2); // adapt contrast to local luminance
|
||||
|
||||
// -> ganglion cells local adaptation (short area adaptation)
|
||||
_multiuseFilter->runFilter_LPfilter(_temp2, grayImageOutput, 1); // compute low pass filtering (high cut frequency (remove spatio-temporal noise)
|
||||
_multiuseFilter->setV0CompressionParameterToneMapping(1.f, _temp2.max(), _meanLuminanceModulatorK*grayImageOutput.sum()/(float)_multiuseFilter->getNBpixels());
|
||||
_multiuseFilter->runFilter_LocalAdapdation(_temp2, grayImageOutput, grayImageOutput); // adapt contrast to local luminance
|
||||
|
||||
}
|
||||
|
||||
// run the initilized retina filter in order to perform color tone mapping, after this call all retina outputs are updated
|
||||
void _runRGBToneMapping(const std::valarray<float> &RGBimageInput, std::valarray<float> &RGBimageOutput, const bool useAdaptiveFiltering)
|
||||
{
|
||||
// multiplex the image with the color sampling method specified in the constructor
|
||||
_colorEngine->runColorMultiplexing(RGBimageInput);
|
||||
|
||||
// apply tone mapping on the multiplexed image
|
||||
_runGrayToneMapping(_colorEngine->getMultiplexedFrame(), RGBimageOutput);
|
||||
|
||||
// demultiplex tone maped image
|
||||
_colorEngine->runColorDemultiplexing(RGBimageOutput, useAdaptiveFiltering, _multiuseFilter->getMaxInputValue());//_ColorEngine->getMultiplexedFrame());//_ParvoRetinaFilter->getPhotoreceptorsLPfilteringOutput());
|
||||
|
||||
// rescaling result between 0 and 255
|
||||
_colorEngine->normalizeRGBOutput_0_maxOutputValue(255.0);
|
||||
|
||||
// return the result
|
||||
RGBimageOutput=_colorEngine->getDemultiplexedColorFrame();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CV_EXPORTS Ptr<RetinaFastToneMapping> createRetinaFastToneMapping(Size inputSize)
|
||||
{
|
||||
return makePtr<RetinaFastToneMappingImpl>(inputSize);
|
||||
}
|
||||
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -72,9 +72,11 @@
|
||||
#include <cmath>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
// standard constructor without any log sampling of the input frame
|
||||
RetinaFilter::RetinaFilter(const unsigned int sizeRows, const unsigned int sizeColumns, const bool colorMode, const RETINA_COLORSAMPLINGMETHOD samplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
RetinaFilter::RetinaFilter(const unsigned int sizeRows, const unsigned int sizeColumns, const bool colorMode, const int samplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
:
|
||||
_retinaParvoMagnoMappedFrame(0),
|
||||
_retinaParvoMagnoMapCoefTable(0),
|
||||
@@ -375,21 +377,15 @@ namespace cv
|
||||
// apply tone mapping on the multiplexed image
|
||||
// -> photoreceptors local adaptation (large area adaptation)
|
||||
_photoreceptorsPrefilter.runFilter_LPfilter(grayImageInput, grayImageOutput, 2); // compute low pass filtering modeling the horizontal cells filtering to acess local luminance
|
||||
_photoreceptorsPrefilter.setV0CompressionParameterToneMapping(PhotoreceptorsCompression, grayImageOutput.sum()/(float)_photoreceptorsPrefilter.getNBpixels());
|
||||
_photoreceptorsPrefilter.setV0CompressionParameterToneMapping(1.f-PhotoreceptorsCompression, grayImageOutput.max(), 1.f*grayImageOutput.sum()/(float)_photoreceptorsPrefilter.getNBpixels());
|
||||
_photoreceptorsPrefilter.runFilter_LocalAdapdation(grayImageInput, grayImageOutput, temp2); // adapt contrast to local luminance
|
||||
|
||||
// high pass filter
|
||||
//_spatiotemporalLPfilter(_localBuffer, _filterOutput, 2); // compute low pass filtering (high cut frequency (remove spatio-temporal noise)
|
||||
|
||||
//for (unsigned int i=0;i<_NBpixels;++i)
|
||||
// _localBuffer[i]-= _filterOutput[i]/2.0;
|
||||
|
||||
// -> ganglion cells local adaptation (short area adaptation)
|
||||
_photoreceptorsPrefilter.runFilter_LPfilter(temp2, grayImageOutput, 1); // compute low pass filtering (high cut frequency (remove spatio-temporal noise)
|
||||
_photoreceptorsPrefilter.setV0CompressionParameterToneMapping(ganglionCellsCompression, temp2.max(), temp2.sum()/(float)_photoreceptorsPrefilter.getNBpixels());
|
||||
_photoreceptorsPrefilter.setV0CompressionParameterToneMapping(1.f-ganglionCellsCompression, temp2.max(), 1.f*temp2.sum()/(float)_photoreceptorsPrefilter.getNBpixels());
|
||||
_photoreceptorsPrefilter.runFilter_LocalAdapdation(temp2, grayImageOutput, grayImageOutput); // adapt contrast to local luminance
|
||||
|
||||
}
|
||||
|
||||
// run the initilized retina filter in order to perform color tone mapping, after this call all retina outputs are updated
|
||||
void RetinaFilter::runRGBToneMapping(const std::valarray<float> &RGBimageInput, std::valarray<float> &RGBimageOutput, const bool useAdaptiveFiltering, const float PhotoreceptorsCompression, const float ganglionCellsCompression)
|
||||
{
|
||||
@@ -526,4 +522,5 @@ namespace cv
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -110,7 +110,8 @@
|
||||
//#define __RETINADEBUG // define RETINADEBUG to display debug data
|
||||
namespace cv
|
||||
{
|
||||
|
||||
namespace bioinspired
|
||||
{
|
||||
// retina class that process the 3 outputs of the retina filtering stages
|
||||
class RetinaFilter//: public BasicRetinaFilter
|
||||
{
|
||||
@@ -126,7 +127,7 @@ public:
|
||||
* @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
|
||||
*/
|
||||
RetinaFilter(const unsigned int sizeRows, const unsigned int sizeColumns, const bool colorMode=false, const RETINA_COLORSAMPLINGMETHOD samplingMethod=RETINA_COLOR_BAYER, const bool useRetinaLogSampling=false, const double reductionFactor=1.0, const double samplingStrenght=10.0);
|
||||
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);
|
||||
|
||||
/**
|
||||
* standard destructor
|
||||
@@ -541,9 +542,7 @@ private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
|
||||
#endif /*RETINACLASSES_H_*/
|
||||
|
||||
|
||||
|
||||
|
||||
+10
-10
@@ -6,7 +6,7 @@
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : 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.
|
||||
** 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)
|
||||
@@ -32,7 +32,7 @@
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** 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.
|
||||
@@ -71,6 +71,12 @@
|
||||
#include <cmath>
|
||||
|
||||
|
||||
//#define __TEMPLATEBUFFERDEBUG //define TEMPLATEBUFFERDEBUG in order to display debug information
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace bioinspired
|
||||
{
|
||||
//// If a parallelization method is available then, you should define MAKE_PARALLEL, in the other case, the classical serial code will be used
|
||||
#define MAKE_PARALLEL
|
||||
// ==> then include required includes
|
||||
@@ -101,10 +107,6 @@ public:
|
||||
};
|
||||
#endif
|
||||
|
||||
//#define __TEMPLATEBUFFERDEBUG //define TEMPLATEBUFFERDEBUG in order to display debug information
|
||||
|
||||
namespace cv
|
||||
{
|
||||
/**
|
||||
* @class TemplateBuffer
|
||||
* @brief this class is a simple template memory buffer which contains basic functions to get information on or normalize the buffer content
|
||||
@@ -548,8 +550,6 @@ namespace cv
|
||||
return std::fabs(x);
|
||||
}
|
||||
|
||||
}
|
||||
}// end of namespace bioinspired
|
||||
}// end of namespace cv
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
CV_TEST_MAIN("cv")
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations"
|
||||
# if defined __clang__ || defined __APPLE__
|
||||
# pragma GCC diagnostic ignored "-Wmissing-prototypes"
|
||||
# pragma GCC diagnostic ignored "-Wextra"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/bioinspired.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,144 @@
|
||||
/*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*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#include "opencv2/bioinspired.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
#if defined(HAVE_OPENCV_OCL)
|
||||
|
||||
#include "opencv2/ocl.hpp"
|
||||
#define RETINA_ITERATIONS 5
|
||||
|
||||
static double checkNear(const cv::Mat &m1, const cv::Mat &m2)
|
||||
{
|
||||
return cv::norm(m1, m2, cv::NORM_INF);
|
||||
}
|
||||
|
||||
#define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > >
|
||||
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
|
||||
|
||||
static int oclInit = false;
|
||||
|
||||
PARAM_TEST_CASE(Retina_OCL, bool, int, bool, double, double)
|
||||
{
|
||||
bool colorMode;
|
||||
int colorSamplingMethod;
|
||||
bool useLogSampling;
|
||||
double reductionFactor;
|
||||
double samplingStrength;
|
||||
|
||||
std::vector<cv::ocl::Info> infos;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
colorMode = GET_PARAM(0);
|
||||
colorSamplingMethod = GET_PARAM(1);
|
||||
useLogSampling = GET_PARAM(2);
|
||||
reductionFactor = GET_PARAM(3);
|
||||
samplingStrength = GET_PARAM(4);
|
||||
|
||||
if(!oclInit)
|
||||
{
|
||||
cv::ocl::getDevice(infos);
|
||||
std::cout << "Device name:" << infos[0].DeviceName[0] << std::endl;
|
||||
oclInit = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(Retina_OCL, Accuracy)
|
||||
{
|
||||
using namespace cv;
|
||||
Mat input = imread(cvtest::TS::ptr()->get_data_path() + "shared/lena.png", colorMode);
|
||||
CV_Assert(!input.empty());
|
||||
ocl::oclMat ocl_input(input);
|
||||
|
||||
Ptr<bioinspired::Retina> ocl_retina = bioinspired::createRetina_OCL(
|
||||
input.size(),
|
||||
colorMode,
|
||||
colorSamplingMethod,
|
||||
useLogSampling,
|
||||
reductionFactor,
|
||||
samplingStrength);
|
||||
|
||||
Ptr<bioinspired::Retina> gold_retina = bioinspired::createRetina(
|
||||
input.size(),
|
||||
colorMode,
|
||||
colorSamplingMethod,
|
||||
useLogSampling,
|
||||
reductionFactor,
|
||||
samplingStrength);
|
||||
|
||||
Mat gold_parvo;
|
||||
Mat gold_magno;
|
||||
ocl::oclMat ocl_parvo;
|
||||
ocl::oclMat ocl_magno;
|
||||
|
||||
for(int i = 0; i < RETINA_ITERATIONS; i ++)
|
||||
{
|
||||
ocl_retina->run(ocl_input);
|
||||
gold_retina->run(input);
|
||||
|
||||
gold_retina->getParvo(gold_parvo);
|
||||
gold_retina->getMagno(gold_magno);
|
||||
|
||||
ocl_retina->getParvo(ocl_parvo);
|
||||
ocl_retina->getMagno(ocl_magno);
|
||||
|
||||
EXPECT_LE(checkNear(gold_parvo, (Mat)ocl_parvo), 1.0);
|
||||
EXPECT_LE(checkNear(gold_magno, (Mat)ocl_magno), 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Contrib, Retina_OCL, testing::Combine(
|
||||
testing::Values(false, true),
|
||||
testing::Values((int)cv::bioinspired::RETINA_COLOR_BAYER),
|
||||
testing::Values(false/*,true*/),
|
||||
testing::Values(1.0, 0.5),
|
||||
testing::Values(10.0, 5.0)));
|
||||
#endif
|
||||
@@ -6,4 +6,3 @@ calib3d. Camera Calibration and 3D Reconstruction
|
||||
:maxdepth: 2
|
||||
|
||||
camera_calibration_and_3d_reconstruction
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ is extended as:
|
||||
:math:`s_1`,
|
||||
:math:`s_2`,
|
||||
:math:`s_3`, and
|
||||
:math:`s_4`, are the thin prism distortion coefficients.
|
||||
:math:`s_4`, are the thin prism distortion coefficients.
|
||||
Higher-order coefficients are not considered in OpenCV. In the functions below the coefficients are passed or returned as
|
||||
|
||||
.. math::
|
||||
@@ -109,20 +109,27 @@ The functions below use the above model to do the following:
|
||||
|
||||
* Estimate the relative position and orientation of the stereo camera "heads" and compute the *rectification* transformation that makes the camera optical axes parallel.
|
||||
|
||||
.. note::
|
||||
|
||||
* A calibration sample for 3 cameras in horizontal position can be found at opencv_source_code/samples/cpp/3calibration.cpp
|
||||
* A calibration sample based on a sequence of images can be found at opencv_source_code/samples/cpp/calibration.cpp
|
||||
* A calibration sample in order to do 3D reconstruction can be found at opencv_source_code/samples/cpp/build3dmodel.cpp
|
||||
* A calibration sample of an artificially generated camera and chessboard patterns can be found at opencv_source_code/samples/cpp/calibration_artificial.cpp
|
||||
* A calibration example on stereo calibration can be found at opencv_source_code/samples/cpp/stereo_calib.cpp
|
||||
* A calibration example on stereo matching can be found at opencv_source_code/samples/cpp/stereo_match.cpp
|
||||
|
||||
* (Python) A camera calibration sample can be found at opencv_source_code/samples/python2/calibrate.py
|
||||
|
||||
calibrateCamera
|
||||
---------------
|
||||
Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern.
|
||||
|
||||
.. ocv:function:: double calibrateCamera( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags=0, TermCriteria criteria=TermCriteria( TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON) )
|
||||
.. ocv:function:: double calibrateCamera( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags=0, TermCriteria criteria=TermCriteria( TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) )
|
||||
|
||||
.. ocv:pyfunction:: cv2.calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs[, rvecs[, tvecs[, flags[, criteria]]]]) -> retval, cameraMatrix, distCoeffs, rvecs, tvecs
|
||||
|
||||
.. ocv:cfunction:: double cvCalibrateCamera2( const CvMat* object_points, const CvMat* image_points, const CvMat* point_counts, CvSize image_size, CvMat* camera_matrix, CvMat* distortion_coeffs, CvMat* rotation_vectors=NULL, CvMat* translation_vectors=NULL, int flags=0, CvTermCriteria term_crit=cvTermCriteria( CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON) )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.CalibrateCamera2(objectPoints, imagePoints, pointCounts, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs, flags=0)-> None
|
||||
|
||||
:param objectPoints: In the new interface it is a vector of vectors of calibration pattern points in the calibration pattern coordinate space. The outer vector contains as many elements as the number of the pattern views. If the same calibration pattern is shown in each view and it is fully visible, all the vectors will be the same. Although, it is possible to use partially occluded patterns, or even different patterns in different views. Then, the vectors will be different. The points are 3D, but since they are in a pattern coordinate system, then, if the rig is planar, it may make sense to put the model to a XY coordinate plane so that Z-coordinate of each input object point is 0.
|
||||
|
||||
In the old interface all the vectors of object points from different views are concatenated together.
|
||||
@@ -156,9 +163,9 @@ Finds the camera intrinsic and extrinsic parameters from several views of a cali
|
||||
* **CV_CALIB_FIX_K1,...,CV_CALIB_FIX_K6** The corresponding radial distortion coefficient is not changed during the optimization. If ``CV_CALIB_USE_INTRINSIC_GUESS`` is set, the coefficient from the supplied ``distCoeffs`` matrix is used. Otherwise, it is set to 0.
|
||||
|
||||
* **CV_CALIB_RATIONAL_MODEL** Coefficients k4, k5, and k6 are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the rational model and return 8 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients.
|
||||
|
||||
|
||||
* **CALIB_THIN_PRISM_MODEL** Coefficients s1, s2, s3 and s4 are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the thin prism model and return 12 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients.
|
||||
|
||||
|
||||
* **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during the optimization. If ``CV_CALIB_USE_INTRINSIC_GUESS`` is set, the coefficient from the supplied ``distCoeffs`` matrix is used. Otherwise, it is set to 0.
|
||||
|
||||
|
||||
@@ -279,7 +286,7 @@ For points in an image of a stereo pair, computes the corresponding epilines in
|
||||
|
||||
.. ocv:cfunction:: void cvComputeCorrespondEpilines( const CvMat* points, int which_image, const CvMat* fundamental_matrix, CvMat* correspondent_lines )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.ComputeCorrespondEpilines(points, whichImage, F, lines) -> None
|
||||
.. ocv:pyfunction:: cv2.computeCorrespondEpilines(points, whichImage, F[, lines]) -> lines
|
||||
|
||||
:param points: Input points. :math:`N \times 1` or :math:`1 \times N` matrix of type ``CV_32FC2`` or ``vector<Point2f>`` .
|
||||
|
||||
@@ -354,7 +361,6 @@ Converts points to/from homogeneous coordinates.
|
||||
.. ocv:function:: void convertPointsHomogeneous( InputArray src, OutputArray dst )
|
||||
|
||||
.. ocv:cfunction:: void cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst )
|
||||
.. ocv:pyoldfunction:: cv.ConvertPointsHomogeneous(src, dst) -> None
|
||||
|
||||
:param src: Input array or vector of 2D, 3D, or 4D points.
|
||||
|
||||
@@ -400,8 +406,6 @@ Decomposes a projection matrix into a rotation matrix and a camera matrix.
|
||||
|
||||
.. ocv:cfunction:: void cvDecomposeProjectionMatrix( const CvMat * projMatr, CvMat * calibMatr, CvMat * rotMatr, CvMat * posVect, CvMat * rotMatrX=NULL, CvMat * rotMatrY=NULL, CvMat * rotMatrZ=NULL, CvPoint3D64f * eulerAngles=NULL )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.DecomposeProjectionMatrix(projMatrix, cameraMatrix, rotMatrix, transVect, rotMatrX=None, rotMatrY=None, rotMatrZ=None) -> eulerAngles
|
||||
|
||||
:param projMatrix: 3x4 input projection matrix P.
|
||||
|
||||
:param cameraMatrix: Output 3x3 camera matrix K.
|
||||
@@ -436,7 +440,6 @@ Renders the detected chessboard corners.
|
||||
.. ocv:pyfunction:: cv2.drawChessboardCorners(image, patternSize, corners, patternWasFound) -> image
|
||||
|
||||
.. ocv:cfunction:: void cvDrawChessboardCorners( CvArr* image, CvSize pattern_size, CvPoint2D32f* corners, int count, int pattern_was_found )
|
||||
.. ocv:pyoldfunction:: cv.DrawChessboardCorners(image, patternSize, corners, patternWasFound)-> None
|
||||
|
||||
:param image: Destination image. It must be an 8-bit color image.
|
||||
|
||||
@@ -454,12 +457,11 @@ findChessboardCorners
|
||||
-------------------------
|
||||
Finds the positions of internal corners of the chessboard.
|
||||
|
||||
.. ocv:function:: bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners, int flags=CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE )
|
||||
.. ocv:function:: bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners, int flags=CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE )
|
||||
|
||||
.. ocv:pyfunction:: cv2.findChessboardCorners(image, patternSize[, corners[, flags]]) -> retval, corners
|
||||
|
||||
.. ocv:cfunction:: int cvFindChessboardCorners( const void* image, CvSize pattern_size, CvPoint2D32f* corners, int* corner_count=NULL, int flags=CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE )
|
||||
.. ocv:pyoldfunction:: cv.FindChessboardCorners(image, patternSize, flags=CV_CALIB_CB_ADAPTIVE_THRESH) -> corners
|
||||
|
||||
:param image: Source chessboard view. It must be an 8-bit grayscale or color image.
|
||||
|
||||
@@ -513,9 +515,9 @@ findCirclesGrid
|
||||
-------------------
|
||||
Finds centers in the grid of circles.
|
||||
|
||||
.. ocv:function:: bool findCirclesGrid( InputArray image, Size patternSize, OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID, const Ptr<FeatureDetector> &blobDetector = new SimpleBlobDetector() )
|
||||
.. ocv:function:: bool findCirclesGrid( InputArray image, Size patternSize, OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID, const Ptr<FeatureDetector> &blobDetector = makePtr<SimpleBlobDetector>() )
|
||||
|
||||
.. ocv:pyfunction:: cv2.findCirclesGridDefault(image, patternSize[, centers[, flags]]) -> retval, centers
|
||||
.. ocv:pyfunction:: cv2.findCirclesGrid(image, patternSize[, centers[, flags[, blobDetector]]]) -> retval, centers
|
||||
|
||||
:param image: grid view of input circles; it must be an 8-bit grayscale or color image.
|
||||
|
||||
@@ -564,8 +566,6 @@ Finds an object pose from 3D-2D point correspondences.
|
||||
|
||||
.. ocv:cfunction:: void cvFindExtrinsicCameraParams2( const CvMat* object_points, const CvMat* image_points, const CvMat* camera_matrix, const CvMat* distortion_coeffs, CvMat* rotation_vector, CvMat* translation_vector, int use_extrinsic_guess=0 )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.FindExtrinsicCameraParams2(objectPoints, imagePoints, cameraMatrix, distCoeffs, rvec, tvec, useExtrinsicGuess=0 ) -> None
|
||||
|
||||
:param objectPoints: Array of object points in the object coordinate space, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel, where N is the number of points. ``vector<Point3f>`` can be also passed here.
|
||||
|
||||
:param imagePoints: Array of corresponding image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, where N is the number of points. ``vector<Point2f>`` can be also passed here.
|
||||
@@ -588,7 +588,9 @@ Finds an object pose from 3D-2D point correspondences.
|
||||
|
||||
The function estimates the object pose given a set of object points, their corresponding image projections, as well as the camera matrix and the distortion coefficients.
|
||||
|
||||
.. note::
|
||||
|
||||
* An example of how to use solvePNP for planar augmented reality can be found at opencv_source_code/samples/python2/plane_ar.py
|
||||
|
||||
solvePnPRansac
|
||||
------------------
|
||||
@@ -636,7 +638,6 @@ Calculates a fundamental matrix from the corresponding points in two images.
|
||||
.. ocv:pyfunction:: cv2.findFundamentalMat(points1, points2[, method[, param1[, param2[, mask]]]]) -> retval, mask
|
||||
|
||||
.. ocv:cfunction:: int cvFindFundamentalMat( const CvMat* points1, const CvMat* points2, CvMat* fundamental_matrix, int method=CV_FM_RANSAC, double param1=3., double param2=0.99, CvMat* status=NULL )
|
||||
.. ocv:pyoldfunction:: cv.FindFundamentalMat(points1, points2, fundamentalMatrix, method=CV_FM_RANSAC, param1=1., param2=0.99, status=None) -> retval
|
||||
|
||||
:param points1: Array of ``N`` points from the first image. The point coordinates should be floating-point (single or double precision).
|
||||
|
||||
@@ -694,7 +695,7 @@ findEssentialMat
|
||||
------------------
|
||||
Calculates an essential matrix from the corresponding points in two images.
|
||||
|
||||
.. ocv:function:: Mat findEssentialMat( InputArray points1, InputArray points2, double focal=1.0, Point2d pp=Point2d(0, 0), int method=CV_RANSAC, double prob=0.999, double threshold=1.0, OutputArray mask=noArray() )
|
||||
.. ocv:function:: Mat findEssentialMat( InputArray points1, InputArray points2, double focal=1.0, Point2d pp=Point2d(0, 0), int method=RANSAC, double prob=0.999, double threshold=1.0, OutputArray mask=noArray() )
|
||||
|
||||
:param points1: Array of ``N`` ``(N >= 5)`` 2D points from the first image. The point coordinates should be floating-point (single or double precision).
|
||||
|
||||
@@ -715,7 +716,7 @@ Calculates an essential matrix from the corresponding points in two images.
|
||||
|
||||
:param mask: Output array of N elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in the RANSAC and LMedS methods.
|
||||
|
||||
This function estimates essential matrix based on an implementation of five-point algorithm [Nister03]_ [SteweniusCFS]_.
|
||||
This function estimates essential matrix based on the five-point algorithm solver in [Nister03]_. [SteweniusCFS]_ is also a related.
|
||||
The epipolar geometry is described by the following equation:
|
||||
|
||||
.. math::
|
||||
@@ -820,8 +821,6 @@ Finds a perspective transformation between two planes.
|
||||
|
||||
.. ocv:cfunction:: int cvFindHomography( const CvMat* src_points, const CvMat* dst_points, CvMat* homography, int method=0, double ransacReprojThreshold=3, CvMat* mask=0 )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.FindHomography(srcPoints, dstPoints, H, method=0, ransacReprojThreshold=3.0, status=None) -> None
|
||||
|
||||
:param srcPoints: Coordinates of the points in the original plane, a matrix of the type ``CV_32FC2`` or ``vector<Point2f>`` .
|
||||
|
||||
:param dstPoints: Coordinates of the points in the target plane, a matrix of the type ``CV_32FC2`` or a ``vector<Point2f>`` .
|
||||
@@ -893,6 +892,9 @@ Homography matrix is determined up to a scale. Thus, it is normalized so that
|
||||
:ocv:func:`warpPerspective`,
|
||||
:ocv:func:`perspectiveTransform`
|
||||
|
||||
.. note::
|
||||
|
||||
* A example on calculating a homography for image matching can be found at opencv_source_code/samples/cpp/video_homography.cpp
|
||||
|
||||
estimateAffine3D
|
||||
--------------------
|
||||
@@ -946,8 +948,6 @@ Returns the new camera matrix based on the free scaling parameter.
|
||||
|
||||
.. ocv:cfunction:: void cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix, const CvMat* dist_coeffs, CvSize image_size, double alpha, CvMat* new_camera_matrix, CvSize new_imag_size=cvSize(0,0), CvRect* valid_pixel_ROI=0, int center_principal_point=0 )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.GetOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, alpha, newCameraMatrix, newImageSize=(0, 0), validPixROI=0, centerPrincipalPoint=0) -> None
|
||||
|
||||
:param cameraMatrix: Input camera matrix.
|
||||
|
||||
:param distCoeffs: Input vector of distortion coefficients :math:`(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])` of 4, 5, 8 or 12 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.
|
||||
@@ -975,14 +975,12 @@ initCameraMatrix2D
|
||||
----------------------
|
||||
Finds an initial camera matrix from 3D-2D point correspondences.
|
||||
|
||||
.. ocv:function:: Mat initCameraMatrix2D( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, double aspectRatio=1.)
|
||||
.. ocv:function:: Mat initCameraMatrix2D( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, double aspectRatio=1.0 )
|
||||
|
||||
.. ocv:pyfunction:: cv2.initCameraMatrix2D(objectPoints, imagePoints, imageSize[, aspectRatio]) -> retval
|
||||
|
||||
.. ocv:cfunction:: void cvInitIntrinsicParams2D( const CvMat* object_points, const CvMat* image_points, const CvMat* npoints, CvSize image_size, CvMat* camera_matrix, double aspect_ratio=1. )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.InitIntrinsicParams2D(objectPoints, imagePoints, npoints, imageSize, cameraMatrix, aspectRatio=1.) -> None
|
||||
|
||||
:param objectPoints: Vector of vectors of the calibration pattern points in the calibration pattern coordinate space. In the old interface all the per-view vectors are concatenated. See :ocv:func:`calibrateCamera` for details.
|
||||
|
||||
:param imagePoints: Vector of vectors of the projections of the calibration pattern points. In the old interface all the per-view vectors are concatenated.
|
||||
@@ -1030,8 +1028,6 @@ Projects 3D points to an image plane.
|
||||
|
||||
.. ocv:cfunction:: void cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector, const CvMat* translation_vector, const CvMat* camera_matrix, const CvMat* distortion_coeffs, CvMat* image_points, CvMat* dpdrot=NULL, CvMat* dpdt=NULL, CvMat* dpdf=NULL, CvMat* dpdc=NULL, CvMat* dpddist=NULL, double aspect_ratio=0 )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.ProjectPoints2(objectPoints, rvec, tvec, cameraMatrix, distCoeffs, imagePoints, dpdrot=None, dpdt=None, dpdf=None, dpdc=None, dpddist=None)-> None
|
||||
|
||||
:param objectPoints: Array of object points, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel (or ``vector<Point3f>`` ), where N is the number of points in the view.
|
||||
|
||||
:param rvec: Rotation vector. See :ocv:func:`Rodrigues` for details.
|
||||
@@ -1075,15 +1071,13 @@ Reprojects a disparity image to 3D space.
|
||||
|
||||
.. ocv:cfunction:: void cvReprojectImageTo3D( const CvArr* disparityImage, CvArr* _3dImage, const CvMat* Q, int handleMissingValues=0 )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.ReprojectImageTo3D(disparity, _3dImage, Q, handleMissingValues=0) -> None
|
||||
|
||||
:param disparity: Input single-channel 8-bit unsigned, 16-bit signed, 32-bit signed or 32-bit floating-point disparity image.
|
||||
|
||||
:param _3dImage: Output 3-channel floating-point image of the same size as ``disparity`` . Each element of ``_3dImage(x,y)`` contains 3D coordinates of the point ``(x,y)`` computed from the disparity map.
|
||||
|
||||
:param Q: :math:`4 \times 4` perspective transformation matrix that can be obtained with :ocv:func:`stereoRectify`.
|
||||
|
||||
:param handleMissingValues: Indicates, whether the function should handle missing values (i.e. points where the disparity was not computed). If ``handleMissingValues=true``, then pixels with the minimal disparity that corresponds to the outliers (see :ocv:funcx:`StereoBM::operator()` ) are transformed to 3D points with a very large Z value (currently set to 10000).
|
||||
:param handleMissingValues: Indicates, whether the function should handle missing values (i.e. points where the disparity was not computed). If ``handleMissingValues=true``, then pixels with the minimal disparity that corresponds to the outliers (see :ocv:funcx:`StereoMatcher::compute` ) are transformed to 3D points with a very large Z value (currently set to 10000).
|
||||
|
||||
:param ddepth: The optional output array depth. If it is ``-1``, the output image will have ``CV_32F`` depth. ``ddepth`` can also be set to ``CV_16S``, ``CV_32S`` or ``CV_32F``.
|
||||
|
||||
@@ -1109,7 +1103,6 @@ Computes an RQ decomposition of 3x3 matrices.
|
||||
.. ocv:pyfunction:: cv2.RQDecomp3x3(src[, mtxR[, mtxQ[, Qx[, Qy[, Qz]]]]]) -> retval, mtxR, mtxQ, Qx, Qy, Qz
|
||||
|
||||
.. ocv:cfunction:: void cvRQDecomp3x3( const CvMat * matrixM, CvMat * matrixR, CvMat * matrixQ, CvMat * matrixQx=NULL, CvMat * matrixQy=NULL, CvMat * matrixQz=NULL, CvPoint3D64f * eulerAngles=NULL )
|
||||
.. ocv:pyoldfunction:: cv.RQDecomp3x3(M, R, Q, Qx=None, Qy=None, Qz=None) -> eulerAngles
|
||||
|
||||
:param src: 3x3 input matrix.
|
||||
|
||||
@@ -1140,8 +1133,6 @@ Converts a rotation matrix to a rotation vector or vice versa.
|
||||
|
||||
.. ocv:cfunction:: int cvRodrigues2( const CvMat* src, CvMat* dst, CvMat* jacobian=0 )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.Rodrigues2(src, dst, jacobian=0)-> None
|
||||
|
||||
:param src: Input rotation vector (3x1 or 1x3) or rotation matrix (3x3).
|
||||
|
||||
:param dst: Output rotation matrix (3x3) or rotation vector (3x1 or 1x3), respectively.
|
||||
@@ -1166,155 +1157,84 @@ used in the global 3D geometry optimization procedures like
|
||||
:ocv:func:`solvePnP` .
|
||||
|
||||
|
||||
StereoMatcher
|
||||
-------------
|
||||
.. ocv:class:: StereoMatcher : public Algorithm
|
||||
|
||||
StereoBM
|
||||
--------
|
||||
.. ocv:class:: StereoBM
|
||||
The base class for stereo correspondence algorithms.
|
||||
|
||||
Class for computing stereo correspondence using the block matching algorithm. ::
|
||||
|
||||
// Block matching stereo correspondence algorithm class StereoBM
|
||||
{
|
||||
enum { NORMALIZED_RESPONSE = CV_STEREO_BM_NORMALIZED_RESPONSE,
|
||||
BASIC_PRESET=CV_STEREO_BM_BASIC,
|
||||
FISH_EYE_PRESET=CV_STEREO_BM_FISH_EYE,
|
||||
NARROW_PRESET=CV_STEREO_BM_NARROW };
|
||||
|
||||
StereoBM();
|
||||
// the preset is one of ..._PRESET above.
|
||||
// ndisparities is the size of disparity range,
|
||||
// in which the optimal disparity at each pixel is searched for.
|
||||
// SADWindowSize is the size of averaging window used to match pixel blocks
|
||||
// (larger values mean better robustness to noise, but yield blurry disparity maps)
|
||||
StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);
|
||||
// separate initialization function
|
||||
void init(int preset, int ndisparities=0, int SADWindowSize=21);
|
||||
// computes the disparity for the two rectified 8-bit single-channel images.
|
||||
// the disparity will be 16-bit signed (fixed-point) or 32-bit floating-point image of the same size as left.
|
||||
void operator()( InputArray left, InputArray right, OutputArray disparity, int disptype=CV_16S );
|
||||
|
||||
Ptr<CvStereoBMState> state;
|
||||
};
|
||||
|
||||
The class is a C++ wrapper for the associated functions. In particular, :ocv:funcx:`StereoBM::operator()` is the wrapper for
|
||||
:ocv:cfunc:`cvFindStereoCorrespondenceBM`.
|
||||
|
||||
|
||||
StereoBM::StereoBM
|
||||
------------------
|
||||
The constructors.
|
||||
|
||||
.. ocv:function:: StereoBM::StereoBM()
|
||||
.. ocv:function:: StereoBM::StereoBM(int preset, int ndisparities=0, int SADWindowSize=21)
|
||||
|
||||
.. ocv:pyfunction:: cv2.StereoBM([preset[, ndisparities[, SADWindowSize]]]) -> <StereoBM object>
|
||||
|
||||
.. ocv:cfunction:: CvStereoBMState* cvCreateStereoBMState( int preset=CV_STEREO_BM_BASIC, int numberOfDisparities=0 )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.CreateStereoBMState(preset=CV_STEREO_BM_BASIC, numberOfDisparities=0)-> CvStereoBMState
|
||||
|
||||
:param preset: specifies the whole set of algorithm parameters, one of:
|
||||
|
||||
* BASIC_PRESET - parameters suitable for general cameras
|
||||
* FISH_EYE_PRESET - parameters suitable for wide-angle cameras
|
||||
* NARROW_PRESET - parameters suitable for narrow-angle cameras
|
||||
|
||||
After constructing the class, you can override any parameters set by the preset.
|
||||
|
||||
:param ndisparities: the disparity search range. For each pixel algorithm will find the best disparity from 0 (default minimum disparity) to ``ndisparities``. The search range can then be shifted by changing the minimum disparity.
|
||||
|
||||
:param SADWindowSize: the linear size of the blocks compared by the algorithm. The size should be odd (as the block is centered at the current pixel). Larger block size implies smoother, though less accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher chance for algorithm to find a wrong correspondence.
|
||||
|
||||
The constructors initialize ``StereoBM`` state. You can then call ``StereoBM::operator()`` to compute disparity for a specific stereo pair.
|
||||
|
||||
.. note:: In the C API you need to deallocate ``CvStereoBM`` state when it is not needed anymore using ``cvReleaseStereoBMState(&stereobm)``.
|
||||
|
||||
StereoBM::operator()
|
||||
StereoMatcher::compute
|
||||
-----------------------
|
||||
Computes disparity using the BM algorithm for a rectified stereo pair.
|
||||
Computes disparity map for the specified stereo pair
|
||||
|
||||
.. ocv:function:: void StereoBM::operator()( InputArray left, InputArray right, OutputArray disparity, int disptype=CV_16S )
|
||||
.. ocv:function:: void StereoMatcher::compute( InputArray left, InputArray right, OutputArray disparity )
|
||||
|
||||
.. ocv:pyfunction:: cv2.StereoBM.compute(left, right[, disparity[, disptype]]) -> disparity
|
||||
|
||||
.. ocv:cfunction:: void cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right, CvArr* disparity, CvStereoBMState* state )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.FindStereoCorrespondenceBM(left, right, disparity, state)-> None
|
||||
.. ocv:pyfunction:: cv2.StereoBM.compute(left, right[, disparity]) -> disparity
|
||||
|
||||
:param left: Left 8-bit single-channel image.
|
||||
|
||||
:param right: Right image of the same size and the same type as the left one.
|
||||
|
||||
:param disparity: Output disparity map. It has the same size as the input images. When ``disptype==CV_16S``, the map is a 16-bit signed single-channel image, containing disparity values scaled by 16. To get the true disparity values from such fixed-point representation, you will need to divide each ``disp`` element by 16. If ``disptype==CV_32F``, the disparity map will already contain the real disparity values on output.
|
||||
:param disparity: Output disparity map. It has the same size as the input images. Some algorithms, like StereoBM or StereoSGBM compute 16-bit fixed-point disparity map (where each disparity value has 4 fractional bits), whereas other algorithms output 32-bit floating-point disparity map.
|
||||
|
||||
:param disptype: Type of the output disparity map, ``CV_16S`` (default) or ``CV_32F``.
|
||||
|
||||
:param state: The pre-initialized ``CvStereoBMState`` structure in the case of the old API.
|
||||
StereoBM
|
||||
--------
|
||||
.. ocv:class:: StereoBM : public StereoMatcher
|
||||
|
||||
The method executes the BM algorithm on a rectified stereo pair. See the ``stereo_match.cpp`` OpenCV sample on how to prepare images and call the method. Note that the method is not constant, thus you should not use the same ``StereoBM`` instance from within different threads simultaneously. The function is parallelized with the TBB library.
|
||||
Class for computing stereo correspondence using the block matching algorithm, introduced and contributed to OpenCV by K. Konolige.
|
||||
|
||||
.. Sample code:
|
||||
|
||||
(Ocl) An example for using the stereoBM matching algorithm can be found at opencv_source_code/samples/ocl/stereo_match.cpp
|
||||
|
||||
createStereoBM
|
||||
------------------
|
||||
Creates StereoBM object
|
||||
|
||||
.. ocv:function:: Ptr<StereoBM> createStereoBM(int numDisparities=0, int blockSize=21)
|
||||
|
||||
.. ocv:pyfunction:: cv2.createStereoBM([numDisparities[, blockSize]]) -> retval
|
||||
|
||||
:param numDisparities: the disparity search range. For each pixel algorithm will find the best disparity from 0 (default minimum disparity) to ``numDisparities``. The search range can then be shifted by changing the minimum disparity.
|
||||
|
||||
:param blockSize: the linear size of the blocks compared by the algorithm. The size should be odd (as the block is centered at the current pixel). Larger block size implies smoother, though less accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher chance for algorithm to find a wrong correspondence.
|
||||
|
||||
The function create ``StereoBM`` object. You can then call ``StereoBM::compute()`` to compute disparity for a specific stereo pair.
|
||||
|
||||
|
||||
StereoSGBM
|
||||
----------
|
||||
|
||||
.. ocv:class:: StereoSGBM
|
||||
|
||||
Class for computing stereo correspondence using the semi-global block matching algorithm. ::
|
||||
|
||||
class StereoSGBM
|
||||
{
|
||||
StereoSGBM();
|
||||
StereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,
|
||||
int P1=0, int P2=0, int disp12MaxDiff=0,
|
||||
int preFilterCap=0, int uniquenessRatio=0,
|
||||
int speckleWindowSize=0, int speckleRange=0,
|
||||
bool fullDP=false);
|
||||
virtual ~StereoSGBM();
|
||||
|
||||
virtual void operator()(InputArray left, InputArray right, OutputArray disp);
|
||||
|
||||
int minDisparity;
|
||||
int numberOfDisparities;
|
||||
int SADWindowSize;
|
||||
int preFilterCap;
|
||||
int uniquenessRatio;
|
||||
int P1, P2;
|
||||
int speckleWindowSize;
|
||||
int speckleRange;
|
||||
int disp12MaxDiff;
|
||||
bool fullDP;
|
||||
|
||||
...
|
||||
};
|
||||
.. ocv:class:: StereoSGBM : public StereoMatcher
|
||||
|
||||
The class implements the modified H. Hirschmuller algorithm [HH08]_ that differs from the original one as follows:
|
||||
|
||||
* By default, the algorithm is single-pass, which means that you consider only 5 directions instead of 8. Set ``fullDP=true`` to run the full variant of the algorithm but beware that it may consume a lot of memory.
|
||||
* By default, the algorithm is single-pass, which means that you consider only 5 directions instead of 8. Set ``mode=StereoSGBM::MODE_HH`` in ``createStereoSGBM`` to run the full variant of the algorithm but beware that it may consume a lot of memory.
|
||||
|
||||
* The algorithm matches blocks, not individual pixels. Though, setting ``SADWindowSize=1`` reduces the blocks to single pixels.
|
||||
* The algorithm matches blocks, not individual pixels. Though, setting ``blockSize=1`` reduces the blocks to single pixels.
|
||||
|
||||
* Mutual information cost function is not implemented. Instead, a simpler Birchfield-Tomasi sub-pixel metric from [BT98]_ is used. Though, the color images are supported as well.
|
||||
|
||||
* Some pre- and post- processing steps from K. Konolige algorithm :ocv:funcx:`StereoBM::operator()` are included, for example: pre-filtering (``CV_STEREO_BM_XSOBEL`` type) and post-filtering (uniqueness check, quadratic interpolation and speckle filtering).
|
||||
* Some pre- and post- processing steps from K. Konolige algorithm ``StereoBM`` are included, for example: pre-filtering (``StereoBM::PREFILTER_XSOBEL`` type) and post-filtering (uniqueness check, quadratic interpolation and speckle filtering).
|
||||
|
||||
.. note::
|
||||
|
||||
* (Python) An example illustrating the use of the StereoSGBM matching algorithm can be found at opencv_source_code/samples/python2/stereo_match.py
|
||||
|
||||
StereoSGBM::StereoSGBM
|
||||
createStereoSGBM
|
||||
--------------------------
|
||||
.. ocv:function:: StereoSGBM::StereoSGBM()
|
||||
Creates StereoSGBM object
|
||||
|
||||
.. ocv:function:: StereoSGBM::StereoSGBM( int minDisparity, int numDisparities, int SADWindowSize, int P1=0, int P2=0, int disp12MaxDiff=0, int preFilterCap=0, int uniquenessRatio=0, int speckleWindowSize=0, int speckleRange=0, bool fullDP=false)
|
||||
.. ocv:function:: Ptr<StereoSGBM> createStereoSGBM( int minDisparity, int numDisparities, int blockSize, int P1=0, int P2=0, int disp12MaxDiff=0, int preFilterCap=0, int uniquenessRatio=0, int speckleWindowSize=0, int speckleRange=0, int mode=StereoSGBM::MODE_SGBM)
|
||||
|
||||
.. ocv:pyfunction:: cv2.StereoSGBM([minDisparity, numDisparities, SADWindowSize[, P1[, P2[, disp12MaxDiff[, preFilterCap[, uniquenessRatio[, speckleWindowSize[, speckleRange[, fullDP]]]]]]]]]) -> <StereoSGBM object>
|
||||
|
||||
Initializes ``StereoSGBM`` and sets parameters to custom values.??
|
||||
.. ocv:pyfunction:: cv2.createStereoSGBM(minDisparity, numDisparities, blockSize[, P1[, P2[, disp12MaxDiff[, preFilterCap[, uniquenessRatio[, speckleWindowSize[, speckleRange[, mode]]]]]]]]) -> retval
|
||||
|
||||
:param minDisparity: Minimum possible disparity value. Normally, it is zero but sometimes rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
|
||||
|
||||
:param numDisparities: Maximum disparity minus minimum disparity. The value is always greater than zero. In the current implementation, this parameter must be divisible by 16.
|
||||
|
||||
:param SADWindowSize: Matched block size. It must be an odd number ``>=1`` . Normally, it should be somewhere in the ``3..11`` range.
|
||||
:param blockSize: Matched block size. It must be an odd number ``>=1`` . Normally, it should be somewhere in the ``3..11`` range.
|
||||
|
||||
:param P1: The first parameter controlling the disparity smoothness. See below.
|
||||
|
||||
@@ -1330,32 +1250,12 @@ StereoSGBM::StereoSGBM
|
||||
|
||||
:param speckleRange: Maximum disparity variation within each connected component. If you do speckle filtering, set the parameter to a positive value, it will be implicitly multiplied by 16. Normally, 1 or 2 is good enough.
|
||||
|
||||
:param fullDP: Set it to ``true`` to run the full-scale two-pass dynamic programming algorithm. It will consume O(W*H*numDisparities) bytes, which is large for 640x480 stereo and huge for HD-size pictures. By default, it is set to ``false`` .
|
||||
:param mode: Set it to ``StereoSGBM::MODE_HH`` to run the full-scale two-pass dynamic programming algorithm. It will consume O(W*H*numDisparities) bytes, which is large for 640x480 stereo and huge for HD-size pictures. By default, it is set to ``false`` .
|
||||
|
||||
The first constructor initializes ``StereoSGBM`` with all the default parameters. So, you only have to set ``StereoSGBM::numberOfDisparities`` at minimum. The second constructor enables you to set each parameter to a custom value.
|
||||
The first constructor initializes ``StereoSGBM`` with all the default parameters. So, you only have to set ``StereoSGBM::numDisparities`` at minimum. The second constructor enables you to set each parameter to a custom value.
|
||||
|
||||
|
||||
|
||||
StereoSGBM::operator ()
|
||||
-----------------------
|
||||
|
||||
.. ocv:function:: void StereoSGBM::operator()(InputArray left, InputArray right, OutputArray disp)
|
||||
|
||||
.. ocv:pyfunction:: cv2.StereoSGBM.compute(left, right[, disp]) -> disp
|
||||
|
||||
Computes disparity using the SGBM algorithm for a rectified stereo pair.
|
||||
|
||||
:param left: Left 8-bit single-channel or 3-channel image.
|
||||
|
||||
:param right: Right image of the same size and the same type as the left one.
|
||||
|
||||
:param disp: Output disparity map. It is a 16-bit signed single-channel image of the same size as the input image. It contains disparity values scaled by 16. So, to get the floating-point disparity map, you need to divide each ``disp`` element by 16.
|
||||
|
||||
The method executes the SGBM algorithm on a rectified stereo pair. See ``stereo_match.cpp`` OpenCV sample on how to prepare images and call the method.
|
||||
|
||||
.. note:: The method is not constant, so you should not use the same ``StereoSGBM`` instance from different threads simultaneously.
|
||||
|
||||
|
||||
stereoCalibrate
|
||||
-------------------
|
||||
Calibrates the stereo camera.
|
||||
@@ -1366,8 +1266,6 @@ Calibrates the stereo camera.
|
||||
|
||||
.. ocv:cfunction:: double cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1, const CvMat* image_points2, const CvMat* npoints, CvMat* camera_matrix1, CvMat* dist_coeffs1, CvMat* camera_matrix2, CvMat* dist_coeffs2, CvSize image_size, CvMat* R, CvMat* T, CvMat* E=0, CvMat* F=0, CvTermCriteria term_crit=cvTermCriteria( CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6), int flags=CV_CALIB_FIX_INTRINSIC )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.StereoCalibrate(objectPoints, imagePoints1, imagePoints2, pointCounts, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageSize, R, T, E=None, F=None, term_crit=(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 30, 1e-6), flags=CV_CALIB_FIX_INTRINSIC)-> None
|
||||
|
||||
:param objectPoints: Vector of vectors of the calibration pattern points.
|
||||
|
||||
:param imagePoints1: Vector of vectors of the projections of the calibration pattern points, observed by the first camera.
|
||||
@@ -1413,9 +1311,9 @@ Calibrates the stereo camera.
|
||||
* **CV_CALIB_FIX_K1,...,CV_CALIB_FIX_K6** Do not change the corresponding radial distortion coefficient during the optimization. If ``CV_CALIB_USE_INTRINSIC_GUESS`` is set, the coefficient from the supplied ``distCoeffs`` matrix is used. Otherwise, it is set to 0.
|
||||
|
||||
* **CV_CALIB_RATIONAL_MODEL** Enable coefficients k4, k5, and k6. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the rational model and return 8 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients.
|
||||
|
||||
|
||||
* **CALIB_THIN_PRISM_MODEL** Coefficients s1, s2, s3 and s4 are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the thin prism model and return 12 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients.
|
||||
|
||||
|
||||
* **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during the optimization. If ``CV_CALIB_USE_INTRINSIC_GUESS`` is set, the coefficient from the supplied ``distCoeffs`` matrix is used. Otherwise, it is set to 0.
|
||||
|
||||
The function estimates transformation between two cameras making a stereo pair. If you have a stereo camera where the relative position and orientation of two cameras is fixed, and if you computed poses of an object relative to the first camera and to the second camera, (R1, T1) and (R2, T2), respectively (this can be done with
|
||||
@@ -1459,8 +1357,6 @@ Computes rectification transforms for each head of a calibrated stereo camera.
|
||||
|
||||
.. ocv:cfunction:: void cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2, const CvMat* dist_coeffs1, const CvMat* dist_coeffs2, CvSize image_size, const CvMat* R, const CvMat* T, CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2, CvMat* Q=0, int flags=CV_CALIB_ZERO_DISPARITY, double alpha=-1, CvSize new_image_size=cvSize(0,0), CvRect* valid_pix_ROI1=0, CvRect* valid_pix_ROI2=0 )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.StereoRectify(cameraMatrix1, cameraMatrix2, distCoeffs1, distCoeffs2, imageSize, R, T, R1, R2, P1, P2, Q=None, flags=CV_CALIB_ZERO_DISPARITY, alpha=-1, newImageSize=(0, 0)) -> (roi1, roi2)
|
||||
|
||||
:param cameraMatrix1: First camera matrix.
|
||||
|
||||
:param cameraMatrix2: Second camera matrix.
|
||||
@@ -1548,8 +1444,6 @@ Computes a rectification transform for an uncalibrated stereo camera.
|
||||
|
||||
.. ocv:cfunction:: int cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2, const CvMat* F, CvSize img_size, CvMat* H1, CvMat* H2, double threshold=5 )
|
||||
|
||||
.. ocv:pyoldfunction:: cv.StereoRectifyUncalibrated(points1, points2, F, imageSize, H1, H2, threshold=5)-> None
|
||||
|
||||
:param points1: Array of feature points in the first image.
|
||||
|
||||
:param points2: The corresponding points in the second image. The same formats as in :ocv:func:`findFundamentalMat` are supported.
|
||||
@@ -1614,6 +1508,6 @@ The function reconstructs 3-dimensional points (in homogeneous coordinates) by u
|
||||
|
||||
.. [SteweniusCFS] Stewénius, H., Calibrated Fivepoint solver. http://www.vis.uky.edu/~stewe/FIVEPOINT/
|
||||
|
||||
.. [Slabaugh] Slabaugh, G.G. Computing Euler angles from a rotation matrix. http://gregslabaugh.name/publications/euler.pdf
|
||||
.. [Slabaugh] Slabaugh, G.G. Computing Euler angles from a rotation matrix. http://www.soi.city.ac.uk/~sbbh653/publications/euler.pdf (verified: 2013-04-15)
|
||||
|
||||
.. [Zhang2000] Z. Zhang. A Flexible New Technique for Camera Calibration. IEEE Transactions on Pattern Analysis and Machine Intelligence, 22(11):1330-1334, 2000.
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// 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.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -46,556 +47,181 @@
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/features2d.hpp"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
* Camera Calibration, Pose Estimation and Stereo *
|
||||
\****************************************************************************************/
|
||||
|
||||
typedef struct CvPOSITObject CvPOSITObject;
|
||||
|
||||
/* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
|
||||
CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
|
||||
|
||||
|
||||
/* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
|
||||
an object given its model and projection in a weak-perspective case */
|
||||
CVAPI(void) cvPOSIT( CvPOSITObject* posit_object, CvPoint2D32f* image_points,
|
||||
double focal_length, CvTermCriteria criteria,
|
||||
float* rotation_matrix, float* translation_vector);
|
||||
|
||||
/* Releases CvPOSITObject structure */
|
||||
CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object );
|
||||
|
||||
/* updates the number of RANSAC iterations */
|
||||
CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob,
|
||||
int model_points, int max_iters );
|
||||
|
||||
CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst );
|
||||
|
||||
/* Calculates fundamental matrix given a set of corresponding points */
|
||||
#define CV_FM_7POINT 1
|
||||
#define CV_FM_8POINT 2
|
||||
|
||||
#define CV_LMEDS 4
|
||||
#define CV_RANSAC 8
|
||||
|
||||
#define CV_FM_LMEDS_ONLY CV_LMEDS
|
||||
#define CV_FM_RANSAC_ONLY CV_RANSAC
|
||||
#define CV_FM_LMEDS CV_LMEDS
|
||||
#define CV_FM_RANSAC CV_RANSAC
|
||||
|
||||
enum
|
||||
{
|
||||
CV_ITERATIVE = 0,
|
||||
CV_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation"
|
||||
CV_P3P = 2 // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem"
|
||||
};
|
||||
|
||||
CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,
|
||||
CvMat* fundamental_matrix,
|
||||
int method CV_DEFAULT(CV_FM_RANSAC),
|
||||
double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99),
|
||||
CvMat* status CV_DEFAULT(NULL) );
|
||||
|
||||
/* For each input point on one of images
|
||||
computes parameters of the corresponding
|
||||
epipolar line on the other image */
|
||||
CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
|
||||
int which_image,
|
||||
const CvMat* fundamental_matrix,
|
||||
CvMat* correspondent_lines );
|
||||
|
||||
/* Triangulation functions */
|
||||
|
||||
CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2,
|
||||
CvMat* projPoints1, CvMat* projPoints2,
|
||||
CvMat* points4D);
|
||||
|
||||
CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2,
|
||||
CvMat* new_points1, CvMat* new_points2);
|
||||
|
||||
|
||||
/* Computes the optimal new camera matrix according to the free scaling parameter alpha:
|
||||
alpha=0 - only valid pixels will be retained in the undistorted image
|
||||
alpha=1 - all the source image pixels will be retained in the undistorted image
|
||||
*/
|
||||
CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix,
|
||||
const CvMat* dist_coeffs,
|
||||
CvSize image_size, double alpha,
|
||||
CvMat* new_camera_matrix,
|
||||
CvSize new_imag_size CV_DEFAULT(cvSize(0,0)),
|
||||
CvRect* valid_pixel_ROI CV_DEFAULT(0),
|
||||
int center_principal_point CV_DEFAULT(0));
|
||||
|
||||
/* Converts rotation vector to rotation matrix or vice versa */
|
||||
CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst,
|
||||
CvMat* jacobian CV_DEFAULT(0) );
|
||||
|
||||
/* Finds perspective transformation between the object plane and image (view) plane */
|
||||
CVAPI(int) cvFindHomography( const CvMat* src_points,
|
||||
const CvMat* dst_points,
|
||||
CvMat* homography,
|
||||
int method CV_DEFAULT(0),
|
||||
double ransacReprojThreshold CV_DEFAULT(3),
|
||||
CvMat* mask CV_DEFAULT(0));
|
||||
|
||||
/* Computes RQ decomposition for 3x3 matrices */
|
||||
CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ,
|
||||
CvMat *matrixQx CV_DEFAULT(NULL),
|
||||
CvMat *matrixQy CV_DEFAULT(NULL),
|
||||
CvMat *matrixQz CV_DEFAULT(NULL),
|
||||
CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
|
||||
|
||||
/* Computes projection matrix decomposition */
|
||||
CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr,
|
||||
CvMat *rotMatr, CvMat *posVect,
|
||||
CvMat *rotMatrX CV_DEFAULT(NULL),
|
||||
CvMat *rotMatrY CV_DEFAULT(NULL),
|
||||
CvMat *rotMatrZ CV_DEFAULT(NULL),
|
||||
CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
|
||||
|
||||
/* Computes d(AB)/dA and d(AB)/dB */
|
||||
CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB );
|
||||
|
||||
/* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)),
|
||||
t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */
|
||||
CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1,
|
||||
const CvMat* _rvec2, const CvMat* _tvec2,
|
||||
CvMat* _rvec3, CvMat* _tvec3,
|
||||
CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0),
|
||||
CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0),
|
||||
CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0),
|
||||
CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) );
|
||||
|
||||
/* Projects object points to the view plane using
|
||||
the specified extrinsic and intrinsic camera parameters */
|
||||
CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
|
||||
const CvMat* translation_vector, const CvMat* camera_matrix,
|
||||
const CvMat* distortion_coeffs, CvMat* image_points,
|
||||
CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
|
||||
CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
|
||||
CvMat* dpddist CV_DEFAULT(NULL),
|
||||
double aspect_ratio CV_DEFAULT(0));
|
||||
|
||||
/* Finds extrinsic camera parameters from
|
||||
a few known corresponding point pairs and intrinsic parameters */
|
||||
CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* camera_matrix,
|
||||
const CvMat* distortion_coeffs,
|
||||
CvMat* rotation_vector,
|
||||
CvMat* translation_vector,
|
||||
int use_extrinsic_guess CV_DEFAULT(0) );
|
||||
|
||||
/* Computes initial estimate of the intrinsic camera parameters
|
||||
in case of planar calibration target (e.g. chessboard) */
|
||||
CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* npoints, CvSize image_size,
|
||||
CvMat* camera_matrix,
|
||||
double aspect_ratio CV_DEFAULT(1.) );
|
||||
|
||||
#define CV_CALIB_CB_ADAPTIVE_THRESH 1
|
||||
#define CV_CALIB_CB_NORMALIZE_IMAGE 2
|
||||
#define CV_CALIB_CB_FILTER_QUADS 4
|
||||
#define CV_CALIB_CB_FAST_CHECK 8
|
||||
|
||||
// Performs a fast check if a chessboard is in the input image. This is a workaround to
|
||||
// a problem of cvFindChessboardCorners being slow on images with no chessboard
|
||||
// - src: input image
|
||||
// - size: chessboard size
|
||||
// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called,
|
||||
// 0 if there is no chessboard, -1 in case of error
|
||||
CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size);
|
||||
|
||||
/* Detects corners on a chessboard calibration pattern */
|
||||
CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
|
||||
CvPoint2D32f* corners,
|
||||
int* corner_count CV_DEFAULT(NULL),
|
||||
int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) );
|
||||
|
||||
/* Draws individual chessboard corners or the whole chessboard detected */
|
||||
CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
|
||||
CvPoint2D32f* corners,
|
||||
int count, int pattern_was_found );
|
||||
|
||||
#define CV_CALIB_USE_INTRINSIC_GUESS 1
|
||||
#define CV_CALIB_FIX_ASPECT_RATIO 2
|
||||
#define CV_CALIB_FIX_PRINCIPAL_POINT 4
|
||||
#define CV_CALIB_ZERO_TANGENT_DIST 8
|
||||
#define CV_CALIB_FIX_FOCAL_LENGTH 16
|
||||
#define CV_CALIB_FIX_K1 32
|
||||
#define CV_CALIB_FIX_K2 64
|
||||
#define CV_CALIB_FIX_K3 128
|
||||
#define CV_CALIB_FIX_K4 2048
|
||||
#define CV_CALIB_FIX_K5 4096
|
||||
#define CV_CALIB_FIX_K6 8192
|
||||
#define CV_CALIB_RATIONAL_MODEL 16384
|
||||
#define CV_CALIB_THIN_PRISM_MODEL 32768
|
||||
#define CV_CALIB_FIX_S1_S2_S3_S4 65536
|
||||
|
||||
|
||||
/* Finds intrinsic and extrinsic camera parameters
|
||||
from a few views of known calibration pattern */
|
||||
CVAPI(double) cvCalibrateCamera2( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* point_counts,
|
||||
CvSize image_size,
|
||||
CvMat* camera_matrix,
|
||||
CvMat* distortion_coeffs,
|
||||
CvMat* rotation_vectors CV_DEFAULT(NULL),
|
||||
CvMat* translation_vectors CV_DEFAULT(NULL),
|
||||
int flags CV_DEFAULT(0),
|
||||
CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
|
||||
CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON)) );
|
||||
|
||||
/* Computes various useful characteristics of the camera from the data computed by
|
||||
cvCalibrateCamera2 */
|
||||
CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix,
|
||||
CvSize image_size,
|
||||
double aperture_width CV_DEFAULT(0),
|
||||
double aperture_height CV_DEFAULT(0),
|
||||
double *fovx CV_DEFAULT(NULL),
|
||||
double *fovy CV_DEFAULT(NULL),
|
||||
double *focal_length CV_DEFAULT(NULL),
|
||||
CvPoint2D64f *principal_point CV_DEFAULT(NULL),
|
||||
double *pixel_aspect_ratio CV_DEFAULT(NULL));
|
||||
|
||||
#define CV_CALIB_FIX_INTRINSIC 256
|
||||
#define CV_CALIB_SAME_FOCAL_LENGTH 512
|
||||
|
||||
/* Computes the transformation from one camera coordinate system to another one
|
||||
from a few correspondent views of the same calibration target. Optionally, calibrates
|
||||
both cameras */
|
||||
CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1,
|
||||
const CvMat* image_points2, const CvMat* npoints,
|
||||
CvMat* camera_matrix1, CvMat* dist_coeffs1,
|
||||
CvMat* camera_matrix2, CvMat* dist_coeffs2,
|
||||
CvSize image_size, CvMat* R, CvMat* T,
|
||||
CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0),
|
||||
CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
|
||||
CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)),
|
||||
int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC));
|
||||
|
||||
#define CV_CALIB_ZERO_DISPARITY 1024
|
||||
|
||||
/* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both
|
||||
views parallel (=> to make all the epipolar lines horizontal or vertical) */
|
||||
CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2,
|
||||
const CvMat* dist_coeffs1, const CvMat* dist_coeffs2,
|
||||
CvSize image_size, const CvMat* R, const CvMat* T,
|
||||
CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2,
|
||||
CvMat* Q CV_DEFAULT(0),
|
||||
int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY),
|
||||
double alpha CV_DEFAULT(-1),
|
||||
CvSize new_image_size CV_DEFAULT(cvSize(0,0)),
|
||||
CvRect* valid_pix_ROI1 CV_DEFAULT(0),
|
||||
CvRect* valid_pix_ROI2 CV_DEFAULT(0));
|
||||
|
||||
/* Computes rectification transformations for uncalibrated pair of images using a set
|
||||
of point correspondences */
|
||||
CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2,
|
||||
const CvMat* F, CvSize img_size,
|
||||
CvMat* H1, CvMat* H2,
|
||||
double threshold CV_DEFAULT(5));
|
||||
|
||||
|
||||
|
||||
/* stereo correspondence parameters and functions */
|
||||
|
||||
#define CV_STEREO_BM_NORMALIZED_RESPONSE 0
|
||||
#define CV_STEREO_BM_XSOBEL 1
|
||||
|
||||
/* Block matching algorithm structure */
|
||||
typedef struct CvStereoBMState
|
||||
{
|
||||
// pre-filtering (normalization of input images)
|
||||
int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now
|
||||
int preFilterSize; // averaging window size: ~5x5..21x21
|
||||
int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap]
|
||||
|
||||
// correspondence using Sum of Absolute Difference (SAD)
|
||||
int SADWindowSize; // ~5x5..21x21
|
||||
int minDisparity; // minimum disparity (can be negative)
|
||||
int numberOfDisparities; // maximum disparity - minimum disparity (> 0)
|
||||
|
||||
// post-filtering
|
||||
int textureThreshold; // the disparity is only computed for pixels
|
||||
// with textured enough neighborhood
|
||||
int uniquenessRatio; // accept the computed disparity d* only if
|
||||
// SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.)
|
||||
// for any d != d*+/-1 within the search range.
|
||||
int speckleWindowSize; // disparity variation window
|
||||
int speckleRange; // acceptable range of variation in window
|
||||
|
||||
int trySmallerWindows; // if 1, the results may be more accurate,
|
||||
// at the expense of slower processing
|
||||
CvRect roi1, roi2;
|
||||
int disp12MaxDiff;
|
||||
|
||||
// temporary buffers
|
||||
CvMat* preFilteredImg0;
|
||||
CvMat* preFilteredImg1;
|
||||
CvMat* slidingSumBuf;
|
||||
CvMat* cost;
|
||||
CvMat* disp;
|
||||
} CvStereoBMState;
|
||||
|
||||
#define CV_STEREO_BM_BASIC 0
|
||||
#define CV_STEREO_BM_FISH_EYE 1
|
||||
#define CV_STEREO_BM_NARROW 2
|
||||
|
||||
CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC),
|
||||
int numberOfDisparities CV_DEFAULT(0));
|
||||
|
||||
CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state );
|
||||
|
||||
CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right,
|
||||
CvArr* disparity, CvStereoBMState* state );
|
||||
|
||||
CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,
|
||||
int numberOfDisparities, int SADWindowSize );
|
||||
|
||||
CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost,
|
||||
int minDisparity, int numberOfDisparities,
|
||||
int disp12MaxDiff CV_DEFAULT(1) );
|
||||
|
||||
/* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */
|
||||
CVAPI(void) cvReprojectImageTo3D( const CvArr* disparityImage,
|
||||
CvArr* _3dImage, const CvMat* Q,
|
||||
int handleMissingValues CV_DEFAULT(0) );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
class CV_EXPORTS CvLevMarq
|
||||
{
|
||||
public:
|
||||
CvLevMarq();
|
||||
CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria=
|
||||
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
|
||||
bool completeSymmFlag=false );
|
||||
~CvLevMarq();
|
||||
void init( int nparams, int nerrs, CvTermCriteria criteria=
|
||||
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
|
||||
bool completeSymmFlag=false );
|
||||
bool update( const CvMat*& param, CvMat*& J, CvMat*& err );
|
||||
bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm );
|
||||
|
||||
void clear();
|
||||
void step();
|
||||
enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 };
|
||||
|
||||
cv::Ptr<CvMat> mask;
|
||||
cv::Ptr<CvMat> prevParam;
|
||||
cv::Ptr<CvMat> param;
|
||||
cv::Ptr<CvMat> J;
|
||||
cv::Ptr<CvMat> err;
|
||||
cv::Ptr<CvMat> JtJ;
|
||||
cv::Ptr<CvMat> JtJN;
|
||||
cv::Ptr<CvMat> JtErr;
|
||||
cv::Ptr<CvMat> JtJV;
|
||||
cv::Ptr<CvMat> JtJW;
|
||||
double prevErrNorm, errNorm;
|
||||
int lambdaLg10;
|
||||
CvTermCriteria criteria;
|
||||
int state;
|
||||
int iters;
|
||||
bool completeSymmFlag;
|
||||
};
|
||||
|
||||
namespace cv
|
||||
{
|
||||
//! converts rotation vector to rotation matrix or vice versa using Rodrigues transformation
|
||||
CV_EXPORTS_W void Rodrigues(InputArray src, OutputArray dst, OutputArray jacobian=noArray());
|
||||
|
||||
//! type of the robust estimation algorithm
|
||||
enum
|
||||
{
|
||||
LMEDS=CV_LMEDS, //!< least-median algorithm
|
||||
RANSAC=CV_RANSAC //!< RANSAC algorithm
|
||||
};
|
||||
enum { LMEDS = 4, //!< least-median algorithm
|
||||
RANSAC = 8 //!< RANSAC algorithm
|
||||
};
|
||||
|
||||
enum { ITERATIVE = 0,
|
||||
EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation"
|
||||
P3P = 2 // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem"
|
||||
};
|
||||
|
||||
enum { CALIB_CB_ADAPTIVE_THRESH = 1,
|
||||
CALIB_CB_NORMALIZE_IMAGE = 2,
|
||||
CALIB_CB_FILTER_QUADS = 4,
|
||||
CALIB_CB_FAST_CHECK = 8
|
||||
};
|
||||
|
||||
enum { CALIB_CB_SYMMETRIC_GRID = 1,
|
||||
CALIB_CB_ASYMMETRIC_GRID = 2,
|
||||
CALIB_CB_CLUSTERING = 4
|
||||
};
|
||||
|
||||
enum { CALIB_USE_INTRINSIC_GUESS = 0x00001,
|
||||
CALIB_FIX_ASPECT_RATIO = 0x00002,
|
||||
CALIB_FIX_PRINCIPAL_POINT = 0x00004,
|
||||
CALIB_ZERO_TANGENT_DIST = 0x00008,
|
||||
CALIB_FIX_FOCAL_LENGTH = 0x00010,
|
||||
CALIB_FIX_K1 = 0x00020,
|
||||
CALIB_FIX_K2 = 0x00040,
|
||||
CALIB_FIX_K3 = 0x00080,
|
||||
CALIB_FIX_K4 = 0x00800,
|
||||
CALIB_FIX_K5 = 0x01000,
|
||||
CALIB_FIX_K6 = 0x02000,
|
||||
CALIB_RATIONAL_MODEL = 0x04000,
|
||||
CALIB_THIN_PRISM_MODEL = 0x08000,
|
||||
CALIB_FIX_S1_S2_S3_S4 = 0x10000,
|
||||
// only for stereo
|
||||
CALIB_FIX_INTRINSIC = 0x00100,
|
||||
CALIB_SAME_FOCAL_LENGTH = 0x00200,
|
||||
// for stereo rectification
|
||||
CALIB_ZERO_DISPARITY = 0x00400
|
||||
};
|
||||
|
||||
//! the algorithm for finding fundamental matrix
|
||||
enum { FM_7POINT = 1, //!< 7-point algorithm
|
||||
FM_8POINT = 2, //!< 8-point algorithm
|
||||
FM_LMEDS = 4, //!< least-median algorithm
|
||||
FM_RANSAC = 8 //!< RANSAC algorithm
|
||||
};
|
||||
|
||||
|
||||
|
||||
//! converts rotation vector to rotation matrix or vice versa using Rodrigues transformation
|
||||
CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
|
||||
|
||||
//! computes the best-fit perspective transformation mapping srcPoints to dstPoints.
|
||||
CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints,
|
||||
int method=0, double ransacReprojThreshold=3,
|
||||
int method = 0, double ransacReprojThreshold = 3,
|
||||
OutputArray mask=noArray());
|
||||
|
||||
//! variant of findHomography for backward compatibility
|
||||
CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints,
|
||||
OutputArray mask, int method=0, double ransacReprojThreshold=3);
|
||||
OutputArray mask, int method = 0, double ransacReprojThreshold = 3 );
|
||||
|
||||
//! Computes RQ decomposition of 3x3 matrix
|
||||
CV_EXPORTS_W Vec3d RQDecomp3x3( InputArray src, OutputArray mtxR, OutputArray mtxQ,
|
||||
OutputArray Qx=noArray(),
|
||||
OutputArray Qy=noArray(),
|
||||
OutputArray Qz=noArray());
|
||||
OutputArray Qx = noArray(),
|
||||
OutputArray Qy = noArray(),
|
||||
OutputArray Qz = noArray());
|
||||
|
||||
//! Decomposes the projection matrix into camera matrix and the rotation martix and the translation vector
|
||||
CV_EXPORTS_W void decomposeProjectionMatrix( InputArray projMatrix, OutputArray cameraMatrix,
|
||||
OutputArray rotMatrix, OutputArray transVect,
|
||||
OutputArray rotMatrixX=noArray(),
|
||||
OutputArray rotMatrixY=noArray(),
|
||||
OutputArray rotMatrixZ=noArray(),
|
||||
OutputArray eulerAngles=noArray() );
|
||||
OutputArray rotMatrixX = noArray(),
|
||||
OutputArray rotMatrixY = noArray(),
|
||||
OutputArray rotMatrixZ = noArray(),
|
||||
OutputArray eulerAngles =noArray() );
|
||||
|
||||
//! computes derivatives of the matrix product w.r.t each of the multiplied matrix coefficients
|
||||
CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B,
|
||||
OutputArray dABdA,
|
||||
OutputArray dABdB );
|
||||
CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB );
|
||||
|
||||
//! composes 2 [R|t] transformations together. Also computes the derivatives of the result w.r.t the arguments
|
||||
CV_EXPORTS_W void composeRT( InputArray rvec1, InputArray tvec1,
|
||||
InputArray rvec2, InputArray tvec2,
|
||||
OutputArray rvec3, OutputArray tvec3,
|
||||
OutputArray dr3dr1=noArray(), OutputArray dr3dt1=noArray(),
|
||||
OutputArray dr3dr2=noArray(), OutputArray dr3dt2=noArray(),
|
||||
OutputArray dt3dr1=noArray(), OutputArray dt3dt1=noArray(),
|
||||
OutputArray dt3dr2=noArray(), OutputArray dt3dt2=noArray() );
|
||||
OutputArray dr3dr1 = noArray(), OutputArray dr3dt1 = noArray(),
|
||||
OutputArray dr3dr2 = noArray(), OutputArray dr3dt2 = noArray(),
|
||||
OutputArray dt3dr1 = noArray(), OutputArray dt3dt1 = noArray(),
|
||||
OutputArray dt3dr2 = noArray(), OutputArray dt3dt2 = noArray() );
|
||||
|
||||
//! projects points from the model coordinate space to the image coordinates. Also computes derivatives of the image coordinates w.r.t the intrinsic and extrinsic camera parameters
|
||||
CV_EXPORTS_W void projectPoints( InputArray objectPoints,
|
||||
InputArray rvec, InputArray tvec,
|
||||
InputArray cameraMatrix, InputArray distCoeffs,
|
||||
OutputArray imagePoints,
|
||||
OutputArray jacobian=noArray(),
|
||||
double aspectRatio=0 );
|
||||
OutputArray jacobian = noArray(),
|
||||
double aspectRatio = 0 );
|
||||
|
||||
//! computes the camera pose from a few 3D points and the corresponding projections. The outliers are not handled.
|
||||
enum
|
||||
{
|
||||
ITERATIVE=CV_ITERATIVE,
|
||||
EPNP=CV_EPNP,
|
||||
P3P=CV_P3P
|
||||
};
|
||||
CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints,
|
||||
InputArray cameraMatrix, InputArray distCoeffs,
|
||||
OutputArray rvec, OutputArray tvec,
|
||||
bool useExtrinsicGuess=false, int flags=ITERATIVE);
|
||||
bool useExtrinsicGuess = false, int flags = ITERATIVE );
|
||||
|
||||
//! computes the camera pose from a few 3D points and the corresponding projections. The outliers are possible.
|
||||
CV_EXPORTS_W void solvePnPRansac( InputArray objectPoints,
|
||||
InputArray imagePoints,
|
||||
InputArray cameraMatrix,
|
||||
InputArray distCoeffs,
|
||||
OutputArray rvec,
|
||||
OutputArray tvec,
|
||||
bool useExtrinsicGuess = false,
|
||||
int iterationsCount = 100,
|
||||
float reprojectionError = 8.0,
|
||||
int minInliersCount = 100,
|
||||
OutputArray inliers = noArray(),
|
||||
int flags = ITERATIVE);
|
||||
CV_EXPORTS_W void solvePnPRansac( InputArray objectPoints, InputArray imagePoints,
|
||||
InputArray cameraMatrix, InputArray distCoeffs,
|
||||
OutputArray rvec, OutputArray tvec,
|
||||
bool useExtrinsicGuess = false, int iterationsCount = 100,
|
||||
float reprojectionError = 8.0, int minInliersCount = 100,
|
||||
OutputArray inliers = noArray(), int flags = ITERATIVE );
|
||||
|
||||
//! initializes camera matrix from a few 3D points and the corresponding projections.
|
||||
CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints,
|
||||
InputArrayOfArrays imagePoints,
|
||||
Size imageSize, double aspectRatio=1. );
|
||||
|
||||
enum { CALIB_CB_ADAPTIVE_THRESH = 1, CALIB_CB_NORMALIZE_IMAGE = 2,
|
||||
CALIB_CB_FILTER_QUADS = 4, CALIB_CB_FAST_CHECK = 8 };
|
||||
Size imageSize, double aspectRatio = 1.0 );
|
||||
|
||||
//! finds checkerboard pattern of the specified size in the image
|
||||
CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize,
|
||||
OutputArray corners,
|
||||
int flags=CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE );
|
||||
CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners,
|
||||
int flags = CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE );
|
||||
|
||||
//! finds subpixel-accurate positions of the chessboard corners
|
||||
CV_EXPORTS bool find4QuadCornerSubpix(InputArray img, InputOutputArray corners, Size region_size);
|
||||
CV_EXPORTS bool find4QuadCornerSubpix( InputArray img, InputOutputArray corners, Size region_size );
|
||||
|
||||
//! draws the checkerboard pattern (found or partly found) in the image
|
||||
CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize,
|
||||
InputArray corners, bool patternWasFound );
|
||||
|
||||
enum { CALIB_CB_SYMMETRIC_GRID = 1, CALIB_CB_ASYMMETRIC_GRID = 2,
|
||||
CALIB_CB_CLUSTERING = 4 };
|
||||
|
||||
//! finds circles' grid pattern of the specified size in the image
|
||||
CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize,
|
||||
OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID,
|
||||
const Ptr<FeatureDetector> &blobDetector = new SimpleBlobDetector());
|
||||
|
||||
//! the deprecated function. Use findCirclesGrid() instead of it.
|
||||
CV_EXPORTS_W bool findCirclesGridDefault( InputArray image, Size patternSize,
|
||||
OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID );
|
||||
enum
|
||||
{
|
||||
CALIB_USE_INTRINSIC_GUESS = CV_CALIB_USE_INTRINSIC_GUESS,
|
||||
CALIB_FIX_ASPECT_RATIO = CV_CALIB_FIX_ASPECT_RATIO,
|
||||
CALIB_FIX_PRINCIPAL_POINT = CV_CALIB_FIX_PRINCIPAL_POINT,
|
||||
CALIB_ZERO_TANGENT_DIST = CV_CALIB_ZERO_TANGENT_DIST,
|
||||
CALIB_FIX_FOCAL_LENGTH = CV_CALIB_FIX_FOCAL_LENGTH,
|
||||
CALIB_FIX_K1 = CV_CALIB_FIX_K1,
|
||||
CALIB_FIX_K2 = CV_CALIB_FIX_K2,
|
||||
CALIB_FIX_K3 = CV_CALIB_FIX_K3,
|
||||
CALIB_FIX_K4 = CV_CALIB_FIX_K4,
|
||||
CALIB_FIX_K5 = CV_CALIB_FIX_K5,
|
||||
CALIB_FIX_K6 = CV_CALIB_FIX_K6,
|
||||
CALIB_RATIONAL_MODEL = CV_CALIB_RATIONAL_MODEL,
|
||||
CALIB_THIN_PRISM_MODEL = CV_CALIB_THIN_PRISM_MODEL,
|
||||
CALIB_FIX_S1_S2_S3_S4=CV_CALIB_FIX_S1_S2_S3_S4,
|
||||
// only for stereo
|
||||
CALIB_FIX_INTRINSIC = CV_CALIB_FIX_INTRINSIC,
|
||||
CALIB_SAME_FOCAL_LENGTH = CV_CALIB_SAME_FOCAL_LENGTH,
|
||||
// for stereo rectification
|
||||
CALIB_ZERO_DISPARITY = CV_CALIB_ZERO_DISPARITY
|
||||
};
|
||||
OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID,
|
||||
const Ptr<FeatureDetector> &blobDetector = makePtr<SimpleBlobDetector>());
|
||||
|
||||
//! finds intrinsic and extrinsic camera parameters from several fews of a known calibration pattern.
|
||||
CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints,
|
||||
InputArrayOfArrays imagePoints,
|
||||
Size imageSize,
|
||||
InputOutputArray cameraMatrix,
|
||||
InputOutputArray distCoeffs,
|
||||
InputArrayOfArrays imagePoints, Size imageSize,
|
||||
InputOutputArray cameraMatrix, InputOutputArray distCoeffs,
|
||||
OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs,
|
||||
int flags=0, TermCriteria criteria = TermCriteria(
|
||||
TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON) );
|
||||
int flags = 0, TermCriteria criteria = TermCriteria(
|
||||
TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) );
|
||||
|
||||
//! computes several useful camera characteristics from the camera matrix, camera frame resolution and the physical sensor size.
|
||||
CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix,
|
||||
Size imageSize,
|
||||
double apertureWidth,
|
||||
double apertureHeight,
|
||||
CV_OUT double& fovx,
|
||||
CV_OUT double& fovy,
|
||||
CV_OUT double& focalLength,
|
||||
CV_OUT Point2d& principalPoint,
|
||||
CV_OUT double& aspectRatio );
|
||||
CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix, Size imageSize,
|
||||
double apertureWidth, double apertureHeight,
|
||||
CV_OUT double& fovx, CV_OUT double& fovy,
|
||||
CV_OUT double& focalLength, CV_OUT Point2d& principalPoint,
|
||||
CV_OUT double& aspectRatio );
|
||||
|
||||
//! finds intrinsic and extrinsic parameters of a stereo camera
|
||||
CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints,
|
||||
InputArrayOfArrays imagePoints1,
|
||||
InputArrayOfArrays imagePoints2,
|
||||
InputOutputArray cameraMatrix1,
|
||||
InputOutputArray distCoeffs1,
|
||||
InputOutputArray cameraMatrix2,
|
||||
InputOutputArray distCoeffs2,
|
||||
Size imageSize, OutputArray R,
|
||||
OutputArray T, OutputArray E, OutputArray F,
|
||||
InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2,
|
||||
InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1,
|
||||
InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2,
|
||||
Size imageSize, OutputArray R,OutputArray T, OutputArray E, OutputArray F,
|
||||
TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6),
|
||||
int flags=CALIB_FIX_INTRINSIC );
|
||||
int flags = CALIB_FIX_INTRINSIC );
|
||||
|
||||
|
||||
//! computes the rectification transformation for a stereo camera from its intrinsic and extrinsic parameters
|
||||
CV_EXPORTS_W void stereoRectify( InputArray cameraMatrix1, InputArray distCoeffs1,
|
||||
InputArray cameraMatrix2, InputArray distCoeffs2,
|
||||
Size imageSize, InputArray R, InputArray T,
|
||||
OutputArray R1, OutputArray R2,
|
||||
OutputArray P1, OutputArray P2,
|
||||
OutputArray Q, int flags=CALIB_ZERO_DISPARITY,
|
||||
double alpha=-1, Size newImageSize=Size(),
|
||||
CV_OUT Rect* validPixROI1=0, CV_OUT Rect* validPixROI2=0 );
|
||||
InputArray cameraMatrix2, InputArray distCoeffs2,
|
||||
Size imageSize, InputArray R, InputArray T,
|
||||
OutputArray R1, OutputArray R2,
|
||||
OutputArray P1, OutputArray P2,
|
||||
OutputArray Q, int flags = CALIB_ZERO_DISPARITY,
|
||||
double alpha = -1, Size newImageSize = Size(),
|
||||
CV_OUT Rect* validPixROI1 = 0, CV_OUT Rect* validPixROI2 = 0 );
|
||||
|
||||
//! computes the rectification transformation for an uncalibrated stereo camera (zero distortion is assumed)
|
||||
CV_EXPORTS_W bool stereoRectifyUncalibrated( InputArray points1, InputArray points2,
|
||||
InputArray F, Size imgSize,
|
||||
OutputArray H1, OutputArray H2,
|
||||
double threshold=5 );
|
||||
double threshold = 5 );
|
||||
|
||||
//! computes the rectification transformations for 3-head camera, where all the heads are on the same line.
|
||||
CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distCoeffs1,
|
||||
@@ -611,8 +237,9 @@ CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distC
|
||||
|
||||
//! returns the optimal new camera matrix
|
||||
CV_EXPORTS_W Mat getOptimalNewCameraMatrix( InputArray cameraMatrix, InputArray distCoeffs,
|
||||
Size imageSize, double alpha, Size newImgSize=Size(),
|
||||
CV_OUT Rect* validPixROI=0, bool centerPrincipalPoint=false);
|
||||
Size imageSize, double alpha, Size newImgSize = Size(),
|
||||
CV_OUT Rect* validPixROI = 0,
|
||||
bool centerPrincipalPoint = false);
|
||||
|
||||
//! converts point coordinates from normal pixel coordinates to homogeneous coordinates ((x,y)->(x,y,1))
|
||||
CV_EXPORTS_W void convertPointsToHomogeneous( InputArray src, OutputArray dst );
|
||||
@@ -623,44 +250,36 @@ CV_EXPORTS_W void convertPointsFromHomogeneous( InputArray src, OutputArray dst
|
||||
//! for backward compatibility
|
||||
CV_EXPORTS void convertPointsHomogeneous( InputArray src, OutputArray dst );
|
||||
|
||||
//! the algorithm for finding fundamental matrix
|
||||
enum
|
||||
{
|
||||
FM_7POINT = CV_FM_7POINT, //!< 7-point algorithm
|
||||
FM_8POINT = CV_FM_8POINT, //!< 8-point algorithm
|
||||
FM_LMEDS = CV_FM_LMEDS, //!< least-median algorithm
|
||||
FM_RANSAC = CV_FM_RANSAC //!< RANSAC algorithm
|
||||
};
|
||||
|
||||
//! finds fundamental matrix from a set of corresponding 2D points
|
||||
CV_EXPORTS_W Mat findFundamentalMat( InputArray points1, InputArray points2,
|
||||
int method=FM_RANSAC,
|
||||
double param1=3., double param2=0.99,
|
||||
OutputArray mask=noArray());
|
||||
int method = FM_RANSAC,
|
||||
double param1 = 3., double param2 = 0.99,
|
||||
OutputArray mask = noArray() );
|
||||
|
||||
//! variant of findFundamentalMat for backward compatibility
|
||||
CV_EXPORTS Mat findFundamentalMat( InputArray points1, InputArray points2,
|
||||
OutputArray mask, int method=FM_RANSAC,
|
||||
double param1=3., double param2=0.99);
|
||||
OutputArray mask, int method = FM_RANSAC,
|
||||
double param1 = 3., double param2 = 0.99 );
|
||||
|
||||
//! finds essential matrix from a set of corresponding 2D points using five-point algorithm
|
||||
CV_EXPORTS Mat findEssentialMat( InputArray points1, InputArray points2, double focal = 1.0, Point2d pp = Point2d(0, 0),
|
||||
int method = CV_RANSAC,
|
||||
double prob = 0.999, double threshold = 1.0, OutputArray mask = noArray() );
|
||||
CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2,
|
||||
double focal = 1.0, Point2d pp = Point2d(0, 0),
|
||||
int method = RANSAC, double prob = 0.999,
|
||||
double threshold = 1.0, OutputArray mask = noArray() );
|
||||
|
||||
//! decompose essential matrix to possible rotation matrix and one translation vector
|
||||
CV_EXPORTS void decomposeEssentialMat( InputArray E, OutputArray R1, OutputArray R2, OutputArray t );
|
||||
CV_EXPORTS_W void decomposeEssentialMat( InputArray E, OutputArray R1, OutputArray R2, OutputArray t );
|
||||
|
||||
//! recover relative camera pose from a set of corresponding 2D points
|
||||
CV_EXPORTS int recoverPose( InputArray E, InputArray points1, InputArray points2, OutputArray R, OutputArray t,
|
||||
CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2,
|
||||
OutputArray R, OutputArray t,
|
||||
double focal = 1.0, Point2d pp = Point2d(0, 0),
|
||||
InputOutputArray mask = noArray());
|
||||
InputOutputArray mask = noArray() );
|
||||
|
||||
|
||||
//! finds coordinates of epipolar lines corresponding the specified points
|
||||
CV_EXPORTS void computeCorrespondEpilines( InputArray points,
|
||||
int whichImage, InputArray F,
|
||||
OutputArray lines );
|
||||
CV_EXPORTS_W void computeCorrespondEpilines( InputArray points, int whichImage,
|
||||
InputArray F, OutputArray lines );
|
||||
|
||||
CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2,
|
||||
InputArray projPoints1, InputArray projPoints2,
|
||||
@@ -669,89 +288,10 @@ CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2,
|
||||
CV_EXPORTS_W void correctMatches( InputArray F, InputArray points1, InputArray points2,
|
||||
OutputArray newPoints1, OutputArray newPoints2 );
|
||||
|
||||
|
||||
class CV_EXPORTS_W StereoMatcher : public Algorithm
|
||||
{
|
||||
public:
|
||||
CV_WRAP virtual void compute( InputArray left, InputArray right,
|
||||
OutputArray disparity ) = 0;
|
||||
};
|
||||
|
||||
enum { STEREO_DISP_SCALE=16, STEREO_PREFILTER_NORMALIZED_RESPONSE = 0, STEREO_PREFILTER_XSOBEL = 1 };
|
||||
|
||||
CV_EXPORTS Ptr<StereoMatcher> createStereoBM(int numDisparities=0, int SADWindowSize=21);
|
||||
|
||||
CV_EXPORTS Ptr<StereoMatcher> createStereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,
|
||||
int P1=0, int P2=0, int disp12MaxDiff=0,
|
||||
int preFilterCap=0, int uniquenessRatio=0,
|
||||
int speckleWindowSize=0, int speckleRange=0,
|
||||
bool fullDP=false);
|
||||
|
||||
template<> CV_EXPORTS void Ptr<CvStereoBMState>::delete_obj();
|
||||
|
||||
// to be moved to "compat" module
|
||||
class CV_EXPORTS_W StereoBM
|
||||
{
|
||||
public:
|
||||
enum { PREFILTER_NORMALIZED_RESPONSE = 0, PREFILTER_XSOBEL = 1,
|
||||
BASIC_PRESET=0, FISH_EYE_PRESET=1, NARROW_PRESET=2 };
|
||||
|
||||
//! the default constructor
|
||||
CV_WRAP StereoBM();
|
||||
//! the full constructor taking the camera-specific preset, number of disparities and the SAD window size
|
||||
CV_WRAP StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);
|
||||
//! the method that reinitializes the state. The previous content is destroyed
|
||||
void init(int preset, int ndisparities=0, int SADWindowSize=21);
|
||||
//! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair
|
||||
CV_WRAP_AS(compute) void operator()( InputArray left, InputArray right,
|
||||
OutputArray disparity, int disptype=CV_16S );
|
||||
|
||||
//! pointer to the underlying CvStereoBMState
|
||||
Ptr<CvStereoBMState> state;
|
||||
};
|
||||
|
||||
|
||||
// to be moved to "compat" module
|
||||
class CV_EXPORTS_W StereoSGBM
|
||||
{
|
||||
public:
|
||||
enum { DISP_SHIFT=4, DISP_SCALE = (1<<DISP_SHIFT) };
|
||||
|
||||
//! the default constructor
|
||||
CV_WRAP StereoSGBM();
|
||||
|
||||
//! the full constructor taking all the necessary algorithm parameters
|
||||
CV_WRAP StereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,
|
||||
int P1=0, int P2=0, int disp12MaxDiff=0,
|
||||
int preFilterCap=0, int uniquenessRatio=0,
|
||||
int speckleWindowSize=0, int speckleRange=0,
|
||||
bool fullDP=false);
|
||||
//! the destructor
|
||||
virtual ~StereoSGBM();
|
||||
|
||||
//! the stereo correspondence operator that computes disparity map for the specified rectified stereo pair
|
||||
CV_WRAP_AS(compute) virtual void operator()(InputArray left, InputArray right,
|
||||
OutputArray disp);
|
||||
|
||||
CV_PROP_RW int minDisparity;
|
||||
CV_PROP_RW int numberOfDisparities;
|
||||
CV_PROP_RW int SADWindowSize;
|
||||
CV_PROP_RW int preFilterCap;
|
||||
CV_PROP_RW int uniquenessRatio;
|
||||
CV_PROP_RW int P1;
|
||||
CV_PROP_RW int P2;
|
||||
CV_PROP_RW int speckleWindowSize;
|
||||
CV_PROP_RW int speckleRange;
|
||||
CV_PROP_RW int disp12MaxDiff;
|
||||
CV_PROP_RW bool fullDP;
|
||||
|
||||
protected:
|
||||
Ptr<StereoMatcher> sm;
|
||||
};
|
||||
|
||||
//! filters off speckles (small regions of incorrectly computed disparity)
|
||||
CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal, int maxSpeckleSize, double maxDiff,
|
||||
InputOutputArray buf=noArray() );
|
||||
CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal,
|
||||
int maxSpeckleSize, double maxDiff,
|
||||
InputOutputArray buf = noArray() );
|
||||
|
||||
//! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify())
|
||||
CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2,
|
||||
@@ -761,20 +301,116 @@ CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2,
|
||||
//! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm
|
||||
CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost,
|
||||
int minDisparity, int numberOfDisparities,
|
||||
int disp12MaxDisp=1 );
|
||||
int disp12MaxDisp = 1 );
|
||||
|
||||
//! reprojects disparity image to 3D: (x,y,d)->(X,Y,Z) using the matrix Q returned by cv::stereoRectify
|
||||
CV_EXPORTS_W void reprojectImageTo3D( InputArray disparity,
|
||||
OutputArray _3dImage, InputArray Q,
|
||||
bool handleMissingValues=false,
|
||||
int ddepth=-1 );
|
||||
bool handleMissingValues = false,
|
||||
int ddepth = -1 );
|
||||
|
||||
CV_EXPORTS_W int estimateAffine3D(InputArray src, InputArray dst,
|
||||
OutputArray out, OutputArray inliers,
|
||||
double ransacThreshold=3, double confidence=0.99);
|
||||
double ransacThreshold = 3, double confidence = 0.99);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
class CV_EXPORTS_W StereoMatcher : public Algorithm
|
||||
{
|
||||
public:
|
||||
enum { DISP_SHIFT = 4,
|
||||
DISP_SCALE = (1 << DISP_SHIFT)
|
||||
};
|
||||
|
||||
CV_WRAP virtual void compute( InputArray left, InputArray right,
|
||||
OutputArray disparity ) = 0;
|
||||
|
||||
CV_WRAP virtual int getMinDisparity() const = 0;
|
||||
CV_WRAP virtual void setMinDisparity(int minDisparity) = 0;
|
||||
|
||||
CV_WRAP virtual int getNumDisparities() const = 0;
|
||||
CV_WRAP virtual void setNumDisparities(int numDisparities) = 0;
|
||||
|
||||
CV_WRAP virtual int getBlockSize() const = 0;
|
||||
CV_WRAP virtual void setBlockSize(int blockSize) = 0;
|
||||
|
||||
CV_WRAP virtual int getSpeckleWindowSize() const = 0;
|
||||
CV_WRAP virtual void setSpeckleWindowSize(int speckleWindowSize) = 0;
|
||||
|
||||
CV_WRAP virtual int getSpeckleRange() const = 0;
|
||||
CV_WRAP virtual void setSpeckleRange(int speckleRange) = 0;
|
||||
|
||||
CV_WRAP virtual int getDisp12MaxDiff() const = 0;
|
||||
CV_WRAP virtual void setDisp12MaxDiff(int disp12MaxDiff) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CV_EXPORTS_W StereoBM : public StereoMatcher
|
||||
{
|
||||
public:
|
||||
enum { PREFILTER_NORMALIZED_RESPONSE = 0,
|
||||
PREFILTER_XSOBEL = 1
|
||||
};
|
||||
|
||||
CV_WRAP virtual int getPreFilterType() const = 0;
|
||||
CV_WRAP virtual void setPreFilterType(int preFilterType) = 0;
|
||||
|
||||
CV_WRAP virtual int getPreFilterSize() const = 0;
|
||||
CV_WRAP virtual void setPreFilterSize(int preFilterSize) = 0;
|
||||
|
||||
CV_WRAP virtual int getPreFilterCap() const = 0;
|
||||
CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0;
|
||||
|
||||
CV_WRAP virtual int getTextureThreshold() const = 0;
|
||||
CV_WRAP virtual void setTextureThreshold(int textureThreshold) = 0;
|
||||
|
||||
CV_WRAP virtual int getUniquenessRatio() const = 0;
|
||||
CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0;
|
||||
|
||||
CV_WRAP virtual int getSmallerBlockSize() const = 0;
|
||||
CV_WRAP virtual void setSmallerBlockSize(int blockSize) = 0;
|
||||
|
||||
CV_WRAP virtual Rect getROI1() const = 0;
|
||||
CV_WRAP virtual void setROI1(Rect roi1) = 0;
|
||||
|
||||
CV_WRAP virtual Rect getROI2() const = 0;
|
||||
CV_WRAP virtual void setROI2(Rect roi2) = 0;
|
||||
};
|
||||
|
||||
CV_EXPORTS_W Ptr<StereoBM> createStereoBM(int numDisparities = 0, int blockSize = 21);
|
||||
|
||||
|
||||
class CV_EXPORTS_W StereoSGBM : public StereoMatcher
|
||||
{
|
||||
public:
|
||||
enum { MODE_SGBM = 0,
|
||||
MODE_HH = 1
|
||||
};
|
||||
|
||||
CV_WRAP virtual int getPreFilterCap() const = 0;
|
||||
CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0;
|
||||
|
||||
CV_WRAP virtual int getUniquenessRatio() const = 0;
|
||||
CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0;
|
||||
|
||||
CV_WRAP virtual int getP1() const = 0;
|
||||
CV_WRAP virtual void setP1(int P1) = 0;
|
||||
|
||||
CV_WRAP virtual int getP2() const = 0;
|
||||
CV_WRAP virtual void setP2(int P2) = 0;
|
||||
|
||||
CV_WRAP virtual int getMode() const = 0;
|
||||
CV_WRAP virtual void setMode(int mode) = 0;
|
||||
};
|
||||
|
||||
|
||||
CV_EXPORTS_W Ptr<StereoSGBM> createStereoSGBM(int minDisparity, int numDisparities, int blockSize,
|
||||
int P1 = 0, int P2 = 0, int disp12MaxDiff = 0,
|
||||
int preFilterCap = 0, int uniquenessRatio = 0,
|
||||
int speckleWindowSize = 0, int speckleRange = 0,
|
||||
int mode = StereoSGBM::MODE_SGBM);
|
||||
|
||||
} // cv
|
||||
|
||||
#endif
|
||||
|
||||
@@ -45,4 +45,4 @@
|
||||
#error this is a compatibility header which should not be used inside the OpenCV library
|
||||
#endif
|
||||
|
||||
#include "opencv2/calib3d.hpp"
|
||||
#include "opencv2/calib3d.hpp"
|
||||
|
||||
@@ -0,0 +1,413 @@
|
||||
/*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.
|
||||
// Copyright (C) 2013, OpenCV Foundation, 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_CALIB3D_C_H__
|
||||
#define __OPENCV_CALIB3D_C_H__
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
* Camera Calibration, Pose Estimation and Stereo *
|
||||
\****************************************************************************************/
|
||||
|
||||
typedef struct CvPOSITObject CvPOSITObject;
|
||||
|
||||
/* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
|
||||
CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
|
||||
|
||||
|
||||
/* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
|
||||
an object given its model and projection in a weak-perspective case */
|
||||
CVAPI(void) cvPOSIT( CvPOSITObject* posit_object, CvPoint2D32f* image_points,
|
||||
double focal_length, CvTermCriteria criteria,
|
||||
float* rotation_matrix, float* translation_vector);
|
||||
|
||||
/* Releases CvPOSITObject structure */
|
||||
CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object );
|
||||
|
||||
/* updates the number of RANSAC iterations */
|
||||
CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob,
|
||||
int model_points, int max_iters );
|
||||
|
||||
CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst );
|
||||
|
||||
/* Calculates fundamental matrix given a set of corresponding points */
|
||||
#define CV_FM_7POINT 1
|
||||
#define CV_FM_8POINT 2
|
||||
|
||||
#define CV_LMEDS 4
|
||||
#define CV_RANSAC 8
|
||||
|
||||
#define CV_FM_LMEDS_ONLY CV_LMEDS
|
||||
#define CV_FM_RANSAC_ONLY CV_RANSAC
|
||||
#define CV_FM_LMEDS CV_LMEDS
|
||||
#define CV_FM_RANSAC CV_RANSAC
|
||||
|
||||
enum
|
||||
{
|
||||
CV_ITERATIVE = 0,
|
||||
CV_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation"
|
||||
CV_P3P = 2 // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem"
|
||||
};
|
||||
|
||||
CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,
|
||||
CvMat* fundamental_matrix,
|
||||
int method CV_DEFAULT(CV_FM_RANSAC),
|
||||
double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99),
|
||||
CvMat* status CV_DEFAULT(NULL) );
|
||||
|
||||
/* For each input point on one of images
|
||||
computes parameters of the corresponding
|
||||
epipolar line on the other image */
|
||||
CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
|
||||
int which_image,
|
||||
const CvMat* fundamental_matrix,
|
||||
CvMat* correspondent_lines );
|
||||
|
||||
/* Triangulation functions */
|
||||
|
||||
CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2,
|
||||
CvMat* projPoints1, CvMat* projPoints2,
|
||||
CvMat* points4D);
|
||||
|
||||
CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2,
|
||||
CvMat* new_points1, CvMat* new_points2);
|
||||
|
||||
|
||||
/* Computes the optimal new camera matrix according to the free scaling parameter alpha:
|
||||
alpha=0 - only valid pixels will be retained in the undistorted image
|
||||
alpha=1 - all the source image pixels will be retained in the undistorted image
|
||||
*/
|
||||
CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix,
|
||||
const CvMat* dist_coeffs,
|
||||
CvSize image_size, double alpha,
|
||||
CvMat* new_camera_matrix,
|
||||
CvSize new_imag_size CV_DEFAULT(cvSize(0,0)),
|
||||
CvRect* valid_pixel_ROI CV_DEFAULT(0),
|
||||
int center_principal_point CV_DEFAULT(0));
|
||||
|
||||
/* Converts rotation vector to rotation matrix or vice versa */
|
||||
CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst,
|
||||
CvMat* jacobian CV_DEFAULT(0) );
|
||||
|
||||
/* Finds perspective transformation between the object plane and image (view) plane */
|
||||
CVAPI(int) cvFindHomography( const CvMat* src_points,
|
||||
const CvMat* dst_points,
|
||||
CvMat* homography,
|
||||
int method CV_DEFAULT(0),
|
||||
double ransacReprojThreshold CV_DEFAULT(3),
|
||||
CvMat* mask CV_DEFAULT(0));
|
||||
|
||||
/* Computes RQ decomposition for 3x3 matrices */
|
||||
CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ,
|
||||
CvMat *matrixQx CV_DEFAULT(NULL),
|
||||
CvMat *matrixQy CV_DEFAULT(NULL),
|
||||
CvMat *matrixQz CV_DEFAULT(NULL),
|
||||
CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
|
||||
|
||||
/* Computes projection matrix decomposition */
|
||||
CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr,
|
||||
CvMat *rotMatr, CvMat *posVect,
|
||||
CvMat *rotMatrX CV_DEFAULT(NULL),
|
||||
CvMat *rotMatrY CV_DEFAULT(NULL),
|
||||
CvMat *rotMatrZ CV_DEFAULT(NULL),
|
||||
CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
|
||||
|
||||
/* Computes d(AB)/dA and d(AB)/dB */
|
||||
CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB );
|
||||
|
||||
/* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)),
|
||||
t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */
|
||||
CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1,
|
||||
const CvMat* _rvec2, const CvMat* _tvec2,
|
||||
CvMat* _rvec3, CvMat* _tvec3,
|
||||
CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0),
|
||||
CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0),
|
||||
CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0),
|
||||
CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) );
|
||||
|
||||
/* Projects object points to the view plane using
|
||||
the specified extrinsic and intrinsic camera parameters */
|
||||
CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
|
||||
const CvMat* translation_vector, const CvMat* camera_matrix,
|
||||
const CvMat* distortion_coeffs, CvMat* image_points,
|
||||
CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
|
||||
CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
|
||||
CvMat* dpddist CV_DEFAULT(NULL),
|
||||
double aspect_ratio CV_DEFAULT(0));
|
||||
|
||||
/* Finds extrinsic camera parameters from
|
||||
a few known corresponding point pairs and intrinsic parameters */
|
||||
CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* camera_matrix,
|
||||
const CvMat* distortion_coeffs,
|
||||
CvMat* rotation_vector,
|
||||
CvMat* translation_vector,
|
||||
int use_extrinsic_guess CV_DEFAULT(0) );
|
||||
|
||||
/* Computes initial estimate of the intrinsic camera parameters
|
||||
in case of planar calibration target (e.g. chessboard) */
|
||||
CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* npoints, CvSize image_size,
|
||||
CvMat* camera_matrix,
|
||||
double aspect_ratio CV_DEFAULT(1.) );
|
||||
|
||||
#define CV_CALIB_CB_ADAPTIVE_THRESH 1
|
||||
#define CV_CALIB_CB_NORMALIZE_IMAGE 2
|
||||
#define CV_CALIB_CB_FILTER_QUADS 4
|
||||
#define CV_CALIB_CB_FAST_CHECK 8
|
||||
|
||||
// Performs a fast check if a chessboard is in the input image. This is a workaround to
|
||||
// a problem of cvFindChessboardCorners being slow on images with no chessboard
|
||||
// - src: input image
|
||||
// - size: chessboard size
|
||||
// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called,
|
||||
// 0 if there is no chessboard, -1 in case of error
|
||||
CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size);
|
||||
|
||||
/* Detects corners on a chessboard calibration pattern */
|
||||
CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
|
||||
CvPoint2D32f* corners,
|
||||
int* corner_count CV_DEFAULT(NULL),
|
||||
int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) );
|
||||
|
||||
/* Draws individual chessboard corners or the whole chessboard detected */
|
||||
CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
|
||||
CvPoint2D32f* corners,
|
||||
int count, int pattern_was_found );
|
||||
|
||||
#define CV_CALIB_USE_INTRINSIC_GUESS 1
|
||||
#define CV_CALIB_FIX_ASPECT_RATIO 2
|
||||
#define CV_CALIB_FIX_PRINCIPAL_POINT 4
|
||||
#define CV_CALIB_ZERO_TANGENT_DIST 8
|
||||
#define CV_CALIB_FIX_FOCAL_LENGTH 16
|
||||
#define CV_CALIB_FIX_K1 32
|
||||
#define CV_CALIB_FIX_K2 64
|
||||
#define CV_CALIB_FIX_K3 128
|
||||
#define CV_CALIB_FIX_K4 2048
|
||||
#define CV_CALIB_FIX_K5 4096
|
||||
#define CV_CALIB_FIX_K6 8192
|
||||
#define CV_CALIB_RATIONAL_MODEL 16384
|
||||
#define CV_CALIB_THIN_PRISM_MODEL 32768
|
||||
#define CV_CALIB_FIX_S1_S2_S3_S4 65536
|
||||
|
||||
|
||||
/* Finds intrinsic and extrinsic camera parameters
|
||||
from a few views of known calibration pattern */
|
||||
CVAPI(double) cvCalibrateCamera2( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* point_counts,
|
||||
CvSize image_size,
|
||||
CvMat* camera_matrix,
|
||||
CvMat* distortion_coeffs,
|
||||
CvMat* rotation_vectors CV_DEFAULT(NULL),
|
||||
CvMat* translation_vectors CV_DEFAULT(NULL),
|
||||
int flags CV_DEFAULT(0),
|
||||
CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
|
||||
CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON)) );
|
||||
|
||||
/* Computes various useful characteristics of the camera from the data computed by
|
||||
cvCalibrateCamera2 */
|
||||
CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix,
|
||||
CvSize image_size,
|
||||
double aperture_width CV_DEFAULT(0),
|
||||
double aperture_height CV_DEFAULT(0),
|
||||
double *fovx CV_DEFAULT(NULL),
|
||||
double *fovy CV_DEFAULT(NULL),
|
||||
double *focal_length CV_DEFAULT(NULL),
|
||||
CvPoint2D64f *principal_point CV_DEFAULT(NULL),
|
||||
double *pixel_aspect_ratio CV_DEFAULT(NULL));
|
||||
|
||||
#define CV_CALIB_FIX_INTRINSIC 256
|
||||
#define CV_CALIB_SAME_FOCAL_LENGTH 512
|
||||
|
||||
/* Computes the transformation from one camera coordinate system to another one
|
||||
from a few correspondent views of the same calibration target. Optionally, calibrates
|
||||
both cameras */
|
||||
CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1,
|
||||
const CvMat* image_points2, const CvMat* npoints,
|
||||
CvMat* camera_matrix1, CvMat* dist_coeffs1,
|
||||
CvMat* camera_matrix2, CvMat* dist_coeffs2,
|
||||
CvSize image_size, CvMat* R, CvMat* T,
|
||||
CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0),
|
||||
CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
|
||||
CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)),
|
||||
int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC));
|
||||
|
||||
#define CV_CALIB_ZERO_DISPARITY 1024
|
||||
|
||||
/* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both
|
||||
views parallel (=> to make all the epipolar lines horizontal or vertical) */
|
||||
CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2,
|
||||
const CvMat* dist_coeffs1, const CvMat* dist_coeffs2,
|
||||
CvSize image_size, const CvMat* R, const CvMat* T,
|
||||
CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2,
|
||||
CvMat* Q CV_DEFAULT(0),
|
||||
int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY),
|
||||
double alpha CV_DEFAULT(-1),
|
||||
CvSize new_image_size CV_DEFAULT(cvSize(0,0)),
|
||||
CvRect* valid_pix_ROI1 CV_DEFAULT(0),
|
||||
CvRect* valid_pix_ROI2 CV_DEFAULT(0));
|
||||
|
||||
/* Computes rectification transformations for uncalibrated pair of images using a set
|
||||
of point correspondences */
|
||||
CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2,
|
||||
const CvMat* F, CvSize img_size,
|
||||
CvMat* H1, CvMat* H2,
|
||||
double threshold CV_DEFAULT(5));
|
||||
|
||||
|
||||
|
||||
/* stereo correspondence parameters and functions */
|
||||
|
||||
#define CV_STEREO_BM_NORMALIZED_RESPONSE 0
|
||||
#define CV_STEREO_BM_XSOBEL 1
|
||||
|
||||
/* Block matching algorithm structure */
|
||||
typedef struct CvStereoBMState
|
||||
{
|
||||
// pre-filtering (normalization of input images)
|
||||
int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now
|
||||
int preFilterSize; // averaging window size: ~5x5..21x21
|
||||
int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap]
|
||||
|
||||
// correspondence using Sum of Absolute Difference (SAD)
|
||||
int SADWindowSize; // ~5x5..21x21
|
||||
int minDisparity; // minimum disparity (can be negative)
|
||||
int numberOfDisparities; // maximum disparity - minimum disparity (> 0)
|
||||
|
||||
// post-filtering
|
||||
int textureThreshold; // the disparity is only computed for pixels
|
||||
// with textured enough neighborhood
|
||||
int uniquenessRatio; // accept the computed disparity d* only if
|
||||
// SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.)
|
||||
// for any d != d*+/-1 within the search range.
|
||||
int speckleWindowSize; // disparity variation window
|
||||
int speckleRange; // acceptable range of variation in window
|
||||
|
||||
int trySmallerWindows; // if 1, the results may be more accurate,
|
||||
// at the expense of slower processing
|
||||
CvRect roi1, roi2;
|
||||
int disp12MaxDiff;
|
||||
|
||||
// temporary buffers
|
||||
CvMat* preFilteredImg0;
|
||||
CvMat* preFilteredImg1;
|
||||
CvMat* slidingSumBuf;
|
||||
CvMat* cost;
|
||||
CvMat* disp;
|
||||
} CvStereoBMState;
|
||||
|
||||
#define CV_STEREO_BM_BASIC 0
|
||||
#define CV_STEREO_BM_FISH_EYE 1
|
||||
#define CV_STEREO_BM_NARROW 2
|
||||
|
||||
CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC),
|
||||
int numberOfDisparities CV_DEFAULT(0));
|
||||
|
||||
CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state );
|
||||
|
||||
CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right,
|
||||
CvArr* disparity, CvStereoBMState* state );
|
||||
|
||||
CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,
|
||||
int numberOfDisparities, int SADWindowSize );
|
||||
|
||||
CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost,
|
||||
int minDisparity, int numberOfDisparities,
|
||||
int disp12MaxDiff CV_DEFAULT(1) );
|
||||
|
||||
/* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */
|
||||
CVAPI(void) cvReprojectImageTo3D( const CvArr* disparityImage,
|
||||
CvArr* _3dImage, const CvMat* Q,
|
||||
int handleMissingValues CV_DEFAULT(0) );
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
class CV_EXPORTS CvLevMarq
|
||||
{
|
||||
public:
|
||||
CvLevMarq();
|
||||
CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria=
|
||||
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
|
||||
bool completeSymmFlag=false );
|
||||
~CvLevMarq();
|
||||
void init( int nparams, int nerrs, CvTermCriteria criteria=
|
||||
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
|
||||
bool completeSymmFlag=false );
|
||||
bool update( const CvMat*& param, CvMat*& J, CvMat*& err );
|
||||
bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm );
|
||||
|
||||
void clear();
|
||||
void step();
|
||||
enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 };
|
||||
|
||||
cv::Ptr<CvMat> mask;
|
||||
cv::Ptr<CvMat> prevParam;
|
||||
cv::Ptr<CvMat> param;
|
||||
cv::Ptr<CvMat> J;
|
||||
cv::Ptr<CvMat> err;
|
||||
cv::Ptr<CvMat> JtJ;
|
||||
cv::Ptr<CvMat> JtJN;
|
||||
cv::Ptr<CvMat> JtErr;
|
||||
cv::Ptr<CvMat> JtJV;
|
||||
cv::Ptr<CvMat> JtJW;
|
||||
double prevErrNorm, errNorm;
|
||||
int lambdaLg10;
|
||||
CvTermCriteria criteria;
|
||||
int state;
|
||||
int iters;
|
||||
bool completeSymmFlag;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __OPENCV_CALIB3D_C_H__ */
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "perf_precomp.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
#include "tbb/task_scheduler_init.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -7,7 +10,7 @@ using namespace perf;
|
||||
using std::tr1::make_tuple;
|
||||
using std::tr1::get;
|
||||
|
||||
CV_ENUM(pnpAlgo, CV_ITERATIVE, CV_EPNP /*, CV_P3P*/)
|
||||
CV_ENUM(pnpAlgo, ITERATIVE, EPNP /*, P3P*/)
|
||||
|
||||
typedef std::tr1::tuple<int, pnpAlgo> PointsNum_Algo_t;
|
||||
typedef perf::TestBaseWithParam<PointsNum_Algo_t> PointsNum_Algo;
|
||||
@@ -17,7 +20,7 @@ typedef perf::TestBaseWithParam<int> PointsNum;
|
||||
PERF_TEST_P(PointsNum_Algo, solvePnP,
|
||||
testing::Combine(
|
||||
testing::Values(/*4,*/ 3*9, 7*13), //TODO: find why results on 4 points are too unstable
|
||||
testing::Values((int)CV_ITERATIVE, (int)CV_EPNP)
|
||||
testing::Values((int)ITERATIVE, (int)EPNP)
|
||||
)
|
||||
)
|
||||
{
|
||||
@@ -90,7 +93,7 @@ PERF_TEST(PointsNum_Algo, solveP3P)
|
||||
|
||||
TEST_CYCLE_N(1000)
|
||||
{
|
||||
solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, CV_P3P);
|
||||
solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, P3P);
|
||||
}
|
||||
|
||||
SANITY_CHECK(rvec, 1e-6);
|
||||
@@ -127,7 +130,7 @@ PERF_TEST_P(PointsNum, DISABLED_SolvePnPRansac, testing::Values(4, 3*9, 7*13))
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
// limit concurrency to get determenistic result
|
||||
cv::Ptr<tbb::task_scheduler_init> one_thread = new tbb::task_scheduler_init(1);
|
||||
tbb::task_scheduler_init one_thread(1);
|
||||
#endif
|
||||
|
||||
TEST_CYCLE()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include "perf_precomp.hpp"
|
||||
@@ -47,7 +47,7 @@ using namespace cv;
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@
|
||||
\************************************************************************************/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
#include "circlesgrid.hpp"
|
||||
#include <stdarg.h>
|
||||
|
||||
@@ -269,8 +271,8 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
if( !out_corners )
|
||||
CV_Error( CV_StsNullPtr, "Null pointer to corners" );
|
||||
|
||||
storage = cvCreateMemStorage(0);
|
||||
thresh_img = cvCreateMat( img->rows, img->cols, CV_8UC1 );
|
||||
storage.reset(cvCreateMemStorage(0));
|
||||
thresh_img.reset(cvCreateMat( img->rows, img->cols, CV_8UC1 ));
|
||||
|
||||
#ifdef DEBUG_CHESSBOARD
|
||||
dbg_img = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3 );
|
||||
@@ -282,7 +284,7 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
{
|
||||
// equalize the input image histogram -
|
||||
// that should make the contrast between "black" and "white" areas big enough
|
||||
norm_img = cvCreateMat( img->rows, img->cols, CV_8UC1 );
|
||||
norm_img.reset(cvCreateMat( img->rows, img->cols, CV_8UC1 ));
|
||||
|
||||
if( CV_MAT_CN(img->type) != 1 )
|
||||
{
|
||||
@@ -539,12 +541,12 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
cv::Ptr<CvMat> gray;
|
||||
if( CV_MAT_CN(img->type) != 1 )
|
||||
{
|
||||
gray = cvCreateMat(img->rows, img->cols, CV_8UC1);
|
||||
gray.reset(cvCreateMat(img->rows, img->cols, CV_8UC1));
|
||||
cvCvtColor(img, gray, CV_BGR2GRAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
gray = cvCloneMat(img);
|
||||
gray.reset(cvCloneMat(img));
|
||||
}
|
||||
int wsize = 2;
|
||||
cvFindCornerSubPix( gray, out_corners, pattern_size.width*pattern_size.height,
|
||||
@@ -625,7 +627,7 @@ icvOrderFoundConnectedQuads( int quad_count, CvCBQuad **quads,
|
||||
int *all_count, CvCBQuad **all_quads, CvCBCorner **corners,
|
||||
CvSize pattern_size, CvMemStorage* storage )
|
||||
{
|
||||
cv::Ptr<CvMemStorage> temp_storage = cvCreateChildMemStorage( storage );
|
||||
cv::Ptr<CvMemStorage> temp_storage(cvCreateChildMemStorage( storage ));
|
||||
CvSeq* stack = cvCreateSeq( 0, sizeof(*stack), sizeof(void*), temp_storage );
|
||||
|
||||
// first find an interior quad
|
||||
@@ -1095,7 +1097,7 @@ icvOrderQuad(CvCBQuad *quad, CvCBCorner *corner, int common)
|
||||
static int
|
||||
icvCleanFoundConnectedQuads( int quad_count, CvCBQuad **quad_group, CvSize pattern_size )
|
||||
{
|
||||
CvPoint2D32f center = {0,0};
|
||||
CvPoint2D32f center;
|
||||
int i, j, k;
|
||||
// number of quads this pattern should contain
|
||||
int count = ((pattern_size.width + 1)*(pattern_size.height + 1) + 1)/2;
|
||||
@@ -1107,11 +1109,11 @@ icvCleanFoundConnectedQuads( int quad_count, CvCBQuad **quad_group, CvSize patte
|
||||
|
||||
// create an array of quadrangle centers
|
||||
cv::AutoBuffer<CvPoint2D32f> centers( quad_count );
|
||||
cv::Ptr<CvMemStorage> temp_storage = cvCreateMemStorage(0);
|
||||
cv::Ptr<CvMemStorage> temp_storage(cvCreateMemStorage(0));
|
||||
|
||||
for( i = 0; i < quad_count; i++ )
|
||||
{
|
||||
CvPoint2D32f ci = {0,0};
|
||||
CvPoint2D32f ci;
|
||||
CvCBQuad* q = quad_group[i];
|
||||
|
||||
for( j = 0; j < 4; j++ )
|
||||
@@ -1203,7 +1205,7 @@ static int
|
||||
icvFindConnectedQuads( CvCBQuad *quad, int quad_count, CvCBQuad **out_group,
|
||||
int group_idx, CvMemStorage* storage )
|
||||
{
|
||||
cv::Ptr<CvMemStorage> temp_storage = cvCreateChildMemStorage( storage );
|
||||
cv::Ptr<CvMemStorage> temp_storage(cvCreateChildMemStorage( storage ));
|
||||
CvSeq* stack = cvCreateSeq( 0, sizeof(*stack), sizeof(void*), temp_storage );
|
||||
int i, count = 0;
|
||||
|
||||
@@ -1672,7 +1674,7 @@ icvGenerateQuads( CvCBQuad **out_quads, CvCBCorner **out_corners,
|
||||
min_size = 25; //cvRound( image->cols * image->rows * .03 * 0.01 * 0.92 );
|
||||
|
||||
// create temporary storage for contours and the sequence of pointers to found quadrangles
|
||||
temp_storage = cvCreateChildMemStorage( storage );
|
||||
temp_storage.reset(cvCreateChildMemStorage( storage ));
|
||||
root = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvSeq*), temp_storage );
|
||||
|
||||
// initialize contour retrieving routine
|
||||
@@ -1833,7 +1835,7 @@ cvDrawChessboardCorners( CvArr* _image, CvSize pattern_size,
|
||||
|
||||
if( !found )
|
||||
{
|
||||
CvScalar color = {{0,0,255}};
|
||||
CvScalar color(0,0,255,0);
|
||||
if( cn == 1 )
|
||||
color = cvScalarAll(200);
|
||||
color.val[0] *= scale;
|
||||
@@ -1856,17 +1858,17 @@ cvDrawChessboardCorners( CvArr* _image, CvSize pattern_size,
|
||||
else
|
||||
{
|
||||
int x, y;
|
||||
CvPoint prev_pt = {0, 0};
|
||||
CvPoint prev_pt;
|
||||
const int line_max = 7;
|
||||
static const CvScalar line_colors[line_max] =
|
||||
{
|
||||
{{0,0,255}},
|
||||
{{0,128,255}},
|
||||
{{0,200,200}},
|
||||
{{0,255,0}},
|
||||
{{200,200,0}},
|
||||
{{255,0,0}},
|
||||
{{255,0,255}}
|
||||
CvScalar(0,0,255),
|
||||
CvScalar(0,128,255),
|
||||
CvScalar(0,200,200),
|
||||
CvScalar(0,255,0),
|
||||
CvScalar(200,200,0),
|
||||
CvScalar(255,0,0),
|
||||
CvScalar(255,0,255)
|
||||
};
|
||||
|
||||
for( y = 0, i = 0; y < pattern_size.height; y++ )
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
#include <stdio.h>
|
||||
#include <iterator>
|
||||
|
||||
@@ -566,7 +568,7 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
(objectPoints->rows == count && CV_MAT_CN(objectPoints->type)*objectPoints->cols == 3) ||
|
||||
(objectPoints->rows == 3 && CV_MAT_CN(objectPoints->type) == 1 && objectPoints->cols == count)))
|
||||
{
|
||||
matM = cvCreateMat( objectPoints->rows, objectPoints->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(objectPoints->type)) );
|
||||
matM.reset(cvCreateMat( objectPoints->rows, objectPoints->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(objectPoints->type)) ));
|
||||
cvConvert(objectPoints, matM);
|
||||
}
|
||||
else
|
||||
@@ -582,7 +584,7 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
(imagePoints->rows == count && CV_MAT_CN(imagePoints->type)*imagePoints->cols == 2) ||
|
||||
(imagePoints->rows == 2 && CV_MAT_CN(imagePoints->type) == 1 && imagePoints->cols == count)))
|
||||
{
|
||||
_m = cvCreateMat( imagePoints->rows, imagePoints->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(imagePoints->type)) );
|
||||
_m.reset(cvCreateMat( imagePoints->rows, imagePoints->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(imagePoints->type)) ));
|
||||
cvConvert(imagePoints, _m);
|
||||
}
|
||||
else
|
||||
@@ -662,10 +664,10 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
|
||||
if( CV_MAT_TYPE(dpdr->type) == CV_64FC1 )
|
||||
{
|
||||
_dpdr = cvCloneMat(dpdr);
|
||||
_dpdr.reset(cvCloneMat(dpdr));
|
||||
}
|
||||
else
|
||||
_dpdr = cvCreateMat( 2*count, 3, CV_64FC1 );
|
||||
_dpdr.reset(cvCreateMat( 2*count, 3, CV_64FC1 ));
|
||||
dpdr_p = _dpdr->data.db;
|
||||
dpdr_step = _dpdr->step/sizeof(dpdr_p[0]);
|
||||
}
|
||||
@@ -680,10 +682,10 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
|
||||
if( CV_MAT_TYPE(dpdt->type) == CV_64FC1 )
|
||||
{
|
||||
_dpdt = cvCloneMat(dpdt);
|
||||
_dpdt.reset(cvCloneMat(dpdt));
|
||||
}
|
||||
else
|
||||
_dpdt = cvCreateMat( 2*count, 3, CV_64FC1 );
|
||||
_dpdt.reset(cvCreateMat( 2*count, 3, CV_64FC1 ));
|
||||
dpdt_p = _dpdt->data.db;
|
||||
dpdt_step = _dpdt->step/sizeof(dpdt_p[0]);
|
||||
}
|
||||
@@ -697,10 +699,10 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
|
||||
if( CV_MAT_TYPE(dpdf->type) == CV_64FC1 )
|
||||
{
|
||||
_dpdf = cvCloneMat(dpdf);
|
||||
_dpdf.reset(cvCloneMat(dpdf));
|
||||
}
|
||||
else
|
||||
_dpdf = cvCreateMat( 2*count, 2, CV_64FC1 );
|
||||
_dpdf.reset(cvCreateMat( 2*count, 2, CV_64FC1 ));
|
||||
dpdf_p = _dpdf->data.db;
|
||||
dpdf_step = _dpdf->step/sizeof(dpdf_p[0]);
|
||||
}
|
||||
@@ -714,10 +716,10 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
|
||||
if( CV_MAT_TYPE(dpdc->type) == CV_64FC1 )
|
||||
{
|
||||
_dpdc = cvCloneMat(dpdc);
|
||||
_dpdc.reset(cvCloneMat(dpdc));
|
||||
}
|
||||
else
|
||||
_dpdc = cvCreateMat( 2*count, 2, CV_64FC1 );
|
||||
_dpdc.reset(cvCreateMat( 2*count, 2, CV_64FC1 ));
|
||||
dpdc_p = _dpdc->data.db;
|
||||
dpdc_step = _dpdc->step/sizeof(dpdc_p[0]);
|
||||
}
|
||||
@@ -734,10 +736,10 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
|
||||
if( CV_MAT_TYPE(dpdk->type) == CV_64FC1 )
|
||||
{
|
||||
_dpdk = cvCloneMat(dpdk);
|
||||
_dpdk.reset(cvCloneMat(dpdk));
|
||||
}
|
||||
else
|
||||
_dpdk = cvCreateMat( dpdk->rows, dpdk->cols, CV_64FC1 );
|
||||
_dpdk.reset(cvCreateMat( dpdk->rows, dpdk->cols, CV_64FC1 ));
|
||||
dpdk_p = _dpdk->data.db;
|
||||
dpdk_step = _dpdk->step/sizeof(dpdk_p[0]);
|
||||
}
|
||||
@@ -824,7 +826,7 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
dpdk_p[dpdk_step+7] = fy*y*cdist*(-icdist2)*icdist2*r6;
|
||||
if( _dpdk->cols > 8 )
|
||||
{
|
||||
dpdk_p[8] = fx*r2; //s1
|
||||
dpdk_p[8] = fx*r2; //s1
|
||||
dpdk_p[9] = fx*r4; //s2
|
||||
dpdk_p[10] = 0;//s3
|
||||
dpdk_p[11] = 0;//s4
|
||||
@@ -948,8 +950,8 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints,
|
||||
CV_IS_MAT(A) && CV_IS_MAT(rvec) && CV_IS_MAT(tvec) );
|
||||
|
||||
count = MAX(objectPoints->cols, objectPoints->rows);
|
||||
matM = cvCreateMat( 1, count, CV_64FC3 );
|
||||
_m = cvCreateMat( 1, count, CV_64FC2 );
|
||||
matM.reset(cvCreateMat( 1, count, CV_64FC3 ));
|
||||
_m.reset(cvCreateMat( 1, count, CV_64FC2 ));
|
||||
|
||||
cvConvertPointsHomogeneous( objectPoints, matM );
|
||||
cvConvertPointsHomogeneous( imagePoints, _m );
|
||||
@@ -961,8 +963,8 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints,
|
||||
CV_Assert( (CV_MAT_DEPTH(tvec->type) == CV_64F || CV_MAT_DEPTH(tvec->type) == CV_32F) &&
|
||||
(tvec->rows == 1 || tvec->cols == 1) && tvec->rows*tvec->cols*CV_MAT_CN(tvec->type) == 3 );
|
||||
|
||||
_mn = cvCreateMat( 1, count, CV_64FC2 );
|
||||
_Mxy = cvCreateMat( 1, count, CV_64FC2 );
|
||||
_mn.reset(cvCreateMat( 1, count, CV_64FC2 ));
|
||||
_Mxy.reset(cvCreateMat( 1, count, CV_64FC2 ));
|
||||
|
||||
// normalize image points
|
||||
// (unapply the intrinsic matrix transformation and distortion)
|
||||
@@ -1053,7 +1055,7 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints,
|
||||
CvPoint3D64f* M = (CvPoint3D64f*)matM->data.db;
|
||||
CvPoint2D64f* mn = (CvPoint2D64f*)_mn->data.db;
|
||||
|
||||
matL = cvCreateMat( 2*count, 12, CV_64F );
|
||||
matL.reset(cvCreateMat( 2*count, 12, CV_64F ));
|
||||
L = matL->data.db;
|
||||
|
||||
for( i = 0; i < count; i++, L += 24 )
|
||||
@@ -1160,11 +1162,11 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints,
|
||||
if( objectPoints->rows != 1 || imagePoints->rows != 1 )
|
||||
CV_Error( CV_StsBadSize, "object points and image points must be a single-row matrices" );
|
||||
|
||||
matA = cvCreateMat( 2*nimages, 2, CV_64F );
|
||||
_b = cvCreateMat( 2*nimages, 1, CV_64F );
|
||||
matA.reset(cvCreateMat( 2*nimages, 2, CV_64F ));
|
||||
_b.reset(cvCreateMat( 2*nimages, 1, CV_64F ));
|
||||
a[2] = (imageSize.width - 1)*0.5;
|
||||
a[5] = (imageSize.height - 1)*0.5;
|
||||
_allH = cvCreateMat( nimages, 9, CV_64F );
|
||||
_allH.reset(cvCreateMat( nimages, 9, CV_64F ));
|
||||
|
||||
// extract vanishing points in order to obtain initial value for the focal length
|
||||
for( i = 0, pos = 0; i < nimages; i++, pos += ni )
|
||||
@@ -1254,7 +1256,7 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
|
||||
//when the thin prism model is used the distortion coefficients matrix must have 12 parameters
|
||||
if((flags & CV_CALIB_THIN_PRISM_MODEL) && (distCoeffs->cols*distCoeffs->rows != 12))
|
||||
CV_Error( CV_StsBadArg, "Thin prism model must have 12 parameters in the distortion matrix" );
|
||||
|
||||
|
||||
nimages = npoints->rows*npoints->cols;
|
||||
npstep = npoints->rows == 1 ? 1 : npoints->step/CV_ELEM_SIZE(npoints->type);
|
||||
|
||||
@@ -1308,16 +1310,16 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
|
||||
total += ni;
|
||||
}
|
||||
|
||||
matM = cvCreateMat( 1, total, CV_64FC3 );
|
||||
_m = cvCreateMat( 1, total, CV_64FC2 );
|
||||
matM.reset(cvCreateMat( 1, total, CV_64FC3 ));
|
||||
_m.reset(cvCreateMat( 1, total, CV_64FC2 ));
|
||||
|
||||
cvConvertPointsHomogeneous( objectPoints, matM );
|
||||
cvConvertPointsHomogeneous( imagePoints, _m );
|
||||
|
||||
nparams = NINTRINSIC + nimages*6;
|
||||
_Ji = cvCreateMat( maxPoints*2, NINTRINSIC, CV_64FC1 );
|
||||
_Je = cvCreateMat( maxPoints*2, 6, CV_64FC1 );
|
||||
_err = cvCreateMat( maxPoints*2, 1, CV_64FC1 );
|
||||
_Ji.reset(cvCreateMat( maxPoints*2, NINTRINSIC, CV_64FC1 ));
|
||||
_Je.reset(cvCreateMat( maxPoints*2, 6, CV_64FC1 ));
|
||||
_err.reset(cvCreateMat( maxPoints*2, 1, CV_64FC1 ));
|
||||
cvZero( _Ji );
|
||||
|
||||
_k = cvMat( distCoeffs->rows, distCoeffs->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(distCoeffs->type)), k);
|
||||
@@ -1636,12 +1638,12 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
CvTermCriteria termCrit,
|
||||
int flags )
|
||||
{
|
||||
const int NINTRINSIC = 12;
|
||||
const int NINTRINSIC = 16;
|
||||
Ptr<CvMat> npoints, err, J_LR, Je, Ji, imagePoints[2], objectPoints, RT0;
|
||||
CvLevMarq solver;
|
||||
double reprojErr = 0;
|
||||
|
||||
double A[2][9], dk[2][8]={{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}}, rlr[9];
|
||||
double A[2][9], dk[2][12]={{0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0}}, rlr[9];
|
||||
CvMat K[2], Dist[2], om_LR, T_LR;
|
||||
CvMat R_LR = cvMat(3, 3, CV_64F, rlr);
|
||||
int i, k, p, ni = 0, ofs, nimages, pointsTotal, maxPoints = 0;
|
||||
@@ -1660,7 +1662,7 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
CV_MAT_TYPE(_npoints->type) == CV_32SC1 );
|
||||
|
||||
nimages = _npoints->cols + _npoints->rows - 1;
|
||||
npoints = cvCreateMat( _npoints->rows, _npoints->cols, _npoints->type );
|
||||
npoints.reset(cvCreateMat( _npoints->rows, _npoints->cols, _npoints->type ));
|
||||
cvCopy( _npoints, npoints );
|
||||
|
||||
for( i = 0, pointsTotal = 0; i < nimages; i++ )
|
||||
@@ -1669,8 +1671,8 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
pointsTotal += npoints->data.i[i];
|
||||
}
|
||||
|
||||
objectPoints = cvCreateMat( _objectPoints->rows, _objectPoints->cols,
|
||||
CV_64FC(CV_MAT_CN(_objectPoints->type)));
|
||||
objectPoints.reset(cvCreateMat( _objectPoints->rows, _objectPoints->cols,
|
||||
CV_64FC(CV_MAT_CN(_objectPoints->type))));
|
||||
cvConvert( _objectPoints, objectPoints );
|
||||
cvReshape( objectPoints, objectPoints, 3, 1 );
|
||||
|
||||
@@ -1687,9 +1689,9 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
(_imagePoints1->rows == 1 && _imagePoints1->cols == pointsTotal && cn == 2)) );
|
||||
|
||||
K[k] = cvMat(3,3,CV_64F,A[k]);
|
||||
Dist[k] = cvMat(1,8,CV_64F,dk[k]);
|
||||
Dist[k] = cvMat(1,12,CV_64F,dk[k]);
|
||||
|
||||
imagePoints[k] = cvCreateMat( points->rows, points->cols, CV_64FC(CV_MAT_CN(points->type)));
|
||||
imagePoints[k].reset(cvCreateMat( points->rows, points->cols, CV_64FC(CV_MAT_CN(points->type))));
|
||||
cvConvert( points, imagePoints[k] );
|
||||
cvReshape( imagePoints[k], imagePoints[k], 2, 1 );
|
||||
|
||||
@@ -1727,10 +1729,10 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
|
||||
recomputeIntrinsics = (flags & CV_CALIB_FIX_INTRINSIC) == 0;
|
||||
|
||||
err = cvCreateMat( maxPoints*2, 1, CV_64F );
|
||||
Je = cvCreateMat( maxPoints*2, 6, CV_64F );
|
||||
J_LR = cvCreateMat( maxPoints*2, 6, CV_64F );
|
||||
Ji = cvCreateMat( maxPoints*2, NINTRINSIC, CV_64F );
|
||||
err.reset(cvCreateMat( maxPoints*2, 1, CV_64F ));
|
||||
Je.reset(cvCreateMat( maxPoints*2, 6, CV_64F ));
|
||||
J_LR.reset(cvCreateMat( maxPoints*2, 6, CV_64F ));
|
||||
Ji.reset(cvCreateMat( maxPoints*2, NINTRINSIC, CV_64F ));
|
||||
cvZero( Ji );
|
||||
|
||||
// we optimize for the inter-camera R(3),t(3), then, optionally,
|
||||
@@ -1738,7 +1740,7 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
nparams = 6*(nimages+1) + (recomputeIntrinsics ? NINTRINSIC*2 : 0);
|
||||
|
||||
// storage for initial [om(R){i}|t{i}] (in order to compute the median for each component)
|
||||
RT0 = cvCreateMat( 6, nimages, CV_64F );
|
||||
RT0.reset(cvCreateMat( 6, nimages, CV_64F ));
|
||||
|
||||
solver.init( nparams, 0, termCrit );
|
||||
if( recomputeIntrinsics )
|
||||
@@ -1746,6 +1748,8 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
uchar* imask = solver.mask->data.ptr + nparams - NINTRINSIC*2;
|
||||
if( !(flags & CV_CALIB_RATIONAL_MODEL) )
|
||||
flags |= CV_CALIB_FIX_K4 | CV_CALIB_FIX_K5 | CV_CALIB_FIX_K6;
|
||||
if( !(flags & CV_CALIB_THIN_PRISM_MODEL) )
|
||||
flags |= CV_CALIB_FIX_S1_S2_S3_S4;
|
||||
if( flags & CV_CALIB_FIX_ASPECT_RATIO )
|
||||
imask[0] = imask[NINTRINSIC] = 0;
|
||||
if( flags & CV_CALIB_FIX_FOCAL_LENGTH )
|
||||
@@ -1766,6 +1770,13 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
imask[10] = imask[NINTRINSIC+10] = 0;
|
||||
if( flags & CV_CALIB_FIX_K6 )
|
||||
imask[11] = imask[NINTRINSIC+11] = 0;
|
||||
if( flags & CV_CALIB_FIX_S1_S2_S3_S4 )
|
||||
{
|
||||
imask[12] = imask[NINTRINSIC+12] = 0;
|
||||
imask[13] = imask[NINTRINSIC+13] = 0;
|
||||
imask[14] = imask[NINTRINSIC+14] = 0;
|
||||
imask[15] = imask[NINTRINSIC+15] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1840,6 +1851,10 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
iparam[4] = dk[k][0]; iparam[5] = dk[k][1]; iparam[6] = dk[k][2];
|
||||
iparam[7] = dk[k][3]; iparam[8] = dk[k][4]; iparam[9] = dk[k][5];
|
||||
iparam[10] = dk[k][6]; iparam[11] = dk[k][7];
|
||||
iparam[12] = dk[k][8];
|
||||
iparam[13] = dk[k][9];
|
||||
iparam[14] = dk[k][10];
|
||||
iparam[15] = dk[k][11];
|
||||
}
|
||||
|
||||
om_LR = cvMat(3, 1, CV_64F, solver.param->data.db);
|
||||
@@ -1906,6 +1921,10 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
dk[k][5] = iparam[k*NINTRINSIC+9];
|
||||
dk[k][6] = iparam[k*NINTRINSIC+10];
|
||||
dk[k][7] = iparam[k*NINTRINSIC+11];
|
||||
dk[k][8] = iparam[k*NINTRINSIC+12];
|
||||
dk[k][9] = iparam[k*NINTRINSIC+13];
|
||||
dk[k][10] = iparam[k*NINTRINSIC+14];
|
||||
dk[k][11] = iparam[k*NINTRINSIC+15];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2078,7 +2097,7 @@ icvGetRectangles( const CvMat* cameraMatrix, const CvMat* distCoeffs,
|
||||
{
|
||||
const int N = 9;
|
||||
int x, y, k;
|
||||
cv::Ptr<CvMat> _pts = cvCreateMat(1, N*N, CV_32FC2);
|
||||
cv::Ptr<CvMat> _pts(cvCreateMat(1, N*N, CV_32FC2));
|
||||
CvPoint2D32f* pts = (CvPoint2D32f*)(_pts->data.ptr);
|
||||
|
||||
for( y = k = 0; y < N; y++ )
|
||||
@@ -2437,10 +2456,10 @@ CV_IMPL int cvStereoRectifyUncalibrated(
|
||||
|
||||
npoints = _points1->rows * _points1->cols * CV_MAT_CN(_points1->type) / 2;
|
||||
|
||||
_m1 = cvCreateMat( _points1->rows, _points1->cols, CV_64FC(CV_MAT_CN(_points1->type)) );
|
||||
_m2 = cvCreateMat( _points2->rows, _points2->cols, CV_64FC(CV_MAT_CN(_points2->type)) );
|
||||
_lines1 = cvCreateMat( 1, npoints, CV_64FC3 );
|
||||
_lines2 = cvCreateMat( 1, npoints, CV_64FC3 );
|
||||
_m1.reset(cvCreateMat( _points1->rows, _points1->cols, CV_64FC(CV_MAT_CN(_points1->type)) ));
|
||||
_m2.reset(cvCreateMat( _points2->rows, _points2->cols, CV_64FC(CV_MAT_CN(_points2->type)) ));
|
||||
_lines1.reset(cvCreateMat( 1, npoints, CV_64FC3 ));
|
||||
_lines2.reset(cvCreateMat( 1, npoints, CV_64FC3 ));
|
||||
|
||||
cvConvert( F0, &F );
|
||||
|
||||
@@ -2688,7 +2707,7 @@ void cv::reprojectImageTo3D( InputArray _disparity,
|
||||
for( x = 0; x < cols*3; x++ )
|
||||
{
|
||||
int ival = cvRound(dptr[x]);
|
||||
dptr0[x] = CV_CAST_16S(ival);
|
||||
dptr0[x] = cv::saturate_cast<short>(ival);
|
||||
}
|
||||
}
|
||||
else if( dtype == CV_32SC3 )
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
//M*/
|
||||
|
||||
#include "circlesgrid.hpp"
|
||||
#include <limits>
|
||||
//#define DEBUG_CIRCLES
|
||||
|
||||
#ifdef DEBUG_CIRCLES
|
||||
@@ -202,12 +203,12 @@ void CirclesGridClusterFinder::findCorners(const std::vector<cv::Point2f> &hull2
|
||||
//corners are the most sharp angles (6)
|
||||
Mat anglesMat = Mat(angles);
|
||||
Mat sortedIndices;
|
||||
sortIdx(anglesMat, sortedIndices, CV_SORT_EVERY_COLUMN + CV_SORT_DESCENDING);
|
||||
sortIdx(anglesMat, sortedIndices, SORT_EVERY_COLUMN + SORT_DESCENDING);
|
||||
CV_Assert(sortedIndices.type() == CV_32SC1);
|
||||
CV_Assert(sortedIndices.cols == 1);
|
||||
const int cornersCount = isAsymmetricGrid ? 6 : 4;
|
||||
Mat cornersIndices;
|
||||
cv::sort(sortedIndices.rowRange(0, cornersCount), cornersIndices, CV_SORT_EVERY_COLUMN + CV_SORT_ASCENDING);
|
||||
cv::sort(sortedIndices.rowRange(0, cornersCount), cornersIndices, SORT_EVERY_COLUMN + SORT_ASCENDING);
|
||||
corners.clear();
|
||||
for(int i=0; i<cornersCount; i++)
|
||||
{
|
||||
@@ -438,15 +439,15 @@ bool Graph::doesVertexExist(size_t id) const
|
||||
|
||||
void Graph::addVertex(size_t id)
|
||||
{
|
||||
assert( !doesVertexExist( id ) );
|
||||
CV_Assert( !doesVertexExist( id ) );
|
||||
|
||||
vertices.insert(std::pair<size_t, Vertex> (id, Vertex()));
|
||||
}
|
||||
|
||||
void Graph::addEdge(size_t id1, size_t id2)
|
||||
{
|
||||
assert( doesVertexExist( id1 ) );
|
||||
assert( doesVertexExist( id2 ) );
|
||||
CV_Assert( doesVertexExist( id1 ) );
|
||||
CV_Assert( doesVertexExist( id2 ) );
|
||||
|
||||
vertices[id1].neighbors.insert(id2);
|
||||
vertices[id2].neighbors.insert(id1);
|
||||
@@ -454,8 +455,8 @@ void Graph::addEdge(size_t id1, size_t id2)
|
||||
|
||||
void Graph::removeEdge(size_t id1, size_t id2)
|
||||
{
|
||||
assert( doesVertexExist( id1 ) );
|
||||
assert( doesVertexExist( id2 ) );
|
||||
CV_Assert( doesVertexExist( id1 ) );
|
||||
CV_Assert( doesVertexExist( id2 ) );
|
||||
|
||||
vertices[id1].neighbors.erase(id2);
|
||||
vertices[id2].neighbors.erase(id1);
|
||||
@@ -463,8 +464,8 @@ void Graph::removeEdge(size_t id1, size_t id2)
|
||||
|
||||
bool Graph::areVerticesAdjacent(size_t id1, size_t id2) const
|
||||
{
|
||||
assert( doesVertexExist( id1 ) );
|
||||
assert( doesVertexExist( id2 ) );
|
||||
CV_Assert( doesVertexExist( id1 ) );
|
||||
CV_Assert( doesVertexExist( id2 ) );
|
||||
|
||||
Vertices::const_iterator it = vertices.find(id1);
|
||||
return it->second.neighbors.find(id2) != it->second.neighbors.end();
|
||||
@@ -477,7 +478,7 @@ size_t Graph::getVerticesCount() const
|
||||
|
||||
size_t Graph::getDegree(size_t id) const
|
||||
{
|
||||
assert( doesVertexExist(id) );
|
||||
CV_Assert( doesVertexExist(id) );
|
||||
|
||||
Vertices::const_iterator it = vertices.find(id);
|
||||
return it->second.neighbors.size();
|
||||
@@ -495,7 +496,7 @@ void Graph::floydWarshall(cv::Mat &distanceMatrix, int infinity) const
|
||||
distanceMatrix.at<int> ((int)it1->first, (int)it1->first) = 0;
|
||||
for (Neighbors::const_iterator it2 = it1->second.neighbors.begin(); it2 != it1->second.neighbors.end(); it2++)
|
||||
{
|
||||
assert( it1->first != *it2 );
|
||||
CV_Assert( it1->first != *it2 );
|
||||
distanceMatrix.at<int> ((int)it1->first, (int)*it2) = edgeWeight;
|
||||
}
|
||||
}
|
||||
@@ -524,7 +525,7 @@ void Graph::floydWarshall(cv::Mat &distanceMatrix, int infinity) const
|
||||
|
||||
const Graph::Neighbors& Graph::getNeighbors(size_t id) const
|
||||
{
|
||||
assert( doesVertexExist(id) );
|
||||
CV_Assert( doesVertexExist(id) );
|
||||
|
||||
Vertices::const_iterator it = vertices.find(id);
|
||||
return it->second.neighbors;
|
||||
@@ -604,7 +605,7 @@ bool CirclesGridFinder::findHoles()
|
||||
}
|
||||
|
||||
default:
|
||||
CV_Error(CV_StsBadArg, "Unkown pattern type");
|
||||
CV_Error(Error::StsBadArg, "Unkown pattern type");
|
||||
}
|
||||
return (isDetectionCorrect());
|
||||
//CV_Error( 0, "Detection is not correct" );
|
||||
@@ -813,7 +814,7 @@ void CirclesGridFinder::findMCS(const std::vector<Point2f> &basis, std::vector<G
|
||||
Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const std::vector<Point2f>& centers,
|
||||
const std::vector<Point2f> &keypoints, std::vector<Point2f> &warpedKeypoints)
|
||||
{
|
||||
assert( !centers.empty() );
|
||||
CV_Assert( !centers.empty() );
|
||||
const float edgeLength = 30;
|
||||
const Point2f offset(150, 150);
|
||||
|
||||
@@ -832,7 +833,7 @@ Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const std::vector<Poin
|
||||
}
|
||||
}
|
||||
|
||||
Mat H = findHomography(Mat(centers), Mat(dstPoints), CV_RANSAC);
|
||||
Mat H = findHomography(Mat(centers), Mat(dstPoints), RANSAC);
|
||||
//Mat H = findHomography( Mat( corners ), Mat( dstPoints ) );
|
||||
|
||||
std::vector<Point2f> srcKeypoints;
|
||||
@@ -912,7 +913,7 @@ void CirclesGridFinder::findCandidateLine(std::vector<size_t> &line, size_t seed
|
||||
}
|
||||
}
|
||||
|
||||
assert( line.size() == seeds.size() );
|
||||
CV_Assert( line.size() == seeds.size() );
|
||||
}
|
||||
|
||||
void CirclesGridFinder::findCandidateHoles(std::vector<size_t> &above, std::vector<size_t> &below, bool addRow, Point2f basisVec,
|
||||
@@ -927,9 +928,9 @@ void CirclesGridFinder::findCandidateHoles(std::vector<size_t> &above, std::vect
|
||||
size_t lastIdx = addRow ? holes.size() - 1 : holes[0].size() - 1;
|
||||
findCandidateLine(below, lastIdx, addRow, basisVec, belowSeeds);
|
||||
|
||||
assert( below.size() == above.size() );
|
||||
assert( belowSeeds.size() == aboveSeeds.size() );
|
||||
assert( below.size() == belowSeeds.size() );
|
||||
CV_Assert( below.size() == above.size() );
|
||||
CV_Assert( belowSeeds.size() == aboveSeeds.size() );
|
||||
CV_Assert( below.size() == belowSeeds.size() );
|
||||
}
|
||||
|
||||
bool CirclesGridFinder::areCentersNew(const std::vector<size_t> &newCenters, const std::vector<std::vector<size_t> > &holes)
|
||||
@@ -1000,10 +1001,10 @@ void CirclesGridFinder::insertWinner(float aboveConfidence, float belowConfidenc
|
||||
float CirclesGridFinder::computeGraphConfidence(const std::vector<Graph> &basisGraphs, bool addRow,
|
||||
const std::vector<size_t> &points, const std::vector<size_t> &seeds)
|
||||
{
|
||||
assert( points.size() == seeds.size() );
|
||||
CV_Assert( points.size() == seeds.size() );
|
||||
float confidence = 0;
|
||||
const size_t vCount = basisGraphs[0].getVerticesCount();
|
||||
assert( basisGraphs[0].getVerticesCount() == basisGraphs[1].getVerticesCount() );
|
||||
CV_Assert( basisGraphs[0].getVerticesCount() == basisGraphs[1].getVerticesCount() );
|
||||
|
||||
for (size_t i = 0; i < seeds.size(); i++)
|
||||
{
|
||||
@@ -1087,7 +1088,7 @@ void CirclesGridFinder::findBasis(const std::vector<Point2f> &samples, std::vect
|
||||
const int clustersCount = 4;
|
||||
kmeans(Mat(samples).reshape(1, 0), clustersCount, bestLabels, termCriteria, parameters.kmeansAttempts,
|
||||
KMEANS_RANDOM_CENTERS, centers);
|
||||
assert( centers.type() == CV_32FC1 );
|
||||
CV_Assert( centers.type() == CV_32FC1 );
|
||||
|
||||
std::vector<int> basisIndices;
|
||||
//TODO: only remove duplicate
|
||||
@@ -1204,7 +1205,7 @@ void CirclesGridFinder::computeRNG(Graph &rng, std::vector<cv::Point2f> &vectors
|
||||
|
||||
void computePredecessorMatrix(const Mat &dm, int verticesCount, Mat &predecessorMatrix)
|
||||
{
|
||||
assert( dm.type() == CV_32SC1 );
|
||||
CV_Assert( dm.type() == CV_32SC1 );
|
||||
predecessorMatrix.create(verticesCount, verticesCount, CV_32SC1);
|
||||
predecessorMatrix = -1;
|
||||
for (int i = 0; i < predecessorMatrix.rows; i++)
|
||||
@@ -1253,7 +1254,6 @@ size_t CirclesGridFinder::findLongestPath(std::vector<Graph> &basisGraphs, Path
|
||||
|
||||
double maxVal;
|
||||
Point maxLoc;
|
||||
assert (infinity < 0);
|
||||
minMaxLoc(distanceMatrix, 0, &maxVal, 0, &maxLoc);
|
||||
|
||||
if (maxVal > longestPaths[0].length)
|
||||
@@ -1364,7 +1364,7 @@ void CirclesGridFinder::drawHoles(const Mat &srcImage, Mat &drawImage) const
|
||||
const Scalar holeColor = Scalar(0, 255, 0);
|
||||
|
||||
if (srcImage.channels() == 1)
|
||||
cvtColor(srcImage, drawImage, CV_GRAY2RGB);
|
||||
cvtColor(srcImage, drawImage, COLOR_GRAY2RGB);
|
||||
else
|
||||
srcImage.copyTo(drawImage);
|
||||
|
||||
@@ -1594,9 +1594,3 @@ size_t CirclesGridFinder::getFirstCorner(std::vector<Point> &largeCornerIndices,
|
||||
|
||||
return cornerIdx;
|
||||
}
|
||||
|
||||
bool cv::findCirclesGridDefault( InputArray image, Size patternSize,
|
||||
OutputArray centers, int flags )
|
||||
{
|
||||
return findCirclesGrid(image, patternSize, centers, flags);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <map>
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
/************************************************************************************\
|
||||
Some backward compatibility stuff, to be moved to legacy or compat module
|
||||
@@ -52,7 +53,6 @@ using cv::Ptr;
|
||||
|
||||
CvLevMarq::CvLevMarq()
|
||||
{
|
||||
mask = prevParam = param = J = err = JtJ = JtJN = JtErr = JtJV = JtJW = Ptr<CvMat>();
|
||||
lambdaLg10 = 0; state = DONE;
|
||||
criteria = cvTermCriteria(0,0,0);
|
||||
iters = 0;
|
||||
@@ -61,7 +61,6 @@ CvLevMarq::CvLevMarq()
|
||||
|
||||
CvLevMarq::CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria0, bool _completeSymmFlag )
|
||||
{
|
||||
mask = prevParam = param = J = err = JtJ = JtJN = JtErr = JtJV = JtJW = Ptr<CvMat>();
|
||||
init(nparams, nerrs, criteria0, _completeSymmFlag);
|
||||
}
|
||||
|
||||
@@ -88,19 +87,19 @@ void CvLevMarq::init( int nparams, int nerrs, CvTermCriteria criteria0, bool _co
|
||||
{
|
||||
if( !param || param->rows != nparams || nerrs != (err ? err->rows : 0) )
|
||||
clear();
|
||||
mask = cvCreateMat( nparams, 1, CV_8U );
|
||||
mask.reset(cvCreateMat( nparams, 1, CV_8U ));
|
||||
cvSet(mask, cvScalarAll(1));
|
||||
prevParam = cvCreateMat( nparams, 1, CV_64F );
|
||||
param = cvCreateMat( nparams, 1, CV_64F );
|
||||
JtJ = cvCreateMat( nparams, nparams, CV_64F );
|
||||
JtJN = cvCreateMat( nparams, nparams, CV_64F );
|
||||
JtJV = cvCreateMat( nparams, nparams, CV_64F );
|
||||
JtJW = cvCreateMat( nparams, 1, CV_64F );
|
||||
JtErr = cvCreateMat( nparams, 1, CV_64F );
|
||||
prevParam.reset(cvCreateMat( nparams, 1, CV_64F ));
|
||||
param.reset(cvCreateMat( nparams, 1, CV_64F ));
|
||||
JtJ.reset(cvCreateMat( nparams, nparams, CV_64F ));
|
||||
JtJN.reset(cvCreateMat( nparams, nparams, CV_64F ));
|
||||
JtJV.reset(cvCreateMat( nparams, nparams, CV_64F ));
|
||||
JtJW.reset(cvCreateMat( nparams, 1, CV_64F ));
|
||||
JtErr.reset(cvCreateMat( nparams, 1, CV_64F ));
|
||||
if( nerrs > 0 )
|
||||
{
|
||||
J = cvCreateMat( nerrs, nparams, CV_64F );
|
||||
err = cvCreateMat( nerrs, 1, CV_64F );
|
||||
J.reset(cvCreateMat( nerrs, nparams, CV_64F ));
|
||||
err.reset(cvCreateMat( nerrs, 1, CV_64F ));
|
||||
}
|
||||
prevErrNorm = DBL_MAX;
|
||||
lambdaLg10 = -3;
|
||||
@@ -195,7 +194,7 @@ bool CvLevMarq::updateAlt( const CvMat*& _param, CvMat*& _JtJ, CvMat*& _JtErr, d
|
||||
{
|
||||
double change;
|
||||
|
||||
CV_Assert( err.empty() );
|
||||
CV_Assert( !err );
|
||||
if( state == DONE )
|
||||
{
|
||||
_param = param;
|
||||
@@ -427,4 +426,3 @@ CV_IMPL void cvConvertPointsHomogeneous( const CvMat* _src, CvMat* _dst )
|
||||
dst.convertTo(dst0, dst0.type());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
CvStereoBMState* cvCreateStereoBMState( int /*preset*/, int numberOfDisparities )
|
||||
{
|
||||
@@ -83,10 +84,6 @@ void cvReleaseStereoBMState( CvStereoBMState** state )
|
||||
cvFree( state );
|
||||
}
|
||||
|
||||
template<> void cv::Ptr<CvStereoBMState>::delete_obj()
|
||||
{ cvReleaseStereoBMState(&obj); }
|
||||
|
||||
|
||||
void cvFindStereoCorrespondenceBM( const CvArr* leftarr, const CvArr* rightarr,
|
||||
CvArr* disparr, CvStereoBMState* state )
|
||||
{
|
||||
@@ -124,93 +121,3 @@ void cvValidateDisparity( CvArr* _disp, const CvArr* _cost, int minDisparity,
|
||||
cv::Mat disp = cv::cvarrToMat(_disp), cost = cv::cvarrToMat(_cost);
|
||||
cv::validateDisparity( disp, cost, minDisparity, numberOfDisparities, disp12MaxDiff );
|
||||
}
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
StereoBM::StereoBM()
|
||||
{ init(BASIC_PRESET); }
|
||||
|
||||
StereoBM::StereoBM(int _preset, int _ndisparities, int _SADWindowSize)
|
||||
{ init(_preset, _ndisparities, _SADWindowSize); }
|
||||
|
||||
void StereoBM::init(int _preset, int _ndisparities, int _SADWindowSize)
|
||||
{
|
||||
state = cvCreateStereoBMState(_preset, _ndisparities);
|
||||
state->SADWindowSize = _SADWindowSize;
|
||||
}
|
||||
|
||||
void StereoBM::operator()( InputArray _left, InputArray _right,
|
||||
OutputArray _disparity, int disptype )
|
||||
{
|
||||
Mat left = _left.getMat(), right = _right.getMat();
|
||||
CV_Assert( disptype == CV_16S || disptype == CV_32F );
|
||||
_disparity.create(left.size(), disptype);
|
||||
Mat disp = _disparity.getMat();
|
||||
|
||||
CvMat left_c = left, right_c = right, disp_c = disp;
|
||||
cvFindStereoCorrespondenceBM(&left_c, &right_c, &disp_c, state);
|
||||
}
|
||||
|
||||
|
||||
StereoSGBM::StereoSGBM()
|
||||
{
|
||||
minDisparity = numberOfDisparities = 0;
|
||||
SADWindowSize = 0;
|
||||
P1 = P2 = 0;
|
||||
disp12MaxDiff = 0;
|
||||
preFilterCap = 0;
|
||||
uniquenessRatio = 0;
|
||||
speckleWindowSize = 0;
|
||||
speckleRange = 0;
|
||||
fullDP = false;
|
||||
|
||||
sm = createStereoSGBM(0, 0, 0);
|
||||
}
|
||||
|
||||
StereoSGBM::StereoSGBM( int _minDisparity, int _numDisparities, int _SADWindowSize,
|
||||
int _P1, int _P2, int _disp12MaxDiff, int _preFilterCap,
|
||||
int _uniquenessRatio, int _speckleWindowSize, int _speckleRange,
|
||||
bool _fullDP )
|
||||
{
|
||||
minDisparity = _minDisparity;
|
||||
numberOfDisparities = _numDisparities;
|
||||
SADWindowSize = _SADWindowSize;
|
||||
P1 = _P1;
|
||||
P2 = _P2;
|
||||
disp12MaxDiff = _disp12MaxDiff;
|
||||
preFilterCap = _preFilterCap;
|
||||
uniquenessRatio = _uniquenessRatio;
|
||||
speckleWindowSize = _speckleWindowSize;
|
||||
speckleRange = _speckleRange;
|
||||
fullDP = _fullDP;
|
||||
|
||||
sm = createStereoSGBM(0, 0, 0);
|
||||
}
|
||||
|
||||
StereoSGBM::~StereoSGBM()
|
||||
{
|
||||
}
|
||||
|
||||
void StereoSGBM::operator ()( InputArray _left, InputArray _right,
|
||||
OutputArray _disp )
|
||||
{
|
||||
sm->set("minDisparity", minDisparity);
|
||||
sm->set("numDisparities", numberOfDisparities);
|
||||
sm->set("SADWindowSize", SADWindowSize);
|
||||
sm->set("P1", P1);
|
||||
sm->set("P2", P2);
|
||||
sm->set("disp12MaxDiff", disp12MaxDiff);
|
||||
sm->set("preFilterCap", preFilterCap);
|
||||
sm->set("uniquenessRatio", uniquenessRatio);
|
||||
sm->set("speckleWindowSize", speckleWindowSize);
|
||||
sm->set("speckleRange", speckleRange);
|
||||
sm->set("fullDP", fullDP);
|
||||
|
||||
sm->compute(_left, _right, _disp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -621,4 +621,3 @@ void epnp::qr_solve(CvMat * A, CvMat * b, CvMat * X)
|
||||
pX[i] = (pb[i] - sum) / A2[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define epnp_h
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
|
||||
class epnp {
|
||||
public:
|
||||
|
||||
+431
-546
File diff suppressed because it is too large
Load Diff
@@ -181,12 +181,12 @@ public:
|
||||
LtL[j][k] += Lx[j]*Lx[k] + Ly[j]*Ly[k];
|
||||
}
|
||||
completeSymm( _LtL );
|
||||
|
||||
|
||||
eigen( _LtL, matW, matV );
|
||||
_Htemp = _invHnorm*_H0;
|
||||
_H0 = _Htemp*_Hnorm2;
|
||||
_H0.convertTo(_model, _H0.type(), 1./_H0.at<double>(2,2) );
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -259,6 +259,8 @@ public:
|
||||
Jptr[8] = Jptr[9] = Jptr[10] = 0.;
|
||||
Jptr[11] = Mx*ww; Jptr[12] = My*ww; Jptr[13] = ww;
|
||||
Jptr[14] = -Mx*ww*yi; Jptr[15] = -My*ww*yi;
|
||||
|
||||
Jptr += 16;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +294,7 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2,
|
||||
{
|
||||
npoints = p.checkVector(3, -1, false);
|
||||
if( npoints < 0 )
|
||||
CV_Error(CV_StsBadArg, "The input arrays should be 2D or 3D point sets");
|
||||
CV_Error(Error::StsBadArg, "The input arrays should be 2D or 3D point sets");
|
||||
if( npoints == 0 )
|
||||
return Mat();
|
||||
convertPointsFromHomogeneous(p, p);
|
||||
@@ -305,7 +307,7 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2,
|
||||
if( ransacReprojThreshold <= 0 )
|
||||
ransacReprojThreshold = defaultRANSACReprojThreshold;
|
||||
|
||||
Ptr<PointSetRegistrator::Callback> cb = new HomographyEstimatorCallback;
|
||||
Ptr<PointSetRegistrator::Callback> cb = makePtr<HomographyEstimatorCallback>();
|
||||
|
||||
if( method == 0 || npoints == 4 )
|
||||
{
|
||||
@@ -317,7 +319,7 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2,
|
||||
else if( method == LMEDS )
|
||||
result = createLMeDSPointSetRegistrator(cb, 4, confidence, maxIters)->run(src, dst, H, tempMask);
|
||||
else
|
||||
CV_Error(CV_StsBadArg, "Unknown estimation method");
|
||||
CV_Error(Error::StsBadArg, "Unknown estimation method");
|
||||
|
||||
if( result && npoints > 4 )
|
||||
{
|
||||
@@ -332,7 +334,7 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2,
|
||||
if( method == RANSAC || method == LMEDS )
|
||||
cb->runKernel( src, dst, H );
|
||||
Mat H8(8, 1, CV_64F, H.ptr<double>());
|
||||
createLMSolver(new HomographyRefineCallback(src, dst), 10)->run(H8);
|
||||
createLMSolver(makePtr<HomographyRefineCallback>(src, dst), 10)->run(H8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,7 +477,7 @@ static int run7Point( const Mat& _m1, const Mat& _m2, Mat& _fmatrix )
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int run8Point( const Mat& _m1, const Mat& _m2, Mat& _fmatrix )
|
||||
{
|
||||
double a[9*9], w[9], v[9*9];
|
||||
@@ -585,11 +587,11 @@ static int run8Point( const Mat& _m1, const Mat& _m2, Mat& _fmatrix )
|
||||
gemm( T2, F0, 1., 0, 0., TF, GEMM_1_T );
|
||||
F0 = Mat(3, 3, CV_64F, fmatrix);
|
||||
gemm( TF, T1, 1., 0, 0., F0, 0 );
|
||||
|
||||
|
||||
// make F(3,3) = 1
|
||||
if( fabs(F0.at<double>(2,2)) > FLT_EPSILON )
|
||||
F0 *= 1./F0.at<double>(2,2);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -671,7 +673,7 @@ cv::Mat cv::findFundamentalMat( InputArray _points1, InputArray _points2,
|
||||
{
|
||||
npoints = p.checkVector(3, -1, false);
|
||||
if( npoints < 0 )
|
||||
CV_Error(CV_StsBadArg, "The input arrays should be 2D or 3D point sets");
|
||||
CV_Error(Error::StsBadArg, "The input arrays should be 2D or 3D point sets");
|
||||
if( npoints == 0 )
|
||||
return Mat();
|
||||
convertPointsFromHomogeneous(p, p);
|
||||
@@ -684,7 +686,7 @@ cv::Mat cv::findFundamentalMat( InputArray _points1, InputArray _points2,
|
||||
if( npoints < 7 )
|
||||
return Mat();
|
||||
|
||||
Ptr<PointSetRegistrator::Callback> cb = new FMEstimatorCallback;
|
||||
Ptr<PointSetRegistrator::Callback> cb = makePtr<FMEstimatorCallback>();
|
||||
int result;
|
||||
|
||||
if( npoints == 7 || method == FM_8POINT )
|
||||
@@ -739,7 +741,7 @@ void cv::computeCorrespondEpilines( InputArray _points, int whichImage,
|
||||
{
|
||||
npoints = points.checkVector(3);
|
||||
if( npoints < 0 )
|
||||
CV_Error( CV_StsBadArg, "The input should be a 2D or 3D point set");
|
||||
CV_Error( Error::StsBadArg, "The input should be a 2D or 3D point set");
|
||||
Mat temp;
|
||||
convertPointsFromHomogeneous(points, temp);
|
||||
points = temp;
|
||||
@@ -893,7 +895,7 @@ void cv::convertPointsFromHomogeneous( InputArray _src, OutputArray _dst )
|
||||
}
|
||||
}
|
||||
else
|
||||
CV_Error(CV_StsUnsupportedFormat, "");
|
||||
CV_Error(Error::StsUnsupportedFormat, "");
|
||||
}
|
||||
|
||||
|
||||
@@ -974,7 +976,7 @@ void cv::convertPointsToHomogeneous( InputArray _src, OutputArray _dst )
|
||||
}
|
||||
}
|
||||
else
|
||||
CV_Error(CV_StsUnsupportedFormat, "");
|
||||
CV_Error(Error::StsUnsupportedFormat, "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -47,30 +47,30 @@
|
||||
This is translation to C++ of the Matlab's LMSolve package by Miroslav Balda.
|
||||
Here is the original copyright:
|
||||
============================================================================
|
||||
|
||||
|
||||
Copyright (c) 2007, Miroslav Balda
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
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
|
||||
* 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
|
||||
* 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
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
int ptype = param0.type();
|
||||
|
||||
CV_Assert( (param0.cols == 1 || param0.rows == 1) && (ptype == CV_32F || ptype == CV_64F));
|
||||
CV_Assert( !cb.empty() );
|
||||
CV_Assert( cb );
|
||||
|
||||
int lx = param0.rows + param0.cols - 1;
|
||||
param0.convertTo(x, CV_64F);
|
||||
@@ -112,7 +112,7 @@ public:
|
||||
gemm(J, r, 1, noArray(), 0, v, GEMM_1_T);
|
||||
|
||||
Mat D = A.diag().clone();
|
||||
|
||||
|
||||
const double Rlo = 0.25, Rhi = 0.75;
|
||||
double lambda = 1, lc = 0.75;
|
||||
int i, iter = 0;
|
||||
@@ -220,7 +220,7 @@ CV_INIT_ALGORITHM(LMSolverImpl, "LMSolver",
|
||||
Ptr<LMSolver> createLMSolver(const Ptr<LMSolver::Callback>& cb, int maxIters)
|
||||
{
|
||||
CV_Assert( !LMSolverImpl_info_auto.name().empty() );
|
||||
return new LMSolverImpl(cb, maxIters);
|
||||
return makePtr<LMSolverImpl>(cb, maxIters);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -411,4 +411,3 @@ bool p3p::jacobi_4x4(double * A, double * D, double * U)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,4 +59,3 @@ class p3p
|
||||
};
|
||||
|
||||
#endif // P3P_H
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
//
|
||||
//M*/
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
/* POSIT structure */
|
||||
struct CvPOSITObject
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
/* End of file. */
|
||||
@@ -42,16 +42,12 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
|
||||
#include "opencv2/calib3d.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
#include "opencv2/features2d.hpp"
|
||||
#include <vector>
|
||||
#include "opencv2/core/utility.hpp"
|
||||
|
||||
#include "opencv2/core/private.hpp"
|
||||
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
#include "opencv2/calib3d/calib3d_tegra.hpp"
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace cv
|
||||
int RANSACUpdateNumIters( double p, double ep, int modelPoints, int maxIters )
|
||||
{
|
||||
if( modelPoints <= 0 )
|
||||
CV_Error( CV_StsOutOfRange, "the number of model points should be positive" );
|
||||
CV_Error( Error::StsOutOfRange, "the number of model points should be positive" );
|
||||
|
||||
p = MAX(p, 0.);
|
||||
p = MIN(p, 1.);
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return i == modelPoints && iters < maxAttempts;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public:
|
||||
|
||||
RNG rng((uint64)-1);
|
||||
|
||||
CV_Assert( !cb.empty() );
|
||||
CV_Assert( cb );
|
||||
CV_Assert( confidence > 0 && confidence < 1 );
|
||||
|
||||
CV_Assert( count >= 0 && count2 == count );
|
||||
@@ -235,7 +235,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( maxGoodCount > 0 )
|
||||
{
|
||||
if( bestMask.data != bestMask0.data )
|
||||
@@ -250,7 +250,7 @@ public:
|
||||
}
|
||||
else
|
||||
_model.release();
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -267,9 +267,6 @@ public:
|
||||
int maxIters;
|
||||
};
|
||||
|
||||
|
||||
static CV_IMPLEMENT_QSORT( sortDistances, int, CV_LT )
|
||||
|
||||
class LMeDSPointSetRegistrator : public RANSACPointSetRegistrator
|
||||
{
|
||||
public:
|
||||
@@ -291,7 +288,7 @@ public:
|
||||
|
||||
RNG rng((uint64)-1);
|
||||
|
||||
CV_Assert( !cb.empty() );
|
||||
CV_Assert( cb );
|
||||
CV_Assert( confidence > 0 && confidence < 1 );
|
||||
|
||||
CV_Assert( count >= 0 && count2 == count );
|
||||
@@ -347,7 +344,7 @@ public:
|
||||
else
|
||||
errf = err;
|
||||
CV_Assert( errf.isContinuous() && errf.type() == CV_32F && (int)errf.total() == count );
|
||||
sortDistances( (int*)errf.data, count, 0 );
|
||||
std::sort((int*)errf.data, (int*)errf.data + count);
|
||||
|
||||
double median = count % 2 != 0 ?
|
||||
errf.at<float>(count/2) : (errf.at<float>(count/2-1) + errf.at<float>(count/2))*0.5;
|
||||
@@ -359,7 +356,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( minMedian < DBL_MAX )
|
||||
{
|
||||
sigma = 2.5*1.4826*(1 + 5./(count - modelPoints))*std::sqrt(minMedian);
|
||||
@@ -378,7 +375,7 @@ public:
|
||||
}
|
||||
else
|
||||
_model.release();
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -400,7 +397,8 @@ Ptr<PointSetRegistrator> createRANSACPointSetRegistrator(const Ptr<PointSetRegis
|
||||
double _confidence, int _maxIters)
|
||||
{
|
||||
CV_Assert( !RANSACPointSetRegistrator_info_auto.name().empty() );
|
||||
return new RANSACPointSetRegistrator(_cb, _modelPoints, _threshold, _confidence, _maxIters);
|
||||
return Ptr<PointSetRegistrator>(
|
||||
new RANSACPointSetRegistrator(_cb, _modelPoints, _threshold, _confidence, _maxIters));
|
||||
}
|
||||
|
||||
|
||||
@@ -408,7 +406,8 @@ Ptr<PointSetRegistrator> createLMeDSPointSetRegistrator(const Ptr<PointSetRegist
|
||||
int _modelPoints, double _confidence, int _maxIters)
|
||||
{
|
||||
CV_Assert( !LMeDSPointSetRegistrator_info_auto.name().empty() );
|
||||
return new LMeDSPointSetRegistrator(_cb, _modelPoints, _confidence, _maxIters);
|
||||
return Ptr<PointSetRegistrator>(
|
||||
new LMeDSPointSetRegistrator(_cb, _modelPoints, _confidence, _maxIters));
|
||||
}
|
||||
|
||||
class Affine3DEstimatorCallback : public PointSetRegistrator::Callback
|
||||
@@ -534,7 +533,6 @@ int cv::estimateAffine3D(InputArray _from, InputArray _to,
|
||||
const double epsilon = DBL_EPSILON;
|
||||
param1 = param1 <= 0 ? 3 : param1;
|
||||
param2 = (param2 < epsilon) ? 0.99 : (param2 > 1 - epsilon) ? 0.99 : param2;
|
||||
|
||||
return createRANSACPointSetRegistrator(new Affine3DEstimatorCallback, 4, param1, param2)->run(dFrom, dTo, _out, _inliers);
|
||||
}
|
||||
|
||||
return createRANSACPointSetRegistrator(makePtr<Affine3DEstimatorCallback>(), 4, param1, param2)->run(dFrom, dTo, _out, _inliers);
|
||||
}
|
||||
|
||||
@@ -47,40 +47,8 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
//#define _SUBPIX_VERBOSE
|
||||
|
||||
#undef max
|
||||
|
||||
namespace cv {
|
||||
|
||||
|
||||
// static void drawCircles(Mat& img, const std::vector<Point2f>& corners, const std::vector<float>& radius)
|
||||
// {
|
||||
// for(size_t i = 0; i < corners.size(); i++)
|
||||
// {
|
||||
// circle(img, corners[i], cvRound(radius[i]), CV_RGB(255, 0, 0));
|
||||
// }
|
||||
// }
|
||||
|
||||
// static int histQuantile(const Mat& hist, float quantile)
|
||||
// {
|
||||
// if(hist.dims > 1) return -1; // works for 1D histograms only
|
||||
|
||||
// float cur_sum = 0;
|
||||
// float total_sum = (float)sum(hist).val[0];
|
||||
// float quantile_sum = total_sum*quantile;
|
||||
// for(int j = 0; j < hist.size[0]; j++)
|
||||
// {
|
||||
// cur_sum += (float)hist.at<float>(j);
|
||||
// if(cur_sum > quantile_sum)
|
||||
// {
|
||||
// return j;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return hist.size[0] - 1;
|
||||
// }
|
||||
|
||||
inline bool is_smaller(const std::pair<int, float>& p1, const std::pair<int, float>& p2)
|
||||
{
|
||||
return p1.second < p2.second;
|
||||
@@ -124,29 +92,6 @@ static void findLinesCrossPoint(Point2f origin1, Point2f dir1, Point2f origin2,
|
||||
cross_point = origin1 + dir1*alpha;
|
||||
}
|
||||
|
||||
// static void findCorner(const std::vector<Point>& contour, Point2f point, Point2f& corner)
|
||||
// {
|
||||
// // find the nearest point
|
||||
// double min_dist = std::numeric_limits<double>::max();
|
||||
// int min_idx = -1;
|
||||
|
||||
// // find corner idx
|
||||
// for(size_t i = 0; i < contour.size(); i++)
|
||||
// {
|
||||
// double dist = norm(Point2f((float)contour[i].x, (float)contour[i].y) - point);
|
||||
// if(dist < min_dist)
|
||||
// {
|
||||
// min_dist = dist;
|
||||
// min_idx = (int)i;
|
||||
// }
|
||||
// }
|
||||
// assert(min_idx >= 0);
|
||||
|
||||
// // temporary solution, have to make something more precise
|
||||
// corner = contour[min_idx];
|
||||
// return;
|
||||
// }
|
||||
|
||||
static void findCorner(const std::vector<Point2f>& contour, Point2f point, Point2f& corner)
|
||||
{
|
||||
// find the nearest point
|
||||
@@ -163,7 +108,7 @@ static void findCorner(const std::vector<Point2f>& contour, Point2f point, Point
|
||||
min_idx = (int)i;
|
||||
}
|
||||
}
|
||||
assert(min_idx >= 0);
|
||||
CV_Assert(min_idx >= 0);
|
||||
|
||||
// temporary solution, have to make something more precise
|
||||
corner = contour[min_idx];
|
||||
@@ -173,13 +118,7 @@ static void findCorner(const std::vector<Point2f>& contour, Point2f point, Point
|
||||
static int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh)
|
||||
{
|
||||
Mat bw;
|
||||
//const double max_bell_width = 20; // we expect two bells with width bounded above
|
||||
//const double min_bell_width = 5; // and below
|
||||
|
||||
double total_sum = sum(hist).val[0];
|
||||
//double thresh = total_sum/(2*max_bell_width)*0.25f; // quarter of a bar inside a bell
|
||||
|
||||
// threshold(hist, bw, thresh, 255.0, CV_THRESH_BINARY);
|
||||
|
||||
double quantile_sum = 0.0;
|
||||
//double min_quantile = 0.2;
|
||||
@@ -233,12 +172,6 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
const float* _ranges = ranges;
|
||||
Mat hist;
|
||||
|
||||
#if defined(_SUBPIX_VERBOSE)
|
||||
std::vector<float> radius;
|
||||
radius.assign(corners.size(), 0.0f);
|
||||
#endif //_SUBPIX_VERBOSE
|
||||
|
||||
|
||||
Mat black_comp, white_comp;
|
||||
for(int i = 0; i < ncorners; i++)
|
||||
{
|
||||
@@ -248,39 +181,20 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
Mat img_roi = img(roi);
|
||||
calcHist(&img_roi, 1, &channels, Mat(), hist, 1, &nbins, &_ranges);
|
||||
|
||||
#if 0
|
||||
int black_thresh = histQuantile(hist, 0.45f);
|
||||
int white_thresh = histQuantile(hist, 0.55f);
|
||||
#else
|
||||
int black_thresh = 0, white_thresh = 0;
|
||||
segment_hist_max(hist, black_thresh, white_thresh);
|
||||
#endif
|
||||
|
||||
threshold(img, black_comp, black_thresh, 255.0, CV_THRESH_BINARY_INV);
|
||||
threshold(img, white_comp, white_thresh, 255.0, CV_THRESH_BINARY);
|
||||
threshold(img, black_comp, black_thresh, 255.0, THRESH_BINARY_INV);
|
||||
threshold(img, white_comp, white_thresh, 255.0, THRESH_BINARY);
|
||||
|
||||
const int erode_count = 1;
|
||||
erode(black_comp, black_comp, Mat(), Point(-1, -1), erode_count);
|
||||
erode(white_comp, white_comp, Mat(), Point(-1, -1), erode_count);
|
||||
|
||||
#if defined(_SUBPIX_VERBOSE)
|
||||
namedWindow("roi", 1);
|
||||
imshow("roi", img_roi);
|
||||
imwrite("test.jpg", img);
|
||||
namedWindow("black", 1);
|
||||
imshow("black", black_comp);
|
||||
namedWindow("white", 1);
|
||||
imshow("white", white_comp);
|
||||
cvWaitKey(0);
|
||||
imwrite("black.jpg", black_comp);
|
||||
imwrite("white.jpg", white_comp);
|
||||
#endif
|
||||
|
||||
|
||||
std::vector<std::vector<Point> > white_contours, black_contours;
|
||||
std::vector<Vec4i> white_hierarchy, black_hierarchy;
|
||||
findContours(black_comp, black_contours, black_hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
|
||||
findContours(white_comp, white_contours, white_hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
|
||||
findContours(black_comp, black_contours, black_hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);
|
||||
findContours(white_comp, white_contours, white_hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);
|
||||
|
||||
if(black_contours.size() < 5 || white_contours.size() < 5) continue;
|
||||
|
||||
@@ -302,15 +216,11 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
Point2f quad_corners[4];
|
||||
for(int k = 0; k < 4; k++)
|
||||
{
|
||||
#if 1
|
||||
std::vector<Point2f> temp;
|
||||
for(size_t j = 0; j < quads[k]->size(); j++) temp.push_back((*quads[k])[j]);
|
||||
approxPolyDP(Mat(temp), quads_approx[k], 0.5, true);
|
||||
|
||||
findCorner(quads_approx[k], corners[i], quad_corners[k]);
|
||||
#else
|
||||
findCorner(*quads[k], corners[i], quad_corners[k]);
|
||||
#endif
|
||||
quad_corners[k] += Point2f(0.5f, 0.5f);
|
||||
}
|
||||
|
||||
@@ -323,44 +233,7 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
if(cvIsNaN(angle) || cvIsInf(angle) || angle < 0.5 || angle > CV_PI - 0.5) continue;
|
||||
|
||||
findLinesCrossPoint(origin1, dir1, origin2, dir2, corners[i]);
|
||||
|
||||
#if defined(_SUBPIX_VERBOSE)
|
||||
radius[i] = norm(corners[i] - ground_truth_corners[ground_truth_idx])*6;
|
||||
|
||||
#if 1
|
||||
Mat test(img.size(), CV_32FC3);
|
||||
cvtColor(img, test, CV_GRAY2RGB);
|
||||
// line(test, quad_corners[0] - corners[i] + Point2f(30, 30), quad_corners[1] - corners[i] + Point2f(30, 30), cvScalar(0, 255, 0));
|
||||
// line(test, quad_corners[2] - corners[i] + Point2f(30, 30), quad_corners[3] - corners[i] + Point2f(30, 30), cvScalar(0, 255, 0));
|
||||
std::vector<std::vector<Point> > contrs;
|
||||
contrs.resize(1);
|
||||
for(int k = 0; k < 4; k++)
|
||||
{
|
||||
//contrs[0] = quads_approx[k];
|
||||
contrs[0].clear();
|
||||
for(size_t j = 0; j < quads_approx[k].size(); j++) contrs[0].push_back(quads_approx[k][j]);
|
||||
drawContours(test, contrs, 0, CV_RGB(0, 0, 255), 1, 1, std::vector<Vec4i>(), 2);
|
||||
circle(test, quad_corners[k], 0.5, CV_RGB(255, 0, 0));
|
||||
}
|
||||
Mat test1 = test(Rect(corners[i].x - 30, corners[i].y - 30, 60, 60));
|
||||
namedWindow("1", 1);
|
||||
imshow("1", test1);
|
||||
imwrite("test.jpg", test);
|
||||
waitKey(0);
|
||||
#endif
|
||||
#endif //_SUBPIX_VERBOSE
|
||||
|
||||
}
|
||||
|
||||
#if defined(_SUBPIX_VERBOSE)
|
||||
Mat test(img.size(), CV_32FC3);
|
||||
cvtColor(img, test, CV_GRAY2RGB);
|
||||
drawCircles(test, corners, radius);
|
||||
|
||||
namedWindow("corners", 1);
|
||||
imshow("corners", test);
|
||||
waitKey();
|
||||
#endif //_SUBPIX_VERBOSE
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
#include "precomp.hpp"
|
||||
#include "epnp.h"
|
||||
#include "p3p.h"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
#include <iostream>
|
||||
using namespace cv;
|
||||
|
||||
@@ -57,7 +59,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
|
||||
_tvec.create(3, 1, CV_64F);
|
||||
Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat();
|
||||
|
||||
if (flags == CV_EPNP)
|
||||
if (flags == EPNP)
|
||||
{
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
@@ -68,7 +70,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
|
||||
cv::Rodrigues(R, rvec);
|
||||
return true;
|
||||
}
|
||||
else if (flags == CV_P3P)
|
||||
else if (flags == P3P)
|
||||
{
|
||||
CV_Assert( npoints == 4);
|
||||
cv::Mat undistortedPoints;
|
||||
@@ -81,7 +83,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
|
||||
cv::Rodrigues(R, rvec);
|
||||
return result;
|
||||
}
|
||||
else if (flags == CV_ITERATIVE)
|
||||
else if (flags == ITERATIVE)
|
||||
{
|
||||
CvMat c_objectPoints = opoints, c_imagePoints = ipoints;
|
||||
CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs;
|
||||
@@ -115,31 +117,6 @@ namespace cv
|
||||
transform(points, modif_points, transformation);
|
||||
}
|
||||
|
||||
class Mutex
|
||||
{
|
||||
public:
|
||||
Mutex() {
|
||||
}
|
||||
void lock()
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
resultsMutex.lock();
|
||||
#endif
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
resultsMutex.unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
#ifdef HAVE_TBB
|
||||
tbb::mutex resultsMutex;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct CameraParameters
|
||||
{
|
||||
void init(Mat _intrinsics, Mat _distCoeffs)
|
||||
@@ -342,7 +319,7 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
|
||||
|
||||
if (localInliers.size() >= (size_t)pnpransac::MIN_POINTS_COUNT)
|
||||
{
|
||||
if (flags != CV_P3P)
|
||||
if (flags != P3P)
|
||||
{
|
||||
int i, pointsCount = (int)localInliers.size();
|
||||
Mat inlierObjectPoints(1, pointsCount, CV_32FC3), inlierImagePoints(1, pointsCount, CV_32FC2);
|
||||
@@ -371,4 +348,3 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ struct StereoBMParams
|
||||
{
|
||||
StereoBMParams(int _numDisparities=64, int _SADWindowSize=21)
|
||||
{
|
||||
preFilterType = STEREO_PREFILTER_XSOBEL;
|
||||
preFilterType = StereoBM::PREFILTER_XSOBEL;
|
||||
preFilterSize = 9;
|
||||
preFilterCap = 31;
|
||||
SADWindowSize = _SADWindowSize;
|
||||
@@ -84,7 +84,7 @@ struct StereoBMParams
|
||||
int disp12MaxDiff;
|
||||
int dispType;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void prefilterNorm( const Mat& src, Mat& dst, int winsize, int ftzero, uchar* buf )
|
||||
{
|
||||
@@ -183,7 +183,7 @@ prefilterXSobel( const Mat& src, Mat& dst, int ftzero )
|
||||
if( useSIMD )
|
||||
{
|
||||
__m128i z = _mm_setzero_si128(), ftz = _mm_set1_epi16((short)ftzero),
|
||||
ftz2 = _mm_set1_epi8(CV_CAST_8U(ftzero*2));
|
||||
ftz2 = _mm_set1_epi8(cv::saturate_cast<uchar>(ftzero*2));
|
||||
for( ; x <= size.width-9; x += 8 )
|
||||
{
|
||||
__m128i c0 = _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i*)(srow0 + x - 1)), z);
|
||||
@@ -195,9 +195,9 @@ prefilterXSobel( const Mat& src, Mat& dst, int ftzero )
|
||||
d1 = _mm_sub_epi16(d1, c1);
|
||||
|
||||
__m128i c2 = _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i*)(srow2 + x - 1)), z);
|
||||
__m128i c3 = _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i*)(srow2 + x - 1)), z);
|
||||
__m128i c3 = _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i*)(srow3 + x - 1)), z);
|
||||
__m128i d2 = _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i*)(srow2 + x + 1)), z);
|
||||
__m128i d3 = _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i*)(srow2 + x + 1)), z);
|
||||
__m128i d3 = _mm_unpacklo_epi8(_mm_loadl_epi64((__m128i*)(srow3 + x + 1)), z);
|
||||
|
||||
d2 = _mm_sub_epi16(d2, c2);
|
||||
d3 = _mm_sub_epi16(d3, c3);
|
||||
@@ -676,7 +676,7 @@ struct PrefilterInvoker : public ParallelLoopBody
|
||||
{
|
||||
for( int i = range.start; i < range.end; i++ )
|
||||
{
|
||||
if( state->preFilterType == STEREO_PREFILTER_NORMALIZED_RESPONSE )
|
||||
if( state->preFilterType == StereoBM::PREFILTER_NORMALIZED_RESPONSE )
|
||||
prefilterNorm( *imgs0[i], *imgs[i], state->preFilterSize, state->preFilterCap, buf[i] );
|
||||
else
|
||||
prefilterXSobel( *imgs0[i], *imgs[i], state->preFilterCap );
|
||||
@@ -771,8 +771,7 @@ protected:
|
||||
Rect validDisparityRect;
|
||||
};
|
||||
|
||||
|
||||
class StereoBMImpl : public StereoMatcher
|
||||
class StereoBMImpl : public StereoBM
|
||||
{
|
||||
public:
|
||||
StereoBMImpl()
|
||||
@@ -784,46 +783,46 @@ public:
|
||||
{
|
||||
params = StereoBMParams(_numDisparities, _SADWindowSize);
|
||||
}
|
||||
|
||||
|
||||
void compute( InputArray leftarr, InputArray rightarr, OutputArray disparr )
|
||||
{
|
||||
Mat left0 = leftarr.getMat(), right0 = rightarr.getMat();
|
||||
int dtype = disparr.fixedType() ? disparr.type() : params.dispType;
|
||||
|
||||
if (left0.size() != right0.size())
|
||||
CV_Error( CV_StsUnmatchedSizes, "All the images must have the same size" );
|
||||
CV_Error( Error::StsUnmatchedSizes, "All the images must have the same size" );
|
||||
|
||||
if (left0.type() != CV_8UC1 || right0.type() != CV_8UC1)
|
||||
CV_Error( CV_StsUnsupportedFormat, "Both input images must have CV_8UC1" );
|
||||
CV_Error( Error::StsUnsupportedFormat, "Both input images must have CV_8UC1" );
|
||||
|
||||
if (dtype != CV_16SC1 && dtype != CV_32FC1)
|
||||
CV_Error( CV_StsUnsupportedFormat, "Disparity image must have CV_16SC1 or CV_32FC1 format" );
|
||||
CV_Error( Error::StsUnsupportedFormat, "Disparity image must have CV_16SC1 or CV_32FC1 format" );
|
||||
|
||||
disparr.create(left0.size(), dtype);
|
||||
Mat disp0 = disparr.getMat();
|
||||
|
||||
if( params.preFilterType != STEREO_PREFILTER_NORMALIZED_RESPONSE &&
|
||||
params.preFilterType != STEREO_PREFILTER_XSOBEL )
|
||||
CV_Error( CV_StsOutOfRange, "preFilterType must be = CV_STEREO_BM_NORMALIZED_RESPONSE" );
|
||||
if( params.preFilterType != PREFILTER_NORMALIZED_RESPONSE &&
|
||||
params.preFilterType != PREFILTER_XSOBEL )
|
||||
CV_Error( Error::StsOutOfRange, "preFilterType must be = CV_STEREO_BM_NORMALIZED_RESPONSE" );
|
||||
|
||||
if( params.preFilterSize < 5 || params.preFilterSize > 255 || params.preFilterSize % 2 == 0 )
|
||||
CV_Error( CV_StsOutOfRange, "preFilterSize must be odd and be within 5..255" );
|
||||
CV_Error( Error::StsOutOfRange, "preFilterSize must be odd and be within 5..255" );
|
||||
|
||||
if( params.preFilterCap < 1 || params.preFilterCap > 63 )
|
||||
CV_Error( CV_StsOutOfRange, "preFilterCap must be within 1..63" );
|
||||
CV_Error( Error::StsOutOfRange, "preFilterCap must be within 1..63" );
|
||||
|
||||
if( params.SADWindowSize < 5 || params.SADWindowSize > 255 || params.SADWindowSize % 2 == 0 ||
|
||||
params.SADWindowSize >= std::min(left0.cols, left0.rows) )
|
||||
CV_Error( CV_StsOutOfRange, "SADWindowSize must be odd, be within 5..255 and be not larger than image width or height" );
|
||||
CV_Error( Error::StsOutOfRange, "SADWindowSize must be odd, be within 5..255 and be not larger than image width or height" );
|
||||
|
||||
if( params.numDisparities <= 0 || params.numDisparities % 16 != 0 )
|
||||
CV_Error( CV_StsOutOfRange, "numDisparities must be positive and divisble by 16" );
|
||||
CV_Error( Error::StsOutOfRange, "numDisparities must be positive and divisble by 16" );
|
||||
|
||||
if( params.textureThreshold < 0 )
|
||||
CV_Error( CV_StsOutOfRange, "texture threshold must be non-negative" );
|
||||
CV_Error( Error::StsOutOfRange, "texture threshold must be non-negative" );
|
||||
|
||||
if( params.uniquenessRatio < 0 )
|
||||
CV_Error( CV_StsOutOfRange, "uniqueness ratio must be non-negative" );
|
||||
CV_Error( Error::StsOutOfRange, "uniqueness ratio must be non-negative" );
|
||||
|
||||
preFilteredImg0.create( left0.size(), CV_8U );
|
||||
preFilteredImg1.create( left0.size(), CV_8U );
|
||||
@@ -888,48 +887,111 @@ public:
|
||||
R2.area() > 0 ? Rect(0, 0, width, height) : validDisparityRect,
|
||||
params.minDisparity, params.numDisparities,
|
||||
params.SADWindowSize);
|
||||
|
||||
|
||||
parallel_for_(Range(0, nstripes),
|
||||
FindStereoCorrespInvoker(left, right, disp, ¶ms, nstripes,
|
||||
bufSize0, useShorts, validDisparityRect,
|
||||
slidingSumBuf, cost));
|
||||
|
||||
|
||||
if( params.speckleRange >= 0 && params.speckleWindowSize > 0 )
|
||||
filterSpeckles(disp, FILTERED, params.speckleWindowSize, params.speckleRange, slidingSumBuf);
|
||||
|
||||
|
||||
if (disp0.data != disp.data)
|
||||
disp.convertTo(disp0, disp0.type(), 1./(1 << DISPARITY_SHIFT), 0);
|
||||
}
|
||||
|
||||
AlgorithmInfo* info() const;
|
||||
AlgorithmInfo* info() const { return 0; }
|
||||
|
||||
int getMinDisparity() const { return params.minDisparity; }
|
||||
void setMinDisparity(int minDisparity) { params.minDisparity = minDisparity; }
|
||||
|
||||
int getNumDisparities() const { return params.numDisparities; }
|
||||
void setNumDisparities(int numDisparities) { params.numDisparities = numDisparities; }
|
||||
|
||||
int getBlockSize() const { return params.SADWindowSize; }
|
||||
void setBlockSize(int blockSize) { params.SADWindowSize = blockSize; }
|
||||
|
||||
int getSpeckleWindowSize() const { return params.speckleWindowSize; }
|
||||
void setSpeckleWindowSize(int speckleWindowSize) { params.speckleWindowSize = speckleWindowSize; }
|
||||
|
||||
int getSpeckleRange() const { return params.speckleRange; }
|
||||
void setSpeckleRange(int speckleRange) { params.speckleRange = speckleRange; }
|
||||
|
||||
int getDisp12MaxDiff() const { return params.disp12MaxDiff; }
|
||||
void setDisp12MaxDiff(int disp12MaxDiff) { params.disp12MaxDiff = disp12MaxDiff; }
|
||||
|
||||
int getPreFilterType() const { return params.preFilterType; }
|
||||
void setPreFilterType(int preFilterType) { params.preFilterType = preFilterType; }
|
||||
|
||||
int getPreFilterSize() const { return params.preFilterSize; }
|
||||
void setPreFilterSize(int preFilterSize) { params.preFilterSize = preFilterSize; }
|
||||
|
||||
int getPreFilterCap() const { return params.preFilterCap; }
|
||||
void setPreFilterCap(int preFilterCap) { params.preFilterCap = preFilterCap; }
|
||||
|
||||
int getTextureThreshold() const { return params.textureThreshold; }
|
||||
void setTextureThreshold(int textureThreshold) { params.textureThreshold = textureThreshold; }
|
||||
|
||||
int getUniquenessRatio() const { return params.uniquenessRatio; }
|
||||
void setUniquenessRatio(int uniquenessRatio) { params.uniquenessRatio = uniquenessRatio; }
|
||||
|
||||
int getSmallerBlockSize() const { return 0; }
|
||||
void setSmallerBlockSize(int) {}
|
||||
|
||||
Rect getROI1() const { return params.roi1; }
|
||||
void setROI1(Rect roi1) { params.roi1 = roi1; }
|
||||
|
||||
Rect getROI2() const { return params.roi2; }
|
||||
void setROI2(Rect roi2) { params.roi2 = roi2; }
|
||||
|
||||
void write(FileStorage& fs) const
|
||||
{
|
||||
fs << "name" << name_
|
||||
<< "minDisparity" << params.minDisparity
|
||||
<< "numDisparities" << params.numDisparities
|
||||
<< "blockSize" << params.SADWindowSize
|
||||
<< "speckleWindowSize" << params.speckleWindowSize
|
||||
<< "speckleRange" << params.speckleRange
|
||||
<< "disp12MaxDiff" << params.disp12MaxDiff
|
||||
<< "preFilterType" << params.preFilterType
|
||||
<< "preFilterSize" << params.preFilterSize
|
||||
<< "preFilterCap" << params.preFilterCap
|
||||
<< "textureThreshold" << params.textureThreshold
|
||||
<< "uniquenessRatio" << params.uniquenessRatio;
|
||||
}
|
||||
|
||||
void read(const FileNode& fn)
|
||||
{
|
||||
FileNode n = fn["name"];
|
||||
CV_Assert( n.isString() && String(n) == name_ );
|
||||
params.minDisparity = (int)fn["minDisparity"];
|
||||
params.numDisparities = (int)fn["numDisparities"];
|
||||
params.SADWindowSize = (int)fn["blockSize"];
|
||||
params.speckleWindowSize = (int)fn["speckleWindowSize"];
|
||||
params.speckleRange = (int)fn["speckleRange"];
|
||||
params.disp12MaxDiff = (int)fn["disp12MaxDiff"];
|
||||
params.preFilterType = (int)fn["preFilterType"];
|
||||
params.preFilterSize = (int)fn["preFilterSize"];
|
||||
params.preFilterCap = (int)fn["preFilterCap"];
|
||||
params.textureThreshold = (int)fn["textureThreshold"];
|
||||
params.uniquenessRatio = (int)fn["uniquenessRatio"];
|
||||
params.roi1 = params.roi2 = Rect();
|
||||
}
|
||||
|
||||
StereoBMParams params;
|
||||
Mat preFilteredImg0, preFilteredImg1, cost, dispbuf;
|
||||
Mat slidingSumBuf;
|
||||
|
||||
static const char* name_;
|
||||
};
|
||||
|
||||
#define add_param(n) \
|
||||
obj.info()->addParam(obj, #n, obj.params.n)
|
||||
|
||||
CV_INIT_ALGORITHM(StereoBMImpl, "StereoMatcher.BM",
|
||||
add_param(preFilterType);
|
||||
add_param(preFilterSize);
|
||||
add_param(preFilterCap);
|
||||
add_param(SADWindowSize);
|
||||
add_param(minDisparity);
|
||||
add_param(numDisparities);
|
||||
add_param(textureThreshold);
|
||||
add_param(uniquenessRatio);
|
||||
add_param(speckleRange);
|
||||
add_param(speckleWindowSize);
|
||||
add_param(disp12MaxDiff);
|
||||
add_param(dispType));
|
||||
const char* StereoBMImpl::name_ = "StereoMatcher.BM";
|
||||
|
||||
}
|
||||
|
||||
cv::Ptr<cv::StereoMatcher> cv::createStereoBM(int _numDisparities, int _SADWindowSize)
|
||||
cv::Ptr<cv::StereoBM> cv::createStereoBM(int _numDisparities, int _SADWindowSize)
|
||||
{
|
||||
return new StereoBMImpl(_numDisparities, _SADWindowSize);
|
||||
return makePtr<StereoBMImpl>(_numDisparities, _SADWindowSize);
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -75,13 +75,13 @@ struct StereoSGBMParams
|
||||
uniquenessRatio = 0;
|
||||
speckleWindowSize = 0;
|
||||
speckleRange = 0;
|
||||
fullDP = false;
|
||||
mode = StereoSGBM::MODE_SGBM;
|
||||
}
|
||||
|
||||
StereoSGBMParams( int _minDisparity, int _numDisparities, int _SADWindowSize,
|
||||
int _P1, int _P2, int _disp12MaxDiff, int _preFilterCap,
|
||||
int _uniquenessRatio, int _speckleWindowSize, int _speckleRange,
|
||||
bool _fullDP )
|
||||
int _mode )
|
||||
{
|
||||
minDisparity = _minDisparity;
|
||||
numDisparities = _numDisparities;
|
||||
@@ -93,7 +93,7 @@ struct StereoSGBMParams
|
||||
uniquenessRatio = _uniquenessRatio;
|
||||
speckleWindowSize = _speckleWindowSize;
|
||||
speckleRange = _speckleRange;
|
||||
fullDP = _fullDP;
|
||||
mode = _mode;
|
||||
}
|
||||
|
||||
int minDisparity;
|
||||
@@ -106,7 +106,7 @@ struct StereoSGBMParams
|
||||
int speckleWindowSize;
|
||||
int speckleRange;
|
||||
int disp12MaxDiff;
|
||||
bool fullDP;
|
||||
int mode;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -328,8 +328,8 @@ static void computeDisparitySGBM( const Mat& img1, const Mat& img2,
|
||||
#endif
|
||||
|
||||
const int ALIGN = 16;
|
||||
const int DISP_SHIFT = StereoSGBM::DISP_SHIFT;
|
||||
const int DISP_SCALE = StereoSGBM::DISP_SCALE;
|
||||
const int DISP_SHIFT = StereoMatcher::DISP_SHIFT;
|
||||
const int DISP_SCALE = (1 << DISP_SHIFT);
|
||||
const CostType MAX_COST = SHRT_MAX;
|
||||
|
||||
int minD = params.minDisparity, maxD = minD + params.numDisparities;
|
||||
@@ -344,7 +344,8 @@ static void computeDisparitySGBM( const Mat& img1, const Mat& img2,
|
||||
int D = maxD - minD, width1 = maxX1 - minX1;
|
||||
int INVALID_DISP = minD - 1, INVALID_DISP_SCALED = INVALID_DISP*DISP_SCALE;
|
||||
int SW2 = SADWindowSize.width/2, SH2 = SADWindowSize.height/2;
|
||||
int npasses = params.fullDP ? 2 : 1;
|
||||
bool fullDP = params.mode == StereoSGBM::MODE_HH;
|
||||
int npasses = fullDP ? 2 : 1;
|
||||
const int TAB_OFS = 256*4, TAB_SIZE = 256 + TAB_OFS*2;
|
||||
PixType clipTab[TAB_SIZE];
|
||||
|
||||
@@ -373,7 +374,7 @@ static void computeDisparitySGBM( const Mat& img1, const Mat& img2,
|
||||
// we keep pixel difference cost (C) and the summary cost over NR directions (S).
|
||||
// we also keep all the partial costs for the previous line L_r(x,d) and also min_k L_r(x, k)
|
||||
size_t costBufSize = width1*D;
|
||||
size_t CSBufSize = costBufSize*(params.fullDP ? height : 1);
|
||||
size_t CSBufSize = costBufSize*(fullDP ? height : 1);
|
||||
size_t minLrSize = (width1 + LrBorder*2)*NR2, LrSize = minLrSize*D2;
|
||||
int hsumBufNRows = SH2*2 + 2;
|
||||
size_t totalBufSize = (LrSize + minLrSize)*NLR*sizeof(CostType) + // minLr[] and Lr[]
|
||||
@@ -434,8 +435,8 @@ static void computeDisparitySGBM( const Mat& img1, const Mat& img2,
|
||||
{
|
||||
int x, d;
|
||||
DispType* disp1ptr = disp1.ptr<DispType>(y);
|
||||
CostType* C = Cbuf + (!params.fullDP ? 0 : y*costBufSize);
|
||||
CostType* S = Sbuf + (!params.fullDP ? 0 : y*costBufSize);
|
||||
CostType* C = Cbuf + (!fullDP ? 0 : y*costBufSize);
|
||||
CostType* S = Sbuf + (!fullDP ? 0 : y*costBufSize);
|
||||
|
||||
if( pass == 1 ) // compute C on the first pass, and reuse it on the second pass, if any.
|
||||
{
|
||||
@@ -460,7 +461,7 @@ static void computeDisparitySGBM( const Mat& img1, const Mat& img2,
|
||||
if( y > 0 )
|
||||
{
|
||||
const CostType* hsumSub = hsumBuf + (std::max(y - SH2 - 1, 0) % hsumBufNRows)*costBufSize;
|
||||
const CostType* Cprev = !params.fullDP || y == 0 ? C : C - costBufSize;
|
||||
const CostType* Cprev = !fullDP || y == 0 ? C : C - costBufSize;
|
||||
|
||||
for( x = D; x < width1*D; x += D )
|
||||
{
|
||||
@@ -828,8 +829,7 @@ static void computeDisparitySGBM( const Mat& img1, const Mat& img2,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class StereoSGBMImpl : public StereoMatcher
|
||||
class StereoSGBMImpl : public StereoSGBM
|
||||
{
|
||||
public:
|
||||
StereoSGBMImpl()
|
||||
@@ -840,12 +840,12 @@ public:
|
||||
StereoSGBMImpl( int _minDisparity, int _numDisparities, int _SADWindowSize,
|
||||
int _P1, int _P2, int _disp12MaxDiff, int _preFilterCap,
|
||||
int _uniquenessRatio, int _speckleWindowSize, int _speckleRange,
|
||||
bool _fullDP )
|
||||
int _mode )
|
||||
{
|
||||
params = StereoSGBMParams( _minDisparity, _numDisparities, _SADWindowSize,
|
||||
_P1, _P2, _disp12MaxDiff, _preFilterCap,
|
||||
_uniquenessRatio, _speckleWindowSize, _speckleRange,
|
||||
_fullDP );
|
||||
_mode );
|
||||
}
|
||||
|
||||
void compute( InputArray leftarr, InputArray rightarr, OutputArray disparr )
|
||||
@@ -861,47 +861,100 @@ public:
|
||||
medianBlur(disp, disp, 3);
|
||||
|
||||
if( params.speckleWindowSize > 0 )
|
||||
filterSpeckles(disp, (params.minDisparity - 1)*STEREO_DISP_SCALE, params.speckleWindowSize,
|
||||
STEREO_DISP_SCALE*params.speckleRange, buffer);
|
||||
filterSpeckles(disp, (params.minDisparity - 1)*StereoMatcher::DISP_SCALE, params.speckleWindowSize,
|
||||
StereoMatcher::DISP_SCALE*params.speckleRange, buffer);
|
||||
}
|
||||
|
||||
AlgorithmInfo* info() const;
|
||||
AlgorithmInfo* info() const { return 0; }
|
||||
|
||||
int getMinDisparity() const { return params.minDisparity; }
|
||||
void setMinDisparity(int minDisparity) { params.minDisparity = minDisparity; }
|
||||
|
||||
int getNumDisparities() const { return params.numDisparities; }
|
||||
void setNumDisparities(int numDisparities) { params.numDisparities = numDisparities; }
|
||||
|
||||
int getBlockSize() const { return params.SADWindowSize; }
|
||||
void setBlockSize(int blockSize) { params.SADWindowSize = blockSize; }
|
||||
|
||||
int getSpeckleWindowSize() const { return params.speckleWindowSize; }
|
||||
void setSpeckleWindowSize(int speckleWindowSize) { params.speckleWindowSize = speckleWindowSize; }
|
||||
|
||||
int getSpeckleRange() const { return params.speckleRange; }
|
||||
void setSpeckleRange(int speckleRange) { params.speckleRange = speckleRange; }
|
||||
|
||||
int getDisp12MaxDiff() const { return params.disp12MaxDiff; }
|
||||
void setDisp12MaxDiff(int disp12MaxDiff) { params.disp12MaxDiff = disp12MaxDiff; }
|
||||
|
||||
int getPreFilterCap() const { return params.preFilterCap; }
|
||||
void setPreFilterCap(int preFilterCap) { params.preFilterCap = preFilterCap; }
|
||||
|
||||
int getUniquenessRatio() const { return params.uniquenessRatio; }
|
||||
void setUniquenessRatio(int uniquenessRatio) { params.uniquenessRatio = uniquenessRatio; }
|
||||
|
||||
int getP1() const { return params.P1; }
|
||||
void setP1(int P1) { params.P1 = P1; }
|
||||
|
||||
int getP2() const { return params.P2; }
|
||||
void setP2(int P2) { params.P2 = P2; }
|
||||
|
||||
int getMode() const { return params.mode; }
|
||||
void setMode(int mode) { params.mode = mode; }
|
||||
|
||||
void write(FileStorage& fs) const
|
||||
{
|
||||
fs << "name" << name_
|
||||
<< "minDisparity" << params.minDisparity
|
||||
<< "numDisparities" << params.numDisparities
|
||||
<< "blockSize" << params.SADWindowSize
|
||||
<< "speckleWindowSize" << params.speckleWindowSize
|
||||
<< "speckleRange" << params.speckleRange
|
||||
<< "disp12MaxDiff" << params.disp12MaxDiff
|
||||
<< "preFilterCap" << params.preFilterCap
|
||||
<< "uniquenessRatio" << params.uniquenessRatio
|
||||
<< "P1" << params.P1
|
||||
<< "P2" << params.P2
|
||||
<< "mode" << params.mode;
|
||||
}
|
||||
|
||||
void read(const FileNode& fn)
|
||||
{
|
||||
FileNode n = fn["name"];
|
||||
CV_Assert( n.isString() && String(n) == name_ );
|
||||
params.minDisparity = (int)fn["minDisparity"];
|
||||
params.numDisparities = (int)fn["numDisparities"];
|
||||
params.SADWindowSize = (int)fn["blockSize"];
|
||||
params.speckleWindowSize = (int)fn["speckleWindowSize"];
|
||||
params.speckleRange = (int)fn["speckleRange"];
|
||||
params.disp12MaxDiff = (int)fn["disp12MaxDiff"];
|
||||
params.preFilterCap = (int)fn["preFilterCap"];
|
||||
params.uniquenessRatio = (int)fn["uniquenessRatio"];
|
||||
params.P1 = (int)fn["P1"];
|
||||
params.P2 = (int)fn["P2"];
|
||||
params.mode = (int)fn["mode"];
|
||||
}
|
||||
|
||||
StereoSGBMParams params;
|
||||
Mat buffer;
|
||||
static const char* name_;
|
||||
};
|
||||
|
||||
const char* StereoSGBMImpl::name_ = "StereoMatcher.SGBM";
|
||||
|
||||
Ptr<StereoMatcher> createStereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,
|
||||
int P1, int P2, int disp12MaxDiff,
|
||||
int preFilterCap, int uniquenessRatio,
|
||||
int speckleWindowSize, int speckleRange,
|
||||
bool fullDP)
|
||||
|
||||
Ptr<StereoSGBM> createStereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,
|
||||
int P1, int P2, int disp12MaxDiff,
|
||||
int preFilterCap, int uniquenessRatio,
|
||||
int speckleWindowSize, int speckleRange,
|
||||
int mode)
|
||||
{
|
||||
return new StereoSGBMImpl(minDisparity, numDisparities, SADWindowSize,
|
||||
P1, P2, disp12MaxDiff,
|
||||
preFilterCap, uniquenessRatio,
|
||||
speckleWindowSize, speckleRange,
|
||||
fullDP);
|
||||
return Ptr<StereoSGBM>(
|
||||
new StereoSGBMImpl(minDisparity, numDisparities, SADWindowSize,
|
||||
P1, P2, disp12MaxDiff,
|
||||
preFilterCap, uniquenessRatio,
|
||||
speckleWindowSize, speckleRange,
|
||||
mode));
|
||||
}
|
||||
|
||||
|
||||
#define add_param(n) \
|
||||
obj.info()->addParam(obj, #n, obj.params.n)
|
||||
|
||||
CV_INIT_ALGORITHM(StereoSGBMImpl, "StereoMatcher.SGBM",
|
||||
add_param(minDisparity);
|
||||
add_param(numDisparities);
|
||||
add_param(SADWindowSize);
|
||||
add_param(preFilterCap);
|
||||
add_param(uniquenessRatio);
|
||||
add_param(P1);
|
||||
add_param(P2);
|
||||
add_param(speckleWindowSize);
|
||||
add_param(speckleRange);
|
||||
add_param(disp12MaxDiff);
|
||||
add_param(fullDP));
|
||||
|
||||
Rect getValidDisparityROI( Rect roi1, Rect roi2,
|
||||
int minDisparity,
|
||||
int numberOfDisparities,
|
||||
@@ -1117,4 +1170,3 @@ void cv::validateDisparity( InputOutputArray _disp, InputArray _cost, int minDis
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
// cvCorrectMatches function is Copyright (C) 2009, Jostein Austvik Jacobsen.
|
||||
// cvTriangulatePoints function is derived from icvReconstructPointsFor3View, originally by Valery Mosyagin.
|
||||
@@ -239,32 +240,32 @@ cvCorrectMatches(CvMat *F_, CvMat *points1_, CvMat *points2_, CvMat *new_points1
|
||||
}
|
||||
|
||||
// Make sure F uses double precision
|
||||
F = cvCreateMat(3,3,CV_64FC1);
|
||||
F.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
cvConvert(F_, F);
|
||||
|
||||
// Make sure points1 uses double precision
|
||||
points1 = cvCreateMat(points1_->rows,points1_->cols,CV_64FC2);
|
||||
points1.reset(cvCreateMat(points1_->rows,points1_->cols,CV_64FC2));
|
||||
cvConvert(points1_, points1);
|
||||
|
||||
// Make sure points2 uses double precision
|
||||
points2 = cvCreateMat(points2_->rows,points2_->cols,CV_64FC2);
|
||||
points2.reset(cvCreateMat(points2_->rows,points2_->cols,CV_64FC2));
|
||||
cvConvert(points2_, points2);
|
||||
|
||||
tmp33 = cvCreateMat(3,3,CV_64FC1);
|
||||
tmp31 = cvCreateMat(3,1,CV_64FC1), tmp31_2 = cvCreateMat(3,1,CV_64FC1);
|
||||
T1i = cvCreateMat(3,3,CV_64FC1), T2i = cvCreateMat(3,3,CV_64FC1);
|
||||
R1 = cvCreateMat(3,3,CV_64FC1), R2 = cvCreateMat(3,3,CV_64FC1);
|
||||
TFT = cvCreateMat(3,3,CV_64FC1), TFTt = cvCreateMat(3,3,CV_64FC1), RTFTR = cvCreateMat(3,3,CV_64FC1);
|
||||
U = cvCreateMat(3,3,CV_64FC1);
|
||||
S = cvCreateMat(3,3,CV_64FC1);
|
||||
V = cvCreateMat(3,3,CV_64FC1);
|
||||
e1 = cvCreateMat(3,1,CV_64FC1), e2 = cvCreateMat(3,1,CV_64FC1);
|
||||
tmp33.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
tmp31.reset(cvCreateMat(3,1,CV_64FC1)), tmp31_2.reset(cvCreateMat(3,1,CV_64FC1));
|
||||
T1i.reset(cvCreateMat(3,3,CV_64FC1)), T2i.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
R1.reset(cvCreateMat(3,3,CV_64FC1)), R2.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
TFT.reset(cvCreateMat(3,3,CV_64FC1)), TFTt.reset(cvCreateMat(3,3,CV_64FC1)), RTFTR.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
U.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
S.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
V.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
e1.reset(cvCreateMat(3,1,CV_64FC1)), e2.reset(cvCreateMat(3,1,CV_64FC1));
|
||||
|
||||
double x1, y1, x2, y2;
|
||||
double scale;
|
||||
double f1, f2, a, b, c, d;
|
||||
polynomial = cvCreateMat(1,7,CV_64FC1);
|
||||
result = cvCreateMat(1,6,CV_64FC2);
|
||||
polynomial.reset(cvCreateMat(1,7,CV_64FC1));
|
||||
result.reset(cvCreateMat(1,6,CV_64FC2));
|
||||
double t_min, s_val, t, s;
|
||||
for (int p = 0; p < points1->cols; ++p) {
|
||||
// Replace F by T2-t * F * T1-t
|
||||
|
||||
@@ -52,30 +52,30 @@ TEST(Calib3d_Affine3f, accuracy)
|
||||
|
||||
cv::Mat expected;
|
||||
cv::Rodrigues(rvec, expected);
|
||||
|
||||
|
||||
|
||||
|
||||
ASSERT_EQ(0, norm(cv::Mat(affine.matrix, false).colRange(0, 3).rowRange(0, 3) != expected));
|
||||
ASSERT_EQ(0, norm(cv::Mat(affine.linear()) != expected));
|
||||
|
||||
|
||||
|
||||
|
||||
cv::Matx33d R = cv::Matx33d::eye();
|
||||
|
||||
|
||||
double angle = 50;
|
||||
R.val[0] = R.val[4] = std::cos(CV_PI*angle/180.0);
|
||||
R.val[3] = std::sin(CV_PI*angle/180.0);
|
||||
R.val[1] = -R.val[3];
|
||||
|
||||
|
||||
|
||||
|
||||
cv::Affine3d affine1(cv::Mat(cv::Vec3d(0.2, 0.5, 0.3)).reshape(1, 1), cv::Vec3d(4, 5, 6));
|
||||
cv::Affine3d affine2(R, cv::Vec3d(1, 1, 0.4));
|
||||
|
||||
|
||||
cv::Affine3d result = affine1.inv() * affine2;
|
||||
|
||||
|
||||
expected = cv::Mat(affine1.matrix.inv(cv::DECOMP_SVD)) * cv::Mat(affine2.matrix, false);
|
||||
|
||||
|
||||
|
||||
cv::Mat diff;
|
||||
cv::absdiff(expected, result.matrix, diff);
|
||||
|
||||
|
||||
ASSERT_LT(cv::norm(diff, cv::NORM_INF), 1e-15);
|
||||
}
|
||||
|
||||
@@ -195,4 +195,3 @@ void CV_Affine3D_EstTest::run( int /* start_from */)
|
||||
}
|
||||
|
||||
TEST(Calib3d_EstimateAffineTransform, accuracy) { CV_Affine3D_EstTest test; test.safe_run(); }
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
|
||||
@@ -304,7 +304,7 @@ protected:
|
||||
for(size_t i = 0; i < brdsNum; ++i)
|
||||
{
|
||||
Mat gray;
|
||||
cvtColor(boards[i], gray, CV_BGR2GRAY);
|
||||
cvtColor(boards[i], gray, COLOR_BGR2GRAY);
|
||||
vector<Point2f> tmp = imagePoints_findCb[i];
|
||||
cornerSubPix(gray, tmp, Size(5, 5), Size(-1,-1), tc);
|
||||
imagePoints.push_back(tmp);
|
||||
@@ -314,7 +314,7 @@ protected:
|
||||
for(size_t i = 0; i < brdsNum; ++i)
|
||||
{
|
||||
Mat gray;
|
||||
cvtColor(boards[i], gray, CV_BGR2GRAY);
|
||||
cvtColor(boards[i], gray, COLOR_BGR2GRAY);
|
||||
vector<Point2f> tmp = imagePoints_findCb[i];
|
||||
find4QuadCornerSubpix(gray, tmp, Size(5, 5));
|
||||
imagePoints.push_back(tmp);
|
||||
@@ -327,7 +327,7 @@ protected:
|
||||
Mat camMat_est = Mat::eye(3, 3, CV_64F), distCoeffs_est = Mat::zeros(1, 5, CV_64F);
|
||||
vector<Mat> rvecs_est, tvecs_est;
|
||||
|
||||
int flags = /*CV_CALIB_FIX_K3|*/CV_CALIB_FIX_K4|CV_CALIB_FIX_K5|CV_CALIB_FIX_K6; //CALIB_FIX_K3; //CALIB_FIX_ASPECT_RATIO | | CALIB_ZERO_TANGENT_DIST;
|
||||
int flags = /*CALIB_FIX_K3|*/CALIB_FIX_K4|CALIB_FIX_K5|CALIB_FIX_K6; //CALIB_FIX_K3; //CALIB_FIX_ASPECT_RATIO | | CALIB_ZERO_TANGENT_DIST;
|
||||
TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 100, DBL_EPSILON);
|
||||
double rep_error = calibrateCamera(objectPoints, imagePoints, imgSize, camMat_est, distCoeffs_est, rvecs_est, tvecs_est, flags, criteria);
|
||||
rep_error /= brdsNum * cornersSize.area();
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "test_chessboardgenerator.hpp"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -734,5 +735,3 @@ protected:
|
||||
TEST(Calib3d_CalibrateCamera_C, badarg) { CV_CameraCalibrationBadArgTest test; test.safe_run(); }
|
||||
TEST(Calib3d_Rodrigues_C, badarg) { CV_Rodrigues2BadArgTest test; test.safe_run(); }
|
||||
TEST(Calib3d_ProjectPoints_C, badarg) { CV_ProjectPoints2BadArgTest test; test.safe_run(); }
|
||||
|
||||
|
||||
|
||||
@@ -161,15 +161,15 @@ Mat cv::ChessBoardGenerator::generateChessBoard(const Mat& bg, const Mat& camMat
|
||||
if (rendererResolutionMultiplier == 1)
|
||||
{
|
||||
result = bg.clone();
|
||||
drawContours(result, whole_contour, -1, Scalar::all(255), CV_FILLED, CV_AA);
|
||||
drawContours(result, squares_black, -1, Scalar::all(0), CV_FILLED, CV_AA);
|
||||
drawContours(result, whole_contour, -1, Scalar::all(255), FILLED, LINE_AA);
|
||||
drawContours(result, squares_black, -1, Scalar::all(0), FILLED, LINE_AA);
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat tmp;
|
||||
resize(bg, tmp, bg.size() * rendererResolutionMultiplier);
|
||||
drawContours(tmp, whole_contour, -1, Scalar::all(255), CV_FILLED, CV_AA);
|
||||
drawContours(tmp, squares_black, -1, Scalar::all(0), CV_FILLED, CV_AA);
|
||||
drawContours(tmp, whole_contour, -1, Scalar::all(255), FILLED, LINE_AA);
|
||||
drawContours(tmp, squares_black, -1, Scalar::all(0), FILLED, LINE_AA);
|
||||
resize(tmp, result, bg.size(), 0, 0, INTER_AREA);
|
||||
}
|
||||
|
||||
@@ -329,4 +329,3 @@ Mat cv::ChessBoardGenerator::operator ()(const Mat& bg, const Mat& camMat, const
|
||||
return generateChessBoard(bg, camMat, distCoeffs, zero, pb1, pb2,
|
||||
squareSize.width, squareSize.height, pts3d, corners);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,14 +57,14 @@ void show_points( const Mat& gray, const Mat& u, const vector<Point2f>& v, Size
|
||||
merge(vector<Mat>(3, gray), rgb);
|
||||
|
||||
for(size_t i = 0; i < v.size(); i++ )
|
||||
circle( rgb, v[i], 3, CV_RGB(255, 0, 0), CV_FILLED);
|
||||
circle( rgb, v[i], 3, Scalar(255, 0, 0), FILLED);
|
||||
|
||||
if( !u.empty() )
|
||||
{
|
||||
const Point2f* u_data = u.ptr<Point2f>();
|
||||
size_t count = u.cols * u.rows;
|
||||
for(size_t i = 0; i < count; i++ )
|
||||
circle( rgb, u_data[i], 3, CV_RGB(0, 255, 0), CV_FILLED);
|
||||
circle( rgb, u_data[i], 3, Scalar(0, 255, 0), FILLED);
|
||||
}
|
||||
if (!v.empty())
|
||||
{
|
||||
@@ -208,7 +208,7 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
}
|
||||
|
||||
int progress = 0;
|
||||
int max_idx = board_list.node->data.seq->total/2;
|
||||
int max_idx = board_list.size()/2;
|
||||
double sum_error = 0.0;
|
||||
int count = 0;
|
||||
|
||||
@@ -217,7 +217,7 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
ts->update_context( this, idx, true );
|
||||
|
||||
/* read the image */
|
||||
string img_file = board_list[idx * 2];
|
||||
String img_file = board_list[idx * 2];
|
||||
Mat gray = imread( folder + img_file, 0);
|
||||
|
||||
if( gray.empty() )
|
||||
@@ -227,7 +227,7 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
return;
|
||||
}
|
||||
|
||||
string _filename = folder + (string)board_list[idx * 2 + 1];
|
||||
String _filename = folder + (String)board_list[idx * 2 + 1];
|
||||
bool doesContatinChessboard;
|
||||
Mat expected;
|
||||
{
|
||||
@@ -244,7 +244,7 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
switch( pattern )
|
||||
{
|
||||
case CHESSBOARD:
|
||||
result = findChessboardCorners(gray, pattern_size, v, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE);
|
||||
result = findChessboardCorners(gray, pattern_size, v, CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_NORMALIZE_IMAGE);
|
||||
break;
|
||||
case CIRCLES_GRID:
|
||||
result = findCirclesGrid(gray, pattern_size, v);
|
||||
@@ -459,7 +459,7 @@ bool CV_ChessboardDetectorTest::checkByGenerator()
|
||||
vector<Point>& cnt = cnts[0];
|
||||
cnt.push_back(cg[ 0]); cnt.push_back(cg[0+2]);
|
||||
cnt.push_back(cg[7+0]); cnt.push_back(cg[7+2]);
|
||||
cv::drawContours(cb, cnts, -1, Scalar::all(128), CV_FILLED);
|
||||
cv::drawContours(cb, cnts, -1, Scalar::all(128), FILLED);
|
||||
|
||||
found = findChessboardCorners(cb, cbg.cornersSize(), corners_found);
|
||||
if (found)
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "test_chessboardgenerator.hpp"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
class CV_ChessboardDetectorTimingTest : public cvtest::BaseTest
|
||||
{
|
||||
@@ -66,7 +68,7 @@ void CV_ChessboardDetectorTimingTest::run( int start_from )
|
||||
CvMat* _v = 0;
|
||||
CvPoint2D32f* v;
|
||||
|
||||
IplImage* img = 0;
|
||||
IplImage img;
|
||||
IplImage* gray = 0;
|
||||
IplImage* thresh = 0;
|
||||
|
||||
@@ -105,9 +107,10 @@ void CV_ChessboardDetectorTimingTest::run( int start_from )
|
||||
/* read the image */
|
||||
sprintf( filename, "%s%s", filepath, imgname );
|
||||
|
||||
img = cvLoadImage( filename );
|
||||
cv::Mat img2 = cv::imread( filename );
|
||||
img = img2;
|
||||
|
||||
if( !img )
|
||||
if( img2.empty() )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "one of chessboard images can't be read: %s\n", filename );
|
||||
if( max_idx == 1 )
|
||||
@@ -120,9 +123,9 @@ void CV_ChessboardDetectorTimingTest::run( int start_from )
|
||||
|
||||
ts->printf(cvtest::TS::LOG, "%s: chessboard %d:\n", imgname, is_chessboard);
|
||||
|
||||
gray = cvCreateImage( cvSize( img->width, img->height ), IPL_DEPTH_8U, 1 );
|
||||
thresh = cvCreateImage( cvSize( img->width, img->height ), IPL_DEPTH_8U, 1 );
|
||||
cvCvtColor( img, gray, CV_BGR2GRAY );
|
||||
gray = cvCreateImage( cvSize( img.width, img.height ), IPL_DEPTH_8U, 1 );
|
||||
thresh = cvCreateImage( cvSize( img.width, img.height ), IPL_DEPTH_8U, 1 );
|
||||
cvCvtColor( &img, gray, CV_BGR2GRAY );
|
||||
|
||||
|
||||
count0 = pattern_size.width*pattern_size.height;
|
||||
@@ -164,7 +167,6 @@ void CV_ChessboardDetectorTimingTest::run( int start_from )
|
||||
find_chessboard_time*1e-6, find_chessboard_time/num_pixels);
|
||||
|
||||
cvReleaseMat( &_v );
|
||||
cvReleaseImage( &img );
|
||||
cvReleaseImage( &gray );
|
||||
cvReleaseImage( &thresh );
|
||||
progress = update_progress( progress, idx-1, max_idx, 0 );
|
||||
@@ -175,7 +177,6 @@ _exit_:
|
||||
/* release occupied memory */
|
||||
cvReleaseMat( &_v );
|
||||
cvReleaseFileStorage( &fs );
|
||||
cvReleaseImage( &img );
|
||||
cvReleaseImage( &gray );
|
||||
cvReleaseImage( &thresh );
|
||||
|
||||
|
||||
@@ -212,4 +212,3 @@ protected:
|
||||
};
|
||||
|
||||
TEST(Calib3d_ComposeRT, accuracy) { CV_composeRT_Test test; test.safe_run(); }
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include <limits>
|
||||
#include "test_chessboardgenerator.hpp"
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
@@ -1079,7 +1080,7 @@ protected:
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
|
||||
double sampson_error(const double* f, double x1, double y1, double x2, double y2);
|
||||
double sampson_error(const double* f, double x1, double y1, double x2, double y2);
|
||||
|
||||
int method;
|
||||
int img_size;
|
||||
@@ -1145,9 +1146,8 @@ void CV_EssentialMatTest::get_test_array_types_and_sizes( int /*test_case_idx*/,
|
||||
int pt_count = MAX(5, cvRound(exp(pt_count_exp)));
|
||||
|
||||
dims = cvtest::randInt(rng) % 2 + 2;
|
||||
dims = 2;
|
||||
dims = 2;
|
||||
method = CV_LMEDS << (cvtest::randInt(rng) % 2);
|
||||
|
||||
|
||||
types[INPUT][0] = CV_MAKETYPE(pt_depth, 1);
|
||||
|
||||
@@ -1192,11 +1192,11 @@ void CV_EssentialMatTest::get_test_array_types_and_sizes( int /*test_case_idx*/,
|
||||
sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(3,1);
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;
|
||||
sizes[OUTPUT][1] = sizes[REF_OUTPUT][1] = cvSize(pt_count,1);
|
||||
types[OUTPUT][1] = types[REF_OUTPUT][1] = CV_8UC1;
|
||||
types[OUTPUT][1] = types[REF_OUTPUT][1] = CV_8UC1;
|
||||
sizes[OUTPUT][2] = sizes[REF_OUTPUT][2] = cvSize(1,1);
|
||||
types[OUTPUT][2] = types[REF_OUTPUT][2] = CV_64FC1;
|
||||
sizes[OUTPUT][3] = sizes[REF_OUTPUT][3] = cvSize(1,1);
|
||||
types[OUTPUT][3] = types[REF_OUTPUT][3] = CV_8UC1;
|
||||
types[OUTPUT][3] = types[REF_OUTPUT][3] = CV_8UC1;
|
||||
|
||||
}
|
||||
|
||||
@@ -1289,46 +1289,46 @@ int CV_EssentialMatTest::prepare_test_case( int test_case_idx )
|
||||
void CV_EssentialMatTest::run_func()
|
||||
{
|
||||
Mat _input0(test_mat[INPUT][0]), _input1(test_mat[INPUT][1]);
|
||||
Mat K(test_mat[INPUT][4]);
|
||||
double focal(K.at<double>(0, 0));
|
||||
cv::Point2d pp(K.at<double>(0, 2), K.at<double>(1, 2));
|
||||
Mat K(test_mat[INPUT][4]);
|
||||
double focal(K.at<double>(0, 0));
|
||||
cv::Point2d pp(K.at<double>(0, 2), K.at<double>(1, 2));
|
||||
|
||||
RNG& rng = ts->get_rng();
|
||||
Mat E, mask1(test_mat[TEMP][1]);
|
||||
E = cv::findEssentialMat( _input0, _input1, focal, pp, method, 0.99, MAX(sigma*3, 0.0001), mask1 );
|
||||
if (E.rows > 3)
|
||||
E = cv::findEssentialMat( _input0, _input1, focal, pp, method, 0.99, MAX(sigma*3, 0.0001), mask1 );
|
||||
if (E.rows > 3)
|
||||
{
|
||||
int count = E.rows / 3;
|
||||
int row = (cvtest::randInt(rng) % count) * 3;
|
||||
E = E.rowRange(row, row + 3) * 1.0;
|
||||
int count = E.rows / 3;
|
||||
int row = (cvtest::randInt(rng) % count) * 3;
|
||||
E = E.rowRange(row, row + 3) * 1.0;
|
||||
}
|
||||
|
||||
E.copyTo(test_mat[TEMP][0]);
|
||||
E.copyTo(test_mat[TEMP][0]);
|
||||
|
||||
Mat R, t, mask2;
|
||||
recoverPose( E, _input0, _input1, R, t, focal, pp, mask2 );
|
||||
R.copyTo(test_mat[TEMP][2]);
|
||||
t.copyTo(test_mat[TEMP][3]);
|
||||
mask2.copyTo(test_mat[TEMP][4]);
|
||||
Mat R, t, mask2;
|
||||
recoverPose( E, _input0, _input1, R, t, focal, pp, mask2 );
|
||||
R.copyTo(test_mat[TEMP][2]);
|
||||
t.copyTo(test_mat[TEMP][3]);
|
||||
mask2.copyTo(test_mat[TEMP][4]);
|
||||
}
|
||||
|
||||
double CV_EssentialMatTest::sampson_error(const double * f, double x1, double y1, double x2, double y2)
|
||||
{
|
||||
double Fx1[3] = {
|
||||
f[0] * x1 + f[1] * y1 + f[2],
|
||||
f[3] * x1 + f[4] * y1 + f[5],
|
||||
f[0] * x1 + f[1] * y1 + f[2],
|
||||
f[3] * x1 + f[4] * y1 + f[5],
|
||||
f[6] * x1 + f[7] * y1 + f[8]
|
||||
};
|
||||
};
|
||||
double Ftx2[3] = {
|
||||
f[0] * x2 + f[3] * y2 + f[6],
|
||||
f[1] * x2 + f[4] * y2 + f[7],
|
||||
f[0] * x2 + f[3] * y2 + f[6],
|
||||
f[1] * x2 + f[4] * y2 + f[7],
|
||||
f[2] * x2 + f[5] * y2 + f[8]
|
||||
};
|
||||
double x2tFx1 = Fx1[0] * x2 + Fx1[1] * y2 + Fx1[2];
|
||||
};
|
||||
double x2tFx1 = Fx1[0] * x2 + Fx1[1] * y2 + Fx1[2];
|
||||
|
||||
double error = x2tFx1 * x2tFx1 / (Fx1[0] * Fx1[0] + Fx1[1] * Fx1[1] + Ftx2[0] * Ftx2[0] + Ftx2[1] * Ftx2[1]);
|
||||
error = sqrt(error);
|
||||
return error;
|
||||
double error = x2tFx1 * x2tFx1 / (Fx1[0] * Fx1[0] + Fx1[1] * Fx1[1] + Ftx2[0] * Ftx2[0] + Ftx2[1] * Ftx2[1]);
|
||||
error = sqrt(error);
|
||||
return error;
|
||||
|
||||
}
|
||||
|
||||
@@ -1338,7 +1338,7 @@ void CV_EssentialMatTest::prepare_to_validation( int test_case_idx )
|
||||
const Mat& A = test_mat[INPUT][4];
|
||||
double f0[9], f[9], e[9];
|
||||
Mat F0(3, 3, CV_64FC1, f0), F(3, 3, CV_64F, f);
|
||||
Mat E(3, 3, CV_64F, e);
|
||||
Mat E(3, 3, CV_64F, e);
|
||||
|
||||
Mat invA, R=Rt0.colRange(0, 3), T1, T2;
|
||||
|
||||
@@ -1362,7 +1362,7 @@ void CV_EssentialMatTest::prepare_to_validation( int test_case_idx )
|
||||
uchar* mtfm2 = test_mat[OUTPUT][1].data;
|
||||
double* e_prop1 = (double*)test_mat[REF_OUTPUT][0].data;
|
||||
double* e_prop2 = (double*)test_mat[OUTPUT][0].data;
|
||||
Mat E_prop2 = Mat(3, 1, CV_64F, e_prop2);
|
||||
Mat E_prop2 = Mat(3, 1, CV_64F, e_prop2);
|
||||
|
||||
int i, pt_count = test_mat[INPUT][2].cols;
|
||||
Mat p1( 1, pt_count, CV_64FC2 );
|
||||
@@ -1381,8 +1381,8 @@ void CV_EssentialMatTest::prepare_to_validation( int test_case_idx )
|
||||
double y1 = p1.at<Point2d>(i).y;
|
||||
double x2 = p2.at<Point2d>(i).x;
|
||||
double y2 = p2.at<Point2d>(i).y;
|
||||
// double t0 = sampson_error(f0, x1, y1, x2, y2);
|
||||
// double t = sampson_error(f, x1, y1, x2, y2);
|
||||
// double t0 = sampson_error(f0, x1, y1, x2, y2);
|
||||
// double t = sampson_error(f, x1, y1, x2, y2);
|
||||
double n1 = 1./sqrt(x1*x1 + y1*y1 + 1);
|
||||
double n2 = 1./sqrt(x2*x2 + y2*y2 + 1);
|
||||
double t0 = fabs(f0[0]*x2*x1 + f0[1]*x2*y1 + f0[2]*x2 +
|
||||
@@ -1394,7 +1394,7 @@ void CV_EssentialMatTest::prepare_to_validation( int test_case_idx )
|
||||
mtfm1[i] = 1;
|
||||
mtfm2[i] = !status[i] || t0 > err_level || t < err_level;
|
||||
}
|
||||
|
||||
|
||||
e_prop1[0] = sqrt(0.5);
|
||||
e_prop1[1] = sqrt(0.5);
|
||||
e_prop1[2] = 0;
|
||||
@@ -1402,26 +1402,26 @@ void CV_EssentialMatTest::prepare_to_validation( int test_case_idx )
|
||||
e_prop2[0] = 0;
|
||||
e_prop2[1] = 0;
|
||||
e_prop2[2] = 0;
|
||||
SVD::compute(E, E_prop2);
|
||||
SVD::compute(E, E_prop2);
|
||||
|
||||
|
||||
|
||||
double* pose_prop1 = (double*)test_mat[REF_OUTPUT][2].data;
|
||||
double* pose_prop2 = (double*)test_mat[OUTPUT][2].data;
|
||||
double terr1 = norm(Rt0.col(3) / norm(Rt0.col(3)) + test_mat[TEMP][3]);
|
||||
double terr2 = norm(Rt0.col(3) / norm(Rt0.col(3)) - test_mat[TEMP][3]);
|
||||
Mat rvec;
|
||||
Rodrigues(Rt0.colRange(0, 3), rvec);
|
||||
pose_prop1[0] = 0;
|
||||
// No check for CV_LMeDS on translation. Since it
|
||||
// involves with some degraded problem, when data is exact inliers.
|
||||
pose_prop2[0] = method == CV_LMEDS || pt_count == 5 ? 0 : MIN(terr1, terr2);
|
||||
double* pose_prop1 = (double*)test_mat[REF_OUTPUT][2].data;
|
||||
double* pose_prop2 = (double*)test_mat[OUTPUT][2].data;
|
||||
double terr1 = norm(Rt0.col(3) / norm(Rt0.col(3)) + test_mat[TEMP][3]);
|
||||
double terr2 = norm(Rt0.col(3) / norm(Rt0.col(3)) - test_mat[TEMP][3]);
|
||||
Mat rvec;
|
||||
Rodrigues(Rt0.colRange(0, 3), rvec);
|
||||
pose_prop1[0] = 0;
|
||||
// No check for CV_LMeDS on translation. Since it
|
||||
// involves with some degraded problem, when data is exact inliers.
|
||||
pose_prop2[0] = method == CV_LMEDS || pt_count == 5 ? 0 : MIN(terr1, terr2);
|
||||
|
||||
|
||||
// int inliers_count = countNonZero(test_mat[TEMP][1]);
|
||||
// int good_count = countNonZero(test_mat[TEMP][4]);
|
||||
test_mat[OUTPUT][3] = true; //good_count >= inliers_count / 2;
|
||||
test_mat[REF_OUTPUT][3] = true;
|
||||
// int inliers_count = countNonZero(test_mat[TEMP][1]);
|
||||
// int good_count = countNonZero(test_mat[TEMP][4]);
|
||||
test_mat[OUTPUT][3] = true; //good_count >= inliers_count / 2;
|
||||
test_mat[REF_OUTPUT][3] = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
#define METHODS_COUNT 3
|
||||
|
||||
int NORM_TYPE[COUNT_NORM_TYPES] = {cv::NORM_L1, cv::NORM_L2, cv::NORM_INF};
|
||||
int METHOD[METHODS_COUNT] = {0, CV_RANSAC, CV_LMEDS};
|
||||
int METHOD[METHODS_COUNT] = {0, cv::RANSAC, cv::LMEDS};
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
@@ -309,7 +309,7 @@ void CV_HomographyTest::run(int)
|
||||
switch (method)
|
||||
{
|
||||
case 0:
|
||||
case CV_LMEDS:
|
||||
case LMEDS:
|
||||
{
|
||||
Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, method),
|
||||
cv::findHomography(src_mat_2f, dst_vec, method),
|
||||
@@ -339,14 +339,14 @@ void CV_HomographyTest::run(int)
|
||||
|
||||
continue;
|
||||
}
|
||||
case CV_RANSAC:
|
||||
case RANSAC:
|
||||
{
|
||||
cv::Mat mask [4]; double diff;
|
||||
|
||||
Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, CV_RANSAC, reproj_threshold, mask[0]),
|
||||
cv::findHomography(src_mat_2f, dst_vec, CV_RANSAC, reproj_threshold, mask[1]),
|
||||
cv::findHomography(src_vec, dst_mat_2f, CV_RANSAC, reproj_threshold, mask[2]),
|
||||
cv::findHomography(src_vec, dst_vec, CV_RANSAC, reproj_threshold, mask[3]) };
|
||||
Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, RANSAC, reproj_threshold, mask[0]),
|
||||
cv::findHomography(src_mat_2f, dst_vec, RANSAC, reproj_threshold, mask[1]),
|
||||
cv::findHomography(src_vec, dst_mat_2f, RANSAC, reproj_threshold, mask[2]),
|
||||
cv::findHomography(src_vec, dst_vec, RANSAC, reproj_threshold, mask[3]) };
|
||||
|
||||
for (int j = 0; j < 4; ++j)
|
||||
{
|
||||
@@ -411,7 +411,7 @@ void CV_HomographyTest::run(int)
|
||||
switch (method)
|
||||
{
|
||||
case 0:
|
||||
case CV_LMEDS:
|
||||
case LMEDS:
|
||||
{
|
||||
Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f),
|
||||
cv::findHomography(src_mat_2f, dst_vec),
|
||||
@@ -466,14 +466,14 @@ void CV_HomographyTest::run(int)
|
||||
|
||||
continue;
|
||||
}
|
||||
case CV_RANSAC:
|
||||
case RANSAC:
|
||||
{
|
||||
cv::Mat mask_res [4];
|
||||
|
||||
Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, CV_RANSAC, reproj_threshold, mask_res[0]),
|
||||
cv::findHomography(src_mat_2f, dst_vec, CV_RANSAC, reproj_threshold, mask_res[1]),
|
||||
cv::findHomography(src_vec, dst_mat_2f, CV_RANSAC, reproj_threshold, mask_res[2]),
|
||||
cv::findHomography(src_vec, dst_vec, CV_RANSAC, reproj_threshold, mask_res[3]) };
|
||||
Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, RANSAC, reproj_threshold, mask_res[0]),
|
||||
cv::findHomography(src_mat_2f, dst_vec, RANSAC, reproj_threshold, mask_res[1]),
|
||||
cv::findHomography(src_vec, dst_mat_2f, RANSAC, reproj_threshold, mask_res[2]),
|
||||
cv::findHomography(src_vec, dst_vec, RANSAC, reproj_threshold, mask_res[3]) };
|
||||
|
||||
for (int j = 0; j < 4; ++j)
|
||||
{
|
||||
|
||||
@@ -229,4 +229,3 @@ void CV_ModelEstimator2_Test::run_func()
|
||||
TEST(Calib3d_ModelEstimator2, accuracy) { CV_ModelEstimator2_Test test; test.safe_run(); }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
@@ -189,13 +190,13 @@ void CV_POSITTest::run( int start_from )
|
||||
rotation->data.fl, translation->data.fl );
|
||||
cvReleasePOSITObject( &object );
|
||||
|
||||
//Mat _rotation = cvarrToMat(rotation), _true_rotation = cvarrToMat(true_rotation);
|
||||
//Mat _translation = cvarrToMat(translation), _true_translation = cvarrToMat(true_translation);
|
||||
code = cvtest::cmpEps2( ts, rotation, true_rotation, flEpsilon, false, "rotation matrix" );
|
||||
Mat _rotation = cvarrToMat(rotation), _true_rotation = cvarrToMat(true_rotation);
|
||||
Mat _translation = cvarrToMat(translation), _true_translation = cvarrToMat(true_translation);
|
||||
code = cvtest::cmpEps2( ts, _rotation, _true_rotation, flEpsilon, false, "rotation matrix" );
|
||||
if( code < 0 )
|
||||
break;
|
||||
|
||||
code = cvtest::cmpEps2( ts, translation, true_translation, flEpsilon, false, "translation vector" );
|
||||
code = cvtest::cmpEps2( ts, _translation, _true_translation, flEpsilon, false, "translation vector" );
|
||||
if( code < 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include "test_precomp.hpp"
|
||||
@@ -9,12 +9,11 @@
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
#include <iostream>
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/calib3d.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace cvtest
|
||||
{
|
||||
@@ -22,4 +21,3 @@ namespace cvtest
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/calib3d/calib3d_c.h"
|
||||
#include <string>
|
||||
#include <limits>
|
||||
|
||||
@@ -172,4 +173,3 @@ protected:
|
||||
};
|
||||
|
||||
TEST(Calib3d_ReprojectImageTo3D, accuracy) { CV_ReprojectImageTo3DTest test; test.safe_run(); }
|
||||
|
||||
|
||||
@@ -41,7 +41,10 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
#include "tbb/task_scheduler_init.h"
|
||||
#endif
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
@@ -51,9 +54,9 @@ class CV_solvePnPRansac_Test : public cvtest::BaseTest
|
||||
public:
|
||||
CV_solvePnPRansac_Test()
|
||||
{
|
||||
eps[CV_ITERATIVE] = 1.0e-2;
|
||||
eps[CV_EPNP] = 1.0e-2;
|
||||
eps[CV_P3P] = 1.0e-2;
|
||||
eps[ITERATIVE] = 1.0e-2;
|
||||
eps[EPNP] = 1.0e-2;
|
||||
eps[P3P] = 1.0e-2;
|
||||
totalTestsCount = 10;
|
||||
}
|
||||
~CV_solvePnPRansac_Test() {}
|
||||
@@ -190,9 +193,9 @@ class CV_solvePnP_Test : public CV_solvePnPRansac_Test
|
||||
public:
|
||||
CV_solvePnP_Test()
|
||||
{
|
||||
eps[CV_ITERATIVE] = 1.0e-6;
|
||||
eps[CV_EPNP] = 1.0e-6;
|
||||
eps[CV_P3P] = 1.0e-4;
|
||||
eps[ITERATIVE] = 1.0e-6;
|
||||
eps[EPNP] = 1.0e-6;
|
||||
eps[P3P] = 1.0e-4;
|
||||
totalTestsCount = 1000;
|
||||
}
|
||||
|
||||
@@ -236,7 +239,7 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Calib3d_SolvePnPRansac, accuracy) { CV_solvePnPRansac_Test test; test.safe_run(); }
|
||||
TEST(DISABLED_Calib3d_SolvePnPRansac, accuracy) { CV_solvePnPRansac_Test test; test.safe_run(); }
|
||||
TEST(Calib3d_SolvePnP, accuracy) { CV_solvePnP_Test test; test.safe_run(); }
|
||||
|
||||
|
||||
@@ -273,7 +276,7 @@ TEST(DISABLED_Calib3d_SolvePnPRansac, concurrency)
|
||||
{
|
||||
// limit concurrency to get determenistic result
|
||||
cv::theRNG().state = 20121010;
|
||||
cv::Ptr<tbb::task_scheduler_init> one_thread = new tbb::task_scheduler_init(1);
|
||||
tbb::task_scheduler_init one_thread(1);
|
||||
solvePnPRansac(object, image, camera_mat, dist_coef, rvec1, tvec1);
|
||||
}
|
||||
|
||||
@@ -292,7 +295,7 @@ TEST(DISABLED_Calib3d_SolvePnPRansac, concurrency)
|
||||
{
|
||||
// single thread again
|
||||
cv::theRNG().state = 20121010;
|
||||
cv::Ptr<tbb::task_scheduler_init> one_thread = new tbb::task_scheduler_init(1);
|
||||
tbb::task_scheduler_init one_thread(1);
|
||||
solvePnPRansac(object, image, camera_mat, dist_coef, rvec2, tvec2);
|
||||
}
|
||||
|
||||
@@ -303,4 +306,4 @@ TEST(DISABLED_Calib3d_SolvePnPRansac, concurrency)
|
||||
EXPECT_LT(tnorm, 1e-6);
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "test_precomp.hpp"
|
||||
#include <limits>
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -74,12 +75,12 @@ void computeTextureBasedMasks( const Mat& _img, Mat* texturelessMask, Mat* textu
|
||||
if( !texturelessMask && !texturedMask )
|
||||
return;
|
||||
if( _img.empty() )
|
||||
CV_Error( CV_StsBadArg, "img is empty" );
|
||||
CV_Error( Error::StsBadArg, "img is empty" );
|
||||
|
||||
Mat img = _img;
|
||||
if( _img.channels() > 1)
|
||||
{
|
||||
Mat tmp; cvtColor( _img, tmp, CV_BGR2GRAY ); img = tmp;
|
||||
Mat tmp; cvtColor( _img, tmp, COLOR_BGR2GRAY ); img = tmp;
|
||||
}
|
||||
Mat dxI; Sobel( img, dxI, CV_32FC1, 1, 0, 3 );
|
||||
Mat dxI2; pow( dxI / 8.f/*normalize*/, 2, dxI2 );
|
||||
@@ -94,21 +95,21 @@ void computeTextureBasedMasks( const Mat& _img, Mat* texturelessMask, Mat* textu
|
||||
void checkTypeAndSizeOfDisp( const Mat& dispMap, const Size* sz )
|
||||
{
|
||||
if( dispMap.empty() )
|
||||
CV_Error( CV_StsBadArg, "dispMap is empty" );
|
||||
CV_Error( Error::StsBadArg, "dispMap is empty" );
|
||||
if( dispMap.type() != CV_32FC1 )
|
||||
CV_Error( CV_StsBadArg, "dispMap must have CV_32FC1 type" );
|
||||
CV_Error( Error::StsBadArg, "dispMap must have CV_32FC1 type" );
|
||||
if( sz && (dispMap.rows != sz->height || dispMap.cols != sz->width) )
|
||||
CV_Error( CV_StsBadArg, "dispMap has incorrect size" );
|
||||
CV_Error( Error::StsBadArg, "dispMap has incorrect size" );
|
||||
}
|
||||
|
||||
void checkTypeAndSizeOfMask( const Mat& mask, Size sz )
|
||||
{
|
||||
if( mask.empty() )
|
||||
CV_Error( CV_StsBadArg, "mask is empty" );
|
||||
CV_Error( Error::StsBadArg, "mask is empty" );
|
||||
if( mask.type() != CV_8UC1 )
|
||||
CV_Error( CV_StsBadArg, "mask must have CV_8UC1 type" );
|
||||
CV_Error( Error::StsBadArg, "mask must have CV_8UC1 type" );
|
||||
if( mask.rows != sz.height || mask.cols != sz.width )
|
||||
CV_Error( CV_StsBadArg, "mask has incorrect size" );
|
||||
CV_Error( Error::StsBadArg, "mask has incorrect size" );
|
||||
}
|
||||
|
||||
void checkDispMapsAndUnknDispMasks( const Mat& leftDispMap, const Mat& rightDispMap,
|
||||
@@ -142,7 +143,7 @@ void checkDispMapsAndUnknDispMasks( const Mat& leftDispMap, const Mat& rightDisp
|
||||
minMaxLoc( rightDispMap, &rightMinVal, 0, 0, 0, ~rightUnknDispMask );
|
||||
}
|
||||
if( leftMinVal < 0 || rightMinVal < 0)
|
||||
CV_Error( CV_StsBadArg, "known disparity values must be positive" );
|
||||
CV_Error( Error::StsBadArg, "known disparity values must be positive" );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -162,7 +163,7 @@ void computeOcclusionBasedMasks( const Mat& leftDisp, const Mat& _rightDisp,
|
||||
if( _rightDisp.empty() )
|
||||
{
|
||||
if( !rightUnknDispMask.empty() )
|
||||
CV_Error( CV_StsBadArg, "rightUnknDispMask must be empty if _rightDisp is empty" );
|
||||
CV_Error( Error::StsBadArg, "rightUnknDispMask must be empty if _rightDisp is empty" );
|
||||
rightDisp.create(leftDisp.size(), CV_32FC1);
|
||||
rightDisp.setTo(Scalar::all(0) );
|
||||
for( int leftY = 0; leftY < leftDisp.rows; leftY++ )
|
||||
@@ -229,9 +230,9 @@ void computeDepthDiscontMask( const Mat& disp, Mat& depthDiscontMask, const Mat&
|
||||
float dispGap = EVAL_DISP_GAP, int discontWidth = EVAL_DISCONT_WIDTH )
|
||||
{
|
||||
if( disp.empty() )
|
||||
CV_Error( CV_StsBadArg, "disp is empty" );
|
||||
CV_Error( Error::StsBadArg, "disp is empty" );
|
||||
if( disp.type() != CV_32FC1 )
|
||||
CV_Error( CV_StsBadArg, "disp must have CV_32FC1 type" );
|
||||
CV_Error( Error::StsBadArg, "disp must have CV_32FC1 type" );
|
||||
if( !unknDispMask.empty() )
|
||||
checkTypeAndSizeOfMask( unknDispMask, disp.size() );
|
||||
|
||||
@@ -459,14 +460,29 @@ void CV_StereoMatchingTest::run(int)
|
||||
continue;
|
||||
}
|
||||
int dispScaleFactor = datasetsParams[datasetName].dispScaleFactor;
|
||||
Mat tmp; trueLeftDisp.convertTo( tmp, CV_32FC1, 1.f/dispScaleFactor ); trueLeftDisp = tmp; tmp.release();
|
||||
Mat tmp;
|
||||
|
||||
trueLeftDisp.convertTo( tmp, CV_32FC1, 1.f/dispScaleFactor );
|
||||
trueLeftDisp = tmp;
|
||||
tmp.release();
|
||||
|
||||
if( !trueRightDisp.empty() )
|
||||
trueRightDisp.convertTo( tmp, CV_32FC1, 1.f/dispScaleFactor ); trueRightDisp = tmp; tmp.release();
|
||||
{
|
||||
trueRightDisp.convertTo( tmp, CV_32FC1, 1.f/dispScaleFactor );
|
||||
trueRightDisp = tmp;
|
||||
tmp.release();
|
||||
}
|
||||
|
||||
Mat leftDisp, rightDisp;
|
||||
int ignBorder = max(runStereoMatchingAlgorithm(leftImg, rightImg, leftDisp, rightDisp, ci), EVAL_IGNORE_BORDER);
|
||||
leftDisp.convertTo( tmp, CV_32FC1 ); leftDisp = tmp; tmp.release();
|
||||
rightDisp.convertTo( tmp, CV_32FC1 ); rightDisp = tmp; tmp.release();
|
||||
|
||||
leftDisp.convertTo( tmp, CV_32FC1 );
|
||||
leftDisp = tmp;
|
||||
tmp.release();
|
||||
|
||||
rightDisp.convertTo( tmp, CV_32FC1 );
|
||||
rightDisp = tmp;
|
||||
tmp.release();
|
||||
|
||||
int tempCode = processStereoMatchingResults( resFS, ci, isWrite,
|
||||
leftImg, rightImg, trueLeftDisp, trueRightDisp, leftDisp, rightDisp, QualityEvalParams(ignBorder));
|
||||
@@ -530,7 +546,8 @@ int CV_StereoMatchingTest::processStereoMatchingResults( FileStorage& fs, int ca
|
||||
// rightDisp is not used in current test virsion
|
||||
int code = cvtest::TS::OK;
|
||||
assert( fs.isOpened() );
|
||||
assert( trueLeftDisp.type() == CV_32FC1 && trueRightDisp.type() == CV_32FC1 );
|
||||
assert( trueLeftDisp.type() == CV_32FC1 );
|
||||
assert( trueRightDisp.empty() || trueRightDisp.type() == CV_32FC1 );
|
||||
assert( leftDisp.type() == CV_32FC1 && rightDisp.type() == CV_32FC1 );
|
||||
|
||||
// get masks for unknown ground truth disparity values
|
||||
@@ -554,9 +571,9 @@ int CV_StereoMatchingTest::processStereoMatchingResults( FileStorage& fs, int ca
|
||||
if( isWrite )
|
||||
{
|
||||
fs << caseNames[caseIdx] << "{";
|
||||
cvWriteComment( fs.fs, RMS_STR.c_str(), 0 );
|
||||
//cvWriteComment( fs.fs, RMS_STR.c_str(), 0 );
|
||||
writeErrors( RMS_STR, rmss, &fs );
|
||||
cvWriteComment( fs.fs, BAD_PXLS_FRACTION_STR.c_str(), 0 );
|
||||
//cvWriteComment( fs.fs, BAD_PXLS_FRACTION_STR.c_str(), 0 );
|
||||
writeErrors( BAD_PXLS_FRACTION_STR, badPxlsFractions, &fs );
|
||||
fs << "}"; // datasetName
|
||||
}
|
||||
@@ -593,10 +610,10 @@ int CV_StereoMatchingTest::readDatasetsParams( FileStorage& fs )
|
||||
assert(fn.isSeq());
|
||||
for( int i = 0; i < (int)fn.size(); i+=3 )
|
||||
{
|
||||
string _name = fn[i];
|
||||
String _name = fn[i];
|
||||
DatasetParams params;
|
||||
string sf = fn[i+1]; params.dispScaleFactor = atoi(sf.c_str());
|
||||
string uv = fn[i+2]; params.dispUnknVal = atoi(uv.c_str());
|
||||
String sf = fn[i+1]; params.dispScaleFactor = atoi(sf.c_str());
|
||||
String uv = fn[i+2]; params.dispUnknVal = atoi(uv.c_str());
|
||||
datasetsParams[_name] = params;
|
||||
}
|
||||
return cvtest::TS::OK;
|
||||
@@ -680,10 +697,10 @@ protected:
|
||||
assert(fn.isSeq());
|
||||
for( int i = 0; i < (int)fn.size(); i+=4 )
|
||||
{
|
||||
string caseName = fn[i], datasetName = fn[i+1];
|
||||
String caseName = fn[i], datasetName = fn[i+1];
|
||||
RunParams params;
|
||||
string ndisp = fn[i+2]; params.ndisp = atoi(ndisp.c_str());
|
||||
string winSize = fn[i+3]; params.winSize = atoi(winSize.c_str());
|
||||
String ndisp = fn[i+2]; params.ndisp = atoi(ndisp.c_str());
|
||||
String winSize = fn[i+3]; params.winSize = atoi(winSize.c_str());
|
||||
caseNames.push_back( caseName );
|
||||
caseDatasets.push_back( datasetName );
|
||||
caseRunParams.push_back( params );
|
||||
@@ -697,11 +714,13 @@ protected:
|
||||
RunParams params = caseRunParams[caseIdx];
|
||||
assert( params.ndisp%16 == 0 );
|
||||
assert( _leftImg.type() == CV_8UC3 && _rightImg.type() == CV_8UC3 );
|
||||
Mat leftImg; cvtColor( _leftImg, leftImg, CV_BGR2GRAY );
|
||||
Mat rightImg; cvtColor( _rightImg, rightImg, CV_BGR2GRAY );
|
||||
Mat leftImg; cvtColor( _leftImg, leftImg, COLOR_BGR2GRAY );
|
||||
Mat rightImg; cvtColor( _rightImg, rightImg, COLOR_BGR2GRAY );
|
||||
|
||||
StereoBM bm( StereoBM::BASIC_PRESET, params.ndisp, params.winSize );
|
||||
bm( leftImg, rightImg, leftDisp, CV_32F );
|
||||
Ptr<StereoBM> bm = createStereoBM( params.ndisp, params.winSize );
|
||||
Mat tempDisp;
|
||||
bm->compute( leftImg, rightImg, tempDisp );
|
||||
tempDisp.convertTo(leftDisp, CV_32F, 1./StereoMatcher::DISP_SCALE);
|
||||
return params.winSize/2;
|
||||
}
|
||||
};
|
||||
@@ -734,11 +753,11 @@ protected:
|
||||
assert(fn.isSeq());
|
||||
for( int i = 0; i < (int)fn.size(); i+=5 )
|
||||
{
|
||||
string caseName = fn[i], datasetName = fn[i+1];
|
||||
String caseName = fn[i], datasetName = fn[i+1];
|
||||
RunParams params;
|
||||
string ndisp = fn[i+2]; params.ndisp = atoi(ndisp.c_str());
|
||||
string winSize = fn[i+3]; params.winSize = atoi(winSize.c_str());
|
||||
string fullDP = fn[i+4]; params.fullDP = atoi(fullDP.c_str()) == 0 ? false : true;
|
||||
String ndisp = fn[i+2]; params.ndisp = atoi(ndisp.c_str());
|
||||
String winSize = fn[i+3]; params.winSize = atoi(winSize.c_str());
|
||||
String fullDP = fn[i+4]; params.fullDP = atoi(fullDP.c_str()) == 0 ? false : true;
|
||||
caseNames.push_back( caseName );
|
||||
caseDatasets.push_back( datasetName );
|
||||
caseRunParams.push_back( params );
|
||||
@@ -751,10 +770,13 @@ protected:
|
||||
{
|
||||
RunParams params = caseRunParams[caseIdx];
|
||||
assert( params.ndisp%16 == 0 );
|
||||
StereoSGBM sgbm( 0, params.ndisp, params.winSize, 10*params.winSize*params.winSize, 40*params.winSize*params.winSize,
|
||||
1, 63, 10, 100, 32, params.fullDP );
|
||||
sgbm( leftImg, rightImg, leftDisp );
|
||||
assert( leftDisp.type() == CV_16SC1 );
|
||||
Ptr<StereoSGBM> sgbm = createStereoSGBM( 0, params.ndisp, params.winSize,
|
||||
10*params.winSize*params.winSize,
|
||||
40*params.winSize*params.winSize,
|
||||
1, 63, 10, 100, 32, params.fullDP ?
|
||||
StereoSGBM::MODE_HH : StereoSGBM::MODE_SGBM );
|
||||
sgbm->compute( leftImg, rightImg, leftDisp );
|
||||
CV_Assert( leftDisp.type() == CV_16SC1 );
|
||||
leftDisp/=16;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
@@ -491,7 +492,7 @@ void CV_UndistortPointsTest::distortPoints(const CvMat* _src, CvMat* _dst, const
|
||||
__P = cvCreateMat(3,4,CV_64F);
|
||||
if (matP)
|
||||
{
|
||||
cvTsConvert(matP,__P);
|
||||
cvtest::convert(cvarrToMat(matP), cvarrToMat(__P), -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -500,7 +501,7 @@ void CV_UndistortPointsTest::distortPoints(const CvMat* _src, CvMat* _dst, const
|
||||
__P->data.db[4] = 1;
|
||||
__P->data.db[8] = 1;
|
||||
}
|
||||
CvMat* __R = cvCreateMat(3,3,CV_64F);;
|
||||
CvMat* __R = cvCreateMat(3,3,CV_64F);
|
||||
if (matR)
|
||||
{
|
||||
cvCopy(matR,__R);
|
||||
@@ -847,16 +848,16 @@ void CV_InitUndistortRectifyMapTest::prepare_to_validation(int/* test_case_idx*/
|
||||
CvMat _input3 = test_mat[INPUT][3];
|
||||
CvMat _input4 = test_mat[INPUT][4];
|
||||
|
||||
cvTsConvert(&_input1,&_camera);
|
||||
cvTsConvert(&_input2,&_distort);
|
||||
cvTsConvert(&_input3,&_rot);
|
||||
cvTsConvert(&_input4,&_new_cam);
|
||||
cvtest::convert(cvarrToMat(&_input1), cvarrToMat(&_camera), -1);
|
||||
cvtest::convert(cvarrToMat(&_input2), cvarrToMat(&_distort), -1);
|
||||
cvtest::convert(cvarrToMat(&_input3), cvarrToMat(&_rot), -1);
|
||||
cvtest::convert(cvarrToMat(&_input4), cvarrToMat(&_new_cam), -1);
|
||||
|
||||
//Applying precalculated undistort rectify map
|
||||
if (!useCPlus)
|
||||
{
|
||||
mapx = cv::Mat(_mapx);
|
||||
mapy = cv::Mat(_mapy);
|
||||
mapx = cv::cvarrToMat(_mapx);
|
||||
mapy = cv::cvarrToMat(_mapy);
|
||||
}
|
||||
cv::Mat map1,map2;
|
||||
cv::convertMaps(mapx,mapy,map1,map2,CV_32FC1);
|
||||
@@ -876,7 +877,7 @@ void CV_InitUndistortRectifyMapTest::prepare_to_validation(int/* test_case_idx*/
|
||||
zero_distortion ? 0 : &_distort, zero_R ? 0 : &_rot, zero_new_cam ? &_camera : &_new_cam);
|
||||
//cvTsDistortPoints(&_points,&ref_points,&_camera,&_distort,&_rot,&_new_cam);
|
||||
CvMat dst = test_mat[REF_OUTPUT][0];
|
||||
cvTsConvert(&ref_points,&dst);
|
||||
cvtest::convert(cvarrToMat(&ref_points), cvarrToMat(&dst), -1);
|
||||
|
||||
cvtest::copy(test_mat[INPUT][0],test_mat[OUTPUT][0]);
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
|
||||
class CV_UndistortPointsBadArgTest : public cvtest::BadArgTest
|
||||
{
|
||||
@@ -243,27 +244,27 @@ void CV_UndistortPointsBadArgTest::run(int)
|
||||
//C++ tests
|
||||
useCPlus = true;
|
||||
|
||||
camera_mat = cv::Mat(&_camera_mat_orig);
|
||||
distortion_coeffs = cv::Mat(&_distortion_coeffs_orig);
|
||||
P = cv::Mat(&_P_orig);
|
||||
R = cv::Mat(&_R_orig);
|
||||
src_points = cv::Mat(&_src_points_orig);
|
||||
camera_mat = cv::cvarrToMat(&_camera_mat_orig);
|
||||
distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
|
||||
P = cv::cvarrToMat(&_P_orig);
|
||||
R = cv::cvarrToMat(&_R_orig);
|
||||
src_points = cv::cvarrToMat(&_src_points_orig);
|
||||
|
||||
temp = cvCreateMat(2,2,CV_32FC2);
|
||||
src_points = cv::Mat(temp);
|
||||
src_points = cv::cvarrToMat(temp);
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
|
||||
src_points = cv::Mat(&_src_points_orig);
|
||||
src_points = cv::cvarrToMat(&_src_points_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(1,4,CV_64FC2);
|
||||
src_points = cv::Mat(temp);
|
||||
src_points = cv::cvarrToMat(temp);
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid input data matrix type" );
|
||||
src_points = cv::Mat(&_src_points_orig);
|
||||
src_points = cv::cvarrToMat(&_src_points_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
src_points = cv::Mat();
|
||||
errcount += run_test_case( CV_StsAssert, "Input data matrix is not continuous" );
|
||||
src_points = cv::Mat(&_src_points_orig);
|
||||
src_points = cv::cvarrToMat(&_src_points_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
|
||||
@@ -360,12 +361,12 @@ void CV_InitUndistortRectifyMapBadArgTest::run(int)
|
||||
//C++ tests
|
||||
useCPlus = true;
|
||||
|
||||
camera_mat = cv::Mat(&_camera_mat_orig);
|
||||
distortion_coeffs = cv::Mat(&_distortion_coeffs_orig);
|
||||
new_camera_mat = cv::Mat(&_new_camera_mat_orig);
|
||||
R = cv::Mat(&_R_orig);
|
||||
mapx = cv::Mat(&_mapx_orig);
|
||||
mapy = cv::Mat(&_mapy_orig);
|
||||
camera_mat = cv::cvarrToMat(&_camera_mat_orig);
|
||||
distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
|
||||
new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
|
||||
R = cv::cvarrToMat(&_R_orig);
|
||||
mapx = cv::cvarrToMat(&_mapx_orig);
|
||||
mapy = cv::cvarrToMat(&_mapy_orig);
|
||||
|
||||
|
||||
mat_type = CV_64F;
|
||||
@@ -373,21 +374,21 @@ void CV_InitUndistortRectifyMapBadArgTest::run(int)
|
||||
mat_type = mat_type_orig;
|
||||
|
||||
temp = cvCreateMat(3,2,CV_32FC1);
|
||||
camera_mat = cv::Mat(temp);
|
||||
camera_mat = cv::cvarrToMat(temp);
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
|
||||
camera_mat = cv::Mat(&_camera_mat_orig);
|
||||
camera_mat = cv::cvarrToMat(&_camera_mat_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(4,3,CV_32FC1);
|
||||
R = cv::Mat(temp);
|
||||
R = cv::cvarrToMat(temp);
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
|
||||
R = cv::Mat(&_R_orig);
|
||||
R = cv::cvarrToMat(&_R_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(6,1,CV_32FC1);
|
||||
distortion_coeffs = cv::Mat(temp);
|
||||
distortion_coeffs = cv::cvarrToMat(temp);
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
|
||||
distortion_coeffs = cv::Mat(&_distortion_coeffs_orig);
|
||||
distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
//------------
|
||||
@@ -499,11 +500,11 @@ void CV_UndistortBadArgTest::run(int)
|
||||
//C++ tests
|
||||
useCPlus = true;
|
||||
|
||||
camera_mat = cv::Mat(&_camera_mat_orig);
|
||||
distortion_coeffs = cv::Mat(&_distortion_coeffs_orig);
|
||||
new_camera_mat = cv::Mat(&_new_camera_mat_orig);
|
||||
src = cv::Mat(&_src_orig);
|
||||
dst = cv::Mat(&_dst_orig);
|
||||
camera_mat = cv::cvarrToMat(&_camera_mat_orig);
|
||||
distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
|
||||
new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
|
||||
src = cv::cvarrToMat(&_src_orig);
|
||||
dst = cv::cvarrToMat(&_dst_orig);
|
||||
|
||||
//------------
|
||||
delete[] arr_src;
|
||||
|
||||
@@ -94,4 +94,4 @@ void CV_UndistortTest::run(int /* start_from */)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Calib3d_Undistort, accuracy) { CV_UndistortTest test; test.safe_run(); }
|
||||
TEST(Calib3d_Undistort, accuracy) { CV_UndistortTest test; test.safe_run(); }
|
||||
|
||||
@@ -1 +1 @@
|
||||
ocv_define_module(contrib opencv_imgproc opencv_calib3d opencv_features2d opencv_ml opencv_video opencv_objdetect OPTIONAL opencv_highgui)
|
||||
ocv_define_module(contrib opencv_imgproc opencv_calib3d opencv_ml opencv_video opencv_objdetect OPTIONAL opencv_highgui)
|
||||
|
||||
@@ -9,5 +9,4 @@ The module contains some recently added functionality that has not been stabiliz
|
||||
|
||||
stereo
|
||||
FaceRecognizer Documentation <facerec/index>
|
||||
Retina Documentation <retina/index>
|
||||
openfabmap
|
||||
|
||||
@@ -51,9 +51,9 @@ In OpenCV 2.4 you only need :ocv:func:`applyColorMap` to apply a colormap on a g
|
||||
int main(int argc, const char *argv[]) {
|
||||
// Get the path to the image, if it was given
|
||||
// if no arguments were given.
|
||||
string filename;
|
||||
String filename;
|
||||
if (argc > 1) {
|
||||
filename = string(argv[1]);
|
||||
filename = String(argv[1]);
|
||||
}
|
||||
// The following lines show how to apply a colormap on a given image
|
||||
// and show it with cv::imshow example with an image. An exception is
|
||||
|
||||
@@ -3,6 +3,12 @@ FaceRecognizer
|
||||
|
||||
.. highlight:: cpp
|
||||
|
||||
.. Sample code::
|
||||
|
||||
* An example using the FaceRecognizer class can be found at opencv_source_code/samples/cpp/facerec_demo.cpp
|
||||
|
||||
* (Python) An example using the FaceRecognizer class can be found at opencv_source_code/samples/python2/facerec_demo.py
|
||||
|
||||
FaceRecognizer
|
||||
--------------
|
||||
|
||||
@@ -30,10 +36,10 @@ a unified access to all face recongition algorithms in OpenCV. ::
|
||||
virtual void predict(InputArray src, int &label, double &confidence) const = 0;
|
||||
|
||||
// Serializes this object to a given filename.
|
||||
virtual void save(const string& filename) const;
|
||||
virtual void save(const String& filename) const;
|
||||
|
||||
// Deserializes this object from a given filename.
|
||||
virtual void load(const string& filename);
|
||||
virtual void load(const String& filename);
|
||||
|
||||
// Serializes this object to a given cv::FileStorage.
|
||||
virtual void save(FileStorage& fs) const = 0;
|
||||
@@ -52,7 +58,7 @@ I'll go a bit more into detail explaining :ocv:class:`FaceRecognizer`, because i
|
||||
|
||||
* So called “virtual constructor”. That is, each Algorithm derivative is registered at program start and you can get the list of registered algorithms and create instance of a particular algorithm by its name (see :ocv:func:`Algorithm::create`). If you plan to add your own algorithms, it is good practice to add a unique prefix to your algorithms to distinguish them from other algorithms.
|
||||
|
||||
* Setting/Retrieving algorithm parameters by name. If you used video capturing functionality from OpenCV highgui module, you are probably familar with :ocv:cfunc:`cvSetCaptureProperty`, :ocv:cfunc:`cvGetCaptureProperty`, :ocv:func:`VideoCapture::set` and :ocv:func:`VideoCapture::get`. :ocv:class:`Algorithm` provides similar method where instead of integer id's you specify the parameter names as text strings. See :ocv:func:`Algorithm::set` and :ocv:func:`Algorithm::get` for details.
|
||||
* Setting/Retrieving algorithm parameters by name. If you used video capturing functionality from OpenCV highgui module, you are probably familar with :ocv:cfunc:`cvSetCaptureProperty`, :ocv:cfunc:`cvGetCaptureProperty`, :ocv:func:`VideoCapture::set` and :ocv:func:`VideoCapture::get`. :ocv:class:`Algorithm` provides similar method where instead of integer id's you specify the parameter names as text Strings. See :ocv:func:`Algorithm::set` and :ocv:func:`Algorithm::get` for details.
|
||||
|
||||
* Reading and writing parameters from/to XML or YAML files. Every Algorithm derivative can store all its parameters and then read them back. There is no need to re-implement it each time.
|
||||
|
||||
@@ -64,6 +70,8 @@ Moreover every :ocv:class:`FaceRecognizer` supports the:
|
||||
|
||||
* **Loading/Saving** the model state from/to a given XML or YAML.
|
||||
|
||||
.. note:: When using the FaceRecognizer interface in combination with Python, please stick to Python 2. Some underlying scripts like create_csv will not work in other versions, like Python 3.
|
||||
|
||||
Setting the Thresholds
|
||||
+++++++++++++++++++++++
|
||||
|
||||
@@ -113,7 +121,7 @@ Since every :ocv:class:`FaceRecognizer` is a :ocv:class:`Algorithm`, you can use
|
||||
// Create a FaceRecognizer:
|
||||
Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
|
||||
// And here's how to get its name:
|
||||
std::string name = model->name();
|
||||
String name = model->name();
|
||||
|
||||
|
||||
FaceRecognizer::train
|
||||
@@ -251,7 +259,7 @@ FaceRecognizer::save
|
||||
|
||||
Saves a :ocv:class:`FaceRecognizer` and its model state.
|
||||
|
||||
.. ocv:function:: void FaceRecognizer::save(const string& filename) const
|
||||
.. ocv:function:: void FaceRecognizer::save(const String& filename) const
|
||||
|
||||
Saves this model to a given filename, either as XML or YAML.
|
||||
|
||||
@@ -265,7 +273,7 @@ Saves a :ocv:class:`FaceRecognizer` and its model state.
|
||||
|
||||
|
||||
Every :ocv:class:`FaceRecognizer` overwrites ``FaceRecognizer::save(FileStorage& fs)``
|
||||
to save the internal model state. ``FaceRecognizer::save(const string& filename)`` saves
|
||||
to save the internal model state. ``FaceRecognizer::save(const String& filename)`` saves
|
||||
the state of a model to the given filename.
|
||||
|
||||
The suffix ``const`` means that prediction does not affect the internal model
|
||||
@@ -276,13 +284,13 @@ FaceRecognizer::load
|
||||
|
||||
Loads a :ocv:class:`FaceRecognizer` and its model state.
|
||||
|
||||
.. ocv:function:: void FaceRecognizer::load( const string& filename )
|
||||
.. ocv:function:: void FaceRecognizer::load( const String& filename )
|
||||
.. ocv:function:: void FaceRecognizer::load( const FileStorage& fs ) = 0
|
||||
|
||||
Loads a persisted model and state from a given XML or YAML file . Every
|
||||
:ocv:class:`FaceRecognizer` has to overwrite ``FaceRecognizer::load(FileStorage& fs)``
|
||||
to enable loading the model state. ``FaceRecognizer::load(FileStorage& fs)`` in
|
||||
turn gets called by ``FaceRecognizer::load(const string& filename)``, to ease
|
||||
turn gets called by ``FaceRecognizer::load(const String& filename)``, to ease
|
||||
saving a model.
|
||||
|
||||
createEigenFaceRecognizer
|
||||
|
||||
@@ -7,7 +7,7 @@ Face Recognition with OpenCV
|
||||
Introduction
|
||||
============
|
||||
|
||||
`OpenCV (Open Source Computer Vision) <http://opencv.willowgarage.com>`_ is a popular computer vision library started by `Intel <http://www.intel.com>`_ in 1999. The cross-platform library sets its focus on real-time image processing and includes patent-free implementations of the latest computer vision algorithms. In 2008 `Willow Garage <http://www.willowgarage.com>`_ took over support and OpenCV 2.3.1 now comes with a programming interface to C, C++, `Python <http://www.python.org>`_ and `Android <http://www.android.com>`_. OpenCV is released under a BSD license so it is used in academic projects and commercial products alike.
|
||||
`OpenCV (Open Source Computer Vision) <http://opencv.org>`_ is a popular computer vision library started by `Intel <http://www.intel.com>`_ in 1999. The cross-platform library sets its focus on real-time image processing and includes patent-free implementations of the latest computer vision algorithms. In 2008 `Willow Garage <http://www.willowgarage.com>`_ took over support and OpenCV 2.3.1 now comes with a programming interface to C, C++, `Python <http://www.python.org>`_ and `Android <http://www.android.com>`_. OpenCV is released under a BSD license so it is used in academic projects and commercial products alike.
|
||||
|
||||
OpenCV 2.4 now comes with the very new :ocv:class:`FaceRecognizer` class for face recognition, so you can start experimenting with face recognition right away. This document is the guide I've wished for, when I was working myself into face recognition. It shows you how to perform face recognition with :ocv:class:`FaceRecognizer` in OpenCV (with full source code listings) and gives you an introduction into the algorithms behind. I'll also show how to create the visualizations you can find in many publications, because a lot of people asked for.
|
||||
|
||||
@@ -626,5 +626,3 @@ CSV for the AT&T Facedatabase
|
||||
.. literalinclude:: etc/at.txt
|
||||
:language: none
|
||||
:linenos:
|
||||
|
||||
|
||||
|
||||
@@ -30,4 +30,3 @@ Indices and tables
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ project(facerec_cpp_samples)
|
||||
#SET(OpenCV_DIR /path/to/your/opencv/installation)
|
||||
|
||||
# packages
|
||||
find_package(OpenCV REQUIRED) # http://opencv.willowgarage.com
|
||||
find_package(OpenCV REQUIRED) # http://opencv.org
|
||||
|
||||
# probably you should loop through the sample files here
|
||||
add_executable(facerec_demo facerec_demo.cpp)
|
||||
@@ -23,4 +23,3 @@ target_link_libraries(facerec_fisherfaces opencv_contrib opencv_core opencv_imgp
|
||||
|
||||
add_executable(facerec_lbph facerec_lbph.cpp)
|
||||
target_link_libraries(facerec_lbph opencv_contrib opencv_core opencv_imgproc opencv_highgui)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import os.path
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user