0
点赞
收藏
分享

微信扫一扫

电脑摄像头+物体轮廓识别

闲鱼不咸_99f1 2022-02-17 阅读 68
import cv2
# import matplotlib.pyplot as plt


cap = cv2.VideoCapture(0)
while True:
    ret, frame = cap.read()
    # cv2.imshow("The original figure", frame)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray2 = 255 - gray
    cv2.imshow("The color chart", gray2)
    cv2.resizeWindow("The color chart", 500, 500);
    ret, binary = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
    cv2.imshow("Binary figure", binary)
    cv2.resizeWindow("Binary figure", 500, 500);
    img_median = cv2.medianBlur(binary, 3)
    img_Guassian = cv2.GaussianBlur(img_median, (5, 5), 0)
    img_mean = cv2.blur(img_Guassian, (5, 5))
    img_bilater = cv2.bilateralFilter(img_mean, 9, 75, 75)
    contours, hierarchy = cv2.findContours(img_bilater, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    cv2.drawContours(frame, contours, -1, (0, 0, 255), 6)

    cv2.imshow("Outline of the figure", frame)
    cv2.resizeWindow("Outline of the figure", 500,500);
    boardkey = cv2.waitKey(1) & 0xFF
    if boardkey == 27:
        break
cap.release()
cv2.destroyAllWindows()

在这里插入图片描述

举报

相关推荐

0 条评论