Skip to content

Instantly share code, notes, and snippets.

@aarshtalati
Created October 7, 2017 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarshtalati/adfe84d0aaa0fa9e3bd75c899093a064 to your computer and use it in GitHub Desktop.
Save aarshtalati/adfe84d0aaa0fa9e3bd75c899093a064 to your computer and use it in GitHub Desktop.
Reverse and splice python 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment