"ValueError: operands could not be broadcast together with shapes"
maximepriv opened this issue · 7 comments
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)
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?
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.
@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 :)
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 😉
@maximepriv Thank you ! That fixed it. I made a Python script to resize the images : https://github.com/subins2000/SelfieADay
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.
@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.