# cv::boxFilter and cv::addWeighted are giving worst performance on GPU than CPU

**URL:** <https://forum.opencv.org/t/cv-boxfilter-and-cv-addweighted-are-giving-worst-performance-on-gpu-than-cpu/1292>\
**Category:** Uncategorized\
**Created:** [February 3, 2021, 6:57am UTC](https://forum.opencv.org/t/cv-boxfilter-and-cv-addweighted-are-giving-worst-performance-on-gpu-than-cpu/1292 "2021-02-03T06:57:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajeshchanda](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@rajeshchanda](https://forum.opencv.org/u/rajeshchanda)\
**Post date:** [February 3, 2021, 6:57am UTC](https://forum.opencv.org/t/cv-boxfilter-and-cv-addweighted-are-giving-worst-performance-on-gpu-than-cpu/1292/1 "2021-02-03T06:57:08Z")

</div>

Hi,

In my vision algorithm, I am using opencv UMat based API’s.  
API list are as follows: boxFilter, addWeighted, multiply, divide, subtract, compare and etc.

I am using Adreno GPU to execute above calls.

except boxFilter and addWeighted, other API’s are giving best performance around 1millisecs.  
But boxFilter is giving 30milliseconds, addWeighted is giving 49milliseconds.

When I run boxFilter, addWeighted on CPU, these two are giving 7millisecoonds. Infact when I run these two API’s on Nvidia, Intel platforms, giving good performance around 1milliseconds.

Could you help us why its giving worst performance in GPU(Adreno 650) that too for only above two API’s in UMat.

Thanks and Regards  
Rajesh Chanda

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [February 3, 2021, 9:34am UTC](https://forum.opencv.org/t/cv-boxfilter-and-cv-addweighted-are-giving-worst-performance-on-gpu-than-cpu/1292/2 "2021-02-03T09:34:41Z")

</div>

welcome.

please post minimal but runnable code and necessary data to reproduce the issue.

---

<div class="post-metadata">

**Author:** ![rajeshchanda](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@rajeshchanda](https://forum.opencv.org/u/rajeshchanda)\
**Post date:** [February 3, 2021, 9:47am UTC](https://forum.opencv.org/t/cv-boxfilter-and-cv-addweighted-are-giving-worst-performance-on-gpu-than-cpu/1292/3 "2021-02-03T09:47:00Z")

</div>

float32\_t srcAlpha = 0.5;  
float32\_t srcBeta = 0.5;  
Mat opencvblenddstUMATToMat;  
//using umat  
UMat opencvblendinputUMAT1,opencvblendinputUMAT2,opencvblenddstUMAT;  
cv::imread("/storage/emulated/0/opencvTesting/wp4473260.jpg").copyTo(opencvblendinputUMAT1);  
cv::imread("/storage/emulated/0/opencvTesting/wp4473263.jpg").copyTo(opencvblendinputUMAT2);

addWeighted(opencvblendinputUMAT1,srcAlpha,opencvblendinputUMAT2,srcBeta,0,opencvblenddstUMAT);

cv::ocl::finish();

opencvblenddstUMAT.copyTo(opencvblenddstUMATToMat);  
cv::imwrite("/storage/emulated/0/opencvTesting/opencvblenddstUMATToMat.jpg", opencvblenddstUMATToMat);

---

<div class="post-metadata">

**Author:** ![rajeshchanda](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@rajeshchanda](https://forum.opencv.org/u/rajeshchanda)\
**Post date:** [February 3, 2021, 9:49am UTC](https://forum.opencv.org/t/cv-boxfilter-and-cv-addweighted-are-giving-worst-performance-on-gpu-than-cpu/1292/4 "2021-02-03T09:49:09Z")

</div>

Above code is for addWeighted i.e blending of two images

---

<div class="post-metadata">

**Author:** ![rajeshchanda](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@rajeshchanda](https://forum.opencv.org/u/rajeshchanda)\
**Post date:** [February 3, 2021, 9:50am UTC](https://forum.opencv.org/t/cv-boxfilter-and-cv-addweighted-are-giving-worst-performance-on-gpu-than-cpu/1292/5 "2021-02-03T09:50:24Z")

</div>

UMat opencvfilterinputUMAT,opencvfilterdstUMAT;  
Mat opencvfilterdstUMATToMat;  
Point point1 = Point(-1, -1);  
cv::imread("/storage/emulated/0/opencvTesting/wp4473260.jpg").copyTo(opencvfilterinputUMAT);;

```
boxFilter(opencvfilterinputUMAT, opencvfilterdstUMAT, -1, cv::Size(16,16), point1, true, BORDER_DEFAULT);

opencvfilterdstUMAT.copyTo(opencvfilterdstUMATToMat);
cv::imwrite("/storage/emulated/0/opencvTesting/opencvcvboxfilterUMATToMat.jpg", opencvfilterdstUMATToMat);
```

---

<div class="post-metadata">

**Author:** ![rajeshchanda](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@rajeshchanda](https://forum.opencv.org/u/rajeshchanda)\
**Post date:** [February 3, 2021, 9:52am UTC](https://forum.opencv.org/t/cv-boxfilter-and-cv-addweighted-are-giving-worst-performance-on-gpu-than-cpu/1292/6 "2021-02-03T09:52:02Z")

</div>

above code is for boxFilter
