In: Computer Science
Write a program that creates an image of green and white horizontal stripes. Your program should ask the user for the size of your image, the name of the output file, and create a .png file of stripes.
For example, if the user enters 10, your program should create a 10x10 image, alternating between green and white stripes. A sample run of the program: Enter the size: 10 Enter output file: 10stripes.png
Another sample run of the program: Enter the size: 50 Enter output file: 50stripes.png
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
# Importing the Required Libraries
import cv2
import numpy as np
# Input Prompt for Size and Output File Name
size = int(input("Enter the size: "))
output_file = input("Enter output file: ")
# Creating an Image to make it as per the requirement
image = 255 * np.ones(shape=[size,size, 3], dtype=np.uint8)
# Number of Green Stripes
n = size//2
# Marking the Count for Green Stripes Coordinates
j=0
# Iterating for stripe printing
for i in range(0,n):
# cv.line is used to draw lines
# Syntax: cv2.line(image,start_coordinates,end_coordinates,color,thickness)
image=cv2.line(image, (0,j), (size,j), (0,255,0),1)
j=j+2
# Writing the processed image on to the specified path
cv2.imwrite(output_file,image)