Hello Young,
What you are trying to do is actually fairly difficult (I think.) The pan/tilt demo uses a control loop to control the servos such that the largest detected object is centered in the image. The code does not calculate the position that the servos need to be. It calculates the velocity that the servos need to move to center the object, and it iteratively converges on the location of the object after several control cycles.
You are trying to calculate the position of each object and move the servos to this location. This approach makes good sense, but it’s a much harder problem. In order to calculate the servo positions, you need to have an accurate mathematical expression that maps the detected object position (the x-y position that Pixy provides) to the pan/tilt servo positions. This requires some calibration and is fairly challenging to get decent accuracy.
Anyway, I’m not sure what your application is. You sound like you are new to Pixy. Perhaps you can describe your application and we can suggest a simpler solution.
Edward