main.py 文件源码

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

项目:papacamera 作者: 340StarObserver 项目源码 文件源码
def matchFeatures(queryFeature, trainFeature, matcher):
    """
    match(...) function: match query image features and train image features.
    parameter:
        queryFeature: features of query image
        trainFeature: features of train image
        matcher:      feature matcher
        queryImage:   this is just for test to show the position of the found image which in the query image
                      , input query image data which has processed by cv2.imread().
    return:
        if found matched image ,return image name, otherwise return None.
    """
    queryKeypoints = queryFeature[0]
    queryDescriptors = queryFeature[1]

    trainKeypoints = trainFeature[0]
    trainDescriptors = trainFeature[1]
    trainImgSize = trainFeature[2]
    trainImgHeight = trainImgSize[0]
    trainImgWidth = trainImgSize[1]

    corners=numpy.float32([[0, 0], [trainImgWidth, 0], [trainImgWidth, trainImgHeight], [0, trainImgHeight]])
    raw_matches = matcher.knnMatch(trainDescriptors, queryDescriptors, 2)
    queryGoodPoints, trainGoodPoints = filter_matches(trainKeypoints, queryKeypoints, raw_matches)

    if len(queryGoodPoints) >= 4:
        H,status = cv2.findHomography(queryGoodPoints, trainGoodPoints, cv2.RANSAC, 5.0)
    else:
        H,status = None,None
    res=False
    obj_corners=None
    if H is not None:
        corners = corners.reshape(1, -1, 2)
        obj_corners = numpy.int32(cv2.perspectiveTransform(corners, H).reshape(-1, 2))
        is_polygon = ispolygon(obj_corners)
        if is_polygon:
            res=True
    del queryKeypoints
    del queryDescriptors
    del trainKeypoints
    del trainDescriptors
    del trainImgSize
    del corners
    del raw_matches
    del queryGoodPoints
    del trainGoodPoints
    del obj_corners
    return res
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号