Closed liupgd closed 2 years ago
I tried one solution. As PyReverseDims
can get continuous memory object but not suitable for cv2.circle
, I permuted the data in advance, then the PyReverseDims
can get the right continuous object:
img = cv2.imread("someimage.jpg")
rimg = permutedims(img, ndims(img):-1:1)
# I also tried PermutedDimsArray which doesn't work. PermutedDimsArray only creates a permuted view,
# while permutedims creates a new array with copy.(I hope there will be better solutions without data copy.)
pyimg = PyReverseDims(rimg) # now, pyimg is a PyObject with flag C_CONTIGUOUS=True
out=cv2.circle(pyimg, (100, 200), 50, (0, 0, 255), 20); # cv2.rectangle, ellipse should also work now.
I would be happy if anyone could offer better solutions. Thx.
Layout of the output array img is incompatible with cv::Mat
The basic problem here is that Julia arrays are column-major and cv is expecting row-major. Reversing the dimensions and then using PyReverseDims
array is the right solution.
Error occurred when invoking python cv2 drawing functions.
Code
Error info
Same error happend in
cv2.rectangle
,cv2.ellipse
. And all these codes work well in python.Possible cause
Julia array converted to python numpy is not
C_CONTIGUOUS
:While in python cv2, Arrays are needed to be
C_CONTIGUOUS
. One possible solution isPyReverseDims
:But the
out.jpg
doesn't change, no cirlces drawn. How should I do? Thx.