Friday 9 January 2015

Horizontal and vertical Flip using opencv and python

import numpy as np
import cv2

img=cv2.imread('1.png')
rimg=img.copy()
fimg=img.copy()
rimg=cv2.flip(img,1)
fimg=cv2.flip(img,0)
cv2.imshow("Original", img)
cv2.imshow("vertical flip", rimg)
cv2.imshow("horizontal flip", fimg)
cv2.waitKey(0)
cv2.destroyAllWindows()


14 comments:

  1. Thanks , was looking for this

    ReplyDelete
  2. That ruins my 2 hours. thanks :D

    ReplyDelete
  3. these two lines are not necesary,since fimg and rimg are overwritten later
    rimg=img.copy()
    fimg=img.copy()
    (they cause unnecessary performance loss)

    ReplyDelete
  4. Thank you, very timely, I used the finished code fragment, got a mirror image, helped out, thanks again

    ReplyDelete
  5. This is way to flip a image but is their any to check image is flipped with respect to original image

    ReplyDelete
  6. Horizontal and vertical flips are usually called the other way around. Horizontal when points move horizontally.

    ReplyDelete
    Replies
    1. You are absolutely right.
      I already saw several examples, probably all derived from the same source with this mistake.
      Vertical flip is 0 and horizontal is 1 (and both is -1)

      Delete