import numpy as np import cv2 cap = cv2.VideoCapture(0) cap = cv2.VideoCapture("personas1.avi") fgbg = cv2.BackgroundSubtractorMOG() kernel = np.ones((5,5),np.uint8) ret, primerframe = cap.read() grises = cv2.cvtColor(primerframe,cv2.COLOR_BGR2GRAY) primerth3 = cv2.adaptiveThreshold(grises,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,11,2) while(1): ret, frame = cap.read() grises = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) th3 = cv2.adaptiveThreshold(grises,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,11,2) diferencia = primerth3 - th3 #fgmask = fgbg.apply(th3) #copiafgmask = fgmask #erosion = cv2.dilate(copiafgmask,kernel,iterations = 3) # opcion 1 encontrar contornos contours, hierarchy = cv2.findContours(diferencia,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE) for cont in contours: if cv2.contourArea(cont) > 550: cv2.drawContours(frame, cont, -1, (0,255,0), 1) x,y,w,h = cv2.boundingRect(cont) # la variable cont contiene los punts del contorno cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2) # cv2.drawContours(erosion, cont, -1, (0,0,0), 1) cv2.imshow('primerframe',primerth3) cv2.imshow('diferencia',diferencia) cv2.imshow('frame o',frame) k = cv2.waitKey(30) & 0xff if k == 27: break cap.release() cv2.destroyAllWindows()