opencv
Diferenças
Aqui você vê as diferenças entre duas revisões dessa página.
Ambos lados da revisão anteriorRevisão anteriorPróxima revisão | Revisão anterior | ||
opencv [2023/07/08 00:36] – [Pré-Requisitos] jdos | opencv [2023/07/08 01:22] (atual) – [imread()] jdos | ||
---|---|---|---|
Linha 13: | Linha 13: | ||
=== Importar uma imagem === | === Importar uma imagem === | ||
- | < | + | < |
import cv2 as cv | import cv2 as cv | ||
import sys | import sys | ||
+ | |||
+ | #chama a funcao cv::imread e cria e armazena um objeto cv:Mat | ||
img = cv.imread(cv.samples.findFile(" | img = cv.imread(cv.samples.findFile(" | ||
+ | |||
+ | #verifica se a imagem foi carregada corretamente | ||
if img is None: | if img is None: | ||
- | sys.exit(" | + | sys.exit(" |
+ | |||
+ | #cria uma janela para mostrar a imagem - arg1 = nome da janela, arg2 = obj cv:Mat | ||
cv.imshow(" | cv.imshow(" | ||
+ | |||
+ | #funcao cv:waitkey tempo de espera, entrada em milisegundos, | ||
k = cv.waitKey(0) | k = cv.waitKey(0) | ||
+ | |||
+ | #pressiona ' | ||
if k == ord(" | if k == ord(" | ||
- | cv.imwrite(" | + | #funcao cv:imwrite salva o objeto cv:Mat como png |
+ | cv.imwrite(" | ||
+ | </ | ||
- | </file > | + | Utilize a imagem abaixo para o teste: |
+ | \\ | ||
+ | {{: | ||
+ | |||
+ | ==== imread() ==== | ||
+ | |||
+ | Python: | ||
+ | cv.imread( filename[, | ||
+ | |||
+ | === 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: | Referências: | ||
Linha 33: | Linha 80: | ||
[[https:// | [[https:// | ||
+ | |||
+ | [[https:// |
opencv.1688787416.txt.gz · Última modificação: 2023/07/08 00:36 por jdos