many OpenCV Functions are all used SSE2、AVX Etc . It also contains code that is not optimized .
therefore , If our system supports these features , We should use them ( Almost all modern processors support them ).
It is enabled by default at compile time .
therefore OpenCV Run optimized code when enabled , Otherwise run code that is not optimized .
have access to css . useoptimized() Check if it is enabled / Ban , Use css . setuseoptimized() Check if it is enabled / Ban .
Let's take a simple example .
# check if optimization is enabled cv.useOptimized() # result True %timeit res = cv.medianBlur(img,49) # result 10 loops, best of 3: 34.9 ms per loop # Disable it cv.setUseOptimized(False) cv.useOptimized() # result False %timeit res = cv.medianBlur(img,49) # result 10 loops, best of 3: 64.1 ms per loop
As you can see , The optimized median filter is faster than the unoptimized version 2 times .
If you check the source code , You can see that median filtering uses SIMD Optimize .
therefore , You can use it to enable optimization at the top of the code ( remember , It is enabled by default ).