Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Parallel_for in box Filter and support for 32f box filter in Fastcv hal#27182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
asmorkalov merged 6 commits intoopencv:4.xfromCodeLinaro:boxFilter_hal_changes
Apr 16, 2025
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Parallel_for in box Filter and support for 32f box filter in Fastcv hal
  • Loading branch information
@adsha-quic
adsha-quic committedApr 1, 2025
commit42de7e6ee869339f655c616c69169612ed01b3c9
136 changes: 101 additions & 35 deletions3rdparty/fastcv/src/fastcv_hal_imgproc.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -314,6 +314,69 @@ int fastcv_hal_sobel(
CV_HAL_RETURN(status, hal_sobel);
}

class FcvBoxLoop_Invoker : public cv::ParallelLoopBody
{
public:

FcvBoxLoop_Invoker(cv::Mat src_, int width_, int height_, cv::Mat dst_, int bdr_, int knl_, int normalize_, int stripeHeight_, int nStripes_, int depth_) :
cv::ParallelLoopBody(), src(src_), width(width_), height(height_), dst(dst_), bdr(bdr_), knl(knl_), normalize(normalize_), stripeHeight(stripeHeight_), nStripes(nStripes_), depth(depth_)
{
}

virtual void operator()(const cv::Range& range) const CV_OVERRIDE
{
int height_ = stripeHeight * (range.end - range.start);
int width_ = width;
cv::Mat src_;
int n = knl/2;

if(range.end == nStripes)
height_ += (height - range.end * stripeHeight);

src_ = cv::Mat(height_ + 2*n, width_ + 2*n, depth);

if(range.start == 0 && range.end == nStripes)
cv::copyMakeBorder(src(cv::Rect(0, 0, width_, height_)), src_, n, n, n, n, bdr);
else if(range.start == 0)
cv::copyMakeBorder(src(cv::Rect(0, 0, width_, height_ + n)), src_, n, 0, n, n, bdr);
else if(range.end == nStripes)
cv::copyMakeBorder(src(cv::Rect(0, range.start * stripeHeight - n, width_, height_ + n)), src_, 0, n, n, n, bdr);
else
cv::copyMakeBorder(src(cv::Rect(0, range.start * stripeHeight - n, width_, height_ + 2*n)), src_, 0, 0, n, n, bdr);

cv::Mat dst_padded = cv::Mat(height_ + 2*n, width_ + 2*n, depth);
if(depth == CV_32F)
fcvBoxFilterNxNf32((float*)src_.data, width_ + 2*n, height_ + 2*n, (width_ + 2*n)*sizeof(float),
knl, (float*)dst_padded.data, dst_padded.step[0]);
else
{
auto func = knl == 3 ? fcvBoxFilter3x3u8_v3 : fcvBoxFilter5x5u8_v2;

func(src_.data, width_ + 2*n, height_ + 2*n, width_ + 2*n,
dst_padded.data, dst_padded.step[0], normalize, FASTCV_BORDER_UNDEFINED, 0);
}
int start_val = stripeHeight * range.start;
cv::Mat dst_temp1 = dst_padded(cv::Rect(n, n, width_, height_));
cv::Mat dst_temp2 = dst(cv::Rect(0, start_val, width_, height_));
dst_temp1.copyTo(dst_temp2);
}

private:
cv::Mat src;
const int width;
const int height;
cv::Mat dst;
const int bdr;
const int knl;
const int normalize;
const int stripeHeight;
const int nStripes;
int depth;

FcvBoxLoop_Invoker(const FcvBoxLoop_Invoker &); // = delete;
const FcvBoxLoop_Invoker& operator= (const FcvBoxLoop_Invoker &); // = delete;
};

