I'm currently working on a python script that passes an argument to a function getWeight.m
written in MATLAB.
getWeight.m
returns a weight matrix with the same dimensions given the size of an RGB image. It's source code can be found here.
I'm running the following python script:
import matlab.engine
eng = matlab.engine.start_matlab()
import cv2
image = cv2.imread('warped_image.png')
weight = eng.getWeight(image.shape) # (575, 503, 3)
print(weight)
Passing image.shape
of class tuple
as an argument to the function yields the following error:
Size inputs must be numeric
Are there any workarounds to this error?
Here's the error after following @Chris method:
Traceback (most recent call last):
File "test.py", line 10, in <module>
weight = eng.getWeight(matlab.int8(list(image.shape))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matlab/
mlarray.py", line 106, in __init__
raise ex
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matlab/
mlarray.py", line 104, in __init__
super(int8, self).__init__('b', initializer, size, is_complex)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matlab/
_internal/mlarray_sequence.py", line 57, in __init__
self._data = flat(self, initializer, init_dims, typecode)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matlab/
_internal/mlarray_sequence.py", line 338, in flat
return array.array(typecode, nested_list)
OverflowError: signed char is greater than maximum
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…