To write a python program using OpenCV to do the following image manipulations.
- Read, display, and write an image.
- Access the rows and columns in an image.
- Cut and paste a small portion of the image.
Anaconda - Python 3.7
Choose an image and save it as a filename.jpg
Use imread(filename, flags) to read the file.
Use imshow(window_name, image) to display the image.
Use imwrite(filename, image) to write the image.
End the program and close the output image windows.
Developed By: SWATHKA G
Register Number: 212221230113
import cv2
img = cv2.imread("aot.png")
cv2.imshow("read_pic",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("write_pic.png",img)
print(img.shape)
import random
for i in range (500,1000):
for j in range(150,3582):
img[i][j]=[random.randint(0,100),random.randint(0,80),random.randint(0,250)]
cv2.imshow("row_pic.png",img)
cv2.waitKey(8000)
cv2.destroyAllWindows()
img[1300:2100,:] = img[400:1200,:]
cv2.imshow('cut',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Thus the images are read, displayed, and written successfully using the python program.