资源简介
car_detected.py
代码片段和文件信息
#coding=utf-8
import time
import cv2
import numpy as np
bs = cv2.createBackgroundSubtractorKNN(detectShadows = True)
#camera = cv2.VideoCapture(0) #获取摄像头
camera = cv2.VideoCapture(“video.avi“)
frame_num = 200
start_time = time.time()
#while True:
for _ in range(frame_num):
ret frame = camera.read()
frame = cv2.resize(frame (int(700*frame.shape[1]/frame.shape[0]) 700))
fgmask = bs.apply(frame)
fg2 = fgmask.copy()
# threshold 固定阈值二值化
th = cv2.threshold(fg2150255cv2.THRESH_BINARY)[1]
# 膨胀(dilate)和腐蚀(erode)
dilated = cv2.dilate(thcv2.getStructuringElement(cv2.MORPH_ELLIPSE(33))iterations = 2)
#findContours绘制轮廓轮廓
image contours hier = cv2.findContours(dilatedc
评论
共有 条评论