5,323
edits
(→Usage) |
|||
Line 81: | Line 81: | ||
import cv2 | import cv2 | ||
# cv2.IMREAD_ANYCOLOR | # cv2.IMREAD_ANYCOLOR | ||
# cv2.IMREAD_ANYDEPTH | # cv2.IMREAD_ANYDEPTH | ||
# cv2.IMREAD_COLOR | # cv2.IMREAD_COLOR | ||
# cv2.IMREAD_GRAYSCALE | # cv2.IMREAD_GRAYSCALE | ||
# cv2.IMREAD_UNCHANGED # G or BGR or BGRA | |||
# Use cv2.IMREAD_GRAYSCALE to read in grayscale | # Use cv2.IMREAD_GRAYSCALE to read in grayscale | ||
Line 98: | Line 99: | ||
===Resizing an Image=== | ===Resizing an Image=== | ||
[https://docs.opencv.org/master/da/d6e/tutorial_py_geometric_transformations.html Reference] | [https://docs.opencv.org/master/da/d6e/tutorial_py_geometric_transformations.html Reference] | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="python"> | ||
# Resize to resolution | # Resize to resolution | ||
new_img = cv2.resize(img, (500,200), interpolation=v2.INTER_CUBIC) | new_img = cv2.resize(img, (500,200), interpolation=v2.INTER_CUBIC) | ||
Line 118: | Line 115: | ||
For downscaling, use `INTER_AREA` to avoid aliasing. However, `INTER_NEAREST` will give the the optimal speed.<br> | For downscaling, use `INTER_AREA` to avoid aliasing. However, `INTER_NEAREST` will give the the optimal speed.<br> | ||
For upscaling, use `INTER_CUBIC` for best results or `INTER_LINEAR` for best performance. | For upscaling, use `INTER_CUBIC` for best results or `INTER_LINEAR` for best performance. | ||
===Face Detection=== | |||
[https://towardsdatascience.com/face-detection-in-2-minutes-using-opencv-python-90f89d7c0f81?gi=2fadb2dbc99d face detection in 2 minutes] | |||
# Download [https://raw.githubusercontent.com/kipr/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml haarcascade_frontalface_default.xml] | |||
<syntaxhighlight lang="python"> | |||
face_cascade = cv2.CascadeClassifier( | |||
'haarcascade_frontalface_default.xml') | |||
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |||
faces = face_cascade.detectMultiScale(image_gray, 1.1, 4) | |||
</syntaxhighlight> | |||
==Video== | ==Video== |