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
2025-12-02 15:22:25 +03:00
56 changed files with 1639 additions and 876 deletions
+9 -5
View File
@@ -76,12 +76,16 @@ static int Sklansky_( Point_<_Tp>** array, int start, int end, int* stack, int n
if( CV_SIGN( by ) != nsign )
{
_Tp ax = array[pcur]->x - array[pprev]->x;
_Tp bx = array[pnext]->x - array[pcur]->x;
_Tp ay = cury - array[pprev]->y;
_DotTp convexity = (_DotTp)ay*bx - (_DotTp)ax*by; // if >0 then convex angle
Vec<_Tp, 2> a(array[pcur]->x - array[pprev]->x, cury - array[pprev]->y);
Vec<_Tp, 2> b(array[pnext]->x - array[pcur]->x, by);
if (std::is_floating_point<_Tp>::value)
{
a = normalize(a);
b = normalize(b);
}
_DotTp convexity = (_DotTp)a[1]*b[0] - (_DotTp)a[0]*b[1]; // if >0 then convex angle
if( CV_SIGN( convexity ) == sign2 && (ax != 0 || ay != 0) )
if( CV_SIGN( convexity ) == sign2 && (a[0] != 0 || a[1] != 0) )
{
pprev = pcur;
pcur = pnext;
+42 -6
View File
@@ -1174,13 +1174,31 @@ static bool replacementFilter2D(int stype, int dtype, int kernel_type,
cvhalFilter2D* ctx;
int res = cv_hal_filterInit(&ctx, kernel_data, kernel_step, kernel_type, kernel_width, kernel_height, width, height,
stype, dtype, borderType, delta, anchor_x, anchor_y, isSubmatrix, src_data == dst_data);
if (res != CV_HAL_ERROR_OK)
if (res == CV_HAL_ERROR_NOT_IMPLEMENTED)
{
return false;
} else if (res != CV_HAL_ERROR_OK)
{
CV_Error_(cv::Error::StsInternal,
("HAL implementation filterInit ==> " CVAUX_STR(cv_hal_filterInit) " returned %d (0x%08x)", res, res));
}
res = cv_hal_filter(ctx, src_data, src_step, dst_data, dst_step, width, height, full_width, full_height, offset_x, offset_y);
bool success = (res == CV_HAL_ERROR_OK);
if (res != CV_HAL_ERROR_OK && res != CV_HAL_ERROR_NOT_IMPLEMENTED )
{
CV_Error_(cv::Error::StsInternal,
("HAL implementation filter ==> " CVAUX_STR(cv_hal_filter) " returned %d (0x%08x)", res, res));
}
res = cv_hal_filterFree(ctx);
if (res != CV_HAL_ERROR_OK)
return false;
success &= (res == CV_HAL_ERROR_OK);
if (res != CV_HAL_ERROR_OK && res != CV_HAL_ERROR_NOT_IMPLEMENTED )
{
CV_Error_(cv::Error::StsInternal,
("HAL implementation filterFree ==> " CVAUX_STR(cv_hal_filterFree) " returned %d (0x%08x)", res, res));
}
return success;
}
@@ -1372,13 +1390,31 @@ static bool replacementSepFilter(int stype, int dtype, int ktype,
kernelx_data, kernelx_len,
kernely_data, kernely_len,
anchor_x, anchor_y, delta, borderType);
if (res != CV_HAL_ERROR_OK)
if (res == CV_HAL_ERROR_NOT_IMPLEMENTED)
{
return false;
} else if (res != CV_HAL_ERROR_OK)
{
CV_Error_(cv::Error::StsInternal,
("HAL implementation sepFilterInit ==> " CVAUX_STR(cv_hal_sepFilterInit) " returned %d (0x%08x)", res, res));
}
res = cv_hal_sepFilter(ctx, src_data, src_step, dst_data, dst_step, width, height, full_width, full_height, offset_x, offset_y);
bool success = (res == CV_HAL_ERROR_OK);
if (res != CV_HAL_ERROR_OK && res != CV_HAL_ERROR_NOT_IMPLEMENTED )
{
CV_Error_(cv::Error::StsInternal,
("HAL implementation sepFilter ==> " CVAUX_STR(cv_hal_sepFilter) " returned %d (0x%08x)", res, res));
}
res = cv_hal_sepFilterFree(ctx);
if (res != CV_HAL_ERROR_OK)
return false;
success &= (res == CV_HAL_ERROR_OK);
if (res != CV_HAL_ERROR_OK && res != CV_HAL_ERROR_NOT_IMPLEMENTED )
{
CV_Error_(cv::Error::StsInternal,
("HAL implementation sepFilterFree ==> " CVAUX_STR(cv_hal_sepFilterFree) " returned %d (0x%08x)", res, res));
}
return success;
}
+18 -3
View File
@@ -218,8 +218,14 @@ static bool halMorph(int op, int src_type, int dst_type,
anchor_x, anchor_y,
borderType, borderValue,
iterations, isSubmatrix, src_data == dst_data);
if (res != CV_HAL_ERROR_OK)
if (res == CV_HAL_ERROR_NOT_IMPLEMENTED)
{
return false;
} else if (res != CV_HAL_ERROR_OK)
{
CV_Error_(cv::Error::StsInternal,
("HAL implementation morphInit ==> " CVAUX_STR(cv_hal_morphInit) " returned %d (0x%08x)", res, res));
}
res = cv_hal_morph(ctx, src_data, src_step, dst_data, dst_step, width, height,
roi_width, roi_height,
@@ -227,10 +233,19 @@ static bool halMorph(int op, int src_type, int dst_type,
roi_width2, roi_height2,
roi_x2, roi_y2);
bool success = (res == CV_HAL_ERROR_OK);
if (res != CV_HAL_ERROR_OK && res != CV_HAL_ERROR_NOT_IMPLEMENTED )
{
CV_Error_(cv::Error::StsInternal,
("HAL implementation morph ==> " CVAUX_STR(cv_hal_morph) " returned %d (0x%08x)", res, res));
}
res = cv_hal_morphFree(ctx);
if (res != CV_HAL_ERROR_OK)
return false;
success &= (res == CV_HAL_ERROR_OK);
if (res != CV_HAL_ERROR_OK && res != CV_HAL_ERROR_NOT_IMPLEMENTED )
{
CV_Error_(cv::Error::StsInternal,
("HAL implementation morphFree ==> " CVAUX_STR(cv_hal_morphFree) " returned %d (0x%08x)", res, res));
}
return success;
}
+32 -12
View File
@@ -64,6 +64,7 @@ enum { CALIPERS_MAXHEIGHT=0, CALIPERS_MINAREARECT=1, CALIPERS_MAXDIST=2 };
// Parameters:
// points - convex hull vertices ( any orientation )
// n - number of vertices
// orientation - -1 for clockwise vertices order, 1 for CCW. 0 if unknown.
// mode - concrete application of algorithm
// can be CV_CALIPERS_MAXDIST or
// CV_CALIPERS_MINAREARECT
@@ -115,7 +116,7 @@ static bool firstVecIsRight(const cv::Point2f& vec1, const cv::Point2f &vec2)
}
/* we will use usual cartesian coordinates */
static void rotatingCalipers( const Point2f* points, int n, int mode, float* out )
static void rotatingCalipers( const Point2f* points, int n, float orientation, int mode, float* out )
{
float minarea = FLT_MAX;
float max_dist = 0;
@@ -132,7 +133,6 @@ static void rotatingCalipers( const Point2f* points, int n, int mode, float* out
(a,b) (-b,a) (-a,-b) (b, -a)
*/
/* this is a first base vector (a,b) initialized by (1,0) */
float orientation = 0;
float base_a;
float base_b = 0;
@@ -171,6 +171,7 @@ static void rotatingCalipers( const Point2f* points, int n, int mode, float* out
}
// find convex hull orientation
if (orientation == 0.f)
{
double ax = vect[n-1].x;
double ay = vect[n-1].y;
@@ -364,8 +365,10 @@ cv::RotatedRect cv::minAreaRect( InputArray _points )
Mat hull;
Point2f out[3];
RotatedRect box;
box.angle = -(float)CV_PI / 2; // default angle for box without rotation and single point
convexHull(_points, hull, false, true);
static const bool clockwise = false;
convexHull(_points, hull, clockwise, true);
if( hull.depth() != CV_32F )
{
@@ -379,22 +382,37 @@ cv::RotatedRect cv::minAreaRect( InputArray _points )
if( n > 2 )
{
rotatingCalipers( hpoints, n, CALIPERS_MINAREARECT, (float*)out );
rotatingCalipers( hpoints, n, clockwise ? -1.f : 1.f, CALIPERS_MINAREARECT, (float*)out );
box.center.x = out[0].x + (out[1].x + out[2].x)*0.5f;
box.center.y = out[0].y + (out[1].y + out[2].y)*0.5f;
box.size.width = (float)std::sqrt((double)out[1].x*out[1].x + (double)out[1].y*out[1].y);
box.size.height = (float)std::sqrt((double)out[2].x*out[2].x + (double)out[2].y*out[2].y);
box.angle = (float)atan2( (double)out[1].y, (double)out[1].x );
box.size.width = (float)std::sqrt((double)out[2].x*out[2].x + (double)out[2].y*out[2].y);
box.size.height = (float)std::sqrt((double)out[1].x*out[1].x + (double)out[1].y*out[1].y);
if (out[1].x == 0.f && out[1].y > 0.f)
std::swap(box.size.width, box.size.height);
else
box.angle += (float)atan2( (double)out[1].y, (double)out[1].x );
}
else if( n == 2 )
{
box.center.x = (hpoints[0].x + hpoints[1].x)*0.5f;
box.center.y = (hpoints[0].y + hpoints[1].y)*0.5f;
double dx = hpoints[1].x - hpoints[0].x;
double dy = hpoints[1].y - hpoints[0].y;
box.size.width = (float)std::sqrt(dx*dx + dy*dy);
box.size.height = 0;
box.angle = (float)atan2( dy, dx );
double dx = hpoints[0].x - hpoints[1].x;
double dy = hpoints[0].y - hpoints[1].y;
box.size.width = 0;
box.size.height = (float)std::sqrt(dx*dx + dy*dy);
if (dx == 0)
{
std::swap(box.size.width, box.size.height);
}
else if (dy < 0)
{
box.angle = (float)atan2( dy, dx );
std::swap(box.size.width, box.size.height);
}
else if (dy > 0)
{
box.angle += (float)atan2( dy, dx );
}
}
else
{
@@ -403,6 +421,8 @@ cv::RotatedRect cv::minAreaRect( InputArray _points )
}
box.angle = (float)(box.angle*180/CV_PI);
CV_DbgCheckGE(box.angle, -90.0f, "");
CV_DbgCheckLT(box.angle, 0.0f, "");
return box;
}