Spaces:
Running
Running
feat: Enhance documentation for computer vision filters in app.py
Browse files- Expanded the documentation section to provide detailed descriptions for each available filter, including parameters, usage, and links to relevant OpenCV resources.
- Improved clarity and organization of filter information to enhance user understanding and experience.
- Added fallback messaging for filters without existing documentation.
app.py
CHANGED
@@ -424,7 +424,11 @@ with main_tabs[2]: # Documentation Tab
|
|
424 |
st.markdown(
|
425 |
"""
|
426 |
## Documentation
|
427 |
-
|
|
|
|
|
|
|
|
|
428 |
### Available Filters
|
429 |
"""
|
430 |
)
|
@@ -435,98 +439,225 @@ with main_tabs[2]: # Documentation Tab
|
|
435 |
for filter_name in filters:
|
436 |
st.markdown(f"#### {filter_name}")
|
437 |
|
438 |
-
# Add description for each filter
|
439 |
-
if filter_name == "
|
440 |
st.markdown(
|
441 |
"""
|
442 |
-
|
443 |
-
|
444 |
**Parameters:**
|
445 |
-
- **
|
446 |
-
- **
|
447 |
-
|
448 |
-
|
449 |
-
|
|
|
450 |
"""
|
451 |
)
|
452 |
-
elif filter_name == "
|
453 |
st.markdown(
|
454 |
"""
|
455 |
-
|
456 |
-
|
457 |
**Parameters:**
|
458 |
-
- **
|
459 |
-
|
460 |
-
|
461 |
-
|
|
|
462 |
"""
|
463 |
)
|
464 |
elif filter_name == "Blur":
|
465 |
st.markdown(
|
466 |
"""
|
467 |
-
Applies Gaussian blur to smooth the image.
|
468 |
-
|
469 |
**Parameters:**
|
470 |
-
- **Kernel Size**: Size of the blurring matrix (
|
471 |
-
|
472 |
-
**Usage**: Noise reduction, detail smoothing, pre-processing for other algorithms.
|
|
|
|
|
473 |
"""
|
474 |
)
|
475 |
-
elif filter_name == "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
476 |
st.markdown(
|
477 |
"""
|
478 |
-
|
479 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
480 |
**Parameters:**
|
481 |
-
- **
|
482 |
-
|
483 |
-
|
|
|
|
|
|
|
484 |
"""
|
485 |
)
|
486 |
-
elif filter_name == "
|
487 |
st.markdown(
|
488 |
"""
|
489 |
-
|
490 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
**Parameters:**
|
492 |
-
- **
|
493 |
-
- **
|
494 |
-
|
495 |
-
**Usage**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
496 |
"""
|
497 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
elif filter_name == "Hand Tracker":
|
499 |
st.markdown(
|
500 |
"""
|
501 |
-
Detects and tracks hand positions and landmarks using MediaPipe.
|
502 |
-
|
503 |
-
**Parameters:** None (uses pre-trained models)
|
504 |
-
|
505 |
-
**Usage**: Gesture recognition, hand pose estimation
|
|
|
|
|
506 |
"""
|
507 |
)
|
508 |
elif filter_name == "Face Tracker":
|
509 |
st.markdown(
|
510 |
"""
|
511 |
-
Detects
|
512 |
-
|
513 |
-
**Parameters:** None (uses pre-trained models)
|
514 |
-
|
515 |
-
**Usage**: Face detection, facial
|
|
|
|
|
516 |
"""
|
517 |
)
|
518 |
else:
|
519 |
-
|
|
|
|
|
|
|
|
|
|
|
520 |
|
521 |
st.markdown(
|
522 |
"""
|
523 |
-
### Technical Details
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
- [
|
528 |
-
-
|
529 |
-
- [Streamlit Documentation](https://docs.streamlit.io/)
|
530 |
"""
|
531 |
)
|
532 |
|
@@ -535,7 +666,7 @@ st.markdown(
|
|
535 |
<div style="position: fixed; bottom: 0; width: 100%; background-color: #0E1117;
|
536 |
padding: 8px; text-align: center; border-top: 1px solid #262730;">
|
537 |
<p style="margin: 0; font-size: 13px; color: #AAAAAA;">
|
538 |
-
OpenCV Explorer | Built with Streamlit
|
539 |
</p>
|
540 |
</div>
|
541 |
""",
|
|
|
424 |
st.markdown(
|
425 |
"""
|
426 |
## Documentation
|
427 |
+
|
428 |
+
This section provides details about the available computer vision filters and transformations.
|
429 |
+
You can select multiple filters, and they will be applied sequentially in the order chosen within each category.
|
430 |
+
Adjust the parameters in the control panel to see the effects in real-time.
|
431 |
+
|
432 |
### Available Filters
|
433 |
"""
|
434 |
)
|
|
|
439 |
for filter_name in filters:
|
440 |
st.markdown(f"#### {filter_name}")
|
441 |
|
442 |
+
# Add detailed description and links for each filter
|
443 |
+
if filter_name == "Resize":
|
444 |
st.markdown(
|
445 |
"""
|
446 |
+
Changes the dimensions (width and height) of the video frame. Useful for adjusting the output size or preparing the frame for other operations that require a specific input size.
|
447 |
+
|
448 |
**Parameters:**
|
449 |
+
- **Width**: Target width in pixels.
|
450 |
+
- **Height**: Target height in pixels.
|
451 |
+
|
452 |
+
**Usage**: Scaling for performance, UI fitting, preprocessing for models.
|
453 |
+
|
454 |
+
**Docs**: [OpenCV Geometric Transformations](https://docs.opencv.org/4.x/da/d6e/tutorial_py_geometric_transformations.html) (See `cv2.resize`)
|
455 |
"""
|
456 |
)
|
457 |
+
elif filter_name == "Rotation":
|
458 |
st.markdown(
|
459 |
"""
|
460 |
+
Rotates the video frame around its center by a specified angle.
|
461 |
+
|
462 |
**Parameters:**
|
463 |
+
- **Angle**: Rotation angle in degrees (0-360).
|
464 |
+
|
465 |
+
**Usage**: Image orientation correction, creative effects.
|
466 |
+
|
467 |
+
**Docs**: [OpenCV Geometric Transformations](https://docs.opencv.org/4.x/da/d6e/tutorial_py_geometric_transformations.html) (See `cv2.getRotationMatrix2D` and `cv2.warpAffine`)
|
468 |
"""
|
469 |
)
|
470 |
elif filter_name == "Blur":
|
471 |
st.markdown(
|
472 |
"""
|
473 |
+
Applies Gaussian blur to smooth the image, reducing noise and detail. The kernel size determines the extent of blurring.
|
474 |
+
|
475 |
**Parameters:**
|
476 |
+
- **Kernel Size**: Size of the blurring matrix (must be an odd number). Higher values create more blur.
|
477 |
+
|
478 |
+
**Usage**: Noise reduction, detail smoothing, pre-processing for edge detection or other algorithms.
|
479 |
+
|
480 |
+
**Docs**: [OpenCV Smoothing Images](https://docs.opencv.org/4.x/d4/d13/tutorial_py_filtering.html) (See `cv2.GaussianBlur`)
|
481 |
"""
|
482 |
)
|
483 |
+
elif filter_name == "Sharpen":
|
484 |
+
st.markdown(
|
485 |
+
"""
|
486 |
+
Enhances the edges and details in the image using a sharpening kernel. This is achieved by subtracting a blurred version of the image from the original.
|
487 |
+
|
488 |
+
**Parameters:** None (uses a fixed kernel).
|
489 |
+
|
490 |
+
**Usage**: Enhancing image clarity, highlighting details.
|
491 |
+
|
492 |
+
**Docs**: [OpenCV Image Filtering Concepts](https://docs.opencv.org/4.x/d4/d13/tutorial_py_filtering.html) (Concept explanation, the implementation uses a custom kernel)
|
493 |
+
"""
|
494 |
+
)
|
495 |
+
elif filter_name == "Canny":
|
496 |
+
st.markdown(
|
497 |
+
"""
|
498 |
+
Detects edges in the image using the Canny edge detection algorithm, a multi-stage process to find sharp changes in intensity.
|
499 |
+
|
500 |
+
**Parameters:**
|
501 |
+
- **Lower Threshold**: Minimum intensity gradient to be considered a potential edge.
|
502 |
+
- **Upper Threshold**: Maximum intensity gradient. Edges above this are definite edges. Pixels between the thresholds are included if connected to definite edges.
|
503 |
+
|
504 |
+
**Usage**: Edge detection, feature extraction, object boundary identification.
|
505 |
+
|
506 |
+
**Docs**: [OpenCV Canny Edge Detection](https://docs.opencv.org/4.x/da/d22/tutorial_py_canny.html)
|
507 |
+
"""
|
508 |
+
)
|
509 |
+
elif filter_name == "Contour":
|
510 |
st.markdown(
|
511 |
"""
|
512 |
+
Finds and draws contours (continuous curves joining points along a boundary with the same intensity) in the image. Usually applied after thresholding or edge detection.
|
513 |
+
|
514 |
+
**Parameters:** None (finds contours on the processed image and draws them).
|
515 |
+
|
516 |
+
**Usage**: Object detection, shape analysis, feature extraction.
|
517 |
+
|
518 |
+
**Docs**: [OpenCV Contours](https://docs.opencv.org/4.x/d4/d73/tutorial_py_contours_begin.html) (See `cv2.findContours`, `cv2.drawContours`)
|
519 |
+
"""
|
520 |
+
)
|
521 |
+
elif filter_name == "Hough Lines":
|
522 |
+
st.markdown(
|
523 |
+
"""
|
524 |
+
Detects straight lines in the image using the Hough Line Transform (Probabilistic variant). Works best on edge-detected images.
|
525 |
+
|
526 |
+
**Parameters:** None (uses preset parameters for `cv2.HoughLinesP`).
|
527 |
+
|
528 |
+
**Usage**: Line detection in images, structure identification.
|
529 |
+
|
530 |
+
**Docs**: [OpenCV Hough Line Transform](https://docs.opencv.org/4.x/d6/d10/tutorial_py_houghlines.html) (See `cv2.HoughLinesP`)
|
531 |
+
"""
|
532 |
+
)
|
533 |
+
elif filter_name == "Color Filter":
|
534 |
+
st.markdown(
|
535 |
+
"""
|
536 |
+
Isolates specific colors by converting the image to HSV (Hue, Saturation, Value) color space and applying a threshold based on the selected ranges.
|
537 |
+
|
538 |
**Parameters:**
|
539 |
+
- **Lower Bounds (Hue, Sat, Val)**: Minimum HSV values for the color range.
|
540 |
+
- **Upper Bounds (Hue, Sat, Val)**: Maximum HSV values for the color range.
|
541 |
+
|
542 |
+
**Usage**: Object detection based on color, color segmentation, special effects.
|
543 |
+
|
544 |
+
**Docs**: [OpenCV Changing Colorspaces](https://docs.opencv.org/4.x/df/d9d/tutorial_py_colorspaces.html) (See `cv2.cvtColor` and `cv2.inRange`)
|
545 |
"""
|
546 |
)
|
547 |
+
elif filter_name == "Histogram Equalization":
|
548 |
st.markdown(
|
549 |
"""
|
550 |
+
Improves contrast in grayscale images by redistributing pixel intensities more evenly across the histogram. Applied to the Value channel if the input is color.
|
551 |
+
|
552 |
+
**Parameters:** None.
|
553 |
+
|
554 |
+
**Usage**: Enhancing contrast in low-contrast images, improving visibility of details.
|
555 |
+
|
556 |
+
**Docs**: [OpenCV Histogram Equalization](https://docs.opencv.org/4.x/d5/daf/tutorial_py_histogram_equalization.html) (See `cv2.equalizeHist`)
|
557 |
+
"""
|
558 |
+
)
|
559 |
+
elif filter_name == "Color Quantization":
|
560 |
+
st.markdown(
|
561 |
+
"""
|
562 |
+
Reduces the number of distinct colors in an image using K-Means clustering in the color space. Groups similar colors together.
|
563 |
+
|
564 |
+
**Parameters:** None (uses a fixed number of clusters, K=8).
|
565 |
+
|
566 |
+
**Usage**: Image compression, posterization effect, simplifying color palettes.
|
567 |
+
|
568 |
+
**Docs**: [OpenCV K-Means Clustering](https://docs.opencv.org/4.x/d1/d5c/tutorial_py_kmeans_opencv.html) (Underlying algorithm)
|
569 |
+
"""
|
570 |
+
)
|
571 |
+
elif filter_name == "Pencil Sketch":
|
572 |
+
st.markdown(
|
573 |
+
"""
|
574 |
+
Creates a pencil sketch effect by converting the image to grayscale, inverting it, blurring the inverted image, and blending it with the original grayscale image using color dodge.
|
575 |
+
|
576 |
+
**Parameters:** None.
|
577 |
+
|
578 |
+
**Usage**: Artistic image transformation, creating sketch-like visuals.
|
579 |
+
|
580 |
+
**Docs**: Involves multiple OpenCV steps (Grayscale, Blur, Blending). See [Color Dodge Blending](https://en.wikipedia.org/wiki/Blend_modes#Dodge_and_burn).
|
581 |
+
"""
|
582 |
+
)
|
583 |
+
elif filter_name == "Morphology":
|
584 |
+
st.markdown(
|
585 |
+
"""
|
586 |
+
Applies morphological operations (Erode, Dilate, Open, Close) to modify the shape of features in the image, typically on binary images.
|
587 |
+
|
588 |
**Parameters:**
|
589 |
+
- **Operation**: Type of morphological operation (`erode`, `dilate`, `open`, `close`).
|
590 |
+
- **Kernel Size**: Size of the structuring element used (odd number).
|
591 |
+
|
592 |
+
**Usage**: Noise removal, joining broken parts, thinning/thickening features.
|
593 |
+
|
594 |
+
**Docs**: [OpenCV Morphological Transformations](https://docs.opencv.org/4.x/d9/d61/tutorial_py_morphological_ops.html) (See `cv2.erode`, `cv2.dilate`, `cv2.morphologyEx`)
|
595 |
+
"""
|
596 |
+
)
|
597 |
+
elif filter_name == "Adaptive Threshold":
|
598 |
+
st.markdown(
|
599 |
+
"""
|
600 |
+
Applies adaptive thresholding, where the threshold value is calculated locally for different regions of the image. Useful for images with varying illumination.
|
601 |
+
|
602 |
+
**Parameters:** None (uses `cv2.ADAPTIVE_THRESH_GAUSSIAN_C`).
|
603 |
+
|
604 |
+
**Usage**: Image segmentation in non-uniform lighting conditions.
|
605 |
+
|
606 |
+
**Docs**: [OpenCV Image Thresholding](https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.html) (See `cv2.adaptiveThreshold`)
|
607 |
"""
|
608 |
)
|
609 |
+
elif filter_name == "Optical Flow":
|
610 |
+
st.markdown(
|
611 |
+
"""
|
612 |
+
Calculates and visualizes the apparent motion of objects between consecutive frames using the Farneback algorithm. Shows motion vectors as lines on the image.
|
613 |
+
|
614 |
+
**Parameters:** None (Requires previous frame data internally).
|
615 |
+
|
616 |
+
**Usage**: Motion tracking, video stabilization analysis, action recognition.
|
617 |
+
|
618 |
+
**Docs**: [OpenCV Optical Flow](https://docs.opencv.org/4.x/d4/dee/tutorial_optical_flow.html) (See `cv2.calcOpticalFlowFarneback`)
|
619 |
+
"""
|
620 |
+
)
|
621 |
elif filter_name == "Hand Tracker":
|
622 |
st.markdown(
|
623 |
"""
|
624 |
+
Detects and tracks hand positions and landmarks (joints) in real-time using the MediaPipe Hands solution. Draws landmarks and connections on the detected hands.
|
625 |
+
|
626 |
+
**Parameters:** None (uses pre-trained MediaPipe models).
|
627 |
+
|
628 |
+
**Usage**: Gesture recognition, sign language interpretation, virtual object interaction, hand pose estimation.
|
629 |
+
|
630 |
+
**Docs**: [MediaPipe Hand Landmarker](https://developers.google.com/mediapipe/solutions/vision/hand_landmarker)
|
631 |
"""
|
632 |
)
|
633 |
elif filter_name == "Face Tracker":
|
634 |
st.markdown(
|
635 |
"""
|
636 |
+
Detects faces in the video feed using the MediaPipe Face Detection solution and draws bounding boxes around them.
|
637 |
+
|
638 |
+
**Parameters:** None (uses pre-trained MediaPipe models).
|
639 |
+
|
640 |
+
**Usage**: Face detection, counting people, basic facial analysis applications, input for face recognition or landmark detection.
|
641 |
+
|
642 |
+
**Docs**: [MediaPipe Face Detector](https://developers.google.com/mediapipe/solutions/vision/face_detector)
|
643 |
"""
|
644 |
)
|
645 |
else:
|
646 |
+
# Fallback for any filters missed
|
647 |
+
st.markdown(
|
648 |
+
f"Detailed documentation for the **{filter_name}** filter is pending."
|
649 |
+
)
|
650 |
+
|
651 |
+
st.divider() # Add a separator between filter descriptions
|
652 |
|
653 |
st.markdown(
|
654 |
"""
|
655 |
+
### General Technical Details
|
656 |
+
|
657 |
+
- **OpenCV**: The core library used for most image processing functions. [OpenCV Python Tutorials](https://docs.opencv.org/4.x/d6/d00/tutorial_py_root.html)
|
658 |
+
- **MediaPipe**: Used for the advanced Hand and Face Tracking features. [MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/)
|
659 |
+
- **Streamlit**: The framework used to build this web application interface. [Streamlit Documentation](https://docs.streamlit.io/)
|
660 |
+
- **WebRTC**: Enables real-time video streaming from your webcam to the browser for processing. (Handled by `streamlit-webrtc`)
|
|
|
661 |
"""
|
662 |
)
|
663 |
|
|
|
666 |
<div style="position: fixed; bottom: 0; width: 100%; background-color: #0E1117;
|
667 |
padding: 8px; text-align: center; border-top: 1px solid #262730;">
|
668 |
<p style="margin: 0; font-size: 13px; color: #AAAAAA;">
|
669 |
+
OpenCV Explorer | Built with Streamlit
|
670 |
</p>
|
671 |
</div>
|
672 |
""",
|