Video sampler
EntropyByffer
Bases: FrameBuffer
Measure image entropy as a function of the image usability
Source code in video_sampler/buffer.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|
FrameBuffer
Bases: ABC
Source code in video_sampler/buffer.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
clear()
abstractmethod
Clear the buffer
Source code in video_sampler/buffer.py
30 31 32 33 |
|
final_flush()
abstractmethod
Flush the buffer and return the remaining items
Source code in video_sampler/buffer.py
20 21 22 23 |
|
get_buffer_state()
abstractmethod
Return the current state of the buffer
Source code in video_sampler/buffer.py
25 26 27 28 |
|
GridBuffer
Bases: HashBuffer
A class representing a grid-based buffer for images. Splits the image into a grid and stores the hashes of the grid cells in a mosaic buffer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
The maximum size of the buffer. |
required |
debug_flag |
bool
|
A flag indicating whether debug information should be printed. |
False
|
hash_size |
int
|
The size of the hash. |
4
|
grid_x |
int
|
The number of grid cells in the x-axis. |
4
|
grid_y |
int
|
The number of grid cells in the y-axis. |
4
|
max_hits |
int
|
The maximum number of hits allowed for a hash. |
1
|
Attributes:
Name | Type | Description |
---|---|---|
grid_x |
int
|
The number of grid cells in the x-axis. |
grid_y |
int
|
The number of grid cells in the y-axis. |
max_hits |
int
|
The maximum number of hits allowed for a hash. |
mosaic_buffer |
dict
|
A dictionary storing the mosaic buffer. |
Methods:
Name | Description |
---|---|
add |
Adds an image to the buffer along with its metadata. |
clear |
Clears the buffer and the mosaic buffer. |
update_ttl_buffer |
Updates the buffer by expiring images that are not in the grid. |
Source code in video_sampler/buffer.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
__get_grid_hash(item)
Compute grid hashes for a given image
Source code in video_sampler/buffer.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
GzipBuffer
Bases: FrameBuffer
Measure compression size as a function of the image usability
Source code in video_sampler/buffer.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
HashBuffer
Bases: FrameBuffer
A buffer that stores frames with their corresponding metadata and checks for duplicates based on image hashes. Args: size (int): The maximum size of the buffer. debug_flag (bool, optional): Flag indicating whether to enable debug mode. Defaults to False. hash_size (int, optional): The size of the image hash. Defaults to 4.
Methods:
Name | Description |
---|---|
get_buffer_state |
Returns the current state of the buffer as a list of image hashes. |
add |
Image.Image, metadata: dict[str, Any]) Adds an item to the buffer along with its metadata. |
final_flush |
Yields the stored items and their metadata in the buffer. |
Private Methods
__add(item: Image.Image, hash_: str, metadata: dict) Adds an item to the buffer with the given hash and metadata.
__check_duplicate(hash_: str) -> bool: Checks if the given hash already exists in the buffer and renews its validity if found.
Source code in video_sampler/buffer.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
SlidingTopKBuffer
Bases: FrameBuffer
A class representing a sliding top-k buffer for frames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
The maximum size of the buffer. |
required |
debug_flag |
bool
|
A flag indicating whether debug information should be printed. |
False
|
expiry |
int
|
The expiry count for frames. |
30
|
hash_size |
int
|
The size of the hash. |
8
|
Attributes:
Name | Type | Description |
---|---|---|
sliding_buffer |
list
|
The sliding buffer implemented as a min heap. |
max_size |
int
|
The maximum size of the buffer. |
debug_flag |
bool
|
A flag indicating whether debug information should be printed. |
expiry_count |
int
|
The expiry count for frames. |
hash_size |
int
|
The size of the hash. |
Methods:
Name | Description |
---|---|
get_buffer_state |
Returns the current state of the buffer. |
add |
Adds a frame to the buffer along with its metadata. |
final_flush |
Performs a final flush of the buffer and yields the remaining frames. |
clear |
Clears the buffer. |
Source code in video_sampler/buffer.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
create_buffer(buffer_config)
Create a buffer based on the config
Source code in video_sampler/buffer.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|