<jupyter_start><jupyter_text>***Live Sketching Using Webcam***  Importing Libraries<jupyter_code>import cv2
import numpy as np<jupyter_output><empty_output><jupyter_text>Our Text Generating Function<jupyter_code>def sketch(image):

  #convert image to grayscale
  img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

  #clean up image using Gaussian Blur. To smoothen and remove noise
  img_gray_blur = cv2.GaussianBlur(img_gray, (5,5), 0)

  #Extracting Edges using canny edge detection technique. 10 and 70 are threshold values and can be chanegd around. Feel free to play with them
  canny_edges = cv2.Canny(img_gray_blur, 10, 70)

  #Invert Binarize the image. canny gives black background with white edges so we use inverse to have white background and black edges.
  ret, mask = cv2.threshold(canny_edges, 70, 255, cv2.THRESH_BINARY_INV)
  return mask<jupyter_output><empty_output><jupyter_text>Initiates Webcam, cap is the object provided by VideoCapture. It contains a boolean indicating if it was successful It also contains the images collected from the Webcam(frame)<jupyter_code>cap = cv2.VideoCapture(0)
while True: #Running a loop to continuously pull images/frames from the webcam
  ret, frame = cap.read()  #Pulls Image from the Webcam. ret is a boolean to know whether this command ran successfully
  cv2.imshow('Our Live Sketcher', sketch(frame)) #frame is passed to imshow
  if cv2.waitKey(1) == 13: #13 is enter key. loops only breaks when we press enter key
    break

#Release Camera and Close Window
cap.release() #If we don't use this. opencv hangs
cv2.destroyAllWindows()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07323076923076922, 'fraction_numerical': 0.020923076923076923, 'mean_word_length': 5.3515625, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '334460', 'license': 'MIT', 'n_tokens_mistral': 540, 'n_tokens_neox': 506, 'n_words': 192, 'path': 'Cv_project/Mini_Project_1.ipynb', 'repo_name': 'pragyakapoor/99-ML-Learning-Projects', 'size': '1625'}