if (is_buf_16u)
{
- unsigned short* udst_idx = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
+ unsigned short* udst_idx = (unsigned short*)(buf->data.s + root->buf_idx*get_length_subbuf() +
vi*sample_count + data_root->offset);
for( int i = 0; i < num_valid; i++ )
{
}
else
{
- int* idst_idx = buf->data.i + root->buf_idx*buf->cols +
+ int* idst_idx = buf->data.i + root->buf_idx*get_length_subbuf() +
vi*sample_count + root->offset;
for( int i = 0; i < num_valid; i++ )
{
const int* src_lbls = get_cv_labels(data_root, (int*)(uchar*)inn_buf);
if (is_buf_16u)
{
- unsigned short* udst = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
+ unsigned short* udst = (unsigned short*)(buf->data.s + root->buf_idx*get_length_subbuf() +
(workVarCount-1)*sample_count + root->offset);
for( int i = 0; i < count; i++ )
udst[i] = (unsigned short)src_lbls[sidx[i]];
}
else
{
- int* idst = buf->data.i + root->buf_idx*buf->cols +
+ int* idst = buf->data.i + root->buf_idx*get_length_subbuf() +
(workVarCount-1)*sample_count + root->offset;
for( int i = 0; i < count; i++ )
idst[i] = src_lbls[sidx[i]];
const int* sample_idx_src = get_sample_indices(data_root, (int*)(uchar*)inn_buf);
if (is_buf_16u)
{
- unsigned short* sample_idx_dst = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
+ unsigned short* sample_idx_dst = (unsigned short*)(buf->data.s + root->buf_idx*get_length_subbuf() +
workVarCount*sample_count + root->offset);
for( int i = 0; i < count; i++ )
sample_idx_dst[i] = (unsigned short)sample_idx_src[sidx[i]];
}
else
{
- int* sample_idx_dst = buf->data.i + root->buf_idx*buf->cols +
+ int* sample_idx_dst = buf->data.i + root->buf_idx*get_length_subbuf() +
workVarCount*sample_count + root->offset;
for( int i = 0; i < count; i++ )
sample_idx_dst[i] = sample_idx_src[sidx[i]];
int* idst = 0;
unsigned short* udst = 0;
+ uint64 effective_buf_size = 0;
+ int effective_buf_height = 0, effective_buf_width = 0;
+
+
clear();
shared = true;
have_labels = true;
var_type->data.i[var_count] = cat_var_count;
var_type->data.i[var_count+1] = cat_var_count+1;
work_var_count = ( cat_var_count ? 0 : numPrecalcIdx ) + 1/*cv_lables*/;
- buf_size = (work_var_count + 1) * sample_count/*sample_indices*/;
buf_count = 2;
+ buf_size = -1; // the member buf_size is obsolete
+
+ effective_buf_size = (uint64)(work_var_count + 1)*(uint64)sample_count * buf_count; // this is the total size of "CvMat buf" to be allocated
+ effective_buf_width = sample_count;
+ effective_buf_height = work_var_count+1;
+
+ if (effective_buf_width >= effective_buf_height)
+ effective_buf_height *= buf_count;
+ else
+ effective_buf_width *= buf_count;
+
+ if ((uint64)effective_buf_width * (uint64)effective_buf_height != effective_buf_size)
+ {
+ CV_Error(CV_StsBadArg, "The memory buffer cannot be allocated since its size exceeds integer fields limit");
+ }
+
if ( is_buf_16u )
- buf = cvCreateMat( buf_count, buf_size, CV_16UC1 );
+ buf = cvCreateMat( effective_buf_height, effective_buf_width, CV_16UC1 );
else
- buf = cvCreateMat( buf_count, buf_size, CV_32SC1 );
+ buf = cvCreateMat( effective_buf_height, effective_buf_width, CV_32SC1 );
cat_count = cvCreateMat( 1, cat_var_count + 1, CV_32SC1 );
priors_mult = cvCloneMat( priors );
counts = cvCreateMat( 1, get_num_classes(), CV_32SC1 );
direction = cvCreateMat( 1, sample_count, CV_8UC1 );
- split_buf = cvCreateMat( 1, sample_count, CV_32SC1 );
+ split_buf = cvCreateMat( 1, sample_count, CV_32SC1 );//TODO: make a pointer
}
void CvCascadeBoostTrainData::free_train_data()
if ( vi < numPrecalcIdx )
{
if( !is_buf_16u )
- *sortedIndices = buf->data.i + n->buf_idx*buf->cols + vi*sample_count + n->offset;
+ *sortedIndices = buf->data.i + n->buf_idx*get_length_subbuf() + vi*sample_count + n->offset;
else
{
- const unsigned short* shortIndices = (const unsigned short*)(buf->data.s + n->buf_idx*buf->cols +
+ const unsigned short* shortIndices = (const unsigned short*)(buf->data.s + n->buf_idx*get_length_subbuf() +
vi*sample_count + n->offset );
for( int i = 0; i < nodeSampleCount; i++ )
sortedIndicesBuf[i] = shortIndices[i];
int newBufIdx = data->get_child_buf_idx( node );
int workVarCount = data->get_work_var_count();
CvMat* buf = data->buf;
+ size_t length_buf_row = data->get_length_subbuf();
cv::AutoBuffer<uchar> inn_buf(n*(3*sizeof(int)+sizeof(float)));
int* tempBuf = (int*)(uchar*)inn_buf;
bool splitInputData;
if (data->is_buf_16u)
{
ushort *ldst, *rdst;
- ldst = (ushort*)(buf->data.s + left->buf_idx*buf->cols +
+ ldst = (ushort*)(buf->data.s + left->buf_idx*length_buf_row +
vi*scount + left->offset);
rdst = (ushort*)(ldst + nl);
else
{
int *ldst, *rdst;
- ldst = buf->data.i + left->buf_idx*buf->cols +
+ ldst = buf->data.i + left->buf_idx*length_buf_row +
vi*scount + left->offset;
- rdst = buf->data.i + right->buf_idx*buf->cols +
+ rdst = buf->data.i + right->buf_idx*length_buf_row +
vi*scount + right->offset;
// split sorted
if (data->is_buf_16u)
{
- unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*buf->cols +
+ unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*length_buf_row +
(workVarCount-1)*scount + left->offset);
- unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*buf->cols +
+ unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*length_buf_row +
(workVarCount-1)*scount + right->offset);
for( int i = 0; i < n; i++ )
}
else
{
- int *ldst = buf->data.i + left->buf_idx*buf->cols +
+ int *ldst = buf->data.i + left->buf_idx*length_buf_row +
(workVarCount-1)*scount + left->offset;
- int *rdst = buf->data.i + right->buf_idx*buf->cols +
+ int *rdst = buf->data.i + right->buf_idx*length_buf_row +
(workVarCount-1)*scount + right->offset;
for( int i = 0; i < n; i++ )
if (data->is_buf_16u)
{
- unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
+ unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*length_buf_row +
workVarCount*scount + left->offset);
- unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*buf->cols +
+ unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*length_buf_row +
workVarCount*scount + right->offset);
for (int i = 0; i < n; i++)
{
}
else
{
- int* ldst = buf->data.i + left->buf_idx*buf->cols +
+ int* ldst = buf->data.i + left->buf_idx*length_buf_row +
workVarCount*scount + left->offset;
- int* rdst = buf->data.i + right->buf_idx*buf->cols +
+ int* rdst = buf->data.i + right->buf_idx*length_buf_row +
workVarCount*scount + right->offset;
for (int i = 0; i < n; i++)
{
sampleIdx = data->get_sample_indices( data->data_root, sampleIdxBuf );
}
CvMat* buf = data->buf;
+ size_t length_buf_row = data->get_length_subbuf();
if( !tree ) // before training the first tree, initialize weights and other parameters
{
int* classLabelsBuf = (int*)cur_inn_buf_pos; cur_inn_buf_pos = (uchar*)(classLabelsBuf + n);
if (data->is_buf_16u)
{
- unsigned short* labels = (unsigned short*)(buf->data.s + data->data_root->buf_idx*buf->cols +
+ unsigned short* labels = (unsigned short*)(buf->data.s + data->data_root->buf_idx*length_buf_row +
data->data_root->offset + (data->work_var_count-1)*data->sample_count);
for( int i = 0; i < n; i++ )
{
}
else
{
- int* labels = buf->data.i + data->data_root->buf_idx*buf->cols +
+ int* labels = buf->data.i + data->data_root->buf_idx*length_buf_row +
data->data_root->offset + (data->work_var_count-1)*data->sample_count;
for( int i = 0; i < n; i++ )
include $(PREBUILT_SHARED_LIBRARY)
endef
-ifeq ($(OPENCV_INSTALL_MODULES),on)
-$(foreach module,$(OPENCV_LIBS),$(eval $(call add_opencv_module,$(module))))
-endif
-$(foreach module,$(OPENCV_3RDPARTY_COMPONENTS),$(eval $(call add_opencv_3rdparty_component,$(module))))
-$(foreach module,$(OPENCV_CAMERA_MODULES),$(eval $(call add_opencv_camera_module,$(module))))
+ifeq ($(OPENCV_MK_ALREADY_INCLUDED),)
+ ifeq ($(OPENCV_INSTALL_MODULES),on)
+ $(foreach module,$(OPENCV_LIBS),$(eval $(call add_opencv_module,$(module))))
+ endif
+
+ $(foreach module,$(OPENCV_3RDPARTY_COMPONENTS),$(eval $(call add_opencv_3rdparty_component,$(module))))
+ $(foreach module,$(OPENCV_CAMERA_MODULES),$(eval $(call add_opencv_camera_module,$(module))))
+
+ ifneq ($(OPENCV_BASEDIR),)
+ OPENCV_LOCAL_C_INCLUDES += $(foreach mod, $(OPENCV_MODULES), $(OPENCV_BASEDIR)/modules/$(mod)/include)
+ endif
-ifneq ($(OPENCV_BASEDIR),)
- OPENCV_LOCAL_C_INCLUDES += $(foreach mod, $(OPENCV_MODULES), $(OPENCV_BASEDIR)/modules/$(mod)/include)
+ #turn off module installation to prevent their redefinition
+ OPENCV_MK_ALREADY_INCLUDED:=on
endif
ifeq ($(OPENCV_LOCAL_CFLAGS),)
{
const int dir[][2] = { {-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1} };
coordinate_t next;
- coordinate_t next_temp;
unsigned char ptr;
assert (direction==-1 || !coords.empty());
void ChamferMatcher::Matching::addTemplateFromImage(Mat& templ, float scale)
{
Template* cmt = new Template(templ, scale);
- if(templates.size() > 0)
- templates.clear();
+ templates.clear();
templates.push_back(cmt);
cmt->show();
}
void ChamferMatcher::Matching::addTemplate(Template& template_){
- if(templates.size() > 0)
- templates.clear();
+ templates.clear();
templates.push_back(&template_);
}
/**
* ``"SIFT"`` -- :ocv:class:`SIFT`
* ``"SURF"`` -- :ocv:class:`SURF`
* ``"ORB"`` -- :ocv:class:`ORB`
+ * ``"BRISK"`` -- :ocv:class:`BRISK`
* ``"BRIEF"`` -- :ocv:class:`BriefDescriptorExtractor`
A combined format is also supported: descriptor extractor adapter name ( ``"Opponent"`` --
.. ocv:function:: BFMatcher::BFMatcher( int normType=NORM_L2, bool crossCheck=false )
- :param normType: One of ``NORM_L1``, ``NORM_L2``, ``NORM_HAMMING``, ``NORM_HAMMING2``. ``L1`` and ``L2`` norms are preferable choices for SIFT and SURF descriptors, ``NORM_HAMMING`` should be used with ORB and BRIEF, ``NORM_HAMMING2`` should be used with ORB when ``WTA_K==3`` or ``4`` (see ORB::ORB constructor description).
+ :param normType: One of ``NORM_L1``, ``NORM_L2``, ``NORM_HAMMING``, ``NORM_HAMMING2``. ``L1`` and ``L2`` norms are preferable choices for SIFT and SURF descriptors, ``NORM_HAMMING`` should be used with ORB, BRISK and BRIEF, ``NORM_HAMMING2`` should be used with ORB when ``WTA_K==3`` or ``4`` (see ORB::ORB constructor description).
:param crossCheck: If it is false, this is will be default BFMatcher behaviour when it finds the k nearest neighbors for each query descriptor. If ``crossCheck==true``, then the ``knnMatch()`` method with ``k=1`` will only return pairs ``(i,j)`` such that for ``i-th`` query descriptor the ``j-th`` descriptor in the matcher's collection is the nearest and vice versa, i.e. the ``BFMathcher`` will only return consistent pairs. Such technique usually produces best results with minimal number of outliers when there are enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper.
* ``"SIFT"`` -- :ocv:class:`SIFT` (nonfree module)
* ``"SURF"`` -- :ocv:class:`SURF` (nonfree module)
* ``"ORB"`` -- :ocv:class:`ORB`
+* ``"BRISK"`` -- :ocv:class:`BRISK`
* ``"MSER"`` -- :ocv:class:`MSER`
* ``"GFTT"`` -- :ocv:class:`GoodFeaturesToTrackDetector`
* ``"HARRIS"`` -- :ocv:class:`GoodFeaturesToTrackDetector` with Harris detector enabled
:param useProvidedKeypoints: If it is true, then the method will use the provided vector of keypoints instead of detecting them.
+BRISK
+-----
+.. ocv:class:: BRISK : public Feature2D
+
+Class implementing the BRISK keypoint detector and descriptor extractor, described in [LCS11]_.
+
+.. [LCS11] Stefan Leutenegger, Margarita Chli and Roland Siegwart: BRISK: Binary Robust Invariant Scalable Keypoints. ICCV 2011: 2548-2555.
+
+BRISK::BRISK
+------------
+The BRISK constructor
+
+.. ocv:function:: BRISK::BRISK(int thresh=30, int octaves=3, float patternScale=1.0f)
+
+ :param thresh: FAST/AGAST detection threshold score.
+
+ :param octaves: detection octaves. Use 0 to do single scale.
+
+ :param patternScale: apply this scale to the pattern used for sampling the neighbourhood of a keypoint.
+
+BRISK::BRISK
+------------
+The BRISK constructor for a custom pattern
+
+.. ocv:function:: BRISK::BRISK(std::vector<float> &radiusList, std::vector<int> &numberList, float dMax=5.85f, float dMin=8.2f, std::vector<int> indexChange=std::vector<int>())
+
+ :param radiusList: defines the radii (in pixels) where the samples around a keypoint are taken (for keypoint scale 1).
+
+ :param numberList: defines the number of sampling points on the sampling circle. Must be the same size as radiusList..
+
+ :param dMax: threshold for the short pairings used for descriptor formation (in pixels for keypoint scale 1).
+
+ :param dMin: threshold for the long pairings used for orientation determination (in pixels for keypoint scale 1).
+
+ :param indexChanges: index remapping of the bits.
+
+BRISK::operator()
+-----------------
+Finds keypoints in an image and computes their descriptors
+
+.. ocv:function:: void BRISK::operator()(InputArray image, InputArray mask, vector<KeyPoint>& keypoints, OutputArray descriptors, bool useProvidedKeypoints=false ) const
+
+ :param image: The input 8-bit grayscale image.
+
+ :param mask: The operation mask.
+
+ :param keypoints: The output vector of keypoints.
+
+ :param descriptors: The output descriptors. Pass ``cv::noArray()`` if you do not need it.
+
+ :param useProvidedKeypoints: If it is true, then the method will use the provided vector of keypoints instead of detecting them.
+
FREAK
-----
.. ocv:class:: FREAK : public DescriptorExtractor
{
indexChange.resize(points_ * (points_ - 1) / 2);
indSize = (unsigned int)indexChange.size();
- }
- for (unsigned int i = 0; i < indSize; i++)
- {
- indexChange[i] = i;
+
+ for (unsigned int i = 0; i < indSize; i++)
+ indexChange[i] = i;
}
const float dMin_sq = dMin_ * dMin_;
const float dMax_sq = dMax_ * dMax_;
struct IntersectAreaCounter
{
- IntersectAreaCounter() : bua(0), bna(0) {}
IntersectAreaCounter( float _dr, int _minx,
int _miny, int _maxy,
const Point2f& _diff,
void operator()( const BlockedRange& range )
{
+ CV_Assert( miny < maxy );
+ CV_Assert( dr > FLT_EPSILON );
+
int temp_bua = bua, temp_bna = bna;
for( int i = range.begin(); i != range.end(); i++ )
{
keypoints2 = _keypoints2 != 0 ? _keypoints2 : &buf2;
if( (keypoints1->empty() || keypoints2->empty()) && fdetector.empty() )
- CV_Error( CV_StsBadArg, "fdetector must be no empty when keypoints1 or keypoints2 is empty" );
+ CV_Error( CV_StsBadArg, "fdetector must not be empty when keypoints1 or keypoints2 is empty" );
if( keypoints1->empty() )
fdetector->detect( img1, *keypoints1 );
correctMatches1to2Mask = _correctMatches1to2Mask != 0 ? _correctMatches1to2Mask : &buf2;
if( keypoints1.empty() )
- CV_Error( CV_StsBadArg, "keypoints1 must be no empty" );
+ CV_Error( CV_StsBadArg, "keypoints1 must not be empty" );
if( matches1to2->empty() && dmatcher.empty() )
- CV_Error( CV_StsBadArg, "dmatch must be no empty when matches1to2 is empty" );
+ CV_Error( CV_StsBadArg, "dmatch must not be empty when matches1to2 is empty" );
bool computeKeypoints2ByPrj = keypoints2.empty();
if( computeKeypoints2ByPrj )
haar.bNeedsTiltedII = false;
Ncv32u curMaxTreeDepth;
- std::vector<char> xmlFileCont;
-
std::vector<HaarClassifierNode128> h_TmpClassifierNotRootNodes;
haarStages.resize(0);
haarClassifierNodes.resize(0);
void init();
int index, width, height,fourcc;
+ int widthSet, heightSet;
IplImage* frame;
static videoInput VI;
};
index = -1;
frame = 0;
width = height = fourcc = -1;
+ widthSet = heightSet = -1;
CoInitialize(0);
}
index = -1;
cvReleaseImage(&frame);
}
- width = height = -1;
+ widthSet = heightSet = width = height = -1;
}
// Initialize camera input
{
VI.stopDevice(index);
VI.setIdealFramerate(index,fps);
- VI.setupDevice(index);
+ if (widthSet > 0 && heightSet > 0)
+ VI.setupDevice(index, widthSet, heightSet);
+ else
+ VI.setupDevice(index);
}
- break;
+ return VI.isDeviceSetup(index);
}
VI.setIdealFramerate(index, fps);
VI.setupDeviceFourcc(index, width, height, fourcc);
}
- width = height = fourcc = -1;
- return VI.isDeviceSetup(index);
+
+ bool success = VI.isDeviceSetup(index);
+ if (success)
+ {
+ widthSet = width;
+ heightSet = height;
+ width = height = fourcc = -1;
+ }
+ return success;
}
return true;
}
--- /dev/null
+////////////////////////////////////////////////////////////////////////////////////////
+//
+// 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.
+//
+//
+
+//
+// The code has been contributed by Vladimir N. Litvinenko on 2012 Jul
+// mailto:vladimir.litvinenko@codepaint.ru
+//
+
+#include "precomp.hpp"
+#include <GigEVisionSDK.h>
+#include <GigEVisionSDK.cpp>
+
+#ifdef WIN32
+#include <io.h>
+#else
+#include <stdio.h>
+#endif
+
+#ifdef NDEBUG
+#define CV_WARN(message)
+#else
+#define CV_WARN(message) fprintf(stderr, "warning: %s (%s:%d)\n", message, __FILE__, __LINE__)
+#endif
+
+#define QTGIG_HEARTBEAT_TIME (12000.0)
+#define QTGIG_MAX_WAIT_TIME (2.0)
+#define QTGIG_IMG_WAIT_TIME (3.0)
+
+/*----------------------------------------------------------------------------*/
+/**
+ \internal
+ \fn bool wrprInitGigEVisionAPI();
+ \brief Wrapper to GigEVisionAPI function gige::InitGigEVisionAPI ()
+ \return true -- success
+ See \a wrprExitGigEVisionAPI
+
+*/
+bool
+wrprInitGigEVisionAPI()
+{
+ CV_FUNCNAME("wrprInitGigEVisionAPI");
+ __BEGIN__;
+
+ try {
+ gige::InitGigEVisionAPI ();
+ } catch(...) {
+ CV_ERROR(CV_StsError, "GigEVisionAPI: initialization (InitGigEVisionAPI()) failed.\n");
+ }
+ __END__;
+ return true;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ \internal
+ \fn void wrprExitGigEVisionAPI()
+ \brief Wrapper to GigEVisionAPI function gige::ExitGigEVisionAPI ()
+ \return true -- success
+ See \a wrprInitGigEVisionAPI
+
+*/
+bool
+wrprExitGigEVisionAPI()
+{
+ CV_FUNCNAME("wrprExitGigEVisionAPI");
+ __BEGIN__;
+
+ try {
+ gige::ExitGigEVisionAPI ();
+ } catch(...) {
+ CV_ERROR(CV_StsError, "GigEVisionAPI: finalization (ExitGigEVisionAPI()) failed.\n");
+ return false;
+ }
+ __END__;
+ return true;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ \internal
+ \fn gige::IGigEVisionAPI wrprGetGigEVisionAPI()
+ \brief Wrapper to GigEVisionAPI function gige::GetGigEVisionAPI ()
+ \return item of gige::IGigEVisionAPI type
+ See \a wrprInitGigEVisionAPI, \a gige::IGigEVisionAPI
+*/
+gige::IGigEVisionAPI
+wrprGetGigEVisionAPI()
+{
+
+ gige::IGigEVisionAPI b_ret = 0;
+
+ CV_FUNCNAME("wrprGetGigEVisionAPI");
+ __BEGIN__;
+
+ try {
+ b_ret = gige::GetGigEVisionAPI ();
+ } catch(...) {
+ CV_ERROR(CV_StsError, "GigEVisionAPI: API instance (from GetGigEVisionAPI()) failed.\n");
+ }
+
+ __END__;
+
+ return b_ret;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ \internal
+ \fn bool wrprUnregisterCallback( const gige::IGigEVisionAPI* api, gige::ICallbackEvent* eventHandler)
+ \brief Wrapper to GigEVisionAPI function
+ \param api
+ \param eventHandler
+ \return true - succsess, else - false
+ See \a wrprInitGigEVisionAPI, \a gige::IGigEVisionAPI
+
+*/
+bool
+wrprUnregisterCallback( const gige::IGigEVisionAPI* api, gige::ICallbackEvent* eventHandler)
+{
+ bool b_ret = api != NULL;
+
+ if(b_ret) b_ret = api->IsValid ();
+
+ CV_FUNCNAME("wrprUnregisterCallback");
+ __BEGIN__;
+
+ if(b_ret)
+ {
+ if(eventHandler != NULL)
+ {
+ try {
+ b_ret = ((gige::IGigEVisionAPIInterface*)api)->UnregisterCallback (eventHandler);
+ } catch(...) {
+ CV_ERROR(CV_StsError, "GigEVisionAPI: API unregister callback function (from UnregisterCallback()) failed.\n");
+ b_ret = false;
+ }
+ }
+ }
+ __END__;
+
+ return (b_ret);
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ \internal
+ \fn bool wrprDeviceIsConnect( gige::IDevice& device )
+ \brief Wrapper to GigEVisionAPI function IDevice::IsConnected()
+ \param device - selected device
+ \return true - device connected
+*/
+bool
+wrprDeviceIsConnect( gige::IDevice& device )
+{
+ bool b_ret = device != NULL;
+
+ CV_FUNCNAME("wrprDeviceIsConnect");
+ __BEGIN__;
+
+ if(b_ret)
+ {
+ try {
+ b_ret = device->IsConnected ();
+ } catch (...) {
+ CV_ERROR(CV_StsError, "GigEVisionAPI: API device connection state (from IsConnected()) failed.\n");
+ b_ret = false;
+ }
+ }
+ __END__;
+
+ return (b_ret);
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ \internal
+ \fn bool wrprDeviceIsValid( gige::IDevice& device )
+ \brief Wrapper to GigEVisionAPI function IDevice::Connect()
+ \param device - selected device
+ \return true - device valid
+
+*/
+bool
+wrprDeviceIsValid( gige::IDevice& device )
+{
+ bool b_ret = device != NULL;
+
+ CV_FUNCNAME("wrprDeviceIsConnect");
+ __BEGIN__;
+
+ if(b_ret)
+ {
+ try {
+ b_ret = device.IsValid ();
+ } catch (...) {
+ CV_ERROR(CV_StsError, "GigEVisionAPI: API device validation state (from IsValid()) failed.\n");
+ b_ret = false;
+ }
+ }
+ __END__;
+
+ return (b_ret);
+}
+
+
+/*----------------------------------------------------------------------------*/
+/**
+ \internal
+ \fn bool wrprDeviceDisconnect ( gige::IDevice& device )
+ \brief Wrapper to GigEVisionAPI function IDevice::Disconnect()
+ \param device - selected device
+ \return true - device valid
+
+*/
+bool
+wrprDeviceDisconnect ( gige::IDevice& device )
+{
+ bool b_ret = device != NULL;
+
+ CV_FUNCNAME("wrprDeviceDisconnect");
+ __BEGIN__;
+
+ if(b_ret)
+ {
+ try {
+ device->Disconnect ();
+ } catch (...) {
+ CV_ERROR(CV_StsError, "GigEVisionAPI: API device disconnect (from Disconnect()) failed.\n");
+ b_ret = false;
+ }
+ }
+
+ __END__;
+
+ return (b_ret);
+}
+
+
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+/**
+ \internal
+ \class CvCaptureCAM_Giganetix
+ \brief Capturing video from camera via Smartec Giganetix (use GigEVisualSDK library).
+*/
+
+class CvCaptureCAM_Giganetix : public CvCapture
+{
+ public:
+ CvCaptureCAM_Giganetix();
+ virtual ~CvCaptureCAM_Giganetix();
+
+ virtual bool open( int index );
+ virtual void close();
+ virtual double getProperty(int);
+ virtual bool setProperty(int, double);
+ virtual bool grabFrame();
+ virtual IplImage* retrieveFrame(int);
+ virtual int getCaptureDomain()
+ {
+ return CV_CAP_GIGANETIX;
+ }
+
+ bool start ();
+ bool stop ();
+
+ protected:
+
+ void init ();
+ void grabImage ();
+
+ gige::IGigEVisionAPI m_api;
+ bool m_api_on;
+ gige::IDevice m_device;
+ bool m_active;
+
+ IplImage* m_raw_image;
+ UINT32 m_rawImagePixelType;
+ bool m_monocrome;
+
+};
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+void
+CvCaptureCAM_Giganetix::init ()
+{
+ m_monocrome = m_active = m_api_on = false;
+ m_api = 0;
+ m_device = 0;
+ m_raw_image = 0;
+ m_rawImagePixelType = 0;
+}
+
+/*----------------------------------------------------------------------------*/
+CvCaptureCAM_Giganetix::CvCaptureCAM_Giganetix()
+{
+ init ();
+
+ m_api_on = wrprInitGigEVisionAPI ();
+
+ if(m_api_on)
+ {
+ if((m_api = wrprGetGigEVisionAPI ()) != NULL)
+ {
+ m_api->SetHeartbeatTime (QTGIG_HEARTBEAT_TIME);
+ }
+ }
+}
+
+/*----------------------------------------------------------------------------*/
+CvCaptureCAM_Giganetix::~CvCaptureCAM_Giganetix()
+{
+ close();
+}
+/*----------------------------------------------------------------------------*/
+void
+CvCaptureCAM_Giganetix::close()
+{
+ stop ();
+
+ (void)wrprDeviceDisconnect(m_device);
+
+ (void)wrprExitGigEVisionAPI ();
+
+ if(m_raw_image) cvReleaseImageHeader(&m_raw_image);
+
+ init ();
+}
+
+/*----------------------------------------------------------------------------*/
+bool
+CvCaptureCAM_Giganetix::open( int index )
+{
+ bool b_ret = m_api_on;
+
+ CV_FUNCNAME("CvCaptureCAM_Giganetix::open");
+ __BEGIN__;
+
+ if(b_ret)
+ b_ret = m_api.IsValid ();
+
+ if(b_ret )
+ {
+ m_api->FindAllDevices (QTGIG_MAX_WAIT_TIME);
+
+ //TODO - serch device as DevicesList member
+ gige::DevicesList DevicesList = m_api->GetAllDevices ();
+
+ m_device = 0;
+ b_ret = false;
+
+ for (int i = 0; i < (int) DevicesList.size() && !b_ret; i++)
+ {
+ if((b_ret = i == index))
+ {
+ m_device = DevicesList[i];
+ b_ret = m_device->Connect ();
+
+ if(b_ret)
+ {
+ b_ret =
+ m_device->SetStringNodeValue("AcquisitionStatusSelector", "AcquisitionActive")
+ &&
+ m_device->SetStringNodeValue ("TriggerMode", "Off")
+ &&
+ m_device->SetStringNodeValue ("AcquisitionMode", "Continuous")
+ &&
+ m_device->SetIntegerNodeValue ("AcquisitionFrameCount", 20)
+ ;
+ }
+ }
+ } // for
+ }
+
+ if(!b_ret)
+ {
+ CV_ERROR(CV_StsError, "Giganetix: Error cannot find camera\n");
+ close ();
+ } else {
+ start ();
+ }
+
+ __END__;
+
+ return b_ret;
+}
+
+/*----------------------------------------------------------------------------*/
+void
+CvCaptureCAM_Giganetix::grabImage ()
+{
+ CV_FUNCNAME("CvCaptureCAM_Giganetix::grabImage");
+ __BEGIN__;
+
+ if(wrprDeviceIsValid(m_device) && wrprDeviceIsConnect(m_device))
+ {
+ if(!m_device->IsBufferEmpty ())
+ {
+ gige::IImageInfo imageInfo;
+ m_device->GetImageInfo (&imageInfo);
+ assert(imageInfo.IsValid());
+
+ if (m_device->GetPendingImagesCount() == 1)
+ {
+ UINT32 newPixelType;
+ UINT32 newWidth, newHeight;
+
+ imageInfo->GetPixelType(newPixelType);
+ imageInfo->GetSize(newWidth, newHeight);
+
+ //TODO - validation of image exists
+ bool b_validation = m_raw_image != NULL;
+ if(b_validation)
+ {
+ b_validation =
+ m_raw_image->imageSize == (int)(imageInfo->GetRawDataSize ())
+ &&
+ m_rawImagePixelType == newPixelType;
+ } else {
+ if(m_raw_image) cvReleaseImageHeader(&m_raw_image);
+ }
+
+ m_rawImagePixelType = newPixelType;
+ m_monocrome = GvspGetBitsPerPixel((GVSP_PIXEL_TYPES)newPixelType) == IPL_DEPTH_8U;
+
+ try {
+ if (m_monocrome)
+ {
+ //TODO - For Mono & Color BayerRGB raw pixel types
+ if (!b_validation)
+ {
+ m_raw_image = cvCreateImageHeader (cvSize((int)newWidth, (int)newHeight),IPL_DEPTH_8U,1);
+ m_raw_image->origin = IPL_ORIGIN_TL;
+ m_raw_image->dataOrder = IPL_DATA_ORDER_PIXEL;
+ m_raw_image->widthStep = newWidth;
+ }
+ // Copy image.
+ // ::memcpy(m_raw_image->imageData, imageInfo->GetRawData (), imageInfo->GetRawDataSize ());
+
+ //TODO - Set pointer to image !
+ m_raw_image->imageData = (char*)(imageInfo->GetRawData ());
+ }
+
+ if (!m_monocrome && newPixelType == GVSP_PIX_RGB8_PACKED)
+ {
+ //TODO - 24 bit RGB color image.
+ if (!b_validation)
+ {
+ m_raw_image = cvCreateImageHeader (cvSize((int)newWidth, (int)newHeight), IPL_DEPTH_32F, 3);
+ m_raw_image->origin = IPL_ORIGIN_TL;
+ m_raw_image->dataOrder = IPL_DATA_ORDER_PIXEL;
+ m_raw_image->widthStep = newWidth * 3;
+ }
+ m_raw_image->imageData = (char*)(imageInfo->GetRawData ());
+ }
+ } catch (...) {
+ CV_ERROR(CV_StsError, "Giganetix: failed to queue a buffer on device\n");
+ close ();
+ }
+ } else {
+ //TODO - all other pixel types
+ m_raw_image = 0;
+ CV_WARN("Giganetix: Undefined image pixel type\n");
+ }
+ m_device->PopImage (imageInfo);
+ m_device->ClearImageBuffer ();
+ }
+ }
+
+ __END__;
+}
+
+/*----------------------------------------------------------------------------*/
+bool
+CvCaptureCAM_Giganetix::start ()
+{
+ CV_FUNCNAME("CvCaptureCAM_Giganetix::start");
+ __BEGIN__;
+
+ m_active = wrprDeviceIsValid(m_device) && wrprDeviceIsConnect(m_device);
+
+ if(m_active)
+ {
+ (void)m_device->SetIntegerNodeValue("TLParamsLocked", 1);
+ (void)m_device->CommandNodeExecute("AcquisitionStart");
+ m_active = m_device->GetBooleanNodeValue("AcquisitionStatus", m_active);
+ }
+
+ if(!m_active)
+ {
+ CV_ERROR(CV_StsError, "Giganetix: Cannot open camera\n");
+ close ();
+ }
+
+ __END__;
+
+ return m_active;
+}
+
+/*----------------------------------------------------------------------------*/
+bool
+CvCaptureCAM_Giganetix::stop ()
+{
+ if (!m_active) return true;
+
+ CV_FUNCNAME("CvCaptureCAM_Giganetix::stop");
+ __BEGIN__;
+
+ if(wrprDeviceIsValid(m_device) && wrprDeviceIsConnect(m_device))
+ {
+ (void)m_device->GetBooleanNodeValue("AcquisitionStatus", m_active);
+
+ if(m_active)
+ {
+ (void)m_device->CommandNodeExecute("AcquisitionStop");
+ (void)m_device->SetIntegerNodeValue("TLParamsLocked", 0);
+ m_device->ClearImageBuffer ();
+ (void)m_device->GetBooleanNodeValue("AcquisitionStatus", m_active);
+ }
+ }
+
+ if(m_active)
+ {
+ CV_ERROR(CV_StsError, "Giganetix: Improper closure of the camera\n");
+ close ();
+ }
+ __END__;
+
+ return !m_active;
+}
+
+/*----------------------------------------------------------------------------*/
+bool
+CvCaptureCAM_Giganetix::grabFrame()
+{
+ bool b_ret =
+ wrprDeviceIsValid(m_device)
+ &&
+ wrprDeviceIsConnect(m_device);
+
+ if(b_ret) grabImage ();
+
+ return b_ret;
+}
+
+
+/*----------------------------------------------------------------------------*/
+IplImage*
+CvCaptureCAM_Giganetix::retrieveFrame(int)
+{
+ return (
+ wrprDeviceIsValid(m_device) && wrprDeviceIsConnect(m_device) ?
+ m_raw_image :
+ NULL
+ );
+}
+
+/*----------------------------------------------------------------------------*/
+double
+CvCaptureCAM_Giganetix::getProperty( int property_id )
+{
+ double d_ret = -1.0;
+ INT64 i;
+
+ if(wrprDeviceIsConnect(m_device))
+ {
+ switch ( property_id )
+ {
+ case CV_CAP_PROP_FRAME_WIDTH:
+ m_device->GetIntegerNodeValue ("Width", i);
+ d_ret = i;
+ break;
+ case CV_CAP_PROP_FRAME_HEIGHT:
+ m_device->GetIntegerNodeValue ("Height", i);
+ d_ret = i;
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_OFFSET_X:
+ m_device->GetIntegerNodeValue ("OffsetX", i);
+ d_ret = i;
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_OFFSET_Y:
+ m_device->GetIntegerNodeValue ("OffsetY", i);
+ d_ret = i;
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_WIDTH_MAX:
+ m_device->GetIntegerNodeValue ("WidthMax", i);
+ d_ret = i;
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_HEIGH_MAX:
+ m_device->GetIntegerNodeValue ("HeightMax", i);
+ d_ret = i;
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_SENS_WIDTH:
+ m_device->GetIntegerNodeValue ("SensorWidth", i);
+ d_ret = i;
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_SENS_HEIGH:
+ m_device->GetIntegerNodeValue ("SensorHeight", i);
+ d_ret = i;
+ break;
+ case CV_CAP_PROP_FRAME_COUNT:
+ m_device->GetIntegerNodeValue ("AcquisitionFrameCount", i);
+ d_ret = i;
+ break;
+ case CV_CAP_PROP_EXPOSURE:
+ m_device->GetFloatNodeValue ("ExposureTime",d_ret);
+ break;
+ case CV_CAP_PROP_GAIN :
+ m_device->GetFloatNodeValue ("Gain",d_ret);
+ break;
+ case CV_CAP_PROP_TRIGGER :
+ bool b;
+ m_device->GetBooleanNodeValue ("TriggerMode",b);
+ d_ret = (double)b;
+ break;
+ case CV_CAP_PROP_TRIGGER_DELAY :
+ m_device->GetFloatNodeValue ("TriggerDelay",d_ret);
+ break;
+ default : ;
+ }
+ }
+
+ return d_ret;
+}
+
+/*----------------------------------------------------------------------------*/
+bool
+CvCaptureCAM_Giganetix::setProperty( int property_id, double value )
+{
+ bool b_ret = wrprDeviceIsConnect(m_device);
+
+ if(b_ret)
+ {
+ bool b_val = m_active;
+
+ switch ( property_id )
+ {
+ case CV_CAP_PROP_FRAME_WIDTH:
+ stop ();
+ b_ret = m_device->SetIntegerNodeValue ("Width", (INT64)value);
+ if(b_val) start ();
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_WIDTH_MAX:
+ stop ();
+ b_ret = m_device->SetIntegerNodeValue ("WidthMax", (INT64)value);
+ if(b_val) start ();
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_SENS_WIDTH:
+ stop ();
+ b_ret = m_device->SetIntegerNodeValue ("SensorWidth", (INT64)value);
+ if(b_val) start ();
+ break;
+ case CV_CAP_PROP_FRAME_HEIGHT:
+ stop ();
+ b_ret = m_device->SetIntegerNodeValue ("Height", (INT64)value);
+ if(b_val) start ();
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_HEIGH_MAX:
+ stop ();
+ b_ret = m_device->SetIntegerNodeValue ("HeightMax", (INT64)value);
+ if(b_val) start ();
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_SENS_HEIGH:
+ stop ();
+ b_ret = m_device->SetIntegerNodeValue ("SensorHeight", (INT64)value);
+ if(b_val) start ();
+ break;
+ case CV_CAP_PROP_GIGA_FRAME_OFFSET_X: {
+ INT64 w, wmax, val = (INT64)value;
+ if((b_ret = m_device->GetIntegerNodeValue ("Width", w)))
+ if((b_ret = m_device->GetIntegerNodeValue ("WidthMax", wmax)))
+ b_ret = m_device->SetIntegerNodeValue ("OffsetX", val w > wmax ? wmax - w : val);
+ } break;
+ case CV_CAP_PROP_GIGA_FRAME_OFFSET_Y: {
+ INT64 h, hmax, val = (INT64)value;
+ if((b_ret = m_device->GetIntegerNodeValue ("Height", h)))
+ if((b_ret = m_device->GetIntegerNodeValue ("HeightMax", hmax)))
+ b_ret = m_device->SetIntegerNodeValue ("OffsetY", val h > hmax ? hmax - h : val);
+ b_ret = m_device->SetIntegerNodeValue ("OffsetY", (INT64)value);
+ }
+ break;
+ case CV_CAP_PROP_EXPOSURE:
+ b_ret = m_device->SetFloatNodeValue ("ExposureTime",value);
+ break;
+ case CV_CAP_PROP_GAIN :
+ b_ret = m_device->SetFloatNodeValue ("Gain",value);
+ break;
+ case CV_CAP_PROP_TRIGGER :
+ b_ret = m_device->SetBooleanNodeValue ("TriggerMode",(bool)value);
+ break;
+ case CV_CAP_PROP_TRIGGER_DELAY :
+ stop ();
+ b_ret = m_device->SetFloatNodeValue ("TriggerDelay",value);
+ if(b_val) start ();
+ break;
+ default:
+ b_ret = false;
+ }
+ }
+
+ return b_ret;
+}
+
+
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+CvCapture*
+cvCreateCameraCapture_Giganetix( int index )
+{
+ CvCaptureCAM_Giganetix* capture = new CvCaptureCAM_Giganetix;
+
+ if (!(capture->open( index )))
+ {
+ delete capture;
+ capture = NULL;
+ }
+
+ return ((CvCapture*)capture);
+}
+
+/*----------------------------------------------------------------------------*/
--- /dev/null
+#include "perf_precomp.hpp"
+
+using namespace std;
+using namespace cv;
+using namespace perf;
+using std::tr1::make_tuple;
+using std::tr1::get;
+
+CV_ENUM(MethodType, CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED, CV_TM_CCORR, CV_TM_CCORR_NORMED, CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED)
+
+typedef std::tr1::tuple<Size, Size, MethodType> ImgSize_TmplSize_Method_t;
+typedef perf::TestBaseWithParam<ImgSize_TmplSize_Method_t> ImgSize_TmplSize_Method;
+
+PERF_TEST_P(ImgSize_TmplSize_Method, matchTemplateSmall,
+ testing::Combine(
+ testing::Values(szSmall128, cv::Size(320, 240),
+ cv::Size(640, 480), cv::Size(800, 600),
+ cv::Size(1024, 768), cv::Size(1280, 1024)),
+ testing::Values(cv::Size(12, 12), cv::Size(28, 9),
+ cv::Size(8, 30), cv::Size(16, 16)),
+ testing::ValuesIn(MethodType::all())
+ )
+ )
+{
+ Size imgSz = get<0>(GetParam());
+ Size tmplSz = get<1>(GetParam());
+ int method = get<2>(GetParam());
+
+ Mat img(imgSz, CV_8UC1);
+ Mat tmpl(tmplSz, CV_8UC1);
+ Mat result(imgSz - tmplSz + Size(1,1), CV_32F);
+
+ declare
+ .in(img, WARMUP_RNG)
+ .in(tmpl, WARMUP_RNG)
+ .out(result);
+
+ TEST_CYCLE() matchTemplate(img, tmpl, result, method);
+
+ bool isNormed =
+ method == CV_TM_CCORR_NORMED ||
+ method == CV_TM_SQDIFF_NORMED ||
+ method == CV_TM_CCOEFF_NORMED;
+ double eps = isNormed ? 1e-6
+ : 255 * 255 * tmpl.total() * 1e-6;
+
+ SANITY_CHECK(result, eps);
+}
+
+PERF_TEST_P(ImgSize_TmplSize_Method, matchTemplateBig,
+ testing::Combine(
+ testing::Values(cv::Size(1280, 1024)),
+ testing::Values(cv::Size(1260, 1000), cv::Size(1261, 1013)),
+ testing::ValuesIn(MethodType::all())
+ )
+ )
+{
+ Size imgSz = get<0>(GetParam());
+ Size tmplSz = get<1>(GetParam());
+ int method = get<2>(GetParam());
+
+ Mat img(imgSz, CV_8UC1);
+ Mat tmpl(tmplSz, CV_8UC1);
+ Mat result(imgSz - tmplSz + Size(1,1), CV_32F);
+
+ declare
+ .in(img, WARMUP_RNG)
+ .in(tmpl, WARMUP_RNG)
+ .out(result);
+
+ TEST_CYCLE() matchTemplate(img, tmpl, result, method);
+
+ bool isNormed =
+ method == CV_TM_CCORR_NORMED ||
+ method == CV_TM_SQDIFF_NORMED ||
+ method == CV_TM_CCOEFF_NORMED;
+ double eps = isNormed ? 1e-6
+ : 255 * 255 * tmpl.total() * 1e-6;
+
+ SANITY_CHECK(result, eps);
+}
CV_IMPL void
cvCopyHist( const CvHistogram* src, CvHistogram** _dst )
{
- int eq = 0;
- int is_sparse;
- int i, dims1, dims2;
- int size1[CV_MAX_DIM], size2[CV_MAX_DIM], total = 1;
- float* ranges[CV_MAX_DIM];
- float** thresh = 0;
- CvHistogram* dst;
-
if( !_dst )
CV_Error( CV_StsNullPtr, "Destination double pointer is NULL" );
- dst = *_dst;
+ CvHistogram* dst = *_dst;
if( !CV_IS_HIST(src) || (dst && !CV_IS_HIST(dst)) )
CV_Error( CV_StsBadArg, "Invalid histogram header[s]" );
- is_sparse = CV_IS_SPARSE_MAT(src->bins);
- dims1 = cvGetDims( src->bins, size1 );
- for( i = 0; i < dims1; i++ )
- total *= size1[i];
-
- if( dst && is_sparse == CV_IS_SPARSE_MAT(dst->bins))
+ bool eq = false;
+ int size1[CV_MAX_DIM];
+ bool is_sparse = CV_IS_SPARSE_MAT(src->bins);
+ int dims1 = cvGetDims( src->bins, size1 );
+
+ if( dst && (is_sparse == CV_IS_SPARSE_MAT(dst->bins)))
{
- dims2 = cvGetDims( dst->bins, size2 );
+ int size2[CV_MAX_DIM];
+ int dims2 = cvGetDims( dst->bins, size2 );
if( dims1 == dims2 )
{
+ int i;
+
for( i = 0; i < dims1; i++ )
+ {
if( size1[i] != size2[i] )
break;
+ }
+
+ eq = (i == dims1);
}
-
- eq = i == dims1;
}
if( !eq )
if( CV_HIST_HAS_RANGES( src ))
{
+ float* ranges[CV_MAX_DIM];
+ float** thresh = 0;
+
if( CV_IS_UNIFORM_HIST( src ))
{
- for( i = 0; i < dims1; i++ )
+ for( int i = 0; i < dims1; i++ )
ranges[i] = (float*)src->thresh[i];
+
thresh = ranges;
}
else
+ {
thresh = src->thresh2;
+ }
+
cvSetHistBinRanges( dst, thresh, CV_IS_UNIFORM_HIST(src));
}
CV_Assert( std::abs(dsize.width - ssize.width*2) == dsize.width % 2 &&
std::abs(dsize.height - ssize.height*2) == dsize.height % 2);
- int k, x, sy0 = -PU_SZ/2, sy = sy0, width0 = ssize.width - 1;
+ int k, x, sy0 = -PU_SZ/2, sy = sy0;
ssize.width *= cn;
dsize.width *= cn;
- width0 *= cn;
for( x = 0; x < ssize.width; x++ )
dtab[x] = (x/cn)*2*cn + x % cn;
_result.create(corrSize, CV_32F);
Mat result = _result.getMat();
+#ifdef HAVE_TEGRA_OPTIMIZATION
+ if (tegra::matchTemplate(img, templ, result, method))
+ return;
+#endif
+
int cn = img.channels();
crossCorr( img, templ, result, result.size(), result.type(), Point(0,0), 0, 0);
const CvMat* responses;
CvMat* responses_copy; // used in Boosting
- int buf_count, buf_size;
+ int buf_count, buf_size; // buf_size is obsolete, please do not use it, use expression ((int64)buf->rows * (int64)buf->cols / buf_count) instead
bool shared;
int is_buf_16u;
CvMat* counts;
CvMat* buf;
+ inline size_t get_length_subbuf() const
+ {
+ size_t res = (size_t)(work_var_count + 1) * (size_t)sample_count;
+ return res;
+ }
+
CvMat* direction;
CvMat* split_buf;
int *sample_idx_buf;
const int* sample_idx = 0;
cv::AutoBuffer<uchar> inn_buf;
- size_t _buf_size = (params.boost_type == LOGIT) || (params.boost_type == GENTLE) ? data->sample_count*sizeof(int) : 0;
+ size_t _buf_size = (params.boost_type == LOGIT) || (params.boost_type == GENTLE) ? (size_t)(data->sample_count)*sizeof(int) : 0;
if( !tree )
_buf_size += n*sizeof(int);
else
{
if( have_subsample )
- _buf_size += data->buf->cols*(sizeof(float)+sizeof(uchar));
+ _buf_size += data->get_length_subbuf()*(sizeof(float)+sizeof(uchar));
}
inn_buf.allocate(_buf_size);
uchar* cur_buf_pos = (uchar*)inn_buf;
sample_idx = data->get_sample_indices( data->data_root, sample_idx_buf );
}
CvMat* dtree_data_buf = data->buf;
+ size_t length_buf_row = data->get_length_subbuf();
if( !tree ) // before training the first tree, initialize weights and other parameters
{
int* class_labels_buf = (int*)cur_buf_pos;
if (data->is_buf_16u)
{
- unsigned short* labels = (unsigned short*)(dtree_data_buf->data.s + data->data_root->buf_idx*dtree_data_buf->cols +
+ unsigned short* labels = (unsigned short*)(dtree_data_buf->data.s + data->data_root->buf_idx*length_buf_row +
data->data_root->offset + (data->work_var_count-1)*data->sample_count);
for( i = 0; i < n; i++ )
{
}
else
{
- int* labels = dtree_data_buf->data.i + data->data_root->buf_idx*dtree_data_buf->cols +
+ int* labels = dtree_data_buf->data.i + data->data_root->buf_idx*length_buf_row +
data->data_root->offset + (data->work_var_count-1)*data->sample_count;
for( i = 0; i < n; i++ )
if( have_subsample )
{
float* values = (float*)cur_buf_pos;
- cur_buf_pos = (uchar*)(values + data->buf->cols);
+ cur_buf_pos = (uchar*)(values + data->get_length_subbuf());
uchar* missing = cur_buf_pos;
- cur_buf_pos = missing + data->buf->step;
+ cur_buf_pos = missing + data->get_length_subbuf() * (size_t)CV_ELEM_SIZE(data->buf->type);
+
CvMat _sample, _mask;
// invert the subsample mask
char err[100];
const int *sidx = 0, *vidx = 0;
+ uint64 effective_buf_size = 0;
+ int effective_buf_height = 0, effective_buf_width = 0;
+
if ( _params.use_surrogates )
CV_ERROR(CV_StsBadArg, "CvERTrees do not support surrogate splits");
have_labels = cv_n > 0 || (ord_var_count == 1 && cat_var_count == 0) || _add_labels;
work_var_count = cat_var_count + (is_classifier ? 1 : 0) + (have_labels ? 1 : 0);
- buf_size = (work_var_count + 1)*sample_count;
+
shared = _shared;
buf_count = shared ? 2 : 1;
+ buf_size = -1; // the member buf_size is obsolete
+
+ effective_buf_size = (uint64)(work_var_count + 1)*(uint64)sample_count * buf_count; // this is the total size of "CvMat buf" to be allocated
+ effective_buf_width = sample_count;
+ effective_buf_height = work_var_count+1;
+
+ if (effective_buf_width >= effective_buf_height)
+ effective_buf_height *= buf_count;
+ else
+ effective_buf_width *= buf_count;
+
+ if ((uint64)effective_buf_width * (uint64)effective_buf_height != effective_buf_size)
+ {
+ CV_Error(CV_StsBadArg, "The memory buffer cannot be allocated since its size exceeds integer fields limit");
+ }
+
if ( is_buf_16u )
{
- CV_CALL( buf = cvCreateMat( buf_count, buf_size, CV_16UC1 ));
+ CV_CALL( buf = cvCreateMat( effective_buf_height, effective_buf_width, CV_16UC1 ));
CV_CALL( pair16u32s_ptr = (CvPair16u32s*)cvAlloc( sample_count*sizeof(pair16u32s_ptr[0]) ));
}
else
{
- CV_CALL( buf = cvCreateMat( buf_count, buf_size, CV_32SC1 ));
+ CV_CALL( buf = cvCreateMat( effective_buf_height, effective_buf_width, CV_32SC1 ));
CV_CALL( int_ptr = (int**)cvAlloc( sample_count*sizeof(int_ptr[0]) ));
}
for( i = 0; i < sample_count; i++ )
{
int val = INT_MAX, si = sidx ? sidx[i] : i;
- if( !mask || !mask[si*m_step] )
+ if( !mask || !mask[(size_t)si*m_step] )
{
if( idata )
- val = idata[si*step];
+ val = idata[(size_t)si*step];
else
{
- float t = fdata[si*step];
+ float t = fdata[(size_t)si*step];
val = cvRound(t);
if( val != t )
{
{
float val = ord_nan;
int si = sidx ? sidx[i] : i;
- if( !mask || !mask[si*m_step] )
+ if( !mask || !mask[(size_t)si*m_step] )
{
if( idata )
- val = (float)idata[si*step];
+ val = (float)idata[(size_t)si*step];
else
- val = fdata[si*step];
+ val = fdata[(size_t)si*step];
if( fabs(val) >= ord_nan )
{
int ci = get_var_type( vi);
const int* cat_values = 0;
if( !is_buf_16u )
- cat_values = buf->data.i + n->buf_idx*buf->cols + ci*sample_count + n->offset;
+ cat_values = buf->data.i + n->buf_idx*get_length_subbuf() + ci*sample_count + n->offset;
else {
- const unsigned short* short_values = (const unsigned short*)(buf->data.s + n->buf_idx*buf->cols +
+ const unsigned short* short_values = (const unsigned short*)(buf->data.s + n->buf_idx*get_length_subbuf() +
ci*sample_count + n->offset);
for( int i = 0; i < n->sample_count; i++ )
cat_values_buf[i] = short_values[i];
CvDTreeNode *left = 0, *right = 0;
int new_buf_idx = data->get_child_buf_idx( node );
CvMat* buf = data->buf;
+ size_t length_buf_row = data->get_length_subbuf();
cv::AutoBuffer<int> temp_buf(n);
complete_node_dir(node);
if (data->is_buf_16u)
{
- unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*buf->cols +
+ unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*length_buf_row +
ci*scount + left->offset);
- unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*buf->cols +
+ unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*length_buf_row +
ci*scount + right->offset);
for( i = 0; i < n; i++ )
}
else
{
- int *ldst = buf->data.i + left->buf_idx*buf->cols +
+ int *ldst = buf->data.i + left->buf_idx*length_buf_row +
ci*scount + left->offset;
- int *rdst = buf->data.i + right->buf_idx*buf->cols +
+ int *rdst = buf->data.i + right->buf_idx*length_buf_row +
ci*scount + right->offset;
for( i = 0; i < n; i++ )
if (data->is_buf_16u)
{
- unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
+ unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*length_buf_row +
pos*scount + left->offset);
- unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*buf->cols +
+ unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*length_buf_row +
pos*scount + right->offset);
for (i = 0; i < n; i++)
}
else
{
- int* ldst = buf->data.i + left->buf_idx*buf->cols +
+ int* ldst = buf->data.i + left->buf_idx*length_buf_row +
pos*scount + left->offset;
- int* rdst = buf->data.i + right->buf_idx*buf->cols +
+ int* rdst = buf->data.i + right->buf_idx*length_buf_row +
pos*scount + right->offset;
for (i = 0; i < n; i++)
{
__BEGIN__;
- CvVectors* _samples;
- float** _data;
- int _count, _dims, _dims_all, _rsize;
+ CvVectors* _samples = 0;
+ float** _data = 0;
+ int _count = 0, _dims = 0, _dims_all = 0, _rsize = 0;
if( !_update_base )
clear();
_responses, CV_VAR_ORDERED, 0, _sample_idx, true, (const float***)&_data,
&_count, &_dims, &_dims_all, &responses, 0, 0 ));
+ if( !responses )
+ CV_ERROR( CV_StsNoMem, "Could not allocate memory for responses" );
+
if( _update_base && _dims != var_count )
CV_ERROR( CV_StsBadArg, "The newly added data have different dimensionality" );
CvDTreeTrainData::CvDTreeTrainData()
{
var_idx = var_type = cat_count = cat_ofs = cat_map =
- priors = priors_mult = counts = buf = direction = split_buf = responses_copy = 0;
+ priors = priors_mult = counts = direction = split_buf = responses_copy = 0;
+ buf = 0;
tree_storage = temp_storage = 0;
clear();
bool _shared, bool _add_labels )
{
var_idx = var_type = cat_count = cat_ofs = cat_map =
- priors = priors_mult = counts = buf = direction = split_buf = responses_copy = 0;
+ priors = priors_mult = counts = direction = split_buf = responses_copy = 0;
+ buf = 0;
tree_storage = temp_storage = 0;
char err[100];
const int *sidx = 0, *vidx = 0;
+ uint64 effective_buf_size = 0;
+ int effective_buf_height = 0, effective_buf_width = 0;
+
if( _update_data && data_root )
{
data = new CvDTreeTrainData( _train_data, _tflag, _responses, _var_idx,
work_var_count = var_count + (is_classifier ? 1 : 0) // for responses class_labels
+ (have_labels ? 1 : 0); // for cv_labels
- buf_size = (work_var_count + 1 /*for sample_indices*/) * sample_count;
shared = _shared;
buf_count = shared ? 2 : 1;
+ buf_size = -1; // the member buf_size is obsolete
+
+ effective_buf_size = (uint64)(work_var_count + 1)*(uint64)sample_count * buf_count; // this is the total size of "CvMat buf" to be allocated
+ effective_buf_width = sample_count;
+ effective_buf_height = work_var_count+1;
+
+ if (effective_buf_width >= effective_buf_height)
+ effective_buf_height *= buf_count;
+ else
+ effective_buf_width *= buf_count;
+
+ if ((uint64)effective_buf_width * (uint64)effective_buf_height != effective_buf_size)
+ {
+ CV_Error(CV_StsBadArg, "The memory buffer cannot be allocated since its size exceeds integer fields limit");
+ }
+
+
+
if ( is_buf_16u )
{
- CV_CALL( buf = cvCreateMat( buf_count, buf_size, CV_16UC1 ));
+ CV_CALL( buf = cvCreateMat( effective_buf_height, effective_buf_width, CV_16UC1 ));
CV_CALL( pair16u32s_ptr = (CvPair16u32s*)cvAlloc( sample_count*sizeof(pair16u32s_ptr[0]) ));
}
else
{
- CV_CALL( buf = cvCreateMat( buf_count, buf_size, CV_32SC1 ));
+ CV_CALL( buf = cvCreateMat( effective_buf_height, effective_buf_width, CV_32SC1 ));
CV_CALL( int_ptr = (int**)cvAlloc( sample_count*sizeof(int_ptr[0]) ));
}
{
int ci;
const uchar* mask = 0;
- int m_step = 0, step;
+ int64 m_step = 0, step;
const int* idata = 0;
const float* fdata = 0;
int num_valid = 0;
for( i = 0; i < sample_count; i++ )
{
int val = INT_MAX, si = sidx ? sidx[i] : i;
- if( !mask || !mask[si*m_step] )
+ if( !mask || !mask[(size_t)si*m_step] )
{
if( idata )
- val = idata[si*step];
+ val = idata[(size_t)si*step];
else
{
- float t = fdata[si*step];
+ float t = fdata[(size_t)si*step];
val = cvRound(t);
if( fabs(t - val) > FLT_EPSILON )
{
{
float val = ord_nan;
int si = sidx ? sidx[i] : i;
- if( !mask || !mask[si*m_step] )
+ if( !mask || !mask[(size_t)si*m_step] )
{
if( idata )
- val = (float)idata[si*step];
+ val = (float)idata[(size_t)si*step];
else
- val = fdata[si*step];
+ val = fdata[(size_t)si*step];
if( fabs(val) >= ord_nan )
{
}
if (is_buf_16u)
- udst[i] = (unsigned short)i;
+ udst[i] = (unsigned short)i; // TODO: memory corruption may be here
else
idst[i] = i;
_fdst[i] = val;
if (is_buf_16u)
{
- unsigned short* udst = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
+ unsigned short* udst = (unsigned short*)(buf->data.s + root->buf_idx*get_length_subbuf() +
vi*sample_count + root->offset);
for( i = 0; i < count; i++ )
{
}
else
{
- int* idst = buf->data.i + root->buf_idx*buf->cols +
+ int* idst = buf->data.i + root->buf_idx*get_length_subbuf() +
vi*sample_count + root->offset;
for( i = 0; i < count; i++ )
{
if (is_buf_16u)
{
- unsigned short* udst_idx = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
+ unsigned short* udst_idx = (unsigned short*)(buf->data.s + root->buf_idx*get_length_subbuf() +
vi*sample_count + data_root->offset);
for( i = 0; i < num_valid; i++ )
{
}
else
{
- int* idst_idx = buf->data.i + root->buf_idx*buf->cols +
+ int* idst_idx = buf->data.i + root->buf_idx*get_length_subbuf() +
vi*sample_count + root->offset;
for( i = 0; i < num_valid; i++ )
{
const int* sample_idx_src = get_sample_indices(data_root, (int*)(uchar*)inn_buf);
if (is_buf_16u)
{
- unsigned short* sample_idx_dst = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
+ unsigned short* sample_idx_dst = (unsigned short*)(buf->data.s + root->buf_idx*get_length_subbuf() +
workVarCount*sample_count + root->offset);
for (i = 0; i < count; i++)
sample_idx_dst[i] = (unsigned short)sample_idx_src[sidx[i]];
}
else
{
- int* sample_idx_dst = buf->data.i + root->buf_idx*buf->cols +
+ int* sample_idx_dst = buf->data.i + root->buf_idx*get_length_subbuf() +
workVarCount*sample_count + root->offset;
for (i = 0; i < count; i++)
sample_idx_dst[i] = sample_idx_src[sidx[i]];
const int* sample_indices = get_sample_indices(n, sample_indices_buf);
if( !is_buf_16u )
- *sorted_indices = buf->data.i + n->buf_idx*buf->cols +
+ *sorted_indices = buf->data.i + n->buf_idx*get_length_subbuf() +
vi*sample_count + n->offset;
else {
- const unsigned short* short_indices = (const unsigned short*)(buf->data.s + n->buf_idx*buf->cols +
+ const unsigned short* short_indices = (const unsigned short*)(buf->data.s + n->buf_idx*get_length_subbuf() +
vi*sample_count + n->offset );
for( int i = 0; i < node_sample_count; i++ )
sorted_indices_buf[i] = short_indices[i];
{
const int* cat_values = 0;
if( !is_buf_16u )
- cat_values = buf->data.i + n->buf_idx*buf->cols +
+ cat_values = buf->data.i + n->buf_idx*get_length_subbuf() +
vi*sample_count + n->offset;
else {
- const unsigned short* short_values = (const unsigned short*)(buf->data.s + n->buf_idx*buf->cols +
+ const unsigned short* short_values = (const unsigned short*)(buf->data.s + n->buf_idx*get_length_subbuf() +
vi*sample_count + n->offset);
for( int i = 0; i < n->sample_count; i++ )
cat_values_buf[i] = short_values[i];
int new_buf_idx = data->get_child_buf_idx( node );
int work_var_count = data->get_work_var_count();
CvMat* buf = data->buf;
+ size_t length_buf_row = data->get_length_subbuf();
cv::AutoBuffer<uchar> inn_buf(n*(3*sizeof(int) + sizeof(float)));
int* temp_buf = (int*)(uchar*)inn_buf;
{
unsigned short *ldst, *rdst, *ldst0, *rdst0;
//unsigned short tl, tr;
- ldst0 = ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
+ ldst0 = ldst = (unsigned short*)(buf->data.s + left->buf_idx*length_buf_row +
vi*scount + left->offset);
rdst0 = rdst = (unsigned short*)(ldst + nl);
else
{
int *ldst0, *ldst, *rdst0, *rdst;
- ldst0 = ldst = buf->data.i + left->buf_idx*buf->cols +
+ ldst0 = ldst = buf->data.i + left->buf_idx*length_buf_row +
vi*scount + left->offset;
- rdst0 = rdst = buf->data.i + right->buf_idx*buf->cols +
+ rdst0 = rdst = buf->data.i + right->buf_idx*length_buf_row +
vi*scount + right->offset;
// split sorted
if (data->is_buf_16u)
{
- unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*buf->cols +
+ unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*length_buf_row +
vi*scount + left->offset);
- unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*buf->cols +
+ unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*length_buf_row +
vi*scount + right->offset);
for( i = 0; i < n; i++ )
}
else
{
- int *ldst = buf->data.i + left->buf_idx*buf->cols +
+ int *ldst = buf->data.i + left->buf_idx*length_buf_row +
vi*scount + left->offset;
- int *rdst = buf->data.i + right->buf_idx*buf->cols +
+ int *rdst = buf->data.i + right->buf_idx*length_buf_row +
vi*scount + right->offset;
for( i = 0; i < n; i++ )
int pos = data->get_work_var_count();
if (data->is_buf_16u)
{
- unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
+ unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*length_buf_row +
pos*scount + left->offset);
- unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*buf->cols +
+ unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*length_buf_row +
pos*scount + right->offset);
for (i = 0; i < n; i++)
{
}
else
{
- int* ldst = buf->data.i + left->buf_idx*buf->cols +
+ int* ldst = buf->data.i + left->buf_idx*length_buf_row +
pos*scount + left->offset;
- int* rdst = buf->data.i + right->buf_idx*buf->cols +
+ int* rdst = buf->data.i + right->buf_idx*length_buf_row +
pos*scount + right->offset;
for (i = 0; i < n; i++)
{
float r = (float)predict( &sample, missing ? &miss : 0 )->value;
if( pred_resp )
pred_resp[i] = r;
- int d = fabs((double)r - response->data.fl[si*r_step]) <= FLT_EPSILON ? 0 : 1;
+ int d = fabs((double)r - response->data.fl[(size_t)si*r_step]) <= FLT_EPSILON ? 0 : 1;
err += d;
}
err = sample_count ? err / (float)sample_count * 100 : -FLT_MAX;
float r = (float)predict( &sample, missing ? &miss : 0 )->value;
if( pred_resp )
pred_resp[i] = r;
- float d = r - response->data.fl[si*r_step];
+ float d = r - response->data.fl[(size_t)si*r_step];
err += d*d;
}
err = sample_count ? err / (float)sample_count : -FLT_MAX;
int vi = split->var_idx;
int ci = vtype[vi];
i = vidx ? vidx[vi] : vi;
- float val = sample[i*step];
- if( m && m[i*mstep] )
+ float val = sample[(size_t)i*step];
+ if( m && m[(size_t)i*mstep] )
continue;
if( ci < 0 ) // ordered
dir = val <= split->ord.c ? -1 : 1;
CV_IMPL CvHaarClassifierCascade*
cvLoadHaarClassifierCascade( const char* directory, CvSize orig_window_size )
{
- const char** input_cascade = 0;
- CvHaarClassifierCascade *cascade = 0;
-
- int i, n;
- const char* slash;
- char name[_MAX_PATH];
- int size = 0;
- char* ptr = 0;
-
if( !directory )
CV_Error( CV_StsNullPtr, "Null path is passed" );
- n = (int)strlen(directory)-1;
- slash = directory[n] == '\\' || directory[n] == '/' ? "" : "/";
+ char name[_MAX_PATH];
+
+ int n = (int)strlen(directory)-1;
+ const char* slash = directory[n] == '\\' || directory[n] == '/' ? "" : "/";
+ int size = 0;
/* try to read the classifier from directory */
for( n = 0; ; n++ )
CV_Error( CV_StsBadArg, "Invalid path" );
size += (n+1)*sizeof(char*);
- input_cascade = (const char**)cvAlloc( size );
- ptr = (char*)(input_cascade + n + 1);
-
- for( i = 0; i < n; i++ )
+ const char** input_cascade = (const char**)cvAlloc( size );
+
+ if( !input_cascade )
+ CV_Error( CV_StsNoMem, "Could not allocate memory for input_cascade" );
+
+ char* ptr = (char*)(input_cascade + n + 1);
+
+ for( int i = 0; i < n; i++ )
{
sprintf( name, "%s/%d/AdaBoostCARTHaarClassifier.txt", directory, i );
FILE* f = fopen( name, "rb" );
}
input_cascade[n] = 0;
- cascade = icvLoadCascadeCART( input_cascade, n, orig_window_size );
+
+ CvHaarClassifierCascade* cascade = icvLoadCascadeCART( input_cascade, n, orig_window_size );
if( input_cascade )
cvFree( &input_cascade );
const int n, const int bx, const int by,
const int threadsNum, int *kLevels, int **processingLevels)
{
- int rootFilterDim, sumPartFiltersDim, i, numLevels, dbx, dby, numDotProducts;
+ int rootFilterDim, sumPartFiltersDim, i, numLevels, dbx, dby;
int j, minValue, argMin, lambda, maxValue, k;
int *dotProd, *weights, *disp;
if (H == NULL || all_F == NULL)
// of feature map with part filter
dbx = 2 * bx;
dby = 2 * by;
- // Total number of dot products for all levels
- numDotProducts = 0;
lambda = LAMBDA;
for (i = 0; i < numLevels; i++)
{
H->pyramid[i + lambda]->sizeY * rootFilterDim +
(H->pyramid[i]->sizeX + dbx) *
(H->pyramid[i]->sizeY + dby) * sumPartFiltersDim;
- numDotProducts += dotProd[i];
}
// Allocation memory for saving dot product number performed by each thread
weights = (int *)malloc(sizeof(int) * threadsNum);
//this function may be obsoleted
//CV_EXPORTS cl_device_id getDevice();
//the function must be called before any other cv::ocl::functions, it initialize ocl runtime
+ //each Info relates to an OpenCL platform
+ //there is one or more devices in each platform, each one has a separate name
CV_EXPORTS int getDevice(std::vector<Info> &oclinfo, int devicetype = CVCL_DEVICE_TYPE_GPU);
+
//set device you want to use, optional function after getDevice be called
+ //the devnum is the index of the selected device in DeviceName vector of INfo
CV_EXPORTS void setDevice(Info &oclinfo, int devnum = 0);
- //this function is not ready yet
- //CV_EXPORTS void getComputeCapability(cl_device_id device, int &major, int &minor);
+
//optional function, if you want save opencl binary kernel to the file, set its path
CV_EXPORTS void setBinpath(const char *path);
- //The two functions below are used to get opencl runtime so that opencv can interactive with
-
- //other opencl program
+ //The two functions below enable other opencl program to use ocl module's cl_context and cl_command_queue
CV_EXPORTS void* getoclContext();
CV_EXPORTS void* getoclCommandQueue();
+
+ //this function enable ocl module to use customized cl_context and cl_command_queue
+ //getDevice also need to be called before this function
+ CV_EXPORTS void setDeviceEx(Info &oclinfo, void *ctx, void *qu, int devnum = 0);
+
//////////////////////////////// Error handling ////////////////////////
CV_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func);
CV_Assert(src.type() == CV_8UC1 || src.type() == CV_8UC3 || src.type() == CV_8UC4 || src.type() == CV_8SC3 || src.type() == CV_8SC4 ||
src.type() == CV_16UC2 || src.type() == CV_16SC2 || src.type() == CV_32SC1 || src.type() == CV_32FC1);
- stringstream idxstr;
oclMat emptyMat;
if( src.data == dst.data && dst.cols == dst.rows )
int cols = img1.cols;
int istep = img1.step1();
int wstep = weights1.step1();
- size_t globalSize[] = {cols * channels, rows, 1};
- size_t localSize[] = {16, 16, 1};
+ size_t globalSize[] = {cols * channels / 4, rows, 1};
+ size_t localSize[] = {256, 1, 1};
vector< pair<size_t, const void *> > args;
//
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
+// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// @Authors
// Guoping Long, longguoping@gmail.com
-// Niko Li, newlife20080214@gmail.com
+// Niko Li, newlife20080214@gmail.com
+// Yao Wang, bitwangyaoyao@gmail.com
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
}
return devcienums;
}
- void setDevice(Info &oclinfo, int devnum)
- {
- CV_Assert(devnum >= 0);
- cl_int status = 0;
- cl_context_properties cps[3] =
- {
- CL_CONTEXT_PLATFORM, (cl_context_properties)(oclinfo.impl->oclplatform), 0
- };
- oclinfo.impl->devnum = devnum;
- oclinfo.impl->oclcontext = clCreateContext(cps, 1, &oclinfo.impl->devices[devnum], NULL, NULL, &status);
- openCLVerifyCall(status);
- //create the command queue using the first device of the list
- oclinfo.impl->clCmdQueue = clCreateCommandQueue(oclinfo.impl->oclcontext, oclinfo.impl->devices[devnum],
- CL_QUEUE_PROFILING_ENABLE, &status);
- openCLVerifyCall(status);
+ static void fillClcontext(Info &oclinfo)
+ {
//get device information
+ size_t devnum = oclinfo.impl->devnum;
+
openCLSafeCall(clGetDeviceInfo(oclinfo.impl->devices[devnum], CL_DEVICE_MAX_WORK_GROUP_SIZE,
sizeof(size_t), (void *)&oclinfo.impl->maxWorkGroupSize, NULL));
openCLSafeCall(clGetDeviceInfo(oclinfo.impl->devices[devnum], CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
oclinfo.impl -> double_support = 1;
}
Context::setContext(oclinfo);
+
}
+
+ void setDevice(Info &oclinfo, int devnum)
+ {
+ CV_Assert(devnum >= 0);
+ cl_int status = 0;
+ cl_context_properties cps[3] =
+ {
+ CL_CONTEXT_PLATFORM, (cl_context_properties)(oclinfo.impl->oclplatform), 0
+ };
+ oclinfo.impl->devnum = devnum;
+ oclinfo.impl->oclcontext = clCreateContext(cps, 1, &oclinfo.impl->devices[devnum], NULL, NULL, &status);
+ openCLVerifyCall(status);
+ //create the command queue using the first device of the list
+ oclinfo.impl->clCmdQueue = clCreateCommandQueue(oclinfo.impl->oclcontext, oclinfo.impl->devices[devnum],
+ CL_QUEUE_PROFILING_ENABLE, &status);
+ openCLVerifyCall(status);
+ fillClcontext(oclinfo);
+ }
+
+ void setDeviceEx(Info &oclinfo, void *ctx, void *q, int devnum)
+ {
+ CV_Assert(devnum >= 0);
+ oclinfo.impl->devnum = devnum;
+ if(ctx && q)
+ {
+ oclinfo.impl->oclcontext = (cl_context)ctx;
+ oclinfo.impl->clCmdQueue = (cl_command_queue)q;
+ clRetainContext((cl_context)ctx);
+ clRetainCommandQueue((cl_command_queue)q);
+ fillClcontext(oclinfo);
+ }
+ }
+
void *getoclContext()
{
Context *clcxt = Context::getContext();
clcxt->impl->Binpath = path;
}
- int savetofile(const Context *clcxt, cl_program &program, const char *fileName)
- {
- //cl_int status;
- size_t numDevices = 1;
- cl_device_id *devices = clcxt->impl->devices;
- //figure out the sizes of each of the binaries.
- size_t *binarySizes = (size_t *)malloc( sizeof(size_t) * numDevices );
+ int savetofile(const Context*, cl_program &program, const char *fileName)
+ {
+ size_t binarySize;
openCLSafeCall(clGetProgramInfo(program,
- CL_PROGRAM_BINARY_SIZES,
- sizeof(size_t) * numDevices,
- binarySizes, NULL));
-
- size_t i = 0;
- //copy over all of the generated binaries.
- char **binaries = (char **)malloc( sizeof(char *) * numDevices );
- if(binaries == NULL)
+ CL_PROGRAM_BINARY_SIZES,
+ sizeof(size_t),
+ &binarySize, NULL));
+ char* binary = (char*)malloc(binarySize);
+ if(binary == NULL)
{
- CV_Error(CV_StsNoMem, "Failed to allocate host memory.(binaries)\r\n");
- }
-
- for(i = 0; i < numDevices; i++)
- {
- if(binarySizes[i] != 0)
- {
- binaries[i] = (char *)malloc( sizeof(char) * binarySizes[i]);
- if(binaries[i] == NULL)
- {
- CV_Error(CV_StsNoMem, "Failed to allocate host memory.(binaries[i])\r\n");
- }
- }
- else
- {
- binaries[i] = NULL;
- }
+ CV_Error(CV_StsNoMem, "Failed to allocate host memory.");
}
openCLSafeCall(clGetProgramInfo(program,
- CL_PROGRAM_BINARIES,
- sizeof(char *) * numDevices,
- binaries,
- NULL));
+ CL_PROGRAM_BINARIES,
+ sizeof(char *),
+ &binary,
+ NULL));
- //dump out each binary into its own separate file.
- for(i = 0; i < numDevices; i++)
+ FILE *fp = fopen(fileName, "wb+");
+ if(fp != NULL)
{
- if(binarySizes[i] != 0)
- {
- char deviceName[1024];
- openCLSafeCall(clGetDeviceInfo(devices[i],
- CL_DEVICE_NAME,
- sizeof(deviceName),
- deviceName,
- NULL));
-
- printf( "%s binary kernel: %s\n", deviceName, fileName);
- FILE *fp = fopen(fileName, "wb+");
- if(fp == NULL)
- {
- char *temp = NULL;
- sprintf(temp, "Failed to load kernel file : %s\r\n", fileName);
- CV_Error(CV_GpuApiCallError, temp);
- }
- else
- {
- fwrite(binaries[i], binarySizes[i], 1, fp);
- free(binaries[i]);
- fclose(fp);
- }
- }
- else
- {
- printf("Skipping %s since there is no binary data to write!\n",
- fileName);
- }
+ fwrite(binary, binarySize, 1, fp);
+ free(binary);
+ fclose(fp);
}
- free(binarySizes);
- free(binaries);
return 1;
}
-
cl_kernel openCLGetKernelFromSource(const Context *clCxt, const char **source, string kernelName,
const char *build_options)
{
program = clCreateProgramWithSource(
clCxt->impl->clContext, 1, source, NULL, &status);
openCLVerifyCall(status);
- status = clBuildProgram(program, 1, &(clCxt->impl->devices[0]), all_build_options, NULL, NULL);
+ status = clBuildProgram(program, 1, &(clCxt->impl->devices), all_build_options, NULL, NULL);
if(status == CL_SUCCESS && clCxt->impl->Binpath.size())
savetofile(clCxt, program, filename.c_str());
}
cl_int status = 0;
program = clCreateProgramWithBinary(clCxt->impl->clContext,
1,
- &(clCxt->impl->devices[0]),
+ &(clCxt->impl->devices),
(const size_t *)&binarySize,
(const unsigned char **)&binary,
NULL,
&status);
openCLVerifyCall(status);
- status = clBuildProgram(program, 1, &(clCxt->impl->devices[0]), all_build_options, NULL, NULL);
+ status = clBuildProgram(program, 1, &(clCxt->impl->devices), all_build_options, NULL, NULL);
+ delete[] binary;
}
if(status != CL_SUCCESS)
char *buildLog = NULL;
size_t buildLogSize = 0;
logStatus = clGetProgramBuildInfo(program,
- clCxt->impl->devices[0], CL_PROGRAM_BUILD_LOG, buildLogSize,
+ clCxt->impl->devices, CL_PROGRAM_BUILD_LOG, buildLogSize,
buildLog, &buildLogSize);
if(logStatus != CL_SUCCESS)
cout << "Failed to build the program and get the build info." << endl;
buildLog = new char[buildLogSize];
CV_DbgAssert(!!buildLog);
memset(buildLog, 0, buildLogSize);
- openCLSafeCall(clGetProgramBuildInfo(program, clCxt->impl->devices[0],
+ openCLSafeCall(clGetProgramBuildInfo(program, clCxt->impl->devices,
CL_PROGRAM_BUILD_LOG, buildLogSize, buildLog, NULL));
cout << "\n\t\t\tBUILD LOG\n";
cout << buildLog << endl;
void openCLVerifyKernel(const Context *clCxt, cl_kernel kernel, size_t *localThreads)
{
size_t kernelWorkGroupSize;
- openCLSafeCall(clGetKernelWorkGroupInfo(kernel, clCxt->impl->devices[0],
+ openCLSafeCall(clGetKernelWorkGroupInfo(kernel, clCxt->impl->devices,
CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &kernelWorkGroupSize, 0));
CV_Assert( (localThreads[0] <= clCxt->impl->maxWorkItemSizes[0]) &&
(localThreads[1] <= clCxt->impl->maxWorkItemSizes[1]) &&
Context *clcxt = getContext();
clcxt->impl->clContext = oclinfo.impl->oclcontext;
clcxt->impl->clCmdQueue = oclinfo.impl->clCmdQueue;
- clcxt->impl->devices = &oclinfo.impl->devices[oclinfo.impl->devnum];
+ clcxt->impl->devices = oclinfo.impl->devices[oclinfo.impl->devnum];
clcxt->impl->devName = oclinfo.impl->devName[oclinfo.impl->devnum];
clcxt->impl->maxDimensions = oclinfo.impl->maxDimensions;
clcxt->impl->maxWorkGroupSize = oclinfo.impl->maxWorkGroupSize;
- clcxt->impl->maxWorkItemSizes = oclinfo.impl->maxWorkItemSizes;
+ for(size_t i=0; i<clcxt->impl->maxDimensions && i<4; i++)
+ clcxt->impl->maxWorkItemSizes[i] = oclinfo.impl->maxWorkItemSizes[i];
clcxt->impl->maxComputeUnits = oclinfo.impl->maxComputeUnits;
clcxt->impl->double_support = oclinfo.impl->double_support;
//extra options to recognize compiler options
- clcxt->impl->extra_options = oclinfo.impl->extra_options;
+ memcpy(clcxt->impl->extra_options, oclinfo.impl->extra_options, 512);
}
Context::Context()
{
impl->devices = NULL;
impl->maxDimensions = 0;
impl->maxWorkGroupSize = 0;
- impl->maxWorkItemSizes = NULL;
+ for(int i=0; i<4; i++)
+ impl->maxWorkItemSizes[i] = 0;
impl->maxComputeUnits = 0;
impl->double_support = 0;
//extra options to recognize vendor specific fp64 extensions
- impl->extra_options = NULL;
+ memset(impl->extra_options, 0, 512);
programCache = ProgramCache::getProgramCache();
}
// Third party copyrights are property of their respective owners.
//
// @Authors
-// Liu Liujun, liujun@multicorewareinc.com
+// Liu Liujun, liujun@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//M*/
__kernel void BlendLinear_C1_D0(
- __global uchar *dst,
- __global uchar *img1,
- __global uchar *img2,
- __global float *weight1,
- __global float *weight2,
+ __global uchar4 *dst,
+ __global uchar4 *img1,
+ __global uchar4 *img2,
+ __global float4 *weight1,
+ __global float4 *weight2,
int rows,
int cols,
int istep,
{
int idx = get_global_id(0);
int idy = get_global_id(1);
- if (idx < cols && idy < rows)
+ if (idx << 2 < cols && idy < rows)
{
- int pos = mad24(idy,istep,idx);
- int wpos = mad24(idy,wstep,idx);
- float w1 = weight1[wpos];
- float w2 = weight2[wpos];
- dst[pos] = (img1[pos] * w1 + img2[pos] * w2) / (w1 + w2 + 1e-5f);
-
+ int pos = mad24(idy,istep >> 2,idx);
+ int wpos = mad24(idy,wstep >> 2,idx);
+ float4 w1 = weight1[wpos], w2 = weight2[wpos];
+ dst[pos] = convert_uchar4((convert_float4(img1[pos]) * w1 +
+ convert_float4(img2[pos]) * w2) / (w1 + w2 + 1e-5f));
}
}
__kernel void BlendLinear_C4_D0(
- __global uchar *dst,
- __global uchar *img1,
- __global uchar *img2,
+ __global uchar4 *dst,
+ __global uchar4 *img1,
+ __global uchar4 *img2,
__global float *weight1,
__global float *weight2,
int rows,
{
int idx = get_global_id(0);
int idy = get_global_id(1);
- int x = idx / 4;
- int y = idy;
- if (x < cols && y < rows)
+ if (idx < cols && idy < rows)
{
- int pos = mad24(idy,istep,idx);
- int wpos = mad24(idy,wstep,x);
+ int pos = mad24(idy,istep >> 2,idx);
+ int wpos = mad24(idy,wstep, idx);
float w1 = weight1[wpos];
float w2 = weight2[wpos];
- dst[pos] = (img1[pos] * w1 + img2[pos] * w2) / (w1 + w2 + 1e-5f);
+ dst[pos] = convert_uchar4((convert_float4(img1[pos]) * w1 +
+ convert_float4(img2[pos]) * w2) / (w1 + w2 + 1e-5f));
}
}
+
__kernel void BlendLinear_C1_D5(
- __global float *dst,
- __global float *img1,
- __global float *img2,
- __global float *weight1,
- __global float *weight2,
+ __global float4 *dst,
+ __global float4 *img1,
+ __global float4 *img2,
+ __global float4 *weight1,
+ __global float4 *weight2,
int rows,
int cols,
int istep,
{
int idx = get_global_id(0);
int idy = get_global_id(1);
- if (idx < cols && idy < rows)
+ if (idx << 2 < cols && idy < rows)
{
- int pos = mad24(idy,istep,idx);
- int wpos = mad24(idy,wstep,idx);
- float w1 = weight1[wpos];
- float w2 = weight2[wpos];
+ int pos = mad24(idy,istep >> 2,idx);
+ int wpos = mad24(idy,wstep >> 2,idx);
+ float4 w1 = weight1[wpos], w2 = weight2[wpos];
dst[pos] = (img1[pos] * w1 + img2[pos] * w2) / (w1 + w2 + 1e-5f);
}
}
__kernel void BlendLinear_C4_D5(
- __global float *dst,
- __global float *img1,
- __global float *img2,
+ __global float4 *dst,
+ __global float4 *img1,
+ __global float4 *img2,
__global float *weight1,
__global float *weight2,
int rows,
{
int idx = get_global_id(0);
int idy = get_global_id(1);
- int x = idx / 4;
- int y = idy;
- if (x < cols && y < rows)
+ if (idx < cols && idy < rows)
{
- int pos = mad24(idy,istep,idx);
- int wpos = mad24(idy,wstep,x);
+ int pos = mad24(idy,istep >> 2,idx);
+ int wpos = mad24(idy,wstep, idx);
float w1 = weight1[wpos];
float w2 = weight2[wpos];
dst[pos] = (img1[pos] * w1 + img2[pos] * w2) / (w1 + w2 + 1e-5f);
//
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
+// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// @Authors
// Guoping Long, longguoping@gmail.com
+// Yao Wang, bitwangyaoyao@gmail.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//Information of the OpenCL context
cl_context clContext;
cl_command_queue clCmdQueue;
- cl_device_id *devices;
+ cl_device_id devices;
string devName;
cl_uint maxDimensions;
size_t maxWorkGroupSize;
- size_t *maxWorkItemSizes;
+ size_t maxWorkItemSizes[4];
cl_uint maxComputeUnits;
int double_support;
//extra options to recognize vendor specific fp64 extensions
- char *extra_options;
+ char extra_options[512];
string Binpath;
};
}
Context *clCxt = I.clCxt;
char platform[256] = {0};
cl_platform_id pid;
- clGetDeviceInfo(*clCxt->impl->devices, CL_DEVICE_PLATFORM, sizeof(pid), &pid, NULL);
+ clGetDeviceInfo(clCxt->impl->devices, CL_DEVICE_PLATFORM, sizeof(pid), &pid, NULL);
clGetPlatformInfo(pid, CL_PLATFORM_NAME, 256, platform, NULL);
std::string namestr = platform;
bool isImageSupported = true;