![]() It’s really just a personal preference for the app design. That way the filter will always show in the sidebar. You can also choose to place the filter variable outside of the code block (i.e., above line 2). And we are storing the fetched metadata into a dictionary. And this pipe allows the command to send its output to another command. Here we are using the subprocess module to extract image metadata using popen () method which opens a pipe from a command. By doing so the filter will only appear after users upload an image. Using subprocess to extract image metadata. ![]() Notice that we placed the filter variable inside the ‘ if uploaded_file is not None:’ code block. We use st.sidebar.radio() to only allow single selection at a time. The filter shows five options: Original, Gray Image, Black and White, Pencil Sketch, and Blur Effect. In the code below, line 12 adds the filter in the sidebar. To keep the main interface of the app clean, we can add this filter to the sidebar. We’ll first need to create a filter or single-select box to allow users to specify what they want to do. How can we achieve that? #1: Create a Filter that Takes User Input If the user wants to convert it to a pencil sketch, we will use OpenCV to convert it to a pencil sketch. For example, if a user wants to convert the image to black-and-white, we will convert the original image to black-and-white using OpenCV. Now comes the fun part! In the second column col2 (the place holder for the ‘after’ image), we want to display the converted image based on the user’s input. In less than two hours and with only about sixty lines of code I was able to build a photo editing app using Streamlit and it looks pretty good to me! I’d like to share my project work with you so that you can also have some fun learning to build your own photo editing app! The app we are going to build looks like this (or watch this short YouTube Video Demo): So suddenly something clicked - this could be a perfect hands-on Streamlit project for me to build my own photo editing app with OpenCV! It is a free, open-source, all-python framework that enables data scientists to quickly build data and machine learning web apps with no front-end web development experience required. ![]() streamlit run photoconverterapp. A blank Streamlit app should appear in your local web browser. Then we can fire up Streamlit from the Anaconda terminal window. In the meantime, I have been exploring and learning Streamlit for a while. Let’s open the VS code editor (or any text editor of your choice), create a new empty python file, and save it as photoconverterapp.py in your project folder. I was really amazed by how easy and straightforward it is to use OpenCV to get started with some of the simple tasks in the world of computer vision. Recently, I came across a few articles online that talk about how to use OpenCV, a real-time optimized Computer Vision library in Python, to turn a photo into a sketch, or a gray-scale image, etc. However, for a long time, I haven’t really devoted any time to learning and trying it myself. Have you ever used one of those photo editing apps that allow you to upload your photo online and instantly convert it to a black-and-white image, a cool pencil sketch, or a picture with a nice blurring effect? As a curious data scientist, I am always interested in finding out how those apps were created behind the scene.
0 Comments
Leave a Reply. |