I can get the total number of items in the cart by using:
$shipping_num_boxes = $_SESSION['cart']->count_contents();

How can i get the number of items of a specific product (master category #2)?

Thanks in advance for your help