-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdegradation.py
More file actions
73 lines (55 loc) · 2.17 KB
/
degradation.py
File metadata and controls
73 lines (55 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import cv2
import numpy as np
# ------------------------------------------------------------
# This file contains functions used to simulate visual
# degradation conditions (occlusion and noise) in order to
# evaluate the robustness of visual object trackers.
# ------------------------------------------------------------
def add_occlusion(frame, bbox, ratio=0.5):
"""
Simulates partial occlusion by masking a portion of the
target bounding box.
Parameters:
- frame: current video frame (numpy array)
- bbox: ground-truth bounding box [x, y, width, height]
- ratio: proportion of the bounding box to be occluded
The occlusion is applied as a black rectangle over the
upper-left region of the target.
"""
# Extract bounding box coordinates
x, y, w, h = map(int, bbox)
# Compute occlusion size based on the given ratio
occ_w = int(w * ratio)
occ_h = int(h * ratio)
# Apply occlusion by setting pixel values to zero (black)
frame[y:y + occ_h, x:x + occ_w] = 0
return frame
def add_gaussian_noise(frame, sigma=15):
"""
Adds Gaussian noise to the input frame to simulate
sensor noise or poor lighting conditions.
Parameters:
- frame: current video frame (numpy array)
- sigma: standard deviation of the Gaussian noise
Returns a noisy frame with the same resolution.
"""
# Generate Gaussian noise with zero mean
noise = np.random.normal(0, sigma, frame.shape).astype(np.uint8)
# Add noise to the frame using OpenCV for proper saturation
return cv2.add(frame, noise)
def motion_blur(frame, kernel_size=15):
"""
Applies motion blur to the input frame to simulate
motion-induced degradation.
Parameters:
- frame: current video frame (numpy array)
- kernel_size: size of the motion blur kernel
Returns a blurred frame with the same resolution.
"""
# Create a motion blur kernel
kernel = np.zeros((kernel_size, kernel_size))
kernel[int((kernel_size - 1) / 2), :] = np.ones(kernel_size)
kernel = kernel / kernel_size
# Apply the motion blur using OpenCV filter2D
blurred_frame = cv2.filter2D(frame, -1, kernel)
return blurred_frame