Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

427
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!