MarcoForte / knn-matting

Python implementation of KNN Matting, CVPR 2012 / TPAMI 2013 http://dingzeyu.li/projects/knn/
MIT License
128 stars 29 forks source link

cannot process more than one images ? #6

Open lizhengwei1992 opened 5 years ago

lizhengwei1992 commented 5 years ago

Hi, I find a strange phenomenon when I process more than one image like this:

img = cv2.imread('00003.png')
trimap = cv2.imread('00003_trimap.png')
alpha = knn_matte(img, trimap)

img = cv2.imread('donkey.png')
trimap = cv2.imread('donkeyTrimap.png')
alpha = knn_matte(img, trimap)    

at first image, everything is normal, I get the alpha map. then, the process stops at the second image:

Traceback (most recent call last):
  File "knn_matting.py", line 88, in <module>
    main(args)
  File "knn_matting.py", line 75, in main
    alpha = knn_matte(img, trimap)
  File "knn_matting.py", line 39, in knn_matte
    D_script = scipy.sparse.diags(np.ravel(A.sum(axis=1)))
  File "/home/lzw/.local/lib/python3.5/site-packages/scipy/sparse/base.py", line 1015, in sum
    np.ones((n, 1), dtype=res_dtype))
  File "/home/lzw/.local/lib/python3.5/site-packages/numpy/matrixlib/defmatrix.py", line 68, in asmatrix
    return matrix(data, dtype=dtype, copy=False)
  File "/home/lzw/.local/lib/python3.5/site-packages/numpy/matrixlib/defmatrix.py", line 118, in __new__
    PendingDeprecationWarning, stacklevel=2)
PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
Youcunl commented 5 years ago

I solve the issue by downgrade numpy to 1.14

lizhengwei1992 commented 5 years ago

@Youcunl thanks ! i will try it.