Ad

How To Flip Iamge In Opencv Without Library Functions In Python

- 1 answer

I am trying to flip an image in python but cannot use cv2.flip() as per my design brief. Dose anyone has any ideas to help me? Here is my code so far:

import cv2
import numpy as np

img = cv2.imread('img/bozu.png')
img = cv2.resize(img, (512, 512))

Thanks!

Ad

Answer

You can flip the image like this as well.

import cv2
import numpy as np

img = cv2.imread('img/bozu.png')
img = cv2.resize(img, (512, 512))

# flip vertically
v_flip = img[::-1]

# flip horizontally
h_flip = img[:, ::-1]

# this is bgr to rgb
bgr2rgb = img[:, :, ::-1]
Ad
source: stackoverflow.com
Ad