[Sidefx-houdini-list] Python + numpy + COP

Alvaro Castaneda varomix at gmail.com
Thu Dec 12 19:39:41 EST 2013

Hi guys

I'm trying to run the examples in the docs about
*Define a new COP type using Python*


trying to run this brighten example that involves numpy
I always get and error when it defines the pixels numpy array and tries to
reshape it
the error is

ValueError: total size of new array must be unchanged

here's the code from the docs

thanks for the help

import numpy
def output_planes_to_cook(cop_node):
    return ("C",)
def required_input_planes(cop_node, output_plane):
    if output_plane == "C":
        return ("0", "C")
    return ()
def cook(cop_node, plane, resolution):
    input_cop = cop_node.inputs()[0]

    # Grab the pixels from the corresponding plane in the input, then build
    # a numpy array from the data.
    pixels = numpy.frombuffer(
        input_cop.allPixelsAsString(plane), dtype=numpy.float32).reshape(
        resolution[1], resolution[0], 3).copy()

    # Use numpy to scale all values by the brightness.
    pixels *= cop_node.evalParm("bright")

    # Store the contents of the numpy array back into the pixel data.

More information about the Sidefx-houdini-list mailing list