首页 > 解决方案 > moviepy ValueError: operands could not be broadcast together with shapes

问题描述

I want to add vfx.fadein for my ImageClip for that my code snipped :

def rectangle():
    size = (surfaceW,surfaceH)
    radius = background_radius
    fill = background_text_color
    width, height = size
    rectangle = Image.new('RGBA', size, fill)
    corner = round_corner(radius, fill)
    rectangle.paste(corner, (0, 0))
    rectangle.paste(corner.rotate(90), (0, height - radius))
    rectangle.paste(corner.rotate(180), (width - radius, height - radius))
    rectangle.paste(corner.rotate(270), (width - radius, 0))
    pix = numpy.array(rectangle)
    return pix     =====================>>>>((75, 601, 4))


image = ImageClip(rectangle(), duration=duration_time).set_start(start_point).set_position(position)

print(image.__dict__["img"].shape) ===========>>>>((75, 601, 3))


image = vfx.fadein(image,duration=1, initial_color=[0,0,0,0]) =====> Error Line

But Im getting this error;

ValueError: operands could not be broadcast together with shapes (75,601,3) (4,)

I want to use vfx.fadein with transparant background so I need use alpha channel. How can solve this?

标签: pythonnumpymoviepy

解决方案


推荐阅读