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

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2024-07-01 15:15:08 +03:00
62 changed files with 2178 additions and 243 deletions
+2 -2
View File
@@ -130,7 +130,7 @@ struct RGB2HSV_b
// sdiv = sdiv_table[v]
v_int32 sdiv0, sdiv1, sdiv2, sdiv3;;
v_uint16 vd0, vd1, vd2;
v_uint16 vd0, vd1;
v_expand(v, vd0, vd1);
v_int32 vq0, vq1, vq2, vq3;
v_expand(v_reinterpret_as_s16(vd0), vq0, vq1);
@@ -150,7 +150,7 @@ struct RGB2HSV_b
// hdiv = hdiv_table[diff]
v_int32 hdiv0, hdiv1, hdiv2, hdiv3;
v_uint16 diffd0, diffd1, diffd2;
v_uint16 diffd0, diffd1;
v_expand(diff, diffd0, diffd1);
v_int32 diffq0, diffq1, diffq2, diffq3;
v_expand(v_reinterpret_as_s16(diffd0), diffq0, diffq1);
+3 -9
View File
@@ -593,10 +593,10 @@ class Bayer2Gray_Invoker :
public ParallelLoopBody
{
public:
Bayer2Gray_Invoker(const Mat& _srcmat, Mat& _dstmat, int _start_with_green, bool _brow,
Bayer2Gray_Invoker(const Mat& _srcmat, Mat& _dstmat, int _start_with_green,
const Size& _size, int _bcoeff, int _rcoeff) :
ParallelLoopBody(), srcmat(_srcmat), dstmat(_dstmat), Start_with_green(_start_with_green),
Brow(_brow), size(_size), Bcoeff(_bcoeff), Rcoeff(_rcoeff)
size(_size), Bcoeff(_bcoeff), Rcoeff(_rcoeff)
{
}
@@ -612,13 +612,11 @@ public:
int dst_step = (int)(dstmat.step/sizeof(T));
int bcoeff = Bcoeff, rcoeff = Rcoeff;
int start_with_green = Start_with_green;
bool brow = Brow;
dst0 += dst_step + 1;
if (range.start % 2)
{
brow = !brow;
std::swap(bcoeff, rcoeff);
start_with_green = !start_with_green;
}
@@ -680,7 +678,6 @@ public:
dst0[-1] = dst0[0];
dst0[size.width] = dst0[size.width-1];
brow = !brow;
std::swap(bcoeff, rcoeff);
start_with_green = !start_with_green;
}
@@ -690,7 +687,6 @@ private:
Mat srcmat;
Mat dstmat;
int Start_with_green;
bool Brow;
Size size;
int Bcoeff, Rcoeff;
};
@@ -704,11 +700,9 @@ static void Bayer2Gray_( const Mat& srcmat, Mat& dstmat, int code )
Size size = srcmat.size();
int bcoeff = B2Y, rcoeff = R2Y;
int start_with_green = code == COLOR_BayerGB2GRAY || code == COLOR_BayerGR2GRAY;
bool brow = true;
if( code != COLOR_BayerBG2GRAY && code != COLOR_BayerGB2GRAY )
{
brow = false;
std::swap(bcoeff, rcoeff);
}
size.height -= 2;
@@ -718,7 +712,7 @@ static void Bayer2Gray_( const Mat& srcmat, Mat& dstmat, int code )
{
Range range(0, size.height);
Bayer2Gray_Invoker<T, SIMDInterpolator> invoker(srcmat, dstmat,
start_with_green, brow, size, bcoeff, rcoeff);
start_with_green, size, bcoeff, rcoeff);
parallel_for_(range, invoker, dstmat.total()/static_cast<double>(1<<16));
}
+27 -8
View File
@@ -318,9 +318,12 @@ static void addSharedSeg( Point2f p, Point2f q, Point2f*& result )
*result++ = q;
}
// Note: The function and subroutings use direct pointer arithmetics instead of arrays indexing.
// Each loop iteration may push to result array up to 3 times.
// It means that we need +3 spare result elements against result_size
// to catch agorithmic overflow and prevent actual result array overflow.
static int intersectConvexConvex_( const Point2f* P, int n, const Point2f* Q, int m,
Point2f* result, float* _area )
Point2f* result, int result_size, float* _area )
{
Point2f* result0 = result;
// P has n vertices, Q has m vertices.
@@ -398,7 +401,7 @@ static int intersectConvexConvex_( const Point2f* P, int n, const Point2f* Q, in
}
// Quit when both adv. indices have cycled, or one has cycled twice.
}
while ( ((aa < n) || (ba < m)) && (aa < 2*n) && (ba < 2*m) );
while ( ((aa < n) || (ba < m)) && (aa < 2*n) && (ba < 2*m) && ((int)(result - result0) <= result_size) );
// Deal with special cases: not implemented.
if( inflag == Unknown )
@@ -407,10 +410,16 @@ static int intersectConvexConvex_( const Point2f* P, int n, const Point2f* Q, in
// ...
}
int i, nr = (int)(result - result0);
int nr = (int)(result - result0);
if (nr > result_size)
{
*_area = -1.f;
return -1;
}
double area = 0;
Point2f prev = result0[nr-1];
for( i = 1; i < nr; i++ )
for(int i = 1; i < nr; i++ )
{
result0[i-1] = result0[i];
area += (double)prev.x*result0[i].y - (double)prev.y*result0[i].x;
@@ -445,9 +454,11 @@ float cv::intersectConvexConvex( InputArray _p1, InputArray _p2, OutputArray _p1
return 0.f;
}
AutoBuffer<Point2f> _result(n*2 + m*2 + 1);
Point2f *fp1 = _result.data(), *fp2 = fp1 + n;
AutoBuffer<Point2f> _result(n + m + n+m+1+3);
Point2f* fp1 = _result.data();
Point2f* fp2 = fp1 + n;
Point2f* result = fp2 + m;
int orientation = 0;
for( int k = 1; k <= 2; k++ )
@@ -476,7 +487,15 @@ float cv::intersectConvexConvex( InputArray _p1, InputArray _p2, OutputArray _p1
}
float area = 0.f;
int nr = intersectConvexConvex_(fp1, n, fp2, m, result, &area);
int nr = intersectConvexConvex_(fp1, n, fp2, m, result, n+m+1, &area);
if (nr < 0)
{
// The algorithm did not converge, e.g. some of inputs is not convex
_p12.release();
return -1.f;
}
if( nr == 0 )
{
if( !handleNested )