# python_opencv_toasty_animation
## Requirements
opencv-contrib-python 4.10.0.82
playsound 1.3.0
## Installation
Install with pip
pip install opencv-toasty-animation
## Usage
Add these lines before the main loop to instantiate animation
animation = Animation()
Then before the `cv2.imshow('Video', frame)` execution add these
animation.update_animation_state()
frame = animation.apply_animation(frame)
The animation now is ready to be played, now you need to choice an event to fire the start.
Anywhere in the main loop add this line
animation.start()
Optionally you can pass the `prevent_repetition=True` argument if the animation play too many times in the loop to control the repetition. By default it doesn't play until 300 seconds passed. You can change it passing `repetition_delay=300` in the arguments during the instantiation of the animation.
## How to try it
Create a python file and copy this code, then run it and hit "start" button
import cv2
from opencv_toasty_animation.animation import Animation
# Función para manejar los eventos del mouse
def mouse_callback(event, x, y, flags, param):
global mouseX, mouseY, start_animation, animation_phase
if event == cv2.EVENT_LBUTTONDOWN:
mouseX, mouseY = x, y
# Coordenadas del botón
button_rect = param
# Verificar si el clic ocurrió dentro del botón
if button_rect[0] <= mouseX <= button_rect[2] and button_rect[1] <= mouseY <= button_rect[3]:
animation.start()
# Captura de video desde la webcam
cap = cv2.VideoCapture(0)
# Verificar si la cámara se abrió correctamente
if not cap.isOpened():
print("No se puede abrir la cámara")
exit()
# Variables para almacenar la posición del clic
mouseX, mouseY = 0, 0
# Coordenadas del botón (rectángulo)
button_rect = (50, 50, 150, 100) # (x1, y1, x2, y2)
# Configurar la ventana de OpenCV para capturar eventos del mouse
cv2.namedWindow('Webcam')
cv2.setMouseCallback('Webcam', mouse_callback, button_rect)
animation = Animation()
try:
while True:
ret, frame = cap.read()
if not ret:
print("No se puede recibir frames. Terminando...")
break
# Dibujar el botón (rectángulo) en el frame
cv2.rectangle(frame, (button_rect[0], button_rect[1]),
(button_rect[2], button_rect[3]), (0, 0, 255), cv2.FILLED)
cv2.putText(frame, "Start", (button_rect[0] + 10, button_rect[1] + 30),
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
# Actualizar el estado de la animación y aplicar la animación al frame
animation.update_animation_state()
frame = animation.apply_animation(frame)
# Mostrar el frame con la animación
cv2.imshow('Webcam', frame)
# Finalizar la animación y esperar a que se presione 'q' para salir
if cv2.waitKey(1) & 0xFF == ord('q'):
break
finally:
cap.release()
cv2.destroyAllWindows()
Raw data
{
"_id": null,
"home_page": "https://github.com/adremides/python_opencv_toasty_animation",
"name": "opencv-toasty-animation",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "opencv, animation, VideoCapture, toasty",
"author": "Yamil Jaskolowski",
"author_email": "yamilj@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c9/27/d87e3f2092ce8bf8ef44b6082b3236ead267e1e3783efd5810d53ff2ee8a/opencv_toasty_animation-0.0.1.tar.gz",
"platform": null,
"description": "# python_opencv_toasty_animation\n\n## Requirements\n\nopencv-contrib-python 4.10.0.82\nplaysound 1.3.0\n\n## Installation\n\nInstall with pip\n\n pip install opencv-toasty-animation\n\n## Usage\n\nAdd these lines before the main loop to instantiate animation\n\n animation = Animation()\n\nThen before the `cv2.imshow('Video', frame)` execution add these\n\n animation.update_animation_state()\n frame = animation.apply_animation(frame)\n\nThe animation now is ready to be played, now you need to choice an event to fire the start.\nAnywhere in the main loop add this line\n\n animation.start()\n\nOptionally you can pass the `prevent_repetition=True` argument if the animation play too many times in the loop to control the repetition. By default it doesn't play until 300 seconds passed. You can change it passing `repetition_delay=300` in the arguments during the instantiation of the animation.\n\n## How to try it\n\nCreate a python file and copy this code, then run it and hit \"start\" button\n\n import cv2\n\n from opencv_toasty_animation.animation import Animation\n\n\n # Funci\u00f3n para manejar los eventos del mouse\n def mouse_callback(event, x, y, flags, param):\n global mouseX, mouseY, start_animation, animation_phase\n\n if event == cv2.EVENT_LBUTTONDOWN:\n mouseX, mouseY = x, y\n # Coordenadas del bot\u00f3n\n button_rect = param\n # Verificar si el clic ocurri\u00f3 dentro del bot\u00f3n\n if button_rect[0] <= mouseX <= button_rect[2] and button_rect[1] <= mouseY <= button_rect[3]:\n animation.start()\n\n\n # Captura de video desde la webcam\n cap = cv2.VideoCapture(0)\n\n # Verificar si la c\u00e1mara se abri\u00f3 correctamente\n if not cap.isOpened():\n print(\"No se puede abrir la c\u00e1mara\")\n exit()\n\n # Variables para almacenar la posici\u00f3n del clic\n mouseX, mouseY = 0, 0\n\n # Coordenadas del bot\u00f3n (rect\u00e1ngulo)\n button_rect = (50, 50, 150, 100) # (x1, y1, x2, y2)\n\n # Configurar la ventana de OpenCV para capturar eventos del mouse\n cv2.namedWindow('Webcam')\n cv2.setMouseCallback('Webcam', mouse_callback, button_rect)\n\n animation = Animation()\n\n try:\n while True:\n ret, frame = cap.read()\n\n if not ret:\n print(\"No se puede recibir frames. Terminando...\")\n break\n\n # Dibujar el bot\u00f3n (rect\u00e1ngulo) en el frame\n cv2.rectangle(frame, (button_rect[0], button_rect[1]),\n (button_rect[2], button_rect[3]), (0, 0, 255), cv2.FILLED)\n cv2.putText(frame, \"Start\", (button_rect[0] + 10, button_rect[1] + 30),\n cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)\n\n # Actualizar el estado de la animaci\u00f3n y aplicar la animaci\u00f3n al frame\n animation.update_animation_state()\n frame = animation.apply_animation(frame)\n\n # Mostrar el frame con la animaci\u00f3n\n cv2.imshow('Webcam', frame)\n\n # Finalizar la animaci\u00f3n y esperar a que se presione 'q' para salir\n if cv2.waitKey(1) & 0xFF == ord('q'):\n break\n\n finally:\n cap.release()\n cv2.destroyAllWindows()\n",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "Toasty animation to play in top of OpenCV VideoCapture",
"version": "0.0.1",
"project_urls": {
"Homepage": "https://github.com/adremides/python_opencv_toasty_animation",
"Issue Tracker": "https://github.com/adremides/python_opencv_toasty_animation/issues"
},
"split_keywords": [
"opencv",
" animation",
" videocapture",
" toasty"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "dba6b17636fad86dafea9737cd57cac2730ca58f4bb906c36191f548875cd7a5",
"md5": "b29606eabb456879751b9270caa88998",
"sha256": "7f42186adcd1df1f9af6affbb7be0e4094aa99dc95fde4089924b8afa9ebdf41"
},
"downloads": -1,
"filename": "opencv_toasty_animation-0.0.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "b29606eabb456879751b9270caa88998",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.10",
"size": 44779,
"upload_time": "2024-08-23T15:22:09",
"upload_time_iso_8601": "2024-08-23T15:22:09.951335Z",
"url": "https://files.pythonhosted.org/packages/db/a6/b17636fad86dafea9737cd57cac2730ca58f4bb906c36191f548875cd7a5/opencv_toasty_animation-0.0.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c927d87e3f2092ce8bf8ef44b6082b3236ead267e1e3783efd5810d53ff2ee8a",
"md5": "fd21f95f894426daa6406887d1be81e3",
"sha256": "81778dc8304a14d48d7bd6dd025849321ac67f5143a2e9da809441f3c6b36e6c"
},
"downloads": -1,
"filename": "opencv_toasty_animation-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "fd21f95f894426daa6406887d1be81e3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 47365,
"upload_time": "2024-08-23T15:22:11",
"upload_time_iso_8601": "2024-08-23T15:22:11.970937Z",
"url": "https://files.pythonhosted.org/packages/c9/27/d87e3f2092ce8bf8ef44b6082b3236ead267e1e3783efd5810d53ff2ee8a/opencv_toasty_animation-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-23 15:22:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "adremides",
"github_project": "python_opencv_toasty_animation",
"github_not_found": true,
"lcname": "opencv-toasty-animation"
}