|
| 1 | +# Frame Extraction and Entropy Calculation |
1 | 2 |
|
| 3 | +This project processes video files by extracting frames, saving them as images, converting them to grayscale, and calculating entropy for frame selection based on histogram differences. Selected frames are plotted based on their entropy values. |
| 4 | + |
| 5 | +## Features |
| 6 | +- Extracts frames from a video file. |
| 7 | +- Converts frames to grayscale. |
| 8 | +- Detects significant changes between consecutive frames using histogram comparison. |
| 9 | +- Calculates and visualizes entropy for selected frames. |
| 10 | + |
| 11 | +## Dependencies |
| 12 | + |
| 13 | +- `opencv-python` (`cv2`) |
| 14 | +- `numpy` |
| 15 | +- `matplotlib` |
| 16 | + |
| 17 | +You can install the required packages using the following command: |
| 18 | + |
| 19 | +```bash |
| 20 | +pip install opencv-python numpy matplotlib |
| 21 | +``` |
| 22 | + |
| 23 | +## How It Works |
| 24 | +**1) Frame Extraction:** The video is processed frame by frame using OpenCV. Each frame is saved in two folders: |
| 25 | + |
| 26 | +- `./vout1/` for the original frames. |
| 27 | +- `./grayvout1/` for the grayscale frames. |
| 28 | + |
| 29 | +**2) Histogram Difference Calculation:** The grayscale frames are analyzed using histogram comparison to measure the difference between consecutive frames. |
| 30 | + |
| 31 | +**3) Entropy Calculation:** Entropy is calculated for selected frames based on their pixel distribution. The entropy measures the uncertainty or randomness in the frame. |
| 32 | + |
| 33 | +**4) Frame Selection:** The script sorts the frames based on the histogram differences and selects the top `100` frames with the largest changes. |
| 34 | + |
| 35 | +**5) Entropy Plot:** Finally, the entropy of the selected frames is plotted using `matplotlib`. |
| 36 | + |
| 37 | + |
| 38 | +## Key Functions |
| 39 | +- `calEntropy(image):` |
| 40 | + - This function calculates the entropy of an image by analyzing the pixel distribution. |
| 41 | +- `calculate_frame_changes(files):` |
| 42 | + - This function calculates the histogram difference between consecutive frames. |
| 43 | +- `select_frames(changes, num_frames=100):` |
| 44 | + - This function selects the frames with the most significant changes based on the histogram differences. |
| 45 | + |
| 46 | +## Output |
| 47 | +The script will generate two outputs: |
| 48 | + |
| 49 | +- **Frames:** Saved as PNG files in the specified directories. |
| 50 | +- **Entropy Plot:** A graph showing the entropy values of the selected frames. |
| 51 | + |
| 52 | +## Directory Structure |
| 53 | +``` |
| 54 | +├── Sample.mkv # Input video file |
| 55 | +├── frame_entropy_calculator.py # Main Python script |
| 56 | +├── vout1/ # Directory for original frames |
| 57 | +├── grayvout1/ # Directory for grayscale frames |
| 58 | +└── README.md # This file |
| 59 | +``` |
0 commit comments