import numpy as np import cv2 cap = cv2.VideoCapture(0) # Define the codec and create VideoWriter object #ourcc = cv2.cv.CV_FOURCC(*'XVID') # cv2.VideoWriter_fourcc() does not exist #ut = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480)) kernel = np.ones((5,5),np.uint8) while(cap.isOpened()): ret, frame = cap.read() if ret==True: frame = cv2.flip(frame,1) # write the flipped frame # out.write(frame) # dst = cv2.filter2D(frame,-1,kernel) dst = cv2.blur(frame,(5,5)) gauss = cv2.GaussianBlur(frame,(5,5),0) grises = cv2.cvtColor(gauss,cv2.COLOR_BGR2GRAY) grisesoriginal = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) th3 = cv2.adaptiveThreshold(grises,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2) th3original = cv2.adaptiveThreshold(grisesoriginal,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2) opening = cv2.morphologyEx(th3original, cv2.MORPH_OPEN, kernel) erosion = cv2.erode(th3original,kernel,iterations = 1) dilation = cv2.dilate(th3original,kernel,iterations = 1) dilation = cv2.erode(dilation,kernel,iterations = 2) cv2.imshow('frame',frame) cv2.imshow('Gaussiano',gauss) cv2.imshow('Umbral_sin filtro',th3original) cv2.imshow('eroision',erosion) cv2.imshow('opening',opening) if cv2.waitKey(1) & 0xFF == ord('q'): break else: break # Release everything if job is finished cap.release() out.release() cv2.destroyAllWindows()