6

So, i got from my university a python related task. we need to get s a set of images (from a folder), and then resize them as fast as possible. so i manage to do it using cv2 resize option. but, apparently we can do it a lot faster using the GPU. but unfortenally i was unable to find the best way to do it with the openCV module.

i found this code, but it isn't openCV realted.

import numpy as np
from timeit import default_timer as timer
from numba import vectorize
@vectorize(['float32(float32, float32)'], target='cuda')
def pow(a, b):
 return a ** b
def main():
 vec_size = 100000000
 a = b = np.array(np.random.sample(vec_size), dtype=np.float32)
 c = np.zeros(vec_size, dtype=np.float32)
 start = timer()
 c = pow(a, b)
 duration = timer() - start
 print(duration)
if __name__ == '__main__':
 main()

EDIT: i found something called "UMat" what's the benefits of using it? i tried to use in im my code in this way:

image = cv2.UMat(cv2.resize(image, (0, 0), fx=0.5, fy=0.5)) # Resize image by half
asked Dec 28, 2018 at 11:56
0

1 Answer 1

4

Yes, you can use GPU module in OpenCV, but unfortunately only in C++. There is no wrapper for Python.

Solutions:

answered Dec 28, 2018 at 12:11
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for your replay. i found something called "UMat". what is it?
I think it just says, where the data of Mat are located - regullar, dedicated or shared memory, but doesn't necessarily mean it's conputed on GPU.
So it can use the GPU if available?
Yes. Please, read creafully this link.
Ok, iv'e read it. but it does not say nothing about the GPU. only that the module sends the right task to the right parts of the computer (CPU, GPU etc..), but when i tried to measure time while using the UMat, there isn't any difference
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.