Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

431
Visualizações
How to use img.shape() in javascript

import cv2

read image

img = cv2.imread('/home/img/python.png', cv2.IMREAD_UNCHANGED)

get dimensions of image

dimensions = img.shape

height, width, number of channels in image

height = img.shape[0]
width = img.shape[1]
channels = img.shape[2]

 
print('Image Dimension    : ',dimensions)
print('Image Height       : ',height)
print('Image Width        : ',width)
print('Number of Channels : ',channels)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

for the amount of channels you need to do

channels = image.shape[-1] if image.ndim == 3 else 1

This is because the amount of channels will not be shown if it is grayscale. And that is why image.ndim is checked.

To get width and height just do what you already did in your example

And for dimensions you could do:

dimensions = f"{width}x{height}"

if you want it to return in a string. Otherwise, if you want it to return as a tuple it will just be the first 2 objects in img.shape.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda