1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Prof. Dr. Rudolf Haussmann
2015-03-07 13:10:41 +01:00
211 changed files with 9070 additions and 707 deletions
@@ -1047,14 +1047,14 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
return;
}
CameraHandler* handler=*ppcameraHandler;
// delayed resolution setup to exclude errors during other parameres setup on the fly
// without camera restart
if (((*ppcameraHandler)->width != 0) && ((*ppcameraHandler)->height != 0))
(*ppcameraHandler)->params->setPreviewSize((*ppcameraHandler)->width, (*ppcameraHandler)->height);
if ((handler->width != 0) && (handler->height != 0))
handler->params->setPreviewSize(handler->width, handler->height);
#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) || defined(ANDROID_r4_4_0)
CameraHandler* handler=*ppcameraHandler;
handler->camera->stopPreview();
handler->camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
@@ -1066,7 +1066,7 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
return;
}
handler->camera->setParameters((*ppcameraHandler)->params->flatten());
handler->camera->setParameters(handler->params->flatten());
status_t bufferStatus;
# if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3)
@@ -1107,7 +1107,7 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
LOGD("Preview started successfully");
}
#else
CameraHandler* previousCameraHandler=*ppcameraHandler;
CameraHandler* previousCameraHandler=handler;
CameraCallback cameraCallback=previousCameraHandler->cameraCallback;
void* userData=previousCameraHandler->userData;
int cameraId=previousCameraHandler->cameraId;
@@ -1117,7 +1117,7 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
LOGD("CameraHandler::applyProperties(): after previousCameraHandler->closeCameraConnect");
LOGD("CameraHandler::applyProperties(): before initCameraConnect");
CameraHandler* handler=initCameraConnect(cameraCallback, cameraId, userData, (*ppcameraHandler)->params);
handler=initCameraConnect(cameraCallback, cameraId, userData, handler->params);
LOGD("CameraHandler::applyProperties(): after initCameraConnect, handler=0x%x", (int)handler);
if (handler == NULL) {
LOGE("ERROR in applyProperties --- cannot reinit camera");
+5 -6
View File
@@ -3,11 +3,10 @@ ocv_add_module(core PRIVATE_REQUIRED ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}"
OPTIONAL opencv_cudev
WRAP java python)
if(HAVE_WINRT_CX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
endif()
if(HAVE_WINRT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS /Gm- /AI\"${WINDOWS_SDK_PATH}/References/CommonConfiguration/Neutral\" /AI\"${VISUAL_STUDIO_PATH}/vcpackages\"")
set(extra_libs "")
if(WINRT AND CMAKE_SYSTEM_NAME MATCHES WindowsStore AND CMAKE_SYSTEM_VERSION MATCHES "8.0")
list(APPEND extra_libs ole32.lib)
endif()
if(HAVE_CUDA)
@@ -24,7 +23,7 @@ ocv_glob_module_sources(SOURCES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version
HEADERS ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail})
ocv_module_include_directories(${the_module} ${ZLIB_INCLUDE_DIRS})
ocv_create_module()
ocv_create_module(${extra_libs})
ocv_add_accuracy_tests()
ocv_add_perf_tests()
@@ -184,6 +184,7 @@ public:
// After fix restore code in arithm.cpp: ocl_compare()
inline bool isAMD() const { return vendorID() == VENDOR_AMD; }
inline bool isIntel() const { return vendorID() == VENDOR_INTEL; }
inline bool isNVidia() const { return vendorID() == VENDOR_NVIDIA; }
int maxClockFrequency() const;
int maxComputeUnits() const;
+5 -5
View File
@@ -56,14 +56,14 @@ namespace
struct DIR
{
#ifdef HAVE_WINRT
#ifdef WINRT
WIN32_FIND_DATAW data;
#else
WIN32_FIND_DATA data;
#endif
HANDLE handle;
dirent ent;
#ifdef HAVE_WINRT
#ifdef WINRT
DIR() { }
~DIR()
{
@@ -77,7 +77,7 @@ namespace
{
DIR* dir = new DIR;
dir->ent.d_name = 0;
#ifdef HAVE_WINRT
#ifdef WINRT
cv::String full_path = cv::String(path) + "\\*";
wchar_t wfull_path[MAX_PATH];
size_t copied = mbstowcs(wfull_path, full_path.c_str(), MAX_PATH);
@@ -99,7 +99,7 @@ namespace
dirent* readdir(DIR* dir)
{
#ifdef HAVE_WINRT
#ifdef WINRT
if (dir->ent.d_name != 0)
{
if (::FindNextFileW(dir->handle, &dir->data) != TRUE)
@@ -147,7 +147,7 @@ static bool isDir(const cv::String& path, DIR* dir)
else
{
WIN32_FILE_ATTRIBUTE_DATA all_attrs;
#ifdef HAVE_WINRT
#ifdef WINRT
wchar_t wpath[MAX_PATH];
size_t copied = mbstowcs(wpath, path.c_str(), MAX_PATH);
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
+1 -2
View File
@@ -180,10 +180,9 @@ public:
const int K = centers.rows;
const int dims = centers.cols;
const float *sample;
for( int i = begin; i<end; ++i)
{
sample = data.ptr<float>(i);
const float *sample = data.ptr<float>(i);
int k_best = 0;
double min_dist = DBL_MAX;
+4 -1
View File
@@ -205,9 +205,12 @@ public:
void deallocate(UMatData* u) const
{
if(!u)
return;
CV_Assert(u->urefcount >= 0);
CV_Assert(u->refcount >= 0);
if(u && u->refcount == 0)
if(u->refcount == 0)
{
if( !(u->flags & UMatData::USER_ALLOCATED) )
{
+11 -3
View File
@@ -64,7 +64,15 @@
// TODO Move to some common place
static bool getBoolParameter(const char* name, bool defaultValue)
{
/*
* If your system doesn't support getenv(), define NO_GETENV to disable
* this feature.
*/
#ifdef NO_GETENV
const char* envValue = NULL;
#else
const char* envValue = getenv(name);
#endif
if (envValue == NULL)
{
return defaultValue;
@@ -85,7 +93,7 @@ static bool getBoolParameter(const char* name, bool defaultValue)
// TODO Move to some common place
static size_t getConfigurationParameterForSize(const char* name, size_t defaultValue)
{
#ifdef HAVE_WINRT
#ifdef NO_GETENV
const char* envValue = NULL;
#else
const char* envValue = getenv(name);
@@ -728,7 +736,7 @@ static void* initOpenCLAndLoad(const char* funcname)
static HMODULE handle = 0;
if (!handle)
{
#ifndef HAVE_WINRT
#ifndef WINRT
if(!initialized)
{
handle = LoadLibraryA("OpenCL.dll");
@@ -2231,7 +2239,7 @@ static bool parseOpenCLDeviceConfiguration(const std::string& configurationStr,
return true;
}
#ifdef HAVE_WINRT
#ifdef WINRT
static cl_device_id selectOpenCLDevice()
{
return NULL;
+2 -2
View File
@@ -69,7 +69,7 @@
#define HAVE_GCD
#endif
#if defined _MSC_VER && _MSC_VER >= 1600
#if defined _MSC_VER && _MSC_VER >= 1600 && !defined(WINRT)
#define HAVE_CONCURRENCY
#endif
@@ -458,7 +458,7 @@ int cv::getNumberOfCPUs(void)
{
#if defined WIN32 || defined _WIN32
SYSTEM_INFO sysinfo;
#if defined(_M_ARM) || defined(_M_X64) || defined(HAVE_WINRT)
#if defined(_M_ARM) || defined(_M_X64) || defined(WINRT)
GetNativeSystemInfo( &sysinfo );
#else
GetSystemInfo( &sysinfo );
+17
View File
@@ -2114,6 +2114,12 @@ static bool ocl_minMaxIdx( InputArray _src, double* minVal, double* maxVal, int*
int ddepth = -1, bool absValues = false, InputArray _src2 = noArray(), double * maxVal2 = NULL)
{
const ocl::Device & dev = ocl::Device::getDefault();
#ifdef ANDROID
if (dev.isNVidia())
return false;
#endif
bool doubleSupport = dev.doubleFPConfig() > 0, haveMask = !_mask.empty(),
haveSrc2 = _src2.kind() != _InputArray::NONE;
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type),
@@ -2885,6 +2891,12 @@ static NormDiffFunc getNormDiffFunc(int normType, int depth)
static bool ocl_norm( InputArray _src, int normType, InputArray _mask, double & result )
{
const ocl::Device & d = ocl::Device::getDefault();
#ifdef ANDROID
if (d.isNVidia())
return false;
#endif
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
bool doubleSupport = d.doubleFPConfig() > 0,
haveMask = _mask.kind() != _InputArray::NONE;
@@ -3250,6 +3262,11 @@ namespace cv {
static bool ocl_norm( InputArray _src1, InputArray _src2, int normType, InputArray _mask, double & result )
{
#ifdef ANDROID
if (ocl::Device::getDefault().isNVidia())
return false;
#endif
Scalar sc1, sc2;
int type = _src1.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
bool relative = (normType & NORM_RELATIVE) != 0;
+12 -16
View File
@@ -109,7 +109,7 @@
#endif
#endif
#ifdef HAVE_WINRT
#ifdef WINRT
#include <wrl/client.h>
#ifndef __cplusplus_winrt
#include <windows.storage.h>
@@ -159,7 +159,7 @@ std::wstring GetTempFileNameWinRT(std::wstring prefix)
UINT(g.Data4[2]), UINT(g.Data4[3]), UINT(g.Data4[4]),
UINT(g.Data4[5]), UINT(g.Data4[6]), UINT(g.Data4[7]));
return prefix + std::wstring(guidStr);
return prefix.append(std::wstring(guidStr));
}
#endif
@@ -327,9 +327,9 @@ struct HWFeatures
if (cpufile >= 0)
{
Elf32_auxv_t auxv;
const size_t size_auxv_t = sizeof(Elf32_auxv_t);
const size_t size_auxv_t = sizeof(auxv);
while ((size_t)read(cpufile, &auxv, sizeof(Elf32_auxv_t)) == size_auxv_t)
while ((size_t)read(cpufile, &auxv, size_auxv_t) == size_auxv_t)
{
if (auxv.a_type == AT_HWCAP)
{
@@ -542,24 +542,20 @@ String format( const char* fmt, ... )
String tempfile( const char* suffix )
{
String fname;
#ifndef HAVE_WINRT
#ifndef WINRT
const char *temp_dir = getenv("OPENCV_TEMP_PATH");
#endif
#if defined WIN32 || defined _WIN32
#ifdef HAVE_WINRT
#ifdef WINRT
RoInitialize(RO_INIT_MULTITHREADED);
std::wstring temp_dir = L"";
const wchar_t* opencv_temp_dir = GetTempPathWinRT().c_str();
if (opencv_temp_dir)
temp_dir = std::wstring(opencv_temp_dir);
std::wstring temp_dir = GetTempPathWinRT();
std::wstring temp_file;
temp_file = GetTempFileNameWinRT(L"ocv");
std::wstring temp_file = GetTempFileNameWinRT(L"ocv");
if (temp_file.empty())
return String();
temp_file = temp_dir + std::wstring(L"\\") + temp_file;
temp_file = temp_dir.append(std::wstring(L"\\")).append(temp_file);
DeleteFileW(temp_file.c_str());
char aname[MAX_PATH];
@@ -955,7 +951,7 @@ public:
#pragma warning(disable:4505) // unreferenced local function has been removed
#endif
#ifdef HAVE_WINRT
#ifdef WINRT
// using C++11 thread attribute for local thread data
static __declspec( thread ) TLSStorage* g_tlsdata = NULL;
@@ -1006,10 +1002,10 @@ public:
}
return d;
}
#endif //HAVE_WINRT
#endif //WINRT
#if defined CVAPI_EXPORTS && defined WIN32 && !defined WINCE
#ifdef HAVE_WINRT
#ifdef WINRT
#pragma warning(disable:4447) // Disable warning 'main' signature found without threading model
#endif
+4
View File
@@ -331,7 +331,11 @@ OCL_TEST_P(Mul, Mat_Scale)
OCL_OFF(cv::multiply(src1_roi, src2_roi, dst1_roi, val[0]));
OCL_ON(cv::multiply(usrc1_roi, usrc2_roi, udst1_roi, val[0]));
#ifdef ANDROID
Near(udst1_roi.depth() >= CV_32F ? 2e-1 : 1);
#else
Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1);
#endif
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
if(IOS OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
if(IOS OR WINRT OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
ocv_module_disable(cudaarithm)
endif()
+1 -1
View File
@@ -1,4 +1,4 @@
if(IOS OR APPLE OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
if(IOS OR APPLE OR WINRT OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
ocv_module_disable(cudacodec)
endif()
+1 -1
View File
@@ -1,4 +1,4 @@
if(IOS OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
if(IOS OR WINRT OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
ocv_module_disable(cudafeatures2d)
endif()
+1 -1
View File
@@ -1,4 +1,4 @@
if(IOS OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
if(IOS OR WINRT OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
ocv_module_disable(cudafilters)
endif()
+1 -1
View File
@@ -1,4 +1,4 @@
if(IOS OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
if(IOS OR WINRT OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
ocv_module_disable(cudaimgproc)
endif()
+1 -1
View File
@@ -1,4 +1,4 @@
if(IOS OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
if(IOS OR WINRT OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
ocv_module_disable(cudaoptflow)
endif()
+1 -1
View File
@@ -1,4 +1,4 @@
if(IOS OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
if(IOS OR WINRT OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
ocv_module_disable(cudastereo)
endif()
+1 -1
View File
@@ -1,4 +1,4 @@
if(IOS OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
if(IOS OR WINRT OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
ocv_module_disable(cudawarping)
endif()
+7 -1
View File
@@ -61,6 +61,12 @@ OCL_PERF_TEST_P(ORBFixture, ORB_Full, ORB_IMAGES)
string filename = getDataPath(GetParam());
Mat mframe = imread(filename, IMREAD_GRAYSCALE);
double desc_eps = 1e-6;
#ifdef ANDROID
if (cv::ocl::Device::getDefault().isNVidia())
desc_eps = 2;
#endif
if (mframe.empty())
FAIL() << "Unable to load source image " << filename;
@@ -77,7 +83,7 @@ OCL_PERF_TEST_P(ORBFixture, ORB_Full, ORB_IMAGES)
::perf::sort(points, descriptors);
SANITY_CHECK_KEYPOINTS(points, 1e-5);
SANITY_CHECK(descriptors);
SANITY_CHECK(descriptors, desc_eps);
}
} // ocl
+8 -1
View File
@@ -172,7 +172,14 @@ namespace cv
cvtColor(image, img, COLOR_BGR2GRAY);
Mat img1_32;
img.convertTo(img1_32, CV_32F, 1.0 / 255.0, 0);
if ( img.depth() == CV_32F )
img1_32 = img;
else if ( img.depth() == CV_8U )
img.convertTo(img1_32, CV_32F, 1.0 / 255.0, 0);
else if ( img.depth() == CV_16U )
img.convertTo(img1_32, CV_32F, 1.0 / 65535.0, 0);
CV_Assert( ! img1_32.empty() );
AKAZEOptions options;
options.descriptor = descriptor;
+6 -1
View File
@@ -1,3 +1,7 @@
if (WINRT)
ocv_module_disable(highgui)
endif()
set(the_description "High-level GUI and Media I/O")
ocv_add_module(highgui opencv_imgproc opencv_imgcodecs opencv_videoio OPTIONAL opencv_androidcamera WRAP python)
@@ -7,7 +11,8 @@ ocv_add_module(highgui opencv_imgproc opencv_imgcodecs opencv_videoio OPTIONAL o
# Jose Luis Blanco, 2008
# ----------------------------------------------------------------------------
if(HAVE_WINRT_CX)
# Compilation with /ZW is not allowed for *.c files
if(HAVE_WINRT_CX AND NOT WINRT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
endif()
+5 -1
View File
@@ -1,3 +1,7 @@
if(WINRT)
ocv_module_disable(imgcodecs)
endif()
set(the_description "Image codecs")
ocv_add_module(imgcodecs opencv_imgproc WRAP java python)
@@ -9,7 +13,7 @@ ocv_add_module(imgcodecs opencv_imgproc WRAP java python)
ocv_clear_vars(GRFMT_LIBS)
if(HAVE_WINRT_CX)
if(HAVE_WINRT_CX AND NOT WINRT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
endif()
+16 -1
View File
@@ -1221,7 +1221,22 @@ CV_EXPORTS_W void boxFilter( InputArray src, OutputArray dst, int ddepth,
bool normalize = true,
int borderType = BORDER_DEFAULT );
/** @todo document
/** @brief Calculates the normalized sum of squares of the pixel values overlapping the filter.
For every pixel \f$ (x, y) \f$ in the source image, the function calculates the sum of squares of those neighboring
pixel values which overlap the filter placed over the pixel \f$ (x, y) \f$.
The unnormalized square box filter can be useful in computing local image statistics such as the the local
variance and standard deviation around the neighborhood of a pixel.
@param _src input image
@param _dst output image of the same size and type as _src
@param ddepth the output image depth (-1 to use src.depth())
@param ksize kernel size
@param anchor kernel anchor point. The default value of Point(-1, -1) denotes that the anchor is at the kernel
center.
@param normalize flag, specifying whether the kernel is to be normalized by it's area or not.
@param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
@sa boxFilter
*/
CV_EXPORTS_W void sqrBoxFilter( InputArray _src, OutputArray _dst, int ddepth,
+411 -1
View File
@@ -230,7 +230,352 @@ static bool ocl_Canny(InputArray _src, OutputArray _dst, float low_thresh, float
#endif
}
#ifdef HAVE_TBB
// Queue with peaks that will processed serially.
static tbb::concurrent_queue<uchar*> borderPeaks;
class tbbCanny
{
public:
tbbCanny(const Range _boundaries, const Mat& _src, uchar* _map, int _low,
int _high, int _aperture_size, bool _L2gradient)
: boundaries(_boundaries), src(_src), map(_map), low(_low), high(_high),
aperture_size(_aperture_size), L2gradient(_L2gradient)
{}
// This parallel version of Canny algorithm splits the src image in threadsNumber horizontal slices.
// The first row of each slice contains the last row of the previous slice and
// the last row of each slice contains the first row of the next slice
// so that each slice is independent and no mutexes are required.
void operator()() const
{
#if CV_SSE2
bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2);
#endif
const int type = src.type(), cn = CV_MAT_CN(type);
Mat dx, dy;
ptrdiff_t mapstep = src.cols + 2;
// In sobel transform we calculate ksize2 extra lines for the first and last rows of each slice
// because IPPDerivSobel expects only isolated ROIs, in contrast with the opencv version which
// uses the pixels outside of the ROI to form a border.
uchar ksize2 = aperture_size / 2;
if (boundaries.start == 0 && boundaries.end == src.rows)
{
Mat tempdx(boundaries.end - boundaries.start + 2, src.cols, CV_16SC(cn));
Mat tempdy(boundaries.end - boundaries.start + 2, src.cols, CV_16SC(cn));
memset(tempdx.ptr<short>(0), 0, cn * src.cols*sizeof(short));
memset(tempdy.ptr<short>(0), 0, cn * src.cols*sizeof(short));
memset(tempdx.ptr<short>(tempdx.rows - 1), 0, cn * src.cols*sizeof(short));
memset(tempdy.ptr<short>(tempdy.rows - 1), 0, cn * src.cols*sizeof(short));
Sobel(src, tempdx.rowRange(1, tempdx.rows - 1), CV_16S, 1, 0, aperture_size, 1, 0, BORDER_REPLICATE);
Sobel(src, tempdy.rowRange(1, tempdy.rows - 1), CV_16S, 0, 1, aperture_size, 1, 0, BORDER_REPLICATE);
dx = tempdx;
dy = tempdy;
}
else if (boundaries.start == 0)
{
Mat tempdx(boundaries.end - boundaries.start + 2 + ksize2, src.cols, CV_16SC(cn));
Mat tempdy(boundaries.end - boundaries.start + 2 + ksize2, src.cols, CV_16SC(cn));
memset(tempdx.ptr<short>(0), 0, cn * src.cols*sizeof(short));
memset(tempdy.ptr<short>(0), 0, cn * src.cols*sizeof(short));
Sobel(src.rowRange(boundaries.start, boundaries.end + 1 + ksize2), tempdx.rowRange(1, tempdx.rows),
CV_16S, 1, 0, aperture_size, 1, 0, BORDER_REPLICATE);
Sobel(src.rowRange(boundaries.start, boundaries.end + 1 + ksize2), tempdy.rowRange(1, tempdy.rows),
CV_16S, 0, 1, aperture_size, 1, 0, BORDER_REPLICATE);
dx = tempdx.rowRange(0, tempdx.rows - ksize2);
dy = tempdy.rowRange(0, tempdy.rows - ksize2);
}
else if (boundaries.end == src.rows)
{
Mat tempdx(boundaries.end - boundaries.start + 2 + ksize2, src.cols, CV_16SC(cn));
Mat tempdy(boundaries.end - boundaries.start + 2 + ksize2, src.cols, CV_16SC(cn));
memset(tempdx.ptr<short>(tempdx.rows - 1), 0, cn * src.cols*sizeof(short));
memset(tempdy.ptr<short>(tempdy.rows - 1), 0, cn * src.cols*sizeof(short));
Sobel(src.rowRange(boundaries.start - 1 - ksize2, boundaries.end), tempdx.rowRange(0, tempdx.rows - 1),
CV_16S, 1, 0, aperture_size, 1, 0, BORDER_REPLICATE);
Sobel(src.rowRange(boundaries.start - 1 - ksize2, boundaries.end), tempdy.rowRange(0, tempdy.rows - 1),
CV_16S, 0, 1, aperture_size, 1, 0, BORDER_REPLICATE);
dx = tempdx.rowRange(ksize2, tempdx.rows);
dy = tempdy.rowRange(ksize2, tempdy.rows);
}
else
{
Mat tempdx(boundaries.end - boundaries.start + 2 + 2*ksize2, src.cols, CV_16SC(cn));
Mat tempdy(boundaries.end - boundaries.start + 2 + 2*ksize2, src.cols, CV_16SC(cn));
Sobel(src.rowRange(boundaries.start - 1 - ksize2, boundaries.end + 1 + ksize2), tempdx,
CV_16S, 1, 0, aperture_size, 1, 0, BORDER_REPLICATE);
Sobel(src.rowRange(boundaries.start - 1 - ksize2, boundaries.end + 1 + ksize2), tempdy,
CV_16S, 0, 1, aperture_size, 1, 0, BORDER_REPLICATE);
dx = tempdx.rowRange(ksize2, tempdx.rows - ksize2);
dy = tempdy.rowRange(ksize2, tempdy.rows - ksize2);
}
int maxsize = std::max(1 << 10, src.cols * (boundaries.end - boundaries.start) / 10);
std::vector<uchar*> stack(maxsize);
uchar **stack_top = &stack[0];
uchar **stack_bottom = &stack[0];
AutoBuffer<uchar> buffer(cn * mapstep * 3 * sizeof(int));
int* mag_buf[3];
mag_buf[0] = (int*)(uchar*)buffer;
mag_buf[1] = mag_buf[0] + mapstep*cn;
mag_buf[2] = mag_buf[1] + mapstep*cn;
// calculate magnitude and angle of gradient, perform non-maxima suppression.
// fill the map with one of the following values:
// 0 - the pixel might belong to an edge
// 1 - the pixel can not belong to an edge
// 2 - the pixel does belong to an edge
for (int i = boundaries.start - 1; i <= boundaries.end; i++)
{
int* _norm = mag_buf[(i > boundaries.start) - (i == boundaries.start - 1) + 1] + 1;
short* _dx = dx.ptr<short>(i - boundaries.start + 1);
short* _dy = dy.ptr<short>(i - boundaries.start + 1);
if (!L2gradient)
{
int j = 0, width = src.cols * cn;
#if CV_SSE2
if (haveSSE2)
{
__m128i v_zero = _mm_setzero_si128();
for ( ; j <= width - 8; j += 8)
{
__m128i v_dx = _mm_loadu_si128((const __m128i *)(_dx + j));
__m128i v_dy = _mm_loadu_si128((const __m128i *)(_dy + j));
v_dx = _mm_max_epi16(v_dx, _mm_sub_epi16(v_zero, v_dx));
v_dy = _mm_max_epi16(v_dy, _mm_sub_epi16(v_zero, v_dy));
__m128i v_norm = _mm_add_epi32(_mm_unpacklo_epi16(v_dx, v_zero), _mm_unpacklo_epi16(v_dy, v_zero));
_mm_storeu_si128((__m128i *)(_norm + j), v_norm);
v_norm = _mm_add_epi32(_mm_unpackhi_epi16(v_dx, v_zero), _mm_unpackhi_epi16(v_dy, v_zero));
_mm_storeu_si128((__m128i *)(_norm + j + 4), v_norm);
}
}
#elif CV_NEON
for ( ; j <= width - 8; j += 8)
{
int16x8_t v_dx = vld1q_s16(_dx + j), v_dy = vld1q_s16(_dy + j);
vst1q_s32(_norm + j, vaddq_s32(vabsq_s32(vmovl_s16(vget_low_s16(v_dx))),
vabsq_s32(vmovl_s16(vget_low_s16(v_dy)))));
vst1q_s32(_norm + j + 4, vaddq_s32(vabsq_s32(vmovl_s16(vget_high_s16(v_dx))),
vabsq_s32(vmovl_s16(vget_high_s16(v_dy)))));
}
#endif
for ( ; j < width; ++j)
_norm[j] = std::abs(int(_dx[j])) + std::abs(int(_dy[j]));
}
else
{
int j = 0, width = src.cols * cn;
#if CV_SSE2
if (haveSSE2)
{
for ( ; j <= width - 8; j += 8)
{
__m128i v_dx = _mm_loadu_si128((const __m128i *)(_dx + j));
__m128i v_dy = _mm_loadu_si128((const __m128i *)(_dy + j));
__m128i v_dx_ml = _mm_mullo_epi16(v_dx, v_dx), v_dx_mh = _mm_mulhi_epi16(v_dx, v_dx);
__m128i v_dy_ml = _mm_mullo_epi16(v_dy, v_dy), v_dy_mh = _mm_mulhi_epi16(v_dy, v_dy);
__m128i v_norm = _mm_add_epi32(_mm_unpacklo_epi16(v_dx_ml, v_dx_mh), _mm_unpacklo_epi16(v_dy_ml, v_dy_mh));
_mm_storeu_si128((__m128i *)(_norm + j), v_norm);
v_norm = _mm_add_epi32(_mm_unpackhi_epi16(v_dx_ml, v_dx_mh), _mm_unpackhi_epi16(v_dy_ml, v_dy_mh));
_mm_storeu_si128((__m128i *)(_norm + j + 4), v_norm);
}
}
#elif CV_NEON
for ( ; j <= width - 8; j += 8)
{
int16x8_t v_dx = vld1q_s16(_dx + j), v_dy = vld1q_s16(_dy + j);
int16x4_t v_dxp = vget_low_s16(v_dx), v_dyp = vget_low_s16(v_dy);
int32x4_t v_dst = vmlal_s16(vmull_s16(v_dxp, v_dxp), v_dyp, v_dyp);
vst1q_s32(_norm + j, v_dst);
v_dxp = vget_high_s16(v_dx), v_dyp = vget_high_s16(v_dy);
v_dst = vmlal_s16(vmull_s16(v_dxp, v_dxp), v_dyp, v_dyp);
vst1q_s32(_norm + j + 4, v_dst);
}
#endif
for ( ; j < width; ++j)
_norm[j] = int(_dx[j])*_dx[j] + int(_dy[j])*_dy[j];
}
if (cn > 1)
{
for(int j = 0, jn = 0; j < src.cols; ++j, jn += cn)
{
int maxIdx = jn;
for(int k = 1; k < cn; ++k)
if(_norm[jn + k] > _norm[maxIdx]) maxIdx = jn + k;
_norm[j] = _norm[maxIdx];
_dx[j] = _dx[maxIdx];
_dy[j] = _dy[maxIdx];
}
}
_norm[-1] = _norm[src.cols] = 0;
// at the very beginning we do not have a complete ring
// buffer of 3 magnitude rows for non-maxima suppression
if (i <= boundaries.start)
continue;
uchar* _map = map + mapstep*i + 1;
_map[-1] = _map[src.cols] = 1;
int* _mag = mag_buf[1] + 1; // take the central row
ptrdiff_t magstep1 = mag_buf[2] - mag_buf[1];
ptrdiff_t magstep2 = mag_buf[0] - mag_buf[1];
const short* _x = dx.ptr<short>(i - boundaries.start);
const short* _y = dy.ptr<short>(i - boundaries.start);
if ((stack_top - stack_bottom) + src.cols > maxsize)
{
int sz = (int)(stack_top - stack_bottom);
maxsize = std::max(maxsize * 3/2, sz + src.cols);
stack.resize(maxsize);
stack_bottom = &stack[0];
stack_top = stack_bottom + sz;
}
#define CANNY_PUSH(d) *(d) = uchar(2), *stack_top++ = (d)
#define CANNY_POP(d) (d) = *--stack_top
int prev_flag = 0;
bool canny_push = false;
for (int j = 0; j < src.cols; j++)
{
#define CANNY_SHIFT 15
const int TG22 = (int)(0.4142135623730950488016887242097*(1<<CANNY_SHIFT) + 0.5);
int m = _mag[j];
if (m > low)
{
int xs = _x[j];
int ys = _y[j];
int x = std::abs(xs);
int y = std::abs(ys) << CANNY_SHIFT;
int tg22x = x * TG22;
if (y < tg22x)
{
if (m > _mag[j-1] && m >= _mag[j+1]) canny_push = true;
}
else
{
int tg67x = tg22x + (x << (CANNY_SHIFT+1));
if (y > tg67x)
{
if (m > _mag[j+magstep2] && m >= _mag[j+magstep1]) canny_push = true;
}
else
{
int s = (xs ^ ys) < 0 ? -1 : 1;
if (m > _mag[j+magstep2-s] && m > _mag[j+magstep1+s]) canny_push = true;
}
}
}
if (!canny_push)
{
prev_flag = 0;
_map[j] = uchar(1);
continue;
}
else
{
// _map[j-mapstep] is short-circuited at the start because previous thread is
// responsible for initializing it.
if (!prev_flag && m > high && (i <= boundaries.start+1 || _map[j-mapstep] != 2) )
{
CANNY_PUSH(_map + j);
prev_flag = 1;
}
else
_map[j] = 0;
canny_push = false;
}
}
// scroll the ring buffer
_mag = mag_buf[0];
mag_buf[0] = mag_buf[1];
mag_buf[1] = mag_buf[2];
mag_buf[2] = _mag;
}
// now track the edges (hysteresis thresholding)
while (stack_top > stack_bottom)
{
if ((stack_top - stack_bottom) + 8 > maxsize)
{
int sz = (int)(stack_top - stack_bottom);
maxsize = maxsize * 3/2;
stack.resize(maxsize);
stack_bottom = &stack[0];
stack_top = stack_bottom + sz;
}
uchar* m;
CANNY_POP(m);
// Stops thresholding from expanding to other slices by sending pixels in the borders of each
// slice in a queue to be serially processed later.
if ( (m < map + (boundaries.start + 2) * mapstep) || (m >= map + boundaries.end * mapstep) )
{
borderPeaks.push(m);
continue;
}
if (!m[-1]) CANNY_PUSH(m - 1);
if (!m[1]) CANNY_PUSH(m + 1);
if (!m[-mapstep-1]) CANNY_PUSH(m - mapstep - 1);
if (!m[-mapstep]) CANNY_PUSH(m - mapstep);
if (!m[-mapstep+1]) CANNY_PUSH(m - mapstep + 1);
if (!m[mapstep-1]) CANNY_PUSH(m + mapstep - 1);
if (!m[mapstep]) CANNY_PUSH(m + mapstep);
if (!m[mapstep+1]) CANNY_PUSH(m + mapstep + 1);
}
}
private:
const Range boundaries;
const Mat& src;
uchar* map;
int low;
int high;
int aperture_size;
bool L2gradient;
};
#endif
} // namespace cv
void cv::Canny( InputArray _src, OutputArray _dst,
double low_thresh, double high_thresh,
@@ -280,6 +625,69 @@ void cv::Canny( InputArray _src, OutputArray _dst,
}
#endif
#ifdef HAVE_TBB
if (L2gradient)
{
low_thresh = std::min(32767.0, low_thresh);
high_thresh = std::min(32767.0, high_thresh);
if (low_thresh > 0) low_thresh *= low_thresh;
if (high_thresh > 0) high_thresh *= high_thresh;
}
int low = cvFloor(low_thresh);
int high = cvFloor(high_thresh);
ptrdiff_t mapstep = src.cols + 2;
AutoBuffer<uchar> buffer((src.cols+2)*(src.rows+2));
uchar* map = (uchar*)buffer;
memset(map, 1, mapstep);
memset(map + mapstep*(src.rows + 1), 1, mapstep);
int threadsNumber = tbb::task_scheduler_init::default_num_threads();
int grainSize = src.rows / threadsNumber;
// Make a fallback for pictures with too few rows.
uchar ksize2 = aperture_size / 2;
int minGrainSize = 1 + ksize2;
int maxGrainSize = src.rows - 2 - 2*ksize2;
if ( !( minGrainSize <= grainSize && grainSize <= maxGrainSize ) )
{
threadsNumber = 1;
grainSize = src.rows;
}
tbb::task_group g;
for (int i = 0; i < threadsNumber; ++i)
{
if (i < threadsNumber - 1)
g.run(tbbCanny(Range(i * grainSize, (i + 1) * grainSize), src, map, low, high, aperture_size, L2gradient));
else
g.run(tbbCanny(Range(i * grainSize, src.rows), src, map, low, high, aperture_size, L2gradient));
}
g.wait();
#define CANNY_PUSH_SERIAL(d) *(d) = uchar(2), borderPeaks.push(d)
// now track the edges (hysteresis thresholding)
uchar* m;
while (borderPeaks.try_pop(m))
{
if (!m[-1]) CANNY_PUSH_SERIAL(m - 1);
if (!m[1]) CANNY_PUSH_SERIAL(m + 1);
if (!m[-mapstep-1]) CANNY_PUSH_SERIAL(m - mapstep - 1);
if (!m[-mapstep]) CANNY_PUSH_SERIAL(m - mapstep);
if (!m[-mapstep+1]) CANNY_PUSH_SERIAL(m - mapstep + 1);
if (!m[mapstep-1]) CANNY_PUSH_SERIAL(m + mapstep - 1);
if (!m[mapstep]) CANNY_PUSH_SERIAL(m + mapstep);
if (!m[mapstep+1]) CANNY_PUSH_SERIAL(m + mapstep + 1);
}
#else
Mat dx(src.rows, src.cols, CV_16SC(cn));
Mat dy(src.rows, src.cols, CV_16SC(cn));
@@ -540,6 +948,8 @@ __ocv_canny_push:
if (!m[mapstep+1]) CANNY_PUSH(m + mapstep + 1);
}
#endif
// the final pass, form the final image
const uchar* pmap = map + mapstep + 1;
uchar* pdst = dst.ptr();
+6 -1
View File
@@ -1548,7 +1548,7 @@ static bool ocl_morphOp(InputArray _src, OutputArray _dst, InputArray _kernel,
return true;
}
#if defined ANDROID
#ifdef ANDROID
size_t localThreads[2] = { 16, 8 };
#else
size_t localThreads[2] = { 16, 16 };
@@ -1563,6 +1563,11 @@ static bool ocl_morphOp(InputArray _src, OutputArray _dst, InputArray _kernel,
if (localThreads[0]*localThreads[1] * 2 < (localThreads[0] + ksize.width - 1) * (localThreads[1] + ksize.height - 1))
return false;
#ifdef ANDROID
if (dev.isNVidia())
return false;
#endif
// build processing
String processing;
Mat kernel8u;
+5
View File
@@ -2966,6 +2966,11 @@ static bool ocl_bilateralFilter_8u(InputArray _src, OutputArray _dst, int d,
double sigma_color, double sigma_space,
int borderType)
{
#ifdef ANDROID
if (ocl::Device::getDefault().isNVidia())
return false;
#endif
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
int i, j, maxk, radius;
+7 -2
View File
@@ -99,12 +99,17 @@ OCL_TEST_P(Canny, Accuracy)
generateTestData();
const double low_thresh = 50.0, high_thresh = 100.0;
double eps = 1e-2;
#ifdef ANDROID
if (cv::ocl::Device::getDefault().isNVidia())
eps = 12e-3;
#endif
OCL_OFF(cv::Canny(src_roi, dst_roi, low_thresh, high_thresh, apperture_size, useL2gradient));
OCL_ON(cv::Canny(usrc_roi, udst_roi, low_thresh, high_thresh, apperture_size, useL2gradient));
EXPECT_MAT_SIMILAR(dst_roi, udst_roi, 1e-2);
EXPECT_MAT_SIMILAR(dst, udst, 1e-2);
EXPECT_MAT_SIMILAR(dst_roi, udst_roi, eps);
EXPECT_MAT_SIMILAR(dst, udst, eps);
}
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, Canny, testing::Combine(
+1 -1
View File
@@ -128,7 +128,7 @@ OCL_TEST_P(CvtColor, BGR2GRAY) { performTest(3, 1, CVTCODE(BGR2GRAY)); }
OCL_TEST_P(CvtColor, GRAY2BGR) { performTest(1, 3, CVTCODE(GRAY2BGR)); }
OCL_TEST_P(CvtColor, RGBA2GRAY) { performTest(4, 1, CVTCODE(RGBA2GRAY)); }
OCL_TEST_P(CvtColor, GRAY2RGBA) { performTest(1, 4, CVTCODE(GRAY2RGBA)); }
OCL_TEST_P(CvtColor, BGRA2GRAY) { performTest(4, 1, CVTCODE(BGRA2GRAY)); }
OCL_TEST_P(CvtColor, BGRA2GRAY) { performTest(4, 1, CVTCODE(BGRA2GRAY), cv::ocl::Device::getDefault().isNVidia() ? 1 : 1e-3); }
OCL_TEST_P(CvtColor, GRAY2BGRA) { performTest(1, 4, CVTCODE(GRAY2BGRA)); }
// RGB <-> YUV
+8 -1
View File
@@ -319,10 +319,17 @@ OCL_TEST_P(Remap_INTER_LINEAR, Mat)
{
random_roi();
double eps = 2.0;
#ifdef ANDROID
// TODO investigate accuracy
if (cv::ocl::Device::getDefault().isNVidia())
eps = 8.0;
#endif
OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_LINEAR, borderType, val));
OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_LINEAR, borderType, val));
Near(2.0);
Near(eps);
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
# ----------------------------------------------------------------------------
# CMake file for java support
# ----------------------------------------------------------------------------
if(IOS OR NOT PYTHON_DEFAULT_AVAILABLE OR NOT ANT_EXECUTABLE OR NOT (JNI_FOUND OR (ANDROID AND ANDROID_NATIVE_API_LEVEL GREATER 7))
if(IOS OR WINRT OR NOT PYTHON_DEFAULT_AVAILABLE OR NOT ANT_EXECUTABLE OR NOT (JNI_FOUND OR (ANDROID AND ANDROID_NATIVE_API_LEVEL GREATER 7))
OR BUILD_opencv_world
)
ocv_module_disable(java)
+1 -1
View File
@@ -9,7 +9,7 @@ if((WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
ocv_module_disable(python3)
endif()
if(ANDROID OR IOS)
if(ANDROID OR IOS OR WINRT)
ocv_module_disable(python2)
ocv_module_disable(python3)
endif()
+1 -1
View File
@@ -1,4 +1,4 @@
if(IOS)
if(IOS OR WINRT)
ocv_module_disable(superres)
endif()
+1 -1
View File
@@ -1,6 +1,6 @@
set(the_description "The ts module")
if(IOS)
if(IOS OR WINRT)
ocv_module_disable(ts)
endif()
+1 -1
View File
@@ -6,7 +6,7 @@
#include "cvconfig.h"
#ifdef HAVE_WINRT
#ifdef WINRT
#pragma warning(disable:4447) // Disable warning 'main' signature found without threading model
#endif
+43 -42
View File
@@ -458,10 +458,8 @@ CV_INLINE void
uchar nShadowDetection
)
{
int size=_src.rows*_src.cols;
int nchannels = CV_MAT_CN(_src.type());
const uchar* pDataCurrent=_src.ptr(0);
uchar* pDataOutput=_dst.ptr(0);
//model
uchar* m_aModel=_bgmodel.ptr(0);
uchar* m_nNextLongUpdate=_nNextLongUpdate.ptr(0);
@@ -509,48 +507,51 @@ CV_INLINE void
if (_nLongCounter >= m_nLongUpdate) _nLongCounter = 0;
//go through the image
for (long i=0;i<size;i++)
long i = 0;
for (long y = 0; y < _src.rows; y++)
{
const uchar* data=pDataCurrent;
pDataCurrent=pDataCurrent+nchannels;
//update model+ background subtract
uchar include=0;
int result= _cvCheckPixelBackgroundNP(i, data, nchannels,
m_nN, m_aModel, m_fTb,m_nkNN, m_fTau,m_bShadowDetection,include);
_cvUpdatePixelBackgroundNP(i,data,nchannels,
m_nN, m_aModel,
m_nNextLongUpdate,
m_nNextMidUpdate,
m_nNextShortUpdate,
m_aModelIndexLong,
m_aModelIndexMid,
m_aModelIndexShort,
m_nLongCounter,
m_nMidCounter,
m_nShortCounter,
m_nLongUpdate,
m_nMidUpdate,
m_nShortUpdate,
include
);
switch (result)
for (long x = 0; x < _src.cols; x++)
{
case 0:
//foreground
(* pDataOutput)=255;
break;
case 1:
//background
(* pDataOutput)=0;
break;
case 2:
//shadow
(* pDataOutput)=nShadowDetection;
break;
const uchar* data = _src.ptr(y, x);
//update model+ background subtract
uchar include=0;
int result= _cvCheckPixelBackgroundNP(i, data, nchannels,
m_nN, m_aModel, m_fTb,m_nkNN, m_fTau,m_bShadowDetection,include);
_cvUpdatePixelBackgroundNP(i,data,nchannels,
m_nN, m_aModel,
m_nNextLongUpdate,
m_nNextMidUpdate,
m_nNextShortUpdate,
m_aModelIndexLong,
m_aModelIndexMid,
m_aModelIndexShort,
m_nLongCounter,
m_nMidCounter,
m_nShortCounter,
m_nLongUpdate,
m_nMidUpdate,
m_nShortUpdate,
include
);
switch (result)
{
case 0:
//foreground
*_dst.ptr(y, x) = 255;
break;
case 1:
//background
*_dst.ptr(y, x) = 0;
break;
case 2:
//shadow
*_dst.ptr(y, x) = nShadowDetection;
break;
}
i++;
}
pDataOutput++;
}
};
+5 -1
View File
@@ -1,3 +1,7 @@
if(WINRT)
ocv_module_disable(videoio)
endif()
set(the_description "Media I/O")
ocv_add_module(videoio opencv_imgproc opencv_imgcodecs OPTIONAL opencv_androidcamera WRAP java python)
@@ -7,7 +11,7 @@ ocv_add_module(videoio opencv_imgproc opencv_imgcodecs OPTIONAL opencv_androidca
# Jose Luis Blanco, 2008
# ----------------------------------------------------------------------------
if(HAVE_WINRT_CX)
if(HAVE_WINRT_CX AND NOT WINRT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
endif()
+2 -1
View File
@@ -135,7 +135,8 @@ enum { CAP_PROP_POS_MSEC =0,
// Currently, these are supported through the libv4l interface only.
enum { CAP_MODE_BGR = 0, // BGR24 (default)
CAP_MODE_RGB = 1, // RGB24
CAP_MODE_GRAY = 2 // Y8
CAP_MODE_GRAY = 2, // Y8
CAP_MODE_YUYV = 3 // YUYV
};
@@ -299,7 +299,8 @@ enum
{
CV_CAP_MODE_BGR = 0, // BGR24 (default)
CV_CAP_MODE_RGB = 1, // RGB24
CV_CAP_MODE_GRAY = 2 // Y8
CV_CAP_MODE_GRAY = 2, // Y8
CV_CAP_MODE_YUYV = 3 // YUYV
};
enum
+1 -1
View File
@@ -85,7 +85,7 @@ private:
icvInitFFMPEG()
{
#if defined WIN32 || defined _WIN32
# ifdef HAVE_WINRT
# ifdef WINRT
const wchar_t* module_name = L"opencv_ffmpeg"
CVAUX_STRW(CV_MAJOR_VERSION) CVAUX_STRW(CV_MINOR_VERSION) CVAUX_STRW(CV_SUBMINOR_VERSION)
#if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__)
+17 -10
View File
@@ -646,6 +646,8 @@ static inline int channels_for_mode(int mode)
switch(mode) {
case CV_CAP_MODE_GRAY:
return 1;
case CV_CAP_MODE_YUYV:
return 2;
default:
return 3;
}
@@ -713,31 +715,26 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture, char *deviceName)
/* libv4l will convert from any format to V4L2_PIX_FMT_BGR24,
V4L2_PIX_FMT_RGV24, or V4L2_PIX_FMT_YUV420 */
unsigned int requestedPixelFormat;
int width;
int height;
switch (capture->mode) {
case CV_CAP_MODE_RGB:
requestedPixelFormat = V4L2_PIX_FMT_RGB24;
width = capture->width;
height = capture->height;
break;
case CV_CAP_MODE_GRAY:
requestedPixelFormat = V4L2_PIX_FMT_YUV420;
width = capture->width;
height = capture->height;
break;
case CV_CAP_MODE_YUYV:
requestedPixelFormat = V4L2_PIX_FMT_YUYV;
break;
default:
requestedPixelFormat = V4L2_PIX_FMT_BGR24;
width = capture->width;
height = capture->height;
break;
}
CLEAR (capture->form);
capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
capture->form.fmt.pix.pixelformat = requestedPixelFormat;
capture->form.fmt.pix.field = V4L2_FIELD_ANY;
capture->form.fmt.pix.width = width;
capture->form.fmt.pix.height = height;
capture->form.fmt.pix.width = capture->width;
capture->form.fmt.pix.height = capture->height;
if (-1 == xioctl (capture->deviceHandle, VIDIOC_S_FMT, &capture->form)) {
fprintf(stderr, "VIDEOIO ERROR: libv4l unable to ioctl S_FMT\n");
@@ -949,6 +946,10 @@ static int _capture_V4L (CvCaptureCAM_V4L *capture, char *deviceName)
requestedVideoPalette = VIDEO_PALETTE_YUV420;
depth = 8;
break;
case CV_CAP_MODE_YUYV:
requestedVideoPalette = VIDEO_PALETTE_YUYV;
depth = 16;
break;
default:
requestedVideoPalette = VIDEO_PALETTE_RGB24;
depth = 24;
@@ -1319,6 +1320,7 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) {
switch(capture->imageProperties.palette) {
case VIDEO_PALETTE_RGB24:
case VIDEO_PALETTE_YUV420:
case VIDEO_PALETTE_YUYV:
memcpy((char *)capture->frame.imageData,
(char *)(capture->memoryMap + capture->memoryBuffer.offsets[capture->bufferIndex]),
capture->frame.imageSize);
@@ -1464,6 +1466,10 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) {
cropHeight = h*8;
cropWidth = w*8;
break;
case CV_CAP_MODE_YUYV:
cropHeight = h*16;
cropWidth = w*16;
break;
default:
cropHeight = h*24;
cropWidth = w*24;
@@ -1719,6 +1725,7 @@ static int icvSetPropertyCAM_V4L(CvCaptureCAM_V4L* capture, int property_id, dou
case CV_CAP_MODE_BGR:
case CV_CAP_MODE_RGB:
case CV_CAP_MODE_GRAY:
case CV_CAP_MODE_YUYV:
capture->mode = mode;
/* recreate the capture buffer for the same output resolution
but a different pixel format */
+37 -37
View File
@@ -86,7 +86,7 @@
#include <mferror.h>
#ifdef HAVE_WINRT
#ifdef WINRT
// for ComPtr usage
#include <wrl/client.h>
#ifdef __cplusplus_winrt
@@ -266,7 +266,7 @@ public:
#endif
struct IMFMediaType;
#ifndef HAVE_WINRT
#ifndef WINRT
struct IMFActivate;
struct IMFMediaSource;
#endif
@@ -406,7 +406,7 @@ private:
ImageGrabberCallback& operator=(const ImageGrabberCallback&); // Declared to fix compilation warning.
};
#ifdef HAVE_WINRT
#ifdef WINRT
extern const __declspec(selectany) WCHAR RuntimeClass_CV_ImageGrabberWinRT[] = L"cv.ImageGrabberWinRT";
class ImageGrabberWinRT :
@@ -547,7 +547,7 @@ public:
CamParametrs getParametrs();
void setParametrs(CamParametrs parametrs);
void setEmergencyStopEvent(void *userData, void(*func)(int, void *));
#ifdef HAVE_WINRT
#ifdef WINRT
long readInfoOfDevice(MAKE_WRL_REF(_IDeviceInformation) pDevice, unsigned int Num);
void waitForDevice()
{
@@ -593,7 +593,7 @@ private:
std::map<UINT64, FrameRateMap> vd_CaptureFormats;
std::vector<MediaType> vd_CurrentFormats;
IMFMediaSource *vd_pSource;
#ifdef HAVE_WINRT
#ifdef WINRT
MAKE_WRL_AGILE_REF(_MediaCapture) vd_pMedCap;
EventRegistrationToken vd_cookie;
ImageGrabberWinRT *vd_pImGr;
@@ -608,7 +608,7 @@ private:
long setDeviceFormat(IMFMediaSource *pSource, unsigned long dwFormatIndex);
void buildLibraryofTypes();
int findType(unsigned int size, unsigned int frameRate = 0);
#ifdef HAVE_WINRT
#ifdef WINRT
HRESULT enumerateCaptureFormats(MAKE_WRL_REF(_MediaCapture) pSource);
long setDeviceFormat(MAKE_WRL_REF(_MediaCapture) pSource, unsigned long dwFormatIndex, MAKE_WRL_REF(_AsyncAction)* pAction);
long resetDevice(MAKE_WRL_REF(_IDeviceInformation) pDevice);
@@ -627,7 +627,7 @@ class videoDevices
{
public:
~videoDevices(void);
#ifdef HAVE_WINRT
#ifdef WINRT
long initDevices(_DeviceClass devClass);
void waitInit() {
if (vds_enumTask) {
@@ -646,7 +646,7 @@ public:
void clearDevices();
private:
UINT32 count;
#ifdef HAVE_WINRT
#ifdef WINRT
MAKE_WRL_REF(_AsyncAction) vds_enumTask;
#endif
std::vector<videoDevice *> vds_Devices;
@@ -715,7 +715,7 @@ public:
bool setupDevice(int deviceID, unsigned int w, unsigned int h, unsigned int idealFramerate = 30);
// Checking of recivig of new frame from video device with deviceID
bool isFrameNew(int deviceID);
#ifdef HAVE_WINRT
#ifdef WINRT
void waitForDevice(int deviceID);
#endif
// Writing of Raw Data pixels from video device with deviceID with correction of RedAndBlue flipping flipRedAndBlue and vertical flipping flipImage
@@ -1237,7 +1237,7 @@ ImageGrabber::~ImageGrabber(void)
DebugPrintOut(L"IMAGEGRABBER VIDEODEVICE %i: Destroying instance of the ImageGrabber class\n", ig_DeviceID);
}
#ifdef HAVE_WINRT
#ifdef WINRT
ImageGrabberWinRT::ImageGrabberWinRT(bool synchronous):
ImageGrabberCallback(synchronous),
@@ -1899,7 +1899,7 @@ Media_Foundation::~Media_Foundation(void)
bool Media_Foundation::buildListOfDevices()
{
HRESULT hr = S_OK;
#ifdef HAVE_WINRT
#ifdef WINRT
videoDevices *vDs = &videoDevices::getInstance();
hr = vDs->initDevices(WRL_ENUM_GET(_DeviceClass, DeviceClass, VideoCapture));
#else
@@ -1987,7 +1987,7 @@ unsigned char * RawImage::getpPixels()
videoDevice::videoDevice(void): vd_IsSetuped(false), vd_LockOut(OpenLock), vd_pFriendlyName(NULL),
vd_Width(0), vd_Height(0), vd_FrameRate(0), vd_pSource(NULL), vd_pImGrTh(NULL), vd_func(NULL), vd_userData(NULL)
{
#ifdef HAVE_WINRT
#ifdef WINRT
vd_pMedCap = nullptr;
vd_cookie.value = 0;
vd_pImGr = NULL;
@@ -2075,7 +2075,7 @@ CamParametrs videoDevice::getParametrs()
return out;
}
#ifdef HAVE_WINRT
#ifdef WINRT
long videoDevice::resetDevice(MAKE_WRL_REF(_IDeviceInformation) pDevice)
#else
long videoDevice::resetDevice(IMFActivate *pActivate)
@@ -2086,7 +2086,7 @@ long videoDevice::resetDevice(IMFActivate *pActivate)
if(vd_pFriendlyName)
CoTaskMemFree(vd_pFriendlyName);
vd_pFriendlyName = NULL;
#ifdef HAVE_WINRT
#ifdef WINRT
if (pDevice)
{
ACTIVATE_OBJ(RuntimeClass_Windows_Media_Capture_MediaCapture, _MediaCapture, pIMedCap, hr)
@@ -2157,7 +2157,7 @@ long videoDevice::resetDevice(IMFActivate *pActivate)
return hr;
}
#ifdef HAVE_WINRT
#ifdef WINRT
long videoDevice::readInfoOfDevice(MAKE_WRL_REF(_IDeviceInformation) pDevice, unsigned int Num)
{
HRESULT hr = -1;
@@ -2173,7 +2173,7 @@ long videoDevice::readInfoOfDevice(IMFActivate *pActivate, unsigned int Num)
}
#endif
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef HAVE_CONCURRENCY
long videoDevice::checkDevice(_DeviceClass devClass, DEFINE_TASK<void>* pTask, MAKE_WRL_REF(_IDeviceInformation)* ppDevice)
{
@@ -2273,7 +2273,7 @@ long videoDevice::initDevice()
{
HRESULT hr = S_OK;
CoInitialize(NULL);
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef HAVE_CONCURRENCY
Concurrency::critical_section::scoped_lock _LockHolder(vd_lock);
MAKE_WRL_REF(_AsyncAction) pOldAction = vd_pAction;
@@ -2381,7 +2381,7 @@ void videoDevice::closeDevice()
{
vd_IsSetuped = false;
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef HAVE_CONCURRENCY
if (DEREF_AGILE_WRL_OBJ(vd_pMedCap)) {
MAKE_WRL_REF(_AsyncAction) action;
@@ -2535,7 +2535,7 @@ void videoDevice::buildLibraryofTypes()
}
}
#ifdef HAVE_WINRT
#ifdef WINRT
long videoDevice::setDeviceFormat(MAKE_WRL_REF(_MediaCapture) pSource, unsigned long dwFormatIndex, MAKE_WRL_REF(_AsyncAction)* pAction)
{
HRESULT hr;
@@ -2596,7 +2596,7 @@ bool videoDevice::isDeviceSetup()
RawImage * videoDevice::getRawImageOut()
{
if(!vd_IsSetuped) return NULL;
#ifdef HAVE_WINRT
#ifdef WINRT
if(vd_pImGr) return vd_pImGr->getRawImage();
#endif
if(vd_pImGrTh)
@@ -2618,7 +2618,7 @@ bool videoDevice::isFrameNew()
vd_LockOut = RawDataLock;
//must already be closed
#ifdef HAVE_WINRT
#ifdef WINRT
if (DEREF_AGILE_WRL_OBJ(vd_pMedCap)) {
MAKE_WRL_REF(_AsyncAction) action;
if (FAILED(ImageGrabberWinRT::CreateInstance(&vd_pImGr))) return false;
@@ -2649,7 +2649,7 @@ bool videoDevice::isFrameNew()
vd_pImGrTh->start();
return true;
}
#ifdef HAVE_WINRT
#ifdef WINRT
if(vd_pImGr)
return vd_pImGr->getRawImage()->isNew();
#endif
@@ -2678,7 +2678,7 @@ bool videoDevice::setupDevice(unsigned int id)
HRESULT hr = initDevice();
if(SUCCEEDED(hr))
{
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef HAVE_CONCURRENCY
Concurrency::critical_section::scoped_lock _LockHolder(vd_lock);
MAKE_WRL_REF(_AsyncAction) pOldAction = vd_pAction;
@@ -2692,7 +2692,7 @@ bool videoDevice::setupDevice(unsigned int id)
vd_Height = vd_CurrentFormats[id].height;
vd_FrameRate = vd_CurrentFormats[id].MF_MT_FRAME_RATE_NUMERATOR /
vd_CurrentFormats[id].MF_MT_FRAME_RATE_DENOMINATOR;
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef HAVE_CONCURRENCY
if (DEREF_AGILE_WRL_OBJ(vd_pMedCap)) {
DEFINE_TASK<void> _task;
@@ -2710,7 +2710,7 @@ bool videoDevice::setupDevice(unsigned int id)
if(vd_IsSetuped)
DebugPrintOut(L"\n\nVIDEODEVICE %i: Device is setuped \n", vd_CurrentNumber);
vd_PrevParametrs = getParametrs();
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef HAVE_CONCURRENCY
END_CREATE_ASYNC(hr));
#endif
@@ -2749,7 +2749,7 @@ wchar_t *videoDevice::getName()
videoDevice::~videoDevice(void)
{
closeDevice();
#ifdef HAVE_WINRT
#ifdef WINRT
RELEASE_WRL(vd_pMedCap)
#endif
SafeRelease(&vd_pSource);
@@ -2757,7 +2757,7 @@ videoDevice::~videoDevice(void)
CoTaskMemFree(vd_pFriendlyName);
}
#ifdef HAVE_WINRT
#ifdef WINRT
HRESULT videoDevice::enumerateCaptureFormats(MAKE_WRL_REF(_MediaCapture) pSource)
{
HRESULT hr;
@@ -2831,7 +2831,7 @@ done:
videoDevices::videoDevices(void): count(0)
{
#ifdef HAVE_WINRT
#ifdef WINRT
vds_enumTask = nullptr;
#endif
}
@@ -2862,7 +2862,7 @@ videoDevice * videoDevices::getDevice(unsigned int i)
return vds_Devices[i];
}
#ifdef HAVE_WINRT
#ifdef WINRT
long videoDevices::initDevices(_DeviceClass devClass)
{
HRESULT hr = S_OK;
@@ -3196,7 +3196,7 @@ bool videoInput::isFrameNew(int deviceID)
return false;
}
#ifdef HAVE_WINRT
#ifdef WINRT
void videoInput::waitForDevice(int deviceID)
{
if (deviceID < 0)
@@ -3405,7 +3405,7 @@ unsigned int videoInput::listDevices(bool silent)
if(accessToDevices)
{
videoDevices *VDS = &videoDevices::getInstance();
#ifdef HAVE_WINRT
#ifdef WINRT
VDS->waitInit();
#endif
out = VDS->getCount();
@@ -3595,7 +3595,7 @@ protected:
int index, width, height, fourcc;
IplImage* frame;
videoInput VI;
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef HAVE_CONCURRENCY
DEFINE_TASK<bool> openTask;
Concurrency::critical_section lock;
@@ -3643,7 +3643,7 @@ void CvCaptureCAM_MSMF::close()
// Initialize camera input
bool CvCaptureCAM_MSMF::open( int _index )
{
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef HAVE_CONCURRENCY
SAVE_CURRENT_CONTEXT(context);
auto func = [_index, context, this](DEFINE_RET_VAL(bool)) -> DEFINE_RET_FORMAL(bool) {
@@ -3656,14 +3656,14 @@ bool CvCaptureCAM_MSMF::open( int _index )
if (devices == 0)
return false;
try_index = try_index < 0 ? 0 : (try_index > devices-1 ? devices-1 : try_index);
#ifdef HAVE_WINRT
#ifdef WINRT
HRESULT hr;
#ifdef HAVE_CONCURRENCY
BEGIN_CALL_IN_CONTEXT(hr, context, this, try_index)
#endif
#endif
VI.setupDevice(try_index, 0, 0, 0); // With maximum frame size.
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef HAVE_CONCURRENCY
END_CALL_IN_CONTEXT_BASE
VI.waitForDevice(try_index);
@@ -3672,13 +3672,13 @@ bool CvCaptureCAM_MSMF::open( int _index )
#endif
#endif
if( !VI.isFrameNew(try_index) )
#ifdef HAVE_WINRT
#ifdef WINRT
hr = E_FAIL;
#else
return false;
#endif
index = try_index;
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef HAVE_CONCURRENCY
END_CALL_IN_CONTEXT_BASE
RET_VAL(true)
+18 -18
View File
@@ -1,4 +1,4 @@
#ifdef HAVE_WINRT
#ifdef WINRT
#define ICustomStreamSink StreamSink
#ifndef __cplusplus_winrt
@@ -380,7 +380,7 @@ MAKE_ENUM(MFSTREAMSINK_MARKER_TYPE) StreamSinkMarkerTypePairs[] = {
};
MAKE_MAP(MFSTREAMSINK_MARKER_TYPE) StreamSinkMarkerTypeMap(StreamSinkMarkerTypePairs, StreamSinkMarkerTypePairs + sizeof(StreamSinkMarkerTypePairs) / sizeof(StreamSinkMarkerTypePairs[0]));
#ifdef HAVE_WINRT
#ifdef WINRT
#ifdef __cplusplus_winrt
#define _ContextCallback Concurrency::details::_ContextCallback
@@ -1070,7 +1070,7 @@ protected:
};
class StreamSink :
#ifdef HAVE_WINRT
#ifdef WINRT
public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::RuntimeClassType::ClassicCom>,
IMFStreamSink,
@@ -1100,7 +1100,7 @@ public:
if (riid == IID_IMarshal) {
return MarshalQI(riid, ppv);
} else {
#ifdef HAVE_WINRT
#ifdef WINRT
hr = RuntimeClassT::QueryInterface(riid, ppv);
#else
if (riid == IID_IUnknown || riid == IID_IMFStreamSink) {
@@ -1126,7 +1126,7 @@ public:
return hr;
}
#ifdef HAVE_WINRT
#ifdef WINRT
STDMETHOD(RuntimeClassInitialize)() { return S_OK; }
#else
ULONG STDMETHODCALLTYPE AddRef()
@@ -1177,7 +1177,7 @@ public:
m_StartTime(0), m_fGetStartTimeFromSample(false), m_fWaitingForFirstSample(false),
m_state(State_TypeNotSet), m_pParent(nullptr),
m_imageWidthInPixels(0), m_imageHeightInPixels(0) {
#ifdef HAVE_WINRT
#ifdef WINRT
m_token.value = 0;
#else
m_bConnected = false;
@@ -1856,7 +1856,7 @@ public:
return hr;
}
private:
#ifdef HAVE_WINRT
#ifdef WINRT
EventRegistrationToken m_token;
#else
bool m_bConnected;
@@ -1864,7 +1864,7 @@ private:
bool m_IsShutdown; // Flag to indicate if Shutdown() method was called.
CRITICAL_SECTION m_critSec;
#ifndef HAVE_WINRT
#ifndef WINRT
long m_cRef;
#endif
IMFAttributes* m_pParent;
@@ -2408,7 +2408,7 @@ protected:
extern const __declspec(selectany) WCHAR RuntimeClass_CV_MediaSink[] = L"cv.MediaSink";
class MediaSink :
#ifdef HAVE_WINRT
#ifdef WINRT
public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::RuntimeClassType::WinRtClassicComMix >,
Microsoft::WRL::Implements<ABI::Windows::Media::IMediaExtension>,
@@ -2420,7 +2420,7 @@ class MediaSink :
public IMFMediaSink, public IMFClockStateSink, public CBaseAttributes<>
#endif
{
#ifdef HAVE_WINRT
#ifdef WINRT
InspectableClass(RuntimeClass_CV_MediaSink, BaseTrust)
public:
#else
@@ -2488,7 +2488,7 @@ public:
return S_OK;
}
}
#ifdef HAVE_WINRT
#ifdef WINRT
STDMETHODIMP SetProperties(ABI::Windows::Foundation::Collections::IPropertySet *pConfiguration)
{
HRESULT hr = S_OK;
@@ -2828,7 +2828,7 @@ public:
if (SUCCEEDED(hr))
{
#ifdef HAVE_WINRT
#ifdef WINRT
pStream = Microsoft::WRL::Make<StreamSink>();
if (pStream == nullptr) {
hr = E_OUTOFMEMORY;
@@ -2940,7 +2940,7 @@ public:
{
hr = m_streams.Remove(pos, nullptr);
_ComPtr<ICustomStreamSink> spCustomSink;
#ifdef HAVE_WINRT
#ifdef WINRT
spCustomSink = static_cast<StreamSink*>(spStream.Get());
hr = S_OK;
#else
@@ -3164,7 +3164,7 @@ public:
{
_ComPtr<ICustomStreamSink> spCustomSink;
HRESULT hr;
#ifdef HAVE_WINRT
#ifdef WINRT
spCustomSink = static_cast<StreamSink*>(pStream);
#else
hr = pStream->QueryInterface(IID_PPV_ARGS(spCustomSink.GetAddressOf()));
@@ -3187,7 +3187,7 @@ public:
{
_ComPtr<ICustomStreamSink> spCustomSink;
HRESULT hr;
#ifdef HAVE_WINRT
#ifdef WINRT
spCustomSink = static_cast<StreamSink*>(pStream);
#else
hr = pStream->QueryInterface(IID_PPV_ARGS(spCustomSink.GetAddressOf()));
@@ -3207,7 +3207,7 @@ public:
{
_ComPtr<ICustomStreamSink> spCustomSink;
HRESULT hr;
#ifdef HAVE_WINRT
#ifdef WINRT
spCustomSink = static_cast<StreamSink*>(pStream);
#else
hr = pStream->QueryInterface(IID_PPV_ARGS(spCustomSink.GetAddressOf()));
@@ -3317,7 +3317,7 @@ public:
return hr;
}
private:
#ifndef HAVE_WINRT
#ifndef WINRT
long m_cRef;
#endif
CRITICAL_SECTION m_critSec;
@@ -3327,6 +3327,6 @@ private:
LONGLONG m_llStartTime;
};
#ifdef HAVE_WINRT
#ifdef WINRT
ActivatableClass(MediaSink);
#endif