sree4411 commited on
Commit
13bd1e9
·
verified ·
1 Parent(s): e4f9064

Update pages/3_Life Cycle Of ML Project.py

Browse files
Files changed (1) hide show
  1. pages/3_Life Cycle Of ML Project.py +483 -60
pages/3_Life Cycle Of ML Project.py CHANGED
@@ -181,68 +181,491 @@ elif st.session_state.page == "unstructured_data":
181
  #gray_image.show()
182
  # """, language='python')
183
 
184
- if st.button("Introduction to Image"):
 
185
  st.session_state.page = "introduction_to_image"
186
- # ----------------- Introduction to Image -----------------
187
- def introduction_to_image_page():
188
- st.header("🖼️ What is Image")
189
- st.markdown(""" An image is a two-dimensional visual representation of objects, people, scenes, or concepts.
190
- It can be captured using devices like cameras, scanners, or created digitally.
191
- Images are composed of individual units called pixels, which contain information about brightness and color.
192
- **Types of Images:** - **Raster Images (Bitmap)**: Composed of a grid of pixels.
193
- Common formats include: - JPEG
194
- - PNG
 
195
  - GIF
196
- - **Vector Images**: Defined by mathematical equations and geometric shapes like lines and curves.
197
- Common format:
198
- - SVG (Scalable Vector Graphics)
199
- - **3D Images**: Represent objects or scenes in three dimensions, often used for rendering and modeling.
200
- **Image Representation:**
201
- - **Grayscale Image**: Each pixel has a single intensity value, typically ranging from 0 (black) to 255 (white), representing different shades of gray.
202
- - **Color Image**: Usually represented in the RGB color space, where each pixel consists of three values indicating the intensity of Red, Green, and Blue.
203
- **Applications of Images:**
204
- - **Photography & Visual Media**: Capturing moments and storytelling.
205
- - **Medical Imaging**: Diagnosing conditions using X-rays, MRIs, etc.
206
- - **Machine Learning & AI**: Tasks like image classification, object detection, and facial recognition.
207
- - **Remote Sensing**: Analyzing geographic and environmental data using satellite imagery.
208
- - **Graphic Design & Art**: Creating creative visual content for marketing and design. """)
209
- st.code(""" from PIL import Image import numpy as np import matplotlib.pyplot as plt
210
- # Open an image file
211
- image = Image.open('sample_image.jpg')
212
- image.show()
213
- # Convert image to grayscale
214
- gray_image = image.convert('L')
215
- gray_image.show()
216
- # Resize the image
217
- resized_image = image.resize((200, 200))
218
- resized_image.show()
219
- # Rotate the image by 90 degrees
220
- rotated_image = image.rotate(90) r
221
- otated_image.show()
222
- # Convert the image to a NumPy array and display its shape
223
- image_array = np.array(image)
224
- print(image_array.shape)
225
- # Display the image array as a plot
226
- plt.imshow(image)
227
- plt.title("Original Image")
228
- plt.axis('off')
229
- plt.show() """, language='python')
230
- st.header("Color Spaces in Machine Learning")
231
- st.markdown(""" A color space is a mathematical model for representing colors.
232
- In machine learning, different color spaces can be used for preprocessing and analyzing image data, depending on the task.
233
- **Common Color Spaces:**
234
- - **RGB (Red, Green, Blue)**: The most common color space for digital images. Each pixel is represented by a combination of three values corresponding to the red, green, and blue channels.
235
- - **Use Cases**: Image classification, general-purpose image analysis.
236
- - **HSV (Hue, Saturation, Value)**: Separates color information (hue) from intensity (value), making it useful for tasks where distinguishing between color variations and intensity is important.
237
- - **Use Cases**: Color-based object detection, image segmentation, color tracking.
238
- - **CMYK (Cyan, Magenta, Yellow, Black)**: Primarily used for printing, not commonly used in machine learning, but useful for preparing images for printers.
239
- - **Use Cases**: Printing applications.
240
- - **LAB (Lightness, A, B)**: Designed to be perceptually uniform, meaning that the perceptual difference between colors is consistent across the space.
241
- - **Use Cases**: Color correction, image processing tasks requiring color consistency. """)
242
- # Button to Navigate to Operations Using OpenCV
243
- if st.button("Operations Using OpenCV"):
244
- st.session_state.page = "operations_using_opencv"
245
- # Navigation Button
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
  if st.button(":red[Back to Data Collection]"):
248
  st.session_state.page = "data_collection"
 
181
  #gray_image.show()
182
  # """, language='python')
183
 
184
+ # Button to Navigate to Introduction to Image
185
+ if st.button("Introduction to Image"):
186
  st.session_state.page = "introduction_to_image"
187
+
188
+ # ----------------- Introduction to Image -----------------
189
+ def introduction_to_image_page():
190
+ st.header("🖼️ What is Image")
191
+ st.markdown("""
192
+ An image is a two-dimensional visual representation of objects, people, scenes, or concepts. It can be captured using devices like cameras, scanners, or created digitally. Images are composed of individual units called pixels, which contain information about brightness and color.
193
+ Types of Images:
194
+ - **Raster Images (Bitmap)**: Composed of a grid of pixels. Common formats include:
195
+ - JPEG
196
+ - PNG
197
  - GIF
198
+ - **Vector Images**: Defined by mathematical equations and geometric shapes like lines and curves. Common format:
199
+ - SVG (Scalable Vector Graphics)
200
+ - **3D Images**: Represent objects or scenes in three dimensions, often used for rendering and modeling.
201
+ Image Representation:
202
+ - **Grayscale Image**: Each pixel has a single intensity value, typically ranging from 0 (black) to 255 (white), representing different shades of gray.
203
+ - **Color Image**: Usually represented in the RGB color space, where each pixel consists of three values indicating the intensity of Red, Green, and Blue.
204
+ Applications of Images:
205
+ - **Photography & Visual Media**: Capturing moments and storytelling.
206
+ - **Medical Imaging**: Diagnosing conditions using X-rays, MRIs, etc.
207
+ - **Machine Learning & AI**: Tasks like image classification, object detection, and facial recognition.
208
+ - **Remote Sensing**: Analyzing geographic and environmental data using satellite imagery.
209
+ - **Graphic Design & Art**: Creating creative visual content for marketing and design.
210
+ """)
211
+
212
+ st.code("""
213
+ from PIL import Image
214
+ import numpy as np
215
+ import matplotlib.pyplot as plt
216
+ # Open an image file
217
+ image = Image.open('sample_image.jpg')
218
+ image.show()
219
+ # Convert image to grayscale
220
+ gray_image = image.convert('L')
221
+ gray_image.show()
222
+ # Resize the image
223
+ resized_image = image.resize((200, 200))
224
+ resized_image.show()
225
+ # Rotate the image by 90 degrees
226
+ rotated_image = image.rotate(90)
227
+ rotated_image.show()
228
+ # Convert the image to a NumPy array and display its shape
229
+ image_array = np.array(image)
230
+ print(image_array.shape)
231
+ # Display the image array as a plot
232
+ plt.imshow(image)
233
+ plt.title("Original Image")
234
+ plt.axis('off')
235
+ plt.show()
236
+ """, language='python')
237
+
238
+ st.header("Color Spaces in Machine Learning")
239
+ st.markdown("""
240
+ A color space is a mathematical model for representing colors. In machine learning, different color spaces can be used for preprocessing and analyzing image data, depending on the task.
241
+ Common Color Spaces:
242
+ - **RGB (Red, Green, Blue)**: The most common color space for digital images. Each pixel is represented by a combination of three values corresponding to the red, green, and blue channels.
243
+ - **Use Cases**: Image classification, general-purpose image analysis.
244
+ - **HSV (Hue, Saturation, Value)**: Separates color information (hue) from intensity (value), making it useful for tasks where distinguishing between color variations and intensity is important.
245
+ - **Use Cases**: Color-based object detection, image segmentation, color tracking.
246
+ - **CMYK (Cyan, Magenta, Yellow, Black)**: Primarily used for printing, not commonly used in machine learning, but useful for preparing images for printers.
247
+ - **Use Cases**: Printing applications.
248
+ - **LAB (Lightness, A, B)**: Designed to be perceptually uniform, meaning that the perceptual difference between colors is consistent across the space.
249
+ - **Use Cases**: Color correction, image processing tasks requiring color consistency.
250
+ """)
251
+
252
+ # Button to Navigate to Operations Using OpenCV
253
+ if st.button("Operations Using OpenCV"):
254
+ st.session_state.page = "operations_using_opencv"
255
+
256
+ # Navigation Button
257
+ if st.button("Back to Data Collection"):
258
+ st.session_state.page = "data_collection"
259
+
260
+ # ---------- OPERATIONS USING OPENCV --------------------------------
261
+
262
+
263
+ def operations_using_opencv_page():
264
+ # Header and description for cv2.imread
265
+ st.header("🗂️ Reading an Image with cv2.imread()")
266
+ st.markdown("""
267
+ **`cv2.imread()` - Read an Image**
268
+ **Purpose:** Load an image from a file and convert it to a NumPy array.
269
+ **Syntax:**
270
+ ```python
271
+ image = cv2.imread(filename, flags)
272
+ ```
273
+ **Common Flags:**
274
+ - `cv2.IMREAD_COLOR` (default, loads a color image).
275
+ - `cv2.IMREAD_GRAYSCALE` (loads the image in grayscale).
276
+ - `cv2.IMREAD_UNCHANGED` (loads the image as is, with alpha transparency if available).
277
+ **Return:**
278
+ - A NumPy array representing the image.
279
+ - Returns `None` if the image cannot be loaded.
280
+ **Example:**
281
+ ```python
282
+ import cv2
283
+ image = cv2.imread('image.jpg', cv2.IMREAD_COLOR)
284
+ ```
285
+ """)
286
+
287
+ # Header and description for cv2.imshow
288
+ st.header("🖼️ Displaying an Image with cv2.imshow()")
289
+ st.markdown("""
290
+ **`cv2.imshow()` - Display an Image**
291
+ **Purpose:** Show an image in a window.
292
+ **Syntax:**
293
+ ```python
294
+ cv2.imshow(window_name, image)
295
+ ```
296
+ **Requirements:**
297
+ - Call `cv2.waitKey()` to keep the window open until a key is pressed.
298
+ - Call `cv2.destroyAllWindows()` to close the window(s).
299
+ **Behavior:**
300
+ - Displays the image in a resizable window.
301
+ - The image must be a NumPy array.
302
+ **Example:**
303
+ ```python
304
+ import cv2
305
+ cv2.imshow('Image Window', image)
306
+ cv2.waitKey(0) # Wait for a key press
307
+ cv2.destroyAllWindows() # Close the window
308
+ ```
309
+ """)
310
+
311
+ # Header and description for cv2.imwrite
312
+ st.header("💾 Saving an Image with cv2.imwrite()")
313
+ st.markdown("""
314
+ **`cv2.imwrite()` - Write/Save an Image**
315
+ **Purpose:** Save an image to a file.
316
+ **Syntax:**
317
+ ```python
318
+ cv2.imwrite(filename, image)
319
+ ```
320
+ **File Format:**
321
+ Determined by the file extension (`.jpg`, `.png`, etc.).
322
+ **Return:**
323
+ - `True` if the image is saved successfully, `False` otherwise.
324
+ **Optional Parameters:**
325
+ - **JPEG Quality:** `cv2.IMWRITE_JPEG_QUALITY` (0 to 100, default is 95).
326
+ - **PNG Compression:** `cv2.IMWRITE_PNG_COMPRESSION` (0 to 9, default is 3).
327
+ **Example:**
328
+ ```python
329
+ import cv2
330
+ cv2.imwrite('output.jpg', image)
331
+ ```
332
+ """)
333
+
334
+ ##Navigation Button
335
+ if st.button("Conversion of Images"):
336
+ st.session_state.page = "Conversion_of_Images"
337
+
338
+ # Navigation Button
339
+ if st.button("Back to Data Collection"):
340
+ st.session_state.page = "data_collection"
341
+
342
+
343
+
344
+ ##------------CONVERSION OF IMAGE-----------------
345
+
346
+
347
+ def Conversion_of_Images_page():
348
+ # Header for Image Conversion
349
+ st.header("🔄 Converting Images Between Different Color Spaces")
350
+
351
+ st.markdown("""
352
+ **OpenCV supports many color spaces for image processing.**
353
+ **Common Conversions:**
354
+
355
+ - **BGR to Grayscale:** Converts a color image to grayscale.
356
+ - **BGR to RGB:** Converts from OpenCV's default BGR format to the standard RGB format.
357
+ - **BGR to HSV:** Converts the image to the HSV (Hue, Saturation, Value) color space.
358
+ **Examples of Conversions:**
359
+ ```python
360
+ import cv2
361
+ # Load the image
362
+ image = cv2.imread('image.jpg')
363
+ # Convert BGR to Grayscale
364
+ gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
365
+ # Convert BGR to RGB
366
+ rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
367
+ # Convert BGR to HSV
368
+ hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
369
+ ```
370
+ **Why Convert Color Spaces?**
371
+ - **Grayscale:** Useful for reducing image complexity in tasks like edge detection.
372
+ - **RGB:** Standard format for visualization in libraries like `matplotlib`.
373
+ - **HSV:** Useful for color-based segmentation, as it separates color information from brightness.
374
+ """)
375
+
376
+ # Header for Splitting Channels
377
+ st.header("🔹 Splitting Color Channels in an Image")
378
+
379
+ st.markdown("""
380
+ **Splitting an image into its individual color channels (B, G, R) allows you to analyze or modify each channel independently.**
381
+ **Syntax:**
382
+ ```python
383
+ b, g, r = cv2.split(image)
384
+ ```
385
+ **Example:**
386
+ ```python
387
+ import cv2
388
+ # Load the image
389
+ image = cv2.imread('image.jpg')
390
+ # Split the image into Blue, Green, and Red channels
391
+ blue_channel, green_channel, red_channel = cv2.split(image)
392
+ # Display the channels separately (Optional)
393
+ cv2.imshow('Blue Channel', blue_channel)
394
+ cv2.imshow('Green Channel', green_channel)
395
+ cv2.imshow('Red Channel', red_channel)
396
+ cv2.waitKey(0)
397
+ cv2.destroyAllWindows()
398
+ ```
399
+ **Explanation:**
400
+ - The `cv2.split()` function returns the Blue, Green, and Red channels as separate images (grayscale format).
401
+ """)
402
+
403
+ # Header for Merging Channels
404
+ st.header("🔹 Merging Color Channels in an Image")
405
+
406
+ st.markdown("""
407
+ **You can merge the individual channels back into a color image using `cv2.merge()`.**
408
+ **Syntax:**
409
+ ```python
410
+ merged_image = cv2.merge((b, g, r))
411
+ ```
412
+ **Example:**
413
+ ```python
414
+ import cv2
415
+ # Load the image
416
+ image = cv2.imread('image.jpg')
417
+ # Split the image into channels
418
+ b, g, r = cv2.split(image)
419
+ # Merge the channels back into a color image
420
+ merged_image = cv2.merge((b, g, r))
421
+ # Display the merged image
422
+ cv2.imshow('Merged Image', merged_image)
423
+ cv2.waitKey(0)
424
+ cv2.destroyAllWindows()
425
+ ```
426
+ **Explanation:**
427
+ - The `cv2.merge()` function takes a tuple of channels `(b, g, r)` and combines them back into a single color image.
428
+ - You can manipulate the individual channels before merging to achieve different effects.
429
+ """)
430
+
431
+ # Header for Combining with Modifications
432
+ st.header("🎨 Modifying Channels Before Merging")
433
+
434
+ st.markdown("""
435
+ **You can modify each channel (e.g., increase brightness in the red channel) before merging them back together.**
436
+ **Example:**
437
+ ```python
438
+ import cv2
439
+ # Load the image
440
+ image = cv2.imread('image.jpg')
441
+ # Split channels
442
+ b, g, r = cv2.split(image)
443
+ # Increase the intensity of the red channel
444
+ r = cv2.add(r, 50)
445
+ # Merge the modified channels
446
+ modified_image = cv2.merge((b, g, r))
447
+ # Display the modified image
448
+ cv2.imshow('Modified Image', modified_image)
449
+ cv2.waitKey(0)
450
+ cv2.destroyAllWindows()
451
+ ```
452
+ **Explanation:**
453
+ - In this example, `cv2.add(r, 50)` increases the intensity of the red channel by 50.
454
+ - After modification, the channels are merged back to create the final image.
455
+ """)
456
+
457
+
458
+
459
+
460
+ # Navigation Button
461
+ if st.button("Video capture and explanation"):
462
+ st.session_state.page = "Video_capture_and_explanation"
463
+
464
+ # Navigation Button
465
+ if st.button("Back to Data Collection"):
466
+ st.session_state.page = "data_collection"
467
+
468
+
469
+ #---------VIDEO CAPTURE AND EXPLANATION OF CV2.WAITKEY-----------
470
+
471
+ def Video_capture_and_explanation_page():
472
+ st.header("🎥 Video Capture with `cv2.VideoCapture()`")
473
+
474
+ st.markdown("""
475
+ **Purpose**: Captures live video from a webcam or reads a video file using OpenCV.
476
+ ### Syntax
477
+ ```python
478
+ cap = cv2.VideoCapture(source)
479
+ source:
480
+ 0: Refers to the default webcam (if you have one connected).
481
+ 'video.mp4': The path to a video file (can be any supported video format like .mp4, .avi).
482
+ ```
483
+ Key Methods:
484
+ - cap.read(): Captures a frame-by-frame video from the source.
485
+ Returns:
486
+ - ret: A Boolean indicating whether the frame was read correctly (True if successful).
487
+ - frame: The captured frame, represented as a NumPy array (this can be processed or displayed).
488
+ - cap.release(): Releases the video source when you are done capturing. It frees up system resources and allows you to safely close the video capture device or file.
489
+ Example:
490
+ Here’s an example that captures video from the default webcam and displays it:
491
+ ```python
492
+ import cv2
493
+ # Open the default webcam (0)
494
+ cap = cv2.VideoCapture(0)
495
+ while cap.isOpened():
496
+ ret, frame = cap.read() # Capture frame-by-frame
497
+ if not ret:
498
+ break # Exit if frame not read correctly
499
+ cv2.imshow('Live Video', frame) # Display the frame
500
+ # Wait for 1 ms and exit if 'q' is pressed
501
+ if cv2.waitKey(1) & 0xFF == ord('q'):
502
+ break
503
+ cap.release() # Release the webcam
504
+ cv2.destroyAllWindows() # Close all OpenCV windows
505
+ ```
506
+ How it Works:
507
+ - cv2.VideoCapture(0): Opens the default webcam (if available).
508
+ - cap.read(): Reads each frame from the video source.
509
+ - cv2.imshow('Live Video', frame): Displays each captured frame in a window.
510
+ - cap.release(): Releases the video capture object when done capturing frames.
511
+ - cv2.destroyAllWindows(): Closes all OpenCV windows to free up resources.
512
+ """)
513
+
514
+
515
+
516
+ ##----------##
517
+
518
+ st.header("⏱️ cv2.waitKey() for Key Event Handling")
519
+ st.markdown("""
520
+ Purpose:
521
+ cv2.waitKey() is a key function used to handle keyboard events in OpenCV. It is commonly used to display images or video frames and wait for a user input.
522
+ Syntax:
523
+ ```python
524
+ cv2.waitKey(delay)
525
+ ```
526
+ delay:
527
+ - 0: Waits indefinitely until a key is pressed. This is useful when displaying images or video and you want to hold the display open until a key is pressed.
528
+ - 1: Waits for 1 millisecond. This is commonly used in real-time video streaming where the program keeps checking for user input every 1 millisecond.
529
+ How it Works:
530
+ - cv2.waitKey(1): This line waits for a key press for 1 millisecond before checking if the user has pressed any key. If no key is pressed within that time, it proceeds to the next frame.
531
+ - Key Event: The function returns an integer value representing the ASCII code of the key pressed. For example, pressing the 'q' key returns 113 (the ASCII value for 'q').
532
+ Example:
533
+ Here’s an example using cv2.waitKey() to exit the video capture loop when the 'q' key is pressed:
534
+ ```python
535
+ if cv2.waitKey(1) & 0xFF == ord('q'):
536
+ break
537
+ ```
538
+ Explanation:
539
+ - ord('q'): Converts the 'q' character to its ASCII value (113).
540
+ - & 0xFF: Masks the higher bits of the returned value to only check for the lower 8 bits, ensuring correct handling of the key press.
541
+ Why is cv2.waitKey() Important?
542
+ - It helps manage user input while displaying images or videos.
543
+ - Without cv2.waitKey(), the OpenCV window would immediately close after displaying the image/video, and you would not be able to interact with it.
544
+ - It enables frame-by-frame processing in real-time video processing (such as live video capture or webcam feeds).
545
+ Example in Context:
546
+ ```python
547
+ import cv2
548
+ # Open the default webcam (0)
549
+ cap = cv2.VideoCapture(0)
550
+ while cap.isOpened():
551
+ ret, frame = cap.read() # Capture frame-by-frame
552
+ if not ret:
553
+ break # Exit if frame not read correctly
554
+ cv2.imshow('Webcam Feed', frame) # Display the frame
555
+ # Wait for 1 ms and exit if 'q' is pressed
556
+ if cv2.waitKey(1) & 0xFF == ord('q'):
557
+ break
558
+ cap.release() # Release the webcam
559
+ cv2.destroyAllWindows() # Close all OpenCV windows
560
+ ```
561
+ Explanation:
562
+ - cv2.VideoCapture(0): Initializes the webcam.
563
+ - cap.read(): Captures each frame from the webcam.
564
+ - cv2.imshow('Webcam Feed', frame): Displays the captured frame.
565
+ - cv2.waitKey(1): Checks for key press every 1 millisecond. If the 'q' key is pressed, the loop breaks, and the webcam feed stops.
566
+ - cap.release(): Releases the webcam when done.
567
+ - cv2.destroyAllWindows(): Closes the OpenCV windows and cleans up resources.
568
+ """)
569
+
570
+ ###------KEY POINTS -----###
571
+
572
+ st.markdown("""
573
+ 1. **Video Capture (`cv2.VideoCapture`)**: Opens and reads video either from the webcam or from a video file.
574
+ - **Method `cap.read()`**: Captures individual frames from the video source.
575
+ - **Releasing the capture (`cap.release()`)**: Ensures that the resources are freed once done.
576
+ 2. **Key Handling (`cv2.waitKey`)**: Waits for user key input and processes it:
577
+ - **`cv2.waitKey(1)`**: Checks for key presses every 1 millisecond.
578
+ - **Exiting the loop**: Pressing the `'q'` key exits the video capture loop.
579
+ This explanation provides both the purpose and practical use cases of `cv2.VideoCapture()` and `cv2.waitKey()` in video capture scenarios, including how the two work together to display video and handle key events effectively.
580
+ """)
581
+
582
+
583
+ # Navigation Button
584
+ if st.button("Affine Transformation Matrix"):
585
+ st.session_state.page = "Affine_Transformation_Matrix"
586
+
587
+ # Navigation Button
588
+ if st.button("Back to Data Collection"):
589
+ st.session_state.page = "data_collection"
590
+
591
+
592
+ st.markdown(
593
+ '<a href="https://github.com/Vamshi-183/Animation_project_using_opencv" target="_blank">'
594
+ '<button style="background-color:#4CAF50; color:white; padding:10px 20px; border:none; border-radius:5px; font-size:16px;">Go to GitHub Project</button>'
595
+ '</a>',
596
+ unsafe_allow_html=True
597
+ )
598
+
599
+
600
+ # ----- AFFINE TRANSFORMATION MATRIX -----
601
+
602
+
603
+
604
+ def affine_transformation_matrix():
605
+ # Header for Affine Transformation Matrix
606
+ st.header("Affine Transformation Matrix")
607
+
608
+ # Description of Affine Transformation
609
+ st.markdown("""
610
+ An **Affine Transformation** is a linear mapping method that preserves points, straight lines, and planes. In other words, it maintains the structure of the original object while allowing for operations like translation, scaling, rotation, reflection, and shearing. Affine transformations are widely used in computer graphics, computer vision, image processing, and geometry.
611
+ Affine transformations can be represented by a **transformation matrix** of the following form:
612
+ \\[
613
+ T(x, y) = \\begin{bmatrix} a & b & tx \\\\ c & d & ty \\\\ 0 & 0 & 1 \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\\\ 1 \\end{bmatrix}
614
+ \\]
615
+ - The **matrix elements (a, b, c, d)** control the linear transformation (scaling, rotation, and shearing).
616
+ - The elements **tx and ty** represent translation (shifting the coordinates).
617
+ ### How the Transformation Works
618
+ Given a point \\((x, y)\\), applying an affine transformation produces a new point \\((x', y')\\) calculated as:
619
+ \\[
620
+ \\begin{bmatrix} x' \\\\ y' \\\\ 1 \\end{bmatrix} = \\begin{bmatrix} a & b & tx \\\\ c & d & ty \\\\ 0 & 0 & 1 \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\\\ 1 \\end{bmatrix}
621
+ \\]
622
+ This means:
623
+ - \\(x' = a \\cdot x + b \\cdot y + tx\\)
624
+ - \\(y' = c \\cdot x + d \\cdot y + ty\\)
625
+ Affine transformations can be visualized as applying a series of transformations to geometric shapes.
626
+ """)
627
+
628
+ # Key Points Section
629
+ st.header("Key Points of Affine Transformations")
630
+
631
+ st.markdown("""
632
+ ### 1. **Preserves Collinearity**
633
+ - Points that lie on a straight line before transformation remain on a straight line after transformation.
634
+ ### 2. **Preserves Ratios of Distances**
635
+ - The ratio of distances between points on a line remains unchanged after transformation.
636
+ ### 3. **Common Operations**
637
+ Affine transformations can perform the following operations:
638
+ - **Translation**: Moves the object along the x and y axes.
639
+ - **Scaling**: Changes the size of the object (uniform or non-uniform).
640
+ - **Rotation**: Rotates the object around a specific point (usually the origin).
641
+ - **Shearing**: Skews the object along one or both axes.
642
+ - **Reflection**: Mirrors the object about a specific axis (e.g., x-axis or y-axis).
643
+ ### 4. **2D Affine Transformation Matrix**
644
+ The general 2D affine transformation matrix can be expressed as:
645
+ \\[
646
+ \\begin{bmatrix} a & b & tx \\\\ c & d & ty \\\\ 0 & 0 & 1 \\end{bmatrix}
647
+ \\]
648
+ Where:
649
+ - \\(a, b, c, d\\) represent the linear transformations (scaling, rotation, shearing).
650
+ - \\(tx, ty\\) represent translation.
651
+ ### 5. **Combining Transformations**
652
+ - Multiple affine transformations can be combined by multiplying their matrices.
653
+ - **Order Matters**: The order in which transformations are applied affects the final result (matrix multiplication is non-commutative).
654
+ ### 6. **Applications of Affine Transformations**
655
+ - **Computer Graphics**: Transforming and rendering shapes and images.
656
+ - **Image Processing**: Geometric operations like rotation, scaling, and shearing of images.
657
+ - **Computer Vision**: Object detection, pattern recognition, and image alignment.
658
+ - **Robotics**: Coordinate transformations for motion planning and navigation.
659
+ - **Geographical Information Systems (GIS)**: Map projection and alignment.
660
+ ### 7. **Homogeneous Coordinates**
661
+ Using homogeneous coordinates \\((x, y, 1)\\) allows us to unify translation with linear transformations in a single matrix operation. This simplifies the combination and chaining of multiple transformations.
662
+ """)
663
+
664
+ # Navigation Button
665
+ if st.button("Back to Data Collection"):
666
+ st.session_state.page = "data_collection"
667
+
668
+
669
 
670
  if st.button(":red[Back to Data Collection]"):
671
  st.session_state.page = "data_collection"