hari3485 commited on
Commit
3bcf57b
·
verified ·
1 Parent(s): e80ceac

Delete pages/video.py

Browse files
Files changed (1) hide show
  1. pages/video.py +0 -139
pages/video.py DELETED
@@ -1,139 +0,0 @@
1
- import streamlit as st
2
- import numpy as np
3
- import matplotlib.pyplot as plt
4
- import seaborn as sns
5
-
6
- # Title
7
- st.title("Understanding Video Data and Processing with OpenCV")
8
-
9
- # Subheader 1: What is Video Data?
10
- st.markdown("### What is Video Data?")
11
- st.markdown("""
12
- - **Video** is a collection of images known as **frames**.
13
- - Frames are visualized sequentially, creating the perception of motion.
14
- - **Frame Rate (FPS)** determines smoothness:
15
- - **30 FPS**: 30 frames per second.
16
- - **60 FPS**: 60 frames per second.
17
- - More FPS = smoother video.
18
- """)
19
-
20
- # Subheader 2: How to Play a Video Using OpenCV
21
- st.markdown("### :blue[How to Play a Video Using OpenCV]")
22
- st.markdown("""
23
- 1. **Break the Video into Frames**:
24
- - A video is essentially a sequence of images (frames).
25
- - Use a `while` loop to iterate through frames, as the total frame count may not be known.
26
- 2. **Key Functions**:
27
- - `cv2.VideoCapture(path)`: Captures the video and extracts frames.
28
- - `cv2.imshow()`: Displays a frame in a pop-up window.
29
- - `cv2.waitKey(1)`: Waits for 1 millisecond before moving to the next frame.
30
- 3. **Exit Condition**:
31
- - Exit the loop when frames are exhausted or a specific key is pressed.
32
- """)
33
-
34
- # Subheader 3: Frame Handling Details
35
- st.markdown("### Frame Handling Details")
36
- st.markdown("""
37
- - Each frame contains:
38
- 1. **Images**: Represented as 3D arrays (height, width, and color channels).
39
- 2. **Boolean Values**:
40
- - `True`: Frame is present.
41
- - `False`: No frame, signaling the loop to terminate.
42
- """)
43
-
44
- # Subheader 4: Converting Video to Tabular Data
45
- st.markdown("### :green[Converting Video to Tabular Data]")
46
- st.markdown("""
47
- 1. Use `cv2.VideoCapture()` to capture frames.
48
- 2. Convert the frames into tabular data, where each frame's pixel values are rows or columns.
49
- """)
50
-
51
- # Subheader 5: Color Space Conversion
52
- st.markdown("### Color Space Conversion")
53
- st.markdown("""
54
- - OpenCV allows color space changes with `cv2.cvtColor()`.
55
- - **Syntax**: `cv2.cvtColor(img, cv2.COLOR_<source>2<destination>)`
56
- - Example:
57
- ```python```
58
- img = cv2.imread("path/to/image")
59
- gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY
60
- """,unsafe_allow_html=True)
61
-
62
-
63
-
64
- from PIL import Image
65
-
66
- # Set the title of the app
67
-
68
- # Function to generate Black & White and Grayscale Images
69
- def generate_bw_and_grayscale():
70
- # Create Black & White binary image
71
- bw_image = np.array([[0, 1, 0, 1],
72
- [1, 0, 1, 0],
73
- [0, 1, 0, 1],
74
- [1, 0, 1, 0]])
75
-
76
- # Create Grayscale image
77
- grayscale_image = np.array([[0, 64, 128, 255],
78
- [255, 128, 64, 0],
79
- [0, 64, 128, 255],
80
- [255, 128, 64, 0]])
81
-
82
- # Plot and save the Black & White and Grayscale images
83
- fig, axes = plt.subplots(1, 2, figsize=(10, 5))
84
-
85
- # Black & White
86
- axes[0].imshow(bw_image, cmap='binary', interpolation='nearest')
87
- axes[0].set_title("Black & White Image")
88
- axes[0].axis('off')
89
-
90
- # Grayscale
91
- axes[1].imshow(grayscale_image, cmap='gray', interpolation='nearest')
92
- axes[1].set_title("Grayscale Image")
93
- axes[1].axis('off')
94
-
95
- plt.tight_layout()
96
- return fig
97
-
98
- # Function to generate RGB Color Space Images
99
- def generate_rgb_color_space():
100
- # Create RGB arrays
101
- red = np.zeros((4, 4, 3), dtype=int)
102
- green = np.zeros((4, 4, 3), dtype=int)
103
- blue = np.zeros((4, 4, 3), dtype=int)
104
-
105
- # Add intensity to respective channels
106
- red[:, :, 0] = 255 # Red channel
107
- green[:, :, 1] = 255 # Green channel
108
- blue[:, :, 2] = 255 # Blue channel
109
-
110
- # Plot RGB components
111
- fig, axes = plt.subplots(1, 3, figsize=(15, 5))
112
-
113
- # Red
114
- axes[0].imshow(red)
115
- axes[0].set_title("Red Component")
116
- axes[0].axis('off')
117
-
118
- # Green
119
- axes[1].imshow(green)
120
- axes[1].set_title("Green Component")
121
- axes[1].axis('off')
122
-
123
- # Blue
124
- axes[2].imshow(blue)
125
- axes[2].set_title("Blue Component")
126
- axes[2].axis('off')
127
-
128
- plt.tight_layout()
129
- return fig
130
-
131
- # Generate Black & White and Grayscale Images
132
- st.subheader("Black & White and Grayscale Images")
133
- bw_grayscale_fig = generate_bw_and_grayscale()
134
- st.pyplot(bw_grayscale_fig)
135
-
136
- # Generate RGB Color Space Images
137
- st.subheader("RGB Color Space Visualization")
138
- rgb_fig = generate_rgb_color_space()
139
- st.pyplot(rgb_fig)