====== OpenCV ======
===== Instalação =====
==== Pré-Requisitos ====
pip install numpy
pip install matplotlib
pip install opencv-python
=== Importar uma imagem ===
import cv2 as cv
import sys
#chama a funcao cv::imread e cria e armazena um objeto cv:Mat
img = cv.imread(cv.samples.findFile("starry_night.jpg"))
#verifica se a imagem foi carregada corretamente
if img is None:
sys.exit("Could not read the image.")
#cria uma janela para mostrar a imagem - arg1 = nome da janela, arg2 = obj cv:Mat
cv.imshow("Display window", img)
#funcao cv:waitkey tempo de espera, entrada em milisegundos, '0' significa para sempre
k = cv.waitKey(0)
#pressiona 's' para salvar o arquivo
if k == ord("s"):
#funcao cv:imwrite salva o objeto cv:Mat como png
cv.imwrite("starry_night.png", img)
Utilize a imagem abaixo para o teste:
\\
{{:starry_night.jpg?50|}}
==== imread() ====
Python:
cv.imread( filename[, flags] ) -> retva
=== filename ===
Formatos suportados:
* Windows bitmaps - *.bmp, *.dib (always supported)
* JPEG files - *.jpeg, *.jpg, *.jpe (see the Note section)
* JPEG 2000 files - *.jp2 (see the Note section)
* Portable Network Graphics - *.png (see the Note section)
* WebP - *.webp (see the Note section)
* AVIF - *.avif (see the Note section)
* Portable image format - *.pbm, *.pgm, *.ppm *.pxm, *.pnm (always supported)
* PFM files - *.pfm (see the Note section)
* Sun rasters - *.sr, *.ras (always supported)
* TIFF files - *.tiff, *.tif (see the Note section)
* OpenEXR Image files - *.exr (see the Note section)
* Radiance HDR - *.hdr, *.pic (always supported)
* Raster and Vector geospatial data supported by GDAL (see the Note section)
=== flags (não obrigatório) ===
* cv.IMREAD_UNCHANGED
* cv.IMREAD_GRAYSCALE
* **cv.IMREAD_COLOR - PADRÂO**
* cv.IMREAD_ANYDEPTH
* cv.IMREAD_ANYCOLOR
* cv.IMREAD_LOAD_GDAL
* cv.IMREAD_REDUCED_GRAYSCALE_2
* cv.IMREAD_REDUCED_COLOR_2
* cv.IMREAD_REDUCED_GRAYSCALE_4
* cv.IMREAD_IGNORE_ORIENTATION
Referências:
[[https://docs.opencv.org/4.x/d5/de5/tutorial_py_setup_in_windows.html|Install OpenCV-Python Windows]]
[[https://docs.opencv.org/4.x/d6/d00/tutorial_py_root.html|OpenCV-Python Tutorials]]
[[https://docs.opencv.org/4.x/db/deb/tutorial_display_image.html| Started with Images]]