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

"ValueError: operands could not be broadcast together with shapes" #1

Open
maximepriv opened this issue Aug 12, 2016 · 7 comments
Open

Comments

@maximepriv
Copy link

Hi!
I try to use your script to align a stack of photos. It works great, but after about 70 pictures, the script stop and I get this message. I tried skipping a few pictures, but it did not help. Unfortunately, I'm not sure how to proceed to debug this myself.

Traceback (most recent call last): File "../pada.py", line 148, in <module> img_thresh=cfg['img_thresh']) File "/home/ubuntu/face-align/pada/align.py", line 177, in align_images for idx, (n, im, lms) in enumerate(ims_and_landmarks): File "/home/ubuntu/face-align/pada/align.py", line 111, in get_ims_and_landmarks for n, im in images: File "/home/ubuntu/face-align/pada/align.py", line 48, in read_ims if prev_im is None or numpy.linalg.norm(prev_im - im) > img_thresh: ValueError: operands could not be broadcast together with shapes (3264,2448,3) (4032,3024,3)

@matthewearl
Copy link
Owner

This issue is that your input images are of varying size. The code was originally written for processing video input (ie. where all the frames are the same size) however there's no reason it can't be adapted to suit sequences of images. Can you try changing the condition to:

if (prev_im is None or prev_im.shape != im.shape or
numpy.linalg.norm(prev_im - im) > img_thresh):

...and reply letting me know if it works?

@maximepriv
Copy link
Author

Oh. That makes sense - I changed my camera after about a month and forgot about it.

I tried changing that same line to a very simple "if 1:", which stopped the errors, but I frankly don't really know what that does. I did not yet see the output that I got from that change.

I'l try your proposition as soon as I can and I'll let you know. Knowing the source of the issue, I may just "make sure" that all my pictures are of the same size (by padding them with black if needed).

Thanks for your fast answer! I'll let you know if it fixes it.

@subins2000
Copy link

@matthewearl I tried that but the landscape image is way out of position from the just previous portrait image. The subsequent landscape images are all aligned correctly.

Is there a way to solve this ?

Thank you :)

@maximepriv
Copy link
Author

I ended-up resizing all my images in Photoshop so they have the same size (adding black letterbox/pillarbox/allaroundbox if needed). The script then aligned them correctly (and I re-cropped them to save space after that).

With that said, I'm sure there's a better solution 😉

@subins2000
Copy link

@maximepriv Thank you ! That fixed it. I made a Python script to resize the images : https://github.com/subins2000/SelfieADay

@maximepriv
Copy link
Author

maximepriv commented Dec 19, 2018

Yay!

It'll be great to scan the inputs to find the largest width/height and use that as the new image size while resizing (or trying to change the original script so it'll work with multiple image size), but I usually just do it by hand - that works well enough for my limited use.

@subins2000
Copy link

@maximepriv Update: I modified that image resize script to adjust with different sizes too. In my project, I change my camera in between, the resolutions got different, but the script still works.

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

3 participants