Zero_to_Hero_Machine_Learning / pages /Basic operations of Image with the help of Open cv.py
shwetashweta05's picture
Rename pages/Basic operations of Image with the help of OpenCV.py to pages/Basic operations of Image with the help of Open cv.py
6945a98 verified
raw
history blame
1.18 kB
import streamlit as st
import pandas as pd
st.subheader(":red[**Basic operations of Image with the help of OpenCV**]")
st.write("The basic OpenCV operations imread, imwrite, and imshow are used for reading, saving, and displaying images, respectively. Here’s how you can implement them in OpenCV ")
st.write(":blue[**1. Reading an Image (cv2.imread)**]")
st.write("This function reads an image from a file.")
code="""
import cv2
# Read an image
image = cv2.imread("example.jpg") # Replace with your file path
cv2.imshow("Original Image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
"""
st.code(code,language="python")
st.write(":blue[**2. Writing/Saving an Image (cv2.imwrite)**]")
st.write("This function saves an image to a file.")
code="""
# Save the image to a new file
cv2.imwrite("saved_image.jpg", image)
print("Image saved as 'saved_image.jpg'")
"""
st.code(code,language="python")
st.write(":blue[**3. Displaying an Image (cv2.imshow)**]")
st.write("This function shows an image in a GUI window.")
code="""
cv2.imshow("Image Display", image)
cv2.waitKey(0) # Wait for a key press to close the window
cv2.destroyAllWindows()
"""
st.code(code,language="python")