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((3,3),np.uint8) while(cap.isOpened()): ret, frame = cap.read() if ret==True: # img = cv2.flip(frame,1) # write the flipped frame # out.write(frame) # dst = cv2.filter2D(frame,-1,kernel) img = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) # Output dtype = cv2.CV_8U sobelx8u = cv2.Sobel(img,cv2.CV_8U,1,0,ksize=5) # Output dtype = cv2.CV_64F. Then take its absolute and convert to cv2.CV_8U sobelx64f = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) abs_sobel64f = np.absolute(sobelx64f) sobel_8u = np.uint8(abs_sobel64f) cv2.imshow('frame',frame) cv2.imshow('sobel x8u',sobelx8u) cv2.imshow('Sobel 8u',sobel_8u) if cv2.waitKey(1) & 0xFF == ord('q'): break else: break # Release everything if job is finished cap.release() cv2.destroyAllWindows()