def getBlockZone(p, aSearch, tBlock, blockSize):
    """
    Retrieves the block searched in the anchor search area to be compared with the macroblock tBlock in the current frame
    :param p: x,y coordinates of macroblock center from current frame
    :param aSearch: anchor search area image
    :param tBlock: macroblock from current frame
    :param blockSize: size of macroblock in pixels
    :return: macroblock from anchor
    """
    px, py = p  # coordinates of macroblock center
    # get top left corner of macroblock
    px, py = px-int(blockSize/2), py-int(blockSize/2)
    px, py = max(0, px), max(0, py)  # ensure macroblock is within bounds

    # retrive macroblock from anchor search area
    aBlock = aSearch[py:py+blockSize, px:px+blockSize]

    try:
        assert aBlock.shape == tBlock.shape  # must be same shape

    except Exception as e:
        print(e)
        print(
            f"ERROR - ABLOCK SHAPE: {aBlock.shape} != TBLOCK SHAPE: {tBlock.shape}")

    return aBlock