March 2020
Intermediate to advanced
366 pages
9h 8m
English
We already know that the center region belongs to the hand. For such a scenario, we can simply apply cv2.floodfill to find all the connected image regions.
Before we do this, we want to be absolutely certain that the seed point for the flood fill belongs to the right mask region. This can be achieved by assigning a grayscale value of 128 to the seed point. However, we also want to make sure that the center pixel does not, by any coincidence, lie within a cavity that the morphological operation failed to close.
So, let's set a small 7 x 7-pixel region with a grayscale value of 128 instead, like this:
small_kernel = 3frame[height // 2 - small_kernel:height // 2 + small_kernel, width // 2 - ...