How to not select objects behind main camera with script in Python?
Add a plane on perspective camera looking forward.

As a quick work around is to add a plane looking forward on a perspective camera, by adding this else clause circa line 32 of original code.

if not is_persp:
    # add a 5th plane to ignore objects behind the view
    n = normal(frame[0], frame[1], frame[2])
    d = -n.dot(origin)
    planes.append((n, d))
else:
    n = (matrix * Vector((0, 0, -1)) - origin).normalized()
    d = 0
    planes.append((n, d))


A cameras line of view is its negative local Z axis. All above does is adds a plane that has a global normal looking in the same direction.


Image shows plane with normal, the Z axis pointing in direction of camera's -Z axis.