<jupyter_start><jupyter_text>OpenCV - ML class- Discussion on OpenCV- How to open camera, load images, convert images<jupyter_code>import cv2
import matplotlib.pyplot as plt
cv2.__version__
import numpy as np
webcam = cv2.VideoCapture(0)
ret, frame = webcam.read()
print (ret)
print(frame)
webcam.release()
type(frame)
cv2.imshow("1", frame)
cv2.destroyAllWindows()
# OpenCV - BGR
# Matplotlib - RGB
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Converting to BGR TO RGB
image
plt.imshow(image, cmap="gray")
data = np.linspace(1,10, num=100)
len(data)<jupyter_output><empty_output><jupyter_text>-  Writing and reading images    To write images we use cv2.imwrite(file_name, frame).    To read images we use cv2.imread(file_name).  Use 0 as the second argument for grayscale images. -  To stack numpy arrays horizontally or vertically    We use np.hstack(x,y) or np.vstack(x,y). -  Basic functions- cv2.waitKey(miliseconds) =>  Waits for miliseconds - cv2.namedWindow(name, flags) =>  Named window - cv2.putText(frame, text, size, flags, color, index) =>  For putting text - cv2.rectange(frame, (length, width), size, color) =>  For drawing rectangle -  Inbuilt Classifiers in OpenCV- CascadeClassifier(xml_file)-  faceDetect which is the CascadeClassifier contains a function detectMultiScale(gray, scaleFactor, minNeighbors, minSize).<jupyter_code># For image cutting (face)
x,y,w,h = faces[0]
img = frame[y:y+h, x:w+h]
cv2.imwrite("name.png")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11577522004062288, 'fraction_numerical': 0.016926201760324982, 'mean_word_length': 5.426086956521739, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '550051', 'license': 'Apache-2.0', 'n_tokens_mistral': 530, 'n_tokens_neox': 513, 'n_words': 148, 'path': 'opencv-ml-class.ipynb', 'repo_name': 'akapoorx00/machinelearning-stuff', 'size': '1477'}