【Python】 Reading, writing and displaying images

 # We don't need to do this again, but it's a good habit

import cv2 


# Load an image using 'imread' specifying the path to image

input = cv2.imread('./images/input.png')


# Our file 'input.jpg' is now loaded and stored in python 

# as a varaible we named 'image'


# To display our image variable, we use 'imshow'

# The first parameter will be title shown on image window

# The second parameter is the image varialbe

cv2.imshow('Hello World', input)


# 'waitKey' allows us to input information when a image window is open# By leaving it blank it just waits for anykey to be pressed before 

# continuing. By placing numbers (except 0), we can specify a delay for# how long you keep the window open (time is in milliseconds here)

cv2.waitKey()


# This closes all open windows 

# Failure to place this will cause your program to hang

cv2.destroyAllWindows()

# Simply use 'imwrite' specificing the file name and the image to be saved

cv2.imwrite('output.jpg', input)

cv2.imwrite('output.png', input)

No comments:

Linear: move fast with little process (with first engineering manager Sabin Roman)

On today’s episode of The Pragmatic Engineer, I’m joined by fellow Uber alum, Sabin Roman, now the first Engineering Manager at Linear. ͏   ...

Contact Form

Name

Email *

Message *