Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on a call to cv2.warpAffine() #2

Closed
PavelPr opened this issue Jun 3, 2018 · 2 comments
Closed

Crash on a call to cv2.warpAffine() #2

PavelPr opened this issue Jun 3, 2018 · 2 comments

Comments

@PavelPr
Copy link

PavelPr commented Jun 3, 2018

Hi!

First, thank you for your hard work!

I am trying to run training and some time after the first epoch begins, I am running into an issue where the following call (in transformer.py) fails:

masks = cv2.warpAffine(masks, M, cv_shape, flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_CONSTANT, borderValue=0)

Specifically, there is an OpenCV assertion error, stating that "error: (-215) _src.channels() <= 4 || (interpolation != INTER_LANCZOS4 && interpolation != INTER_CUBIC) in function cv::warpAffine". Could you please point me at what might be wrong here?

Thanks a lot!

N.B. Looking at the code, at first glace it would so seem that several Mats are passed into warpAffine(), is this intentional?

@PavelPr PavelPr changed the title Crash on cv2.WarpImage() Crash on cv2.warpAffine() Jun 3, 2018
@PavelPr PavelPr changed the title Crash on cv2.warpAffine() Crash on a call to cv2.warpAffine() Jun 3, 2018
@jricheimer
Copy link
Contributor

jricheimer commented Jun 3, 2018

Hi @PavelPr , thanks for your interest.

I trained using opencv v2.4.9, which allows cubic interpolation for affine warping on an image with any number of channels. Apparently, later versions of opencv (including the current master branch) do not allow this. So, you can either step back to opencv 2.4.9 (which in my experience provides faster image resizing and is worthwhile); or remove this line from transformer.py:

masks = cv2.warpAffine(masks, M, cv_shape, flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_CONSTANT, borderValue=0)

and replace it with something like this:

out_masks = np.zeros(cv_shape[::-1]+(masks.shape[-1],))
for i in range(masks.shape[-1]):
    out_masks[:,:,i] = cv2.warpAffine(masks[:,:,i], M, cv_shape, flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_CONSTANT, borderValue=0)
masks = out_masks

That way, you're looping through the mask channels instead of warping them all at once.

Also, please pull the latest master branch to incorporate a new fix I just pushed to the data generation code.

@PavelPr
Copy link
Author

PavelPr commented Jun 3, 2018

I will give that a try! Thank you for your very quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants