LakshmiHarika commited on
Commit
0eb8548
·
verified ·
1 Parent(s): 4d8167e

Update pages/Data Collection.py

Browse files
Files changed (1) hide show
  1. pages/Data Collection.py +88 -4
pages/Data Collection.py CHANGED
@@ -539,12 +539,96 @@ elif st.session_state.current_page == "opencv_operations":
539
  print(cv2.__version__) # This will display the installed OpenCV version
540
  """, language="python")
541
 
 
 
542
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
 
544
-
545
-
546
-
547
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
548
 
549
 
550
  elif st.session_state.current_page == "explore_audio":
 
539
  print(cv2.__version__) # This will display the installed OpenCV version
540
  """, language="python")
541
 
542
+ st.write("With OpenCV installed, let's learn basic image handling in OpenCV.")
543
+ st.write("## Basic Operations in OpenCV")
544
 
545
+ # Heading for Reading Images
546
+ st.write("### Reading an Image")
547
+
548
+ # About imread() function
549
+ st.write("""
550
+ To read an image and convert it into a machine-readable format, we use the **imread()** function from the cv2 module.
551
+ It reads the image file and converts it into a numerical array, where each element represents pixel intensity.
552
+ """)
553
+
554
+ # Code example
555
+ st.code("""
556
+ import cv2
557
+
558
+ # Read the image
559
+ image = cv2.imread('path_to_image.jpg') # Replace 'path_to_image.jpg' with your image file path
560
+
561
+ # Display the numerical matrix
562
+ print(image) # This will print the image as an array of pixel values
563
+ """, language="python")
564
+
565
+ # Explanation for Grayscale Conversion
566
+ st.write("""
567
+ By default, the `imread()` function reads an image as a 3D array in the RGB color space.
568
+ To convert the image to grayscale, pass `0` as the second argument to the `imread()` function. This will return a 2D array where each pixel value represents intensity.
569
+ """)
570
+
571
+ # Code example for Grayscale Conversion
572
+ st.code("""
573
+ import cv2
574
+
575
+ # Read the image in grayscale
576
+ gray_image = cv2.imread('path_to_image.jpg', 0) # Replace 'path_to_image.jpg' with your image file path
577
+
578
+ # Display the numerical matrix for the grayscale image
579
+ print(gray_image) # This will print the 2D array representing pixel intensity
580
+ """, language="python")
581
 
582
+ # Displaying Images with OpenCV
583
+ st.write("### Displaying Images with OpenCV")
584
+
585
+ # Explanation of the functions
586
+ st.write("""
587
+ After creating or reading an image, we can display it using OpenCV. Here’s how the key functions work together:
588
+
589
+ #### imshow()
590
+ - The `imshow()` function creates a **pop-up window** to display the image.
591
+ - Internally, it converts the numerical array into a visual image.
592
+ - **Parameters**:
593
+ 1. `Window Name`: Title of the pop-up window (string).
594
+ 2. `Image Array`: The array representing the image.
595
+
596
+ #### waitKey()
597
+ - **Purpose**: Waits for a key press and adds a delay before closing the pop-up window.
598
+ - **Key Modes**:
599
+ - `waitKey(0)` or `waitKey()`: Keeps the window open indefinitely until a key is pressed.
600
+ - `waitKey(n)`: Delays for `n` milliseconds, closing the window after the delay if no key is pressed.
601
+
602
+ #### destroyAllWindows()
603
+ - The `destroyAllWindows()` function is used to close the pop-up window from **RAM**.
604
+ - It ensures that all windows opened by `imshow()` are completely removed.
605
+ - Without this, the window may stay allocated in memory even after being closed visually.
606
+
607
+ These three functions must work together to display and manage images effectively.
608
+ """)
609
+
610
+ # Syntax for imshow()
611
+ st.write("## imshow()")
612
+ st.code("""
613
+ cv2.imshow(window_name, image_array)
614
+ # window_name: The title of the pop-up window (string)
615
+ # image_array: The image data (usually a NumPy array)
616
+ """, language="python")
617
+
618
+ # Syntax for waitKey()
619
+ st.write("## waitKey()")
620
+ st.code("""
621
+ cv2.waitKey(delay_in_milliseconds)
622
+ # delay_in_milliseconds: Time in milliseconds to keep the window open
623
+ # Use 0 for infinite delay until a key is pressed
624
+ """, language="python")
625
+
626
+ # Syntax for destroyAllWindows()
627
+ st.write("## destroyAllWindows()")
628
+ st.code("""
629
+ cv2.destroyAllWindows()
630
+ # This ensures all windows opened by imshow() are cleared from RAM
631
+ """, language="python")
632
 
633
 
634
  elif st.session_state.current_page == "explore_audio":