SLIDE 20 20
def main(): #Font Type font = cv2.FONT_HERSHEY_SIMPLEX # initialize the camera and grab a reference to the raw camera capture video = cv2.VideoCapture(0) # allow the camera to warmup time.sleep(0.1) #Windows to display frames cv2.namedWindow("Main Frame", cv2.WINDOW_AUTOSIZE) cv2.namedWindow("Matching Operation", cv2.WINDOW_AUTOSIZE) cv2.namedWindow("Corrected Perspective", cv2.WINDOW_AUTOSIZE) cv2.namedWindow("Contours", cv2.WINDOW_AUTOSIZE) #Read all the reference images readRefImages() # capture frames from the camera while True: ret, OriginalFrame = video.read() gray = cv2.cvtColor(OriginalFrame, cv2.COLOR_BGR2GRAY) blurred = cv2.GaussianBlur(gray,(3,3),0) #Detecting Edges edges = auto_canny(blurred) #Contour Detection & checking for squares based on the square area cntr_frame, contours, hierarchy = \ cv2.findContours(edges,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) for cnt in contours: approx = cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True) if len(approx)==4: area = cv2.contourArea(approx) if area > minSquareArea: cv2.drawContours(OriginalFrame,[approx],0,(0,0,255),2) warped = four_point_transform(OriginalFrame,\ approx.reshape(4, 2)) warped_eq = resize_and_threshold_warped(warped) for i in range(6): diffImg = cv2.bitwise_xor(warped_eq,symbol[i].img) diff = cv2.countNonZero(diffImg); if diff < minDiff: match = i #print symbol[i].name, diff cv2.putText(OriginalFrame,symbol[i].name,\ (10,30), font, 1, (255,0,255), 2, cv2.LINE_AA) diff = minDiff break;