Ask Your Question
0

OpenCV and GPU

asked Mar 14 '18

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

Preview: (hide)

Comments

Please refer to the doc.

Eduardo gravatar imageEduardo (Mar 14 '18)edit

did you see the samples here ?

berak gravatar imageberak (Mar 14 '18)edit

2 answers

Sort by » oldest newest most voted
0

answered Mar 14 '18

updated Mar 14 '18

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.

Preview: (hide)

Comments

Thank you friend for you response

abdorreza gravatar imageabdorreza (Mar 15 '18)edit

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

abdorreza gravatar imageabdorreza (Mar 15 '18)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 (Mar 15 '18)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 (Mar 15 '18)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 (Mar 16 '18)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 (Mar 16 '18)edit
0

answered Mar 16 '18

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"

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Mar 14 '18

Seen: 2,565 times

Last updated: Mar 16 '18