QuickNDirty.py 文件源码

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

项目:headlights 作者: Team395 项目源码 文件源码
def contourImg(image):
    # Find contours in the image
    _, contours, hierarchy = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    image.fill(0)
    # Filter out some contours
    i = 0
    found = False
    cnt = []
    boundingRects = []
    while i < len(contours):
        if cv2.contourArea(contours[i]) > 200:
            approx = cv2.convexHull(contours[i])
            x,y,w,h = cv2.boundingRect(contours[i])
            aspect = w/h
            coverage = w*h/cv2.contourArea(contours[i])
            if(abs(aspect - .4) < .1 and coverage > 0.85):
                boundingRects.append([x,y,w,h])
        i += 1
    i = 0
    while i < len(boundingRects):
        j = i+1
        while j < len(boundingRects):
            if(abs(boundingRects[i][1] - boundingRects[j][1]) < 20 and abs(((boundingRects[i][0] - boundingRects[j][0]) / boundingRects[i][1]) - 1.65 < .1)):
                return (createRectCnt(boundingRects[i]), createRectCnt(boundingRects[j]))
            j+=1
        i+=1
    return -1
# Define color range
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号