function for object detection