Commit 292dfc2d authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #10789 from mshabunin:split-matrix

parents 06455fc0 904640c9
......@@ -1448,7 +1448,6 @@ cvGetDiag( const CvArr* arr, CvMat* submat, int diag )
return res;
}
/****************************************************************************************\
* Operations on CvScalar and accessing array elements *
\****************************************************************************************/
......@@ -3215,6 +3214,51 @@ template<> void DefaultDeleter<CvMemStorage>::operator ()(CvMemStorage* obj) con
template<> void DefaultDeleter<CvFileStorage>::operator ()(CvFileStorage* obj) const
{ cvReleaseFileStorage(&obj); }
template <typename T> static inline
void scalarToRawData_(const Scalar& s, T * const buf, const int cn, const int unroll_to)
{
int i = 0;
for(; i < cn; i++)
buf[i] = saturate_cast<T>(s.val[i]);
for(; i < unroll_to; i++)
buf[i] = buf[i-cn];
}
void scalarToRawData(const Scalar& s, void* _buf, int type, int unroll_to)
{
CV_INSTRUMENT_REGION()
const int depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
CV_Assert(cn <= 4);
switch(depth)
{
case CV_8U:
scalarToRawData_<uchar>(s, (uchar*)_buf, cn, unroll_to);
break;
case CV_8S:
scalarToRawData_<schar>(s, (schar*)_buf, cn, unroll_to);
break;
case CV_16U:
scalarToRawData_<ushort>(s, (ushort*)_buf, cn, unroll_to);
break;
case CV_16S:
scalarToRawData_<short>(s, (short*)_buf, cn, unroll_to);
break;
case CV_32S:
scalarToRawData_<int>(s, (int*)_buf, cn, unroll_to);
break;
case CV_32F:
scalarToRawData_<float>(s, (float*)_buf, cn, unroll_to);
break;
case CV_64F:
scalarToRawData_<double>(s, (double*)_buf, cn, unroll_to);
break;
default:
CV_Error(CV_StsUnsupportedFormat,"");
}
}
} // cv::
/* End of file. */
This diff is collapsed.
This diff is collapsed.
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include "precomp.hpp"
......@@ -371,5 +334,4 @@ bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n)
return CholImpl(A, astep, m, b, bstep, n);
}
}}
}} // cv::hal::
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009-2010, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
/* ////////////////////////////////////////////////////////////////////
//
......@@ -1769,6 +1732,4 @@ MatExpr Mat::eye(Size size, int type)
return e;
}
}
/* End of file. */
} // cv::
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include "opencv2/core/mat.hpp"
#include "precomp.hpp"
namespace cv {
NAryMatIterator::NAryMatIterator()
: arrays(0), planes(0), ptrs(0), narrays(0), nplanes(0), size(0), iterdepth(0), idx(0)
{
}
NAryMatIterator::NAryMatIterator(const Mat** _arrays, Mat* _planes, int _narrays)
: arrays(0), planes(0), ptrs(0), narrays(0), nplanes(0), size(0), iterdepth(0), idx(0)
{
init(_arrays, _planes, 0, _narrays);
}
NAryMatIterator::NAryMatIterator(const Mat** _arrays, uchar** _ptrs, int _narrays)
: arrays(0), planes(0), ptrs(0), narrays(0), nplanes(0), size(0), iterdepth(0), idx(0)
{
init(_arrays, 0, _ptrs, _narrays);
}
void NAryMatIterator::init(const Mat** _arrays, Mat* _planes, uchar** _ptrs, int _narrays)
{
CV_Assert( _arrays && (_ptrs || _planes) );
int i, j, d1=0, i0 = -1, d = -1;
arrays = _arrays;
ptrs = _ptrs;
planes = _planes;
narrays = _narrays;
nplanes = 0;
size = 0;
if( narrays < 0 )
{
for( i = 0; _arrays[i] != 0; i++ )
;
narrays = i;
CV_Assert(narrays <= 1000);
}
iterdepth = 0;
for( i = 0; i < narrays; i++ )
{
CV_Assert(arrays[i] != 0);
const Mat& A = *arrays[i];
if( ptrs )
ptrs[i] = A.data;
if( !A.data )
continue;
if( i0 < 0 )
{
i0 = i;
d = A.dims;
// find the first dimensionality which is different from 1;
// in any of the arrays the first "d1" step do not affect the continuity
for( d1 = 0; d1 < d; d1++ )
if( A.size[d1] > 1 )
break;
}
else
CV_Assert( A.size == arrays[i0]->size );
if( !A.isContinuous() )
{
CV_Assert( A.step[d-1] == A.elemSize() );
for( j = d-1; j > d1; j-- )
if( A.step[j]*A.size[j] < A.step[j-1] )
break;
iterdepth = std::max(iterdepth, j);
}
}
if( i0 >= 0 )
{
size = arrays[i0]->size[d-1];
for( j = d-1; j > iterdepth; j-- )
{
int64 total1 = (int64)size*arrays[i0]->size[j-1];
if( total1 != (int)total1 )
break;
size = (int)total1;
}
iterdepth = j;
if( iterdepth == d1 )
iterdepth = 0;
nplanes = 1;
for( j = iterdepth-1; j >= 0; j-- )
nplanes *= arrays[i0]->size[j];
}
else
iterdepth = 0;
idx = 0;
if( !planes )
return;
for( i = 0; i < narrays; i++ )
{
CV_Assert(arrays[i] != 0);
const Mat& A = *arrays[i];
if( !A.data )
{
planes[i] = Mat();
continue;
}
planes[i] = Mat(1, (int)size, A.type(), A.data);
}
}
NAryMatIterator& NAryMatIterator::operator ++()
{
if( idx >= nplanes-1 )
return *this;
++idx;
if( iterdepth == 1 )
{
if( ptrs )
{
for( int i = 0; i < narrays; i++ )
{
if( !ptrs[i] )
continue;
ptrs[i] = arrays[i]->data + arrays[i]->step[0]*idx;
}
}
if( planes )
{
for( int i = 0; i < narrays; i++ )
{
if( !planes[i].data )
continue;
planes[i].data = arrays[i]->data + arrays[i]->step[0]*idx;
}
}
}
else
{
for( int i = 0; i < narrays; i++ )
{
const Mat& A = *arrays[i];
if( !A.data )
continue;
int _idx = (int)idx;
uchar* data = A.data;
for( int j = iterdepth-1; j >= 0 && _idx > 0; j-- )
{
int szi = A.size[j], t = _idx/szi;
data += (_idx - t * szi)*A.step[j];
_idx = t;
}
if( ptrs )
ptrs[i] = data;
if( planes )
planes[i].data = data;
}
}
return *this;
}
NAryMatIterator NAryMatIterator::operator ++(int)
{
NAryMatIterator it = *this;
++*this;
return it;
}
//==================================================================================================
Point MatConstIterator::pos() const
{
if( !m )
return Point();
CV_DbgAssert(m->dims <= 2);
ptrdiff_t ofs = ptr - m->ptr();
int y = (int)(ofs/m->step[0]);
return Point((int)((ofs - y*m->step[0])/elemSize), y);
}
void MatConstIterator::pos(int* _idx) const
{
CV_Assert(m != 0 && _idx);
ptrdiff_t ofs = ptr - m->ptr();
for( int i = 0; i < m->dims; i++ )
{
size_t s = m->step[i], v = ofs/s;
ofs -= v*s;
_idx[i] = (int)v;
}
}
ptrdiff_t MatConstIterator::lpos() const
{
if(!m)
return 0;
if( m->isContinuous() )
return (ptr - sliceStart)/elemSize;
ptrdiff_t ofs = ptr - m->ptr();
int i, d = m->dims;
if( d == 2 )
{
ptrdiff_t y = ofs/m->step[0];
return y*m->cols + (ofs - y*m->step[0])/elemSize;
}
ptrdiff_t result = 0;
for( i = 0; i < d; i++ )
{
size_t s = m->step[i], v = ofs/s;
ofs -= v*s;
result = result*m->size[i] + v;
}
return result;
}
void MatConstIterator::seek(ptrdiff_t ofs, bool relative)
{
if( m->isContinuous() )
{
ptr = (relative ? ptr : sliceStart) + ofs*elemSize;
if( ptr < sliceStart )
ptr = sliceStart;
else if( ptr > sliceEnd )
ptr = sliceEnd;
return;
}
int d = m->dims;
if( d == 2 )
{
ptrdiff_t ofs0, y;
if( relative )
{
ofs0 = ptr - m->ptr();
y = ofs0/m->step[0];
ofs += y*m->cols + (ofs0 - y*m->step[0])/elemSize;
}
y = ofs/m->cols;
int y1 = std::min(std::max((int)y, 0), m->rows-1);
sliceStart = m->ptr(y1);
sliceEnd = sliceStart + m->cols*elemSize;
ptr = y < 0 ? sliceStart : y >= m->rows ? sliceEnd :
sliceStart + (ofs - y*m->cols)*elemSize;
return;
}
if( relative )
ofs += lpos();
if( ofs < 0 )
ofs = 0;
int szi = m->size[d-1];
ptrdiff_t t = ofs/szi;
int v = (int)(ofs - t*szi);
ofs = t;
ptr = m->ptr() + v*elemSize;
sliceStart = m->ptr();
for( int i = d-2; i >= 0; i-- )
{
szi = m->size[i];
t = ofs/szi;
v = (int)(ofs - t*szi);
ofs = t;
sliceStart += v*m->step[i];
}
sliceEnd = sliceStart + m->size[d-1]*elemSize;
if( ofs > 0 )
ptr = sliceEnd;
else
ptr = sliceStart + (ptr - m->ptr());
}
void MatConstIterator::seek(const int* _idx, bool relative)
{
int d = m->dims;
ptrdiff_t ofs = 0;
if( !_idx )
;
else if( d == 2 )
ofs = _idx[0]*m->size[1] + _idx[1];
else
{
for( int i = 0; i < d; i++ )
ofs = ofs*m->size[i] + _idx[i];
}
seek(ofs, relative);
}
//==================================================================================================
SparseMatConstIterator::SparseMatConstIterator(const SparseMat* _m) : m((SparseMat*)_m), hashidx(0), ptr(0)
{
if(!_m || !_m->hdr)
return;
SparseMat::Hdr& hdr = *m->hdr;
const std::vector<size_t>& htab = hdr.hashtab;
size_t i, hsize = htab.size();
for( i = 0; i < hsize; i++ )
{
size_t nidx = htab[i];
if( nidx )
{
hashidx = i;
ptr = &hdr.pool[nidx] + hdr.valueOffset;
return;
}
}
}
SparseMatConstIterator& SparseMatConstIterator::operator ++()
{
if( !ptr || !m || !m->hdr )
return *this;
SparseMat::Hdr& hdr = *m->hdr;
size_t next = ((const SparseMat::Node*)(ptr - hdr.valueOffset))->next;
if( next )
{
ptr = &hdr.pool[next] + hdr.valueOffset;
return *this;
}
size_t i = hashidx + 1, sz = hdr.hashtab.size();
for( ; i < sz; i++ )
{
size_t nidx = hdr.hashtab[i];
if( nidx )
{
hashidx = i;
ptr = &hdr.pool[nidx] + hdr.valueOffset;
return *this;
}
}
hashidx = sz;
ptr = 0;
return *this;
}
} // cv::
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -190,6 +190,9 @@ inline Size getContinuousSize( const Mat& m1, const Mat& m2,
m1.cols, m1.rows, widthScale);
}
void setSize( Mat& m, int _dims, const int* _sz, const size_t* _steps, bool autoSteps=false );
void finalizeHdr(Mat& m);
struct NoVec
{
size_t operator()(const void*, const void*, void*, size_t) const { return 0; }
......
......@@ -46,6 +46,8 @@
namespace cv
{
////////////////////// KeyPoint //////////////////////
size_t KeyPoint::hash() const
{
size_t _Val = 2166136261U, scale = 16777619U;
......@@ -140,4 +142,69 @@ float KeyPoint::overlap( const KeyPoint& kp1, const KeyPoint& kp2 )
return ovrl;
}
////////////////////// RotatedRect //////////////////////
RotatedRect::RotatedRect(const Point2f& _point1, const Point2f& _point2, const Point2f& _point3)
{
Point2f _center = 0.5f * (_point1 + _point3);
Vec2f vecs[2];
vecs[0] = Vec2f(_point1 - _point2);
vecs[1] = Vec2f(_point2 - _point3);
// check that given sides are perpendicular
CV_Assert( abs(vecs[0].dot(vecs[1])) / (norm(vecs[0]) * norm(vecs[1])) <= FLT_EPSILON );
// wd_i stores which vector (0,1) or (1,2) will make the width
// One of them will definitely have slope within -1 to 1
int wd_i = 0;
if( abs(vecs[1][1]) < abs(vecs[1][0]) ) wd_i = 1;
int ht_i = (wd_i + 1) % 2;
float _angle = atan(vecs[wd_i][1] / vecs[wd_i][0]) * 180.0f / (float) CV_PI;
float _width = (float) norm(vecs[wd_i]);
float _height = (float) norm(vecs[ht_i]);
center = _center;
size = Size2f(_width, _height);
angle = _angle;
}
void RotatedRect::points(Point2f pt[]) const
{
double _angle = angle*CV_PI/180.;
float b = (float)cos(_angle)*0.5f;
float a = (float)sin(_angle)*0.5f;
pt[0].x = center.x - a*size.height - b*size.width;
pt[0].y = center.y + b*size.height - a*size.width;
pt[1].x = center.x + a*size.height - b*size.width;
pt[1].y = center.y - b*size.height - a*size.width;
pt[2].x = 2*center.x - pt[0].x;
pt[2].y = 2*center.y - pt[0].y;
pt[3].x = 2*center.x - pt[1].x;
pt[3].y = 2*center.y - pt[1].y;
}
Rect RotatedRect::boundingRect() const
{
Point2f pt[4];
points(pt);
Rect r(cvFloor(std::min(std::min(std::min(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
cvFloor(std::min(std::min(std::min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)),
cvCeil(std::max(std::max(std::max(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
cvCeil(std::max(std::max(std::max(pt[0].y, pt[1].y), pt[2].y), pt[3].y)));
r.width -= r.x - 1;
r.height -= r.y - 1;
return r;
}
Rect_<float> RotatedRect::boundingRect2f() const
{
Point2f pt[4];
points(pt);
Rect_<float> r(Point_<float>(min(min(min(pt[0].x, pt[1].x), pt[2].x), pt[3].x), min(min(min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)),
Point_<float>(max(max(max(pt[0].x, pt[1].x), pt[2].x), pt[3].x), max(max(max(pt[0].y, pt[1].y), pt[2].y), pt[3].y)));
return r;
}
} // cv
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment