How to move an object's origin to the center of its bounding box? What I want:
I want to set the origin of an object to the center of its bounding box using a python command.

What I've tried:

bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')


and

bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')


What happened: 
 

As you can see, the origin isn't centered to the bounding box.

EDIT: I asked the same question as Get center of geometry of an object with the addition of setting the origin to this center.
Have you tried setting the center to BOUNDS?

bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='BOUNDS')