I am trying to make my code faster by using Numba and vectorizing. My code is to get input from two 360 deg cameras and crop them. The main idea here is to learn how to use Numba and vectorizing. Below is my code:
import cv2
import time
from numba import vectorize
import numba
dim = 1440
@vectorize(['int[:, :, 3](int[:, :, 3])'], target='cuda')
def cropFaster(img):
croppedImG = img[:,10:1100]
return croppedImG
cap1 = cv2.VideoCapture(0) # Set input device number
cap1.set(3, dim) # Set Horizontal resolution
cap1.set(4, dim) # Set Vertical resolution
cap2 = cv2.VideoCapture(1) # Set input device number
cap2.set(3, dim) # Set Horizontal resolution
cap2.set(4, dim) # Set Vertical resolution
while (cap1.isOpened()):
t1 = time.clock()
ret1, img1 = cap1.read()
ret2, img2 = cap2.read()
croppedImgL = cropFaster(img1)
croppedImgR = cropFaster(img2)
t2 = time.clock() - t1
print (t2)
cv2.imshow("Left", croppedImgL)
cv2.imshow("Right", croppedImgR)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap1.release()
I get the following error:
Traceback (most recent call last):
File "transparentAPI2.py", line 9, in <module>
@vectorize(['int[:, :, 3](int[:, :, 3])'], target='cuda')
File "/usr/local/lib/python3.6/dist-packages/numba/npyufunc/decorators.py", line 120, in wrap
vec.add(sig)
File "/usr/local/lib/python3.6/dist-packages/numba/npyufunc/deviceufunc.py", line 391, in add
args, return_type = sigutils.normalize_signature(sig)
File "/usr/local/lib/python3.6/dist-packages/numba/sigutils.py", line 26, in normalize_signature
parsed = _parse_signature_string(sig)
File "/usr/local/lib/python3.6/dist-packages/numba/sigutils.py", line 16, in _parse_signature_string
return eval(signature_str, {}, types.__dict__)
File "<string>", line 1, in <module>
TypeError: 'type' object is not subscriptable
Any idea how to fix this? Thanks