Ask Your Question
0

OpenCV and GPU

asked 2018-03-14 05:43:45 -0600

abdorreza gravatar image

Hello

I Built OpenCV 3.4.0 with CUDA. Now my OpenCV works right but I do not know how I can run OpenCV functions on GPU. For example I want run "connectedComponentsWithStats" on GPU.

Thank you for helping me

edit retag flag offensive close merge delete

Comments

Please refer to the doc.

Eduardo gravatar imageEduardo ( 2018-03-14 05:49:47 -0600 )edit

did you see the samples here ?

berak gravatar imageberak ( 2018-03-14 05:50:11 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2018-03-14 08:37:39 -0600

updated 2018-03-14 08:39:06 -0600

Hi, I think you are looking for labelcomponents, but this is legacy and the tests for it have been disabled so it probably doesn't work correctly, see here.

I don't think OpenCV has a working GPU version of exactly what you are looking for (WithStats). ArrayFire did have but it was pretty slow as the part which calculates the size of the connected component blobs was not well optimized.

edit flag offensive delete link more

Comments

Thank you friend for you response

abdorreza gravatar imageabdorreza ( 2018-03-15 09:39:49 -0600 )edit

my opencv do not know "labelcomponents" function !!!

abdorreza gravatar imageabdorreza ( 2018-03-15 09:53:26 -0600 )edit

Have you included the following header?

#include "opencv2/cudalegacy.hpp"

see https://github.com/opencv/opencv/blob... line 165 for its usage.

cudawarped gravatar imagecudawarped ( 2018-03-15 12:06:06 -0600 )edit

Thank you. I include it now . But I have some errors now. error : Severity Code Description Project File Line Suppression State Error C1083 Cannot open include file: 'cuda_runtime.h': No such file or directory ConsoleApplication3 c:\opencv 3.4.0\build\install\include\opencv2\core\cuda\common.hpp 46

abdorreza gravatar imageabdorreza ( 2018-03-15 14:00:11 -0600 )edit

As I said above the code is legacy and probably doesn't work correctly.

Are you sure you need connected components with stats on the GPU? I ask because from memory the CPU routine is not that slow. Additionally if you need to know the size of your connected regions before you can do any additional processing on the GPU (which is usually the case with CCL, at least in my experience) you will have to either a) stall the GPU to retrieve this information, possibly loosing any gain you have made, or b) come up with a strategy to hide this latency by performing some additional processing on the GPU, while you wait.

I understand that your data may already be on the GPU but if your workflow represents case b) then an async copy back to the host for processing there may be a better option.

cudawarped gravatar imagecudawarped ( 2018-03-16 03:16:49 -0600 )edit

Yes dear. I am sure that I need GPU for connected components. Becuase I am working on a real time video processing and speed is so important for me. Why only I have problem with #include "opencv2/cudalegacy.hpp" ?!

do you have any refer for me?

thank you

abdorreza gravatar imageabdorreza ( 2018-03-16 05:33:59 -0600 )edit
0

answered 2018-03-16 17:27:45 -0600

abdorreza gravatar image

I solved my problem with these two steps :

1) Project->Build Dependencies->Build Customisazions...-> Tick CUDA 9.1

2) Project->Properties->Linker->Input->Additional Dependencies-> "cudart.lib"

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-03-14 05:43:45 -0600

Seen: 2,405 times

Last updated: Mar 16 '18