15-112 Introduction to
Computer Science

To use ImageWriter, you would need to install OpenCV.
You can do that by going to the terminal on a MAC or a command prompt on windows and type:

pip3 install opencv-python

To check if you opencv installation works, do the following in IDLE:

import cv2

the import should be successful and you should not see any error messages.

Image Library (Download)

This function loads the image name passed in. The function will pass back a reference to the picture which needs to be stored for any future processing. This function will not show the image

This function shows the image passed in as parameter.

If any changes are made to the picture, the changes are not displayed on the image being shown until this function is called.

This function will save the picture passed in as a file using the name passed in the variable filename. Make sure that the string filename has the proper file extension for an image. File names can have extensions “gif”, “jpg”, “bmp”.

This function returns the width of the picture as an integer.

This function returns the height of the picture as an integer.

This function returns the color at location x, y of the picture. The color is returned as a list of three values representing the red, green, and blue component of the color.

Sets the color of the location x, y to color passed in. The color is a list of three elements representing the red, green, and blue component of the color

Example usage:

import ImageWriter

#load a picture and save the reference in variable called mypic
mypic = ImageWriter.loadPicture("apple.gif")

# show the picture

# loop over complete width of the picture
w = ImageWriter.getWidth(mypic)
for i in range(0,w):
    # set the color of row 40 to color with red = 50
    # green = 5, and blue = 200.

# update the picture so you can see the changes

#save the picture as sav.jpg