templateMatching.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:card-detector 作者: naderchehab 项目源码 文件源码
def highlightRois(image, roisCoords, roiWidthHeight):
    rois = []
    for roiCoord in roisCoords:
        roiTopLeft = roiCoord['topLeft']
        name = roiCoord['name']
        # extract the regions of interest from the image
        roiBottomRight = tuple([sum(x) for x in zip(roiTopLeft, roiWidthHeight)])
        roi = image[roiTopLeft[1]:roiBottomRight[1], roiTopLeft[0]:roiBottomRight[0]]
        rois.append({'topLeft': roiTopLeft, 'bottomRight': roiBottomRight, 'area': roi, 'name': name})

    # construct a darkened transparent 'layer' to darken everything
    # in the image except for the regions of interest
    mask = np.zeros(image.shape, dtype = "uint8")
    image = cv2.addWeighted(image, 0.25, mask, 0.75, 0)

    # put the original rois back in the image so that they look 'brighter'
    for roi in rois:
        image[roi['topLeft'][1]:roi['bottomRight'][1], roi['topLeft'][0]:roi['bottomRight'][0]] = roi['area']
        cv2.putText(image, roi['name'][0], roi['topLeft'], cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,255,255), 2)

    return image
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号