Changed the code a little bit. Added a threshold that counts the boxes.