Computer Vision Design Patterns
![PyPI - Downloads](https://img.shields.io/pypi/dm/computer-vision-design-patterns)
![Coverage Status](/reports/coverage/coverage-badge.svg?dummy=8484744)
Installation
To install the package, you can use either pip:
pip install computer-vision-design-patterns
or poetry:
poetry add computer-vision-design-patterns
You can also install the package from the source code by cloning the repository and running:
poetry install
Features
Events
TimeEvent
TimeEvent activates immediately when triggered and automatically deactivates after a specified duration.
from computer_vision_design_patterns.event import TimeEvent
import time
event = TimeEvent(2)
event.trigger()
print(event.is_active())
time.sleep(2)
print(event.is_active())
event.trigger()
print(event.is_active())
CountdownEvent
CountdownEvent starts inactive, counts down for a specified duration, and then activates.
from computer_vision_design_patterns.event import CountdownEvent
import time
event = CountdownEvent(3)
event.trigger()
print(event.is_active())
time.sleep(3)
print(event.is_active())
event.reset()
print(event.is_active())
Key Differences
-
TimeEvent:
- Activates immediately upon trigger and can be triggered multiple times
- Automatically deactivates after the duration has elapsed
- Can be reset by triggering again
-
CountdownEvent:
- Starts inactive
- Can be triggered multiple times
- Activates only after countdown completes
- Stays active until manually reset
Examples
Check the dev
folder for comprehensive examples of both event types.
Counters
ManualCounter
ManualCounter is a simple counter that activates when it reaches a specified threshold value. It requires manual updates and can be reset to start counting again.
from computer_vision_design_patterns.counter import ManualCounter
import time
counter = ManualCounter(3)
counter.update()
print(counter.is_active())
counter.update()
print(counter.is_active())
counter.update()
print(counter.is_active())
counter.reset()
print(counter.is_active())
Examples
Check the dev/
folder for comprehensive examples of counter usage.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.