欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

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

时间:2023-05-19

import cv2# import matplotlib.pyplot as pltcap = 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: breakcap.release()cv2.destroyAllWindows()

选定区域 00-08-53_51Record

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。