Ask Your Question
1

setNumThreads

asked 2017-01-15 10:42:46 -0600

alecs26 gravatar image

Hello,

I have questions about cv::setNumThreads(int nthreads) that I don't understand even by reading the documentation (with OpenCV 2.4 on Windows).

1- First of all, what should I put as nthreads ? I want my program to work on different computers so I don't want to hardcode a value (ex. 2). Can I set a number that will take all the available cores ?

2- What if I have two threads running my program where there is OpenCV code in both of them. Should I declare this in each thread ? Will it work even with my two threads ?

3- a) With no cv::setNumThreads(), CPU is 20%. b) With cv::setNumThreads(2), CPU is 10%. c) With cv::setNumThreads(4), CPU is 17% (???)

For information, I simply grab an image and apply an optical flow.

Thank you so much,

Alex

edit retag flag offensive close merge delete

Comments

if you want to test :

  1. getNumThread() and test default behavior and it should be 2* available cores+1
  2. setNumThread(1) only one thread

In your test there is a bottleneck : grabbing an image

please don't post duplicate question

LBerger gravatar imageLBerger ( 2017-01-15 10:54:35 -0600 )edit

Thank you for your answer.

  • getNumThread() gives 5. What should I do with this information ?

  • With setNumThreads(1) I get CPU at 6%. I don't get why CPU is lower than with setNumThreads(2) or setNumThreads(4) ???

  • I know there is a bottleneck for the time (30ms) with grabbing an image. That's ok. My concern is really for the CPU usage.

Thank you very much,

Alex

alecs26 gravatar imagealecs26 ( 2017-01-15 11:13:10 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-01-15 12:15:17 -0600

LBerger gravatar image

updated 2017-01-15 13:16:04 -0600

If you want to minimize CPU usage one thread and insert a sleep !

edit flag offensive delete link more

Comments

Thank you for your help.

I just don't get, if I do this: capture >> frame; while (true) { Will it not capture only one frame ?

Also, something was not clear from my question but I want to minimize the CPU usage. I don't care if the process takes more time, but I want the CPU usage to be as low as possible.

Thank you very much,

Alex

alecs26 gravatar imagealecs26 ( 2017-01-15 12:25:20 -0600 )edit

"Will it not capture only one frame ?" yes it is wrong as I wrote.

If you want to minimize CPU usage one thread and insert a sleep !

LBerger gravatar imageLBerger ( 2017-01-15 13:06:47 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-15 10:42:46 -0600

Seen: 5,731 times

Last updated: Jan 15 '17