Python reverse and splice a tuple


""" About:
img is an OpenCV 2 object. img.shape prints a tuple as (height, width, channels) e.g. (512, 768, 3)
We need a tuple as (width, height) e.g. (768, 512)
"""
import cv2
image_path = './image.jpg'
img = cv2.imread(image_path, flags=cv2.CV_LOAD_IMAGE_COLOR)
print img.shape # (512, 768, 3)
print img.shape[::1] # (3, 768, 512)
print img.shape[1::1] # (768, 512)

view raw
code.py
hosted with ❤ by GitHub

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s