hari3485 commited on
Commit
5b7dab5
·
verified ·
1 Parent(s): 472baeb

Update pages/Data Collection.py

Browse files
Files changed (1) hide show
  1. pages/Data Collection.py +74 -7
pages/Data Collection.py CHANGED
@@ -74,14 +74,81 @@ elif page == "Color Spaces":
74
 
75
  # Basic Operations Section
76
  elif page == "Basic Operations":
77
- st.header("Basic Operations Using OpenCV")
78
- st.write("""
79
- OpenCV is a powerful library for image processing. Here are some basic operations you can perform:
80
- - Load and display images.
81
- - Convert between color spaces (e.g., RGB to Grayscale).
82
- - Resize and crop images.
83
- - Apply filters and transformations.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  if st.button("Go Back"):
87
  st.experimental_set_query_params(page="Introduction")
 
74
 
75
  # Basic Operations Section
76
  elif page == "Basic Operations":
77
+
78
+ st.code("""
79
+ import cv2
80
+ import numpy as np
81
+ """)
82
+
83
+ st.title("OpenCV Basics: Image Handling")
84
+
85
+ # Theory Section
86
+ st.header("1. `cv2.imread` - Reading an Image")
87
+ st.markdown("""
88
+ - **Purpose**: Converts an image file into a numerical array that represents its pixel data.
89
+ - **Default Behavior**: Reads the image in the **BGR color space**.
90
+ - **Parameters**:
91
+ - `path`: Specifies the location of the image file.
92
+ - `flags`:
93
+ - `1`: Reads the image as a color image (default).
94
+ - `0`: Reads the image as a grayscale image (2D array).
95
+ - **Output**: A numerical array where each element corresponds to a pixel's intensity or color.
96
+ """)
97
+ st.code("""
98
+ # Code to read an image
99
+ img = cv2.imread('path/to/your/image.jpg', 1) # Read as color image
100
+ st.image(img, channels="BGR") # Display image in Streamlit
101
+ """)
102
+
103
+ # Theory Section
104
+ st.header("2. `cv2.imshow` - Displaying an Image")
105
+ st.markdown("""
106
+ - **Purpose**: Opens a pop-up window to show an image.
107
+ - **Parameters**:
108
+ - `Window Name`: Title of the display window.
109
+ - `Image`: Array data representing the image.
110
+ """)
111
+ st.code("""
112
+ # Code to display an image
113
+ cv2.imshow("Sample Image", img)
114
  """)
115
+
116
+ # Theory Section
117
+ st.header("3. `cv2.waitKey` - Waiting for a Key Input")
118
+ st.markdown("""
119
+ - **Purpose**: Waits for the specified time (in milliseconds) for a key press to proceed or close the window.
120
+ - **Parameters**:
121
+ - `Delay`:
122
+ - If `0`: Waits indefinitely until a key is pressed.
123
+ - If a positive value: Waits for that duration in milliseconds.
124
+ - **Usage**: Prevents the program from closing the window immediately.
125
+ """)
126
+ st.code("""
127
+ # Code to wait for a key press
128
+ cv2.waitKey(0) # Wait indefinitely until key press
129
+ """)
130
+
131
+ # Theory Section
132
+ st.header("4. `cv2.destroyAllWindows` - Closing OpenCV Windows")
133
+ st.markdown("""
134
+ - **Purpose**: Closes all OpenCV-created windows.
135
+ - **Usage**: Ensures proper memory cleanup and avoids crashes by freeing up resources after the display is no longer needed.
136
+ - **Best Practice**: Always use this after displaying images to clean up the resources.
137
+ """)
138
+ st.code("""
139
+ # Code to close all windows
140
+ cv2.destroyAllWindows() # Close all OpenCV windows
141
+ """)
142
+
143
+ st.markdown("""
144
+ ### Additional Notes
145
+ - **Why Use `cv2.waitKey`?**
146
+ Without this, the image display window will close immediately after the program finishes execution.
147
+
148
+ - **Handling Pop-Up Windows**
149
+ - Use `cv2.destroyAllWindows()` to close all pop-up windows and release system resources properly.
150
+ """)
151
+
152
 
153
  if st.button("Go Back"):
154
  st.experimental_set_query_params(page="Introduction")