Ask Your Question
0

imwrite turns image upside down

asked 2018-09-06 14:03:56 -0600

MarceloMota gravatar image

Hello everyone.

I am reading all the frames from a video and saving them in .png picutres.

The imwrite command is saving all the images upside down.. how do I write them in righ orientation? I would try it with windows tool, but it takes more than 15minutes to turn all the 4600 images to the right orientation...

What am I missing? Below follows my code:

" import cv2 import math

def main():

cap = cv2.VideoCapture('finos.mp4')    
i = 1

while (cap.isOpened()):

    ret, frame = cap.read()

    if (ret != True):
        break

    filename = './test/image' +  str(int(i)) + ".png";i+=1
    cv2.imwrite(filename, frame)
    if cv2.waitKey(1) == 27: # exit on ESC
        break

cap.release()
cv2.destroyAllWindows()

if __name__ == "__main__": main() "

Thanks in advance :)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-09-06 20:31:40 -0600

maym86 gravatar image

updated 2018-09-06 20:38:43 -0600

Not sure why, I suspect its likely to do with the video you are reading rather than the imwrite function. Does cv.imshow("Frame", frame) show the image upside down?

You can check for the video file property 'Rotation' or 'Composite:Rotation' using some exif-reader tool (e.g. exiftool) and see if it has any value other than 0.

The simplest solution if you are just looking to dump the images is to just use flip before imwrite.

frame = cv2.flip(frame, 1 )
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-09-06 14:03:56 -0600

Seen: 5,280 times

Last updated: Sep 06 '18