int fastcv_hal_boxFilter(
const uchar* src_data,
size_t src_step,
Expand All@@ -335,24 +398,15 @@ int fastcv_hal_boxFilter(
bool normalize,
int border_type)
{
if((width*height) < (320*240))
{
CV_HAL_RETURN_NOT_IMPLEMENTED("input size not supported");
}
else if(src_data == dst_data)
{
CV_HAL_RETURN_NOT_IMPLEMENTED("in-place processing not supported");
}
else if(src_depth != CV_8U || cn != 1)
if((src_depth != CV_8U && src_depth != CV_32F) || cn != 1)
{
CV_HAL_RETURN_NOT_IMPLEMENTED("src type not supported");
}
else if(dst_depth != src_depth)
{
CV_HAL_RETURN_NOT_IMPLEMENTED("same src and dst type supported");
}
else if(ksize_width != ksize_height ||
(ksize_width != 3 && ksize_width != 5))
else if(ksize_width != ksize_height)
{
CV_HAL_RETURN_NOT_IMPLEMENTED("kernel size not supported");
}
Expand All@@ -363,37 +417,46 @@ int fastcv_hal_boxFilter(
CV_HAL_RETURN_NOT_IMPLEMENTED("ROI not supported");
}

if(src_depth == CV_32F && normalize != 1)
CV_HAL_RETURN_NOT_IMPLEMENTED("normalized kernel supported for float types");

if(src_depth == CV_8U && (ksize_width != 3 && ksize_width != 5))
CV_HAL_RETURN_NOT_IMPLEMENTED("kernel size not supported");

INITIALIZATION_CHECK;

fcvBorderType bdr;
uint8_t bdrVal = 0;
switch(border_type)
{
case cv::BORDER_REPLICATE:
bdr = FASTCV_BORDER_REPLICATE;
break;
case cv::BORDER_REFLECT:
bdr = FASTCV_BORDER_REFLECT;
break;
case cv::BORDER_REFLECT101: // cv::BORDER_REFLECT_101, BORDER_DEFAULT
bdr = FASTCV_BORDER_REFLECT_V2;
break;
default:
CV_HAL_RETURN_NOT_IMPLEMENTED("border type not supported");
}
cv::Mat dst_temp;
bool inPlace = src_data == dst_data ? true : false ;

fcvStatus status = FASTCV_SUCCESS;
if(ksize_width == 3)
int nThreads = cv::getNumThreads();

cv::Mat src = cv::Mat(height, width, src_depth, (void*)src_data, src_step);

if(inPlace)
dst_temp = cv::Mat(height, width, src_depth);
else
dst_temp = cv::Mat(height, width, src_depth, (void*)dst_data, dst_step);

int nStripes, stripeHeight = nThreads * 10;

if(src.rows/stripeHeight == 0)
{
status =fcvBoxFilter3x3u8_v3(src_data, width, height, src_step,
dst_data, dst_step, normalize, bdr, bdrVal);
nStripes =1;
stripeHeight = src.rows;
}
else if(ksize_width == 5)
else
nStripes = (src.rows/stripeHeight);

cv::parallel_for_(cv::Range(0, nStripes),
FcvBoxLoop_Invoker(src, width, height, dst_temp, border_type, ksize_width, normalize, stripeHeight, nStripes, src_depth), nStripes);

if(inPlace)
{
status = fcvBoxFilter5x5u8_v2(src_data, width,height, src_step,
dst_data, dst_step, normalize, bdr, bdrVal);
cv::Mat dst = cv::Mat(height, width,src_depth, (void*)dst_data, dst_step);
dst_temp(cv::Rect(0, 0, width, height)).copyTo(dst(cv::Rect(0, 0, width, height)));
}

fcvStatus status = FASTCV_SUCCESS;
CV_HAL_RETURN(status,hal_boxFilter);
}

Expand DownExpand Up@@ -727,7 +790,7 @@ class FcvPyrLoop_Invoker : public cv::ParallelLoopBody
src_ = cv::Mat(height_ + 2*n, width_ + 2*n, CV_8U);

if(range.start == 0 && range.end == nStripes)
cv::copyMakeBorder(src(cv::Rect(0, 0,width, height)), src_, n, n, n, n, bdr);
cv::copyMakeBorder(src(cv::Rect(0, 0,width_, height_)), src_, n, n, n, n, bdr);
else if(range.start == 0)
cv::copyMakeBorder(src(cv::Rect(0, 0, width_, height_ + n)), src_, n, 0, n, n, bdr);
else if(range.end == nStripes)
Expand DownExpand Up@@ -839,7 +902,10 @@ int fastcv_hal_pyrdown(
int nStripes, stripeHeight = nThreads * 10;

if(src.rows/stripeHeight == 0)
{
nStripes = 1;
stripeHeight = src.rows;
}
else
nStripes = (src.rows/stripeHeight);

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp