A versatile machine vision algorithm for real-time counting manually assembled pieces