Spaces:
Sleeping
Sleeping
Update pages/7_Unstructured_data.py
Browse files- pages/7_Unstructured_data.py +63 -0
pages/7_Unstructured_data.py
CHANGED
|
@@ -187,6 +187,69 @@ if file_type == "IMAGE":
|
|
| 187 |
- Where 2D, 3D array data type should be unsigned int8
|
| 188 |
''')
|
| 189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
|
| 192 |
|
|
|
|
| 187 |
- Where 2D, 3D array data type should be unsigned int8
|
| 188 |
''')
|
| 189 |
|
| 190 |
+
st.subheader('**Handling Images with OpenCV**')
|
| 191 |
+
st.markdown("""
|
| 192 |
+
Handling images involves tasks like reading, displaying, resizing, and modifying images.
|
| 193 |
+
|
| 194 |
+
**Example: Loading and Displaying an Image**
|
| 195 |
+
|
| 196 |
+
```python
|
| 197 |
+
import cv2
|
| 198 |
+
|
| 199 |
+
img = cv2.imread('image.jpg')
|
| 200 |
+
cv2.imshow('Loaded Image', img)
|
| 201 |
+
cv2.waitKey()
|
| 202 |
+
cv2.destroyAllWindows()
|
| 203 |
+
```
|
| 204 |
+
""")
|
| 205 |
+
st.subheader("**Basic Code**")
|
| 206 |
+
st.markdown("""
|
| 207 |
+
Below is an example demonstrating fundamental OpenCV operations.
|
| 208 |
+
The code reads an image, resizes it and then displays and saves the final image.
|
| 209 |
+
""", unsafe_allow_html=True)
|
| 210 |
+
|
| 211 |
+
st.markdown("""
|
| 212 |
+
|
| 213 |
+
**1. Read the image**
|
| 214 |
+
import cv2
|
| 215 |
+
image = cv2.imread('path') # Provide the path to your image
|
| 216 |
+
if image is None:
|
| 217 |
+
print("Error: Image not found")
|
| 218 |
+
exit()
|
| 219 |
+
|
| 220 |
+
**2. Display the original image**
|
| 221 |
+
```python
|
| 222 |
+
cv2.imshow('Original Image', image)
|
| 223 |
+
cv2.waitKey() # It adds the delay and closes the window when a key is given
|
| 224 |
+
cv2.destroyAllWindows()
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
**3. Resize the image to 200x200 pixels**
|
| 228 |
+
```python
|
| 229 |
+
resized_image = cv2.resize(image, (200, 200))
|
| 230 |
+
```
|
| 231 |
+
|
| 232 |
+
**4. Save the loaded image**
|
| 233 |
+
```python
|
| 234 |
+
cv2.imwrite('output_image.jpg',image)
|
| 235 |
+
print("Image saved successfully!")
|
| 236 |
+
```
|
| 237 |
+
""", unsafe_allow_html=True)
|
| 238 |
+
|
| 239 |
+
st.markdown("""
|
| 240 |
+
<h4 style='color:#FFA500;'> Code Explanation</h4>
|
| 241 |
+
|
| 242 |
+
- **Step 1: Reading the Image**: `cv2.imread()` loads the image from the specified file path. If the file is not found, the script will terminate with an error message.
|
| 243 |
+
|
| 244 |
+
- **Step 2: Displaying the Original Image**: `cv2.imshow()` displays the original image in a window. The window will remain open until a key is pressed.
|
| 245 |
+
|
| 246 |
+
- **Step 3: Resizing the Image**: `cv2.resize()` resizes the image to specified dimensions (in this case, 200x200 pixels)
|
| 247 |
+
|
| 248 |
+
- **Step 4: Saving the Loaded Image**: `cv2.imwrite()` saves the final loaded image to a file.
|
| 249 |
+
|
| 250 |
+
By following these steps, you can perform common image operations
|
| 251 |
+
""", unsafe_allow_html=True)
|
| 252 |
+
|
| 253 |
|
| 254 |
|
| 255 |
|