Python COP Filter Example Broken

   265   0   0
User Avatar
4 posts
Joined: Dec. 2017
A number of the examples for writing COP filters/generators in Python seem to be completely broken in at least the latest version of Houdini (haven't ever tried them before).

Notable example:
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.

This fails on the
line because the input pixel buffer is the incorrect resolution.

I've noticed the “cook” method is called twice for each node, once for the actual plane data and a second time at 1/10 resolution. This second invocation creates the error because resolution,resolution are 1/10th the size of input_cop.allPixelsAsString(plane).

The error then is returned as:
Traceback (most recent call last):
File "", line 1, in
File "", line 18, in cook
ValueError: total size of new array must be unchanged

Are there any decent examples for a default python COP filter? Do I actually have to resize the input cop pixels to match the intended plane resolution every time I run a cook?
  • Quick Links