Learning graphs for object tracking and counting