test1.py 文件源码

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

项目:vision-code 作者: FIRST-Team-1699 项目源码 文件源码
def main():
    """im = cv2.imread('307.jpg')
    imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
    ret, thresh = cv2.threshold(imgray, 85, 120, 0)
    """

    image = cv2.imread('307.jpg')

    lower = (120, 120, 0)
    upper = (190, 200, 150)

    # create NumPy arrays from the boundaries
    lower = np.array(lower, dtype="uint8")
    upper = np.array(upper, dtype="uint8")

    # find the colors within the specified boundaries and apply
    # the mask
    mask = cv2.inRange(image, lower, upper)


    output = cv2.bitwise_and(image, image, mask=mask)

    imgray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY)
    ret, thresh = cv2.threshold(imgray, 85, 120, 0)

    # Detect contours using both methods on the same image
    _, contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

    # Copy over the original image to separate variables
    img1 = image.copy()

    new_contours = []

    min_area = float(input("Enter the minimum area: "))

    for x in contours:
        if (cv2.contourArea(x) < min_area):
            pass
        else:
            new_contours.append(x)
        pass

    # Draw both contours onto the separate images
    cv2.drawContours(img1, new_contours, -1, (2, 21, 200), 3)

    print cv2.contourArea(new_contours[0])

    # Now show the image
    print(new_contours)
    #cv2.imwrite('test-process' + str(int(min_area)) + '.jpg', img1)
    cv2.imshow('Output', img1)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号