senguptaumd / Background-Matting

Background Matting: The World is Your Green Screen
https://grail.cs.washington.edu/projects/background-matting/
4.78k stars 662 forks source link

Assertion failed #33

Closed shxiangyan closed 4 years ago

shxiangyan commented 4 years ago

There is no problem in running the alignment part of the demo.What is the reason for the following error when running my own picture?

python test_pre_process.py -i sample_data/my_photo/

Traceback (most recent call last): File "test_pre_process.py", line 108, in back_align = alignImages(back, image,mask) File "test_pre_process.py", line 42, in alignImages im1Reg = cv2.warpPerspective(im1, h, (width, height)) cv2.error: OpenCV(3.4.5) /io/opencv/modules/imgproc/src/imgwarp.cpp:2927: error: (-215:Assertion failed) (M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 3 && M0.cols == 3 in function 'warpPerspective'

sunkest commented 4 years ago

I have same issue, and I recognized that the matrix H(returned from cv2.findHomography) was None. I found that cv2.findHomography can return None if the matrix H cannot be calculated but I could not find any solution for that.. Is anybody know how to solve the problem?

senguptaumd commented 4 years ago

This may happen if the background is featureless, like a flat wall. For homography, it needs to find sufficient keypoints via AKAZE features, match them reliably and calculate homography (needs at least 8 points), if not it will break.