Skip to main content

简单易用的摄像头工具包,支持本地和Web显示,Jupyter优化版(端口重用+默认200帧)

Project description

AIToolkit Camera Logo

AIToolkit Camera

一个为中学生和初学者设计的超简单Python摄像头库

PyPI Version License Python Version


aitoolkit-cam 是一个强大的Python摄像头工具库,它将复杂的摄像头操作封装成极其简洁的接口。无论你是编程新手还是经验丰富的开发者,都可以用最少的代码快速实现本地窗口显示和网页流媒体功能。

✨ 核心特性

  • 极简API: 只需几行代码即可启动摄像头并显示视频。
  • Jupyter 模式: 默认开启安全模式,在Jupyter环境中自动处理资源释放,避免内核崩溃。
  • 双显示模式: 同时支持本地OpenCV窗口和Web浏览器实时视频流。
  • 自动管理: 使用with语句自动完成摄像头的启动和关闭,无需手动管理。
  • 智能健壮: 自动检测可用摄像头,处理各种异常。
  • 中文友好: 完美支持在窗口标题中显示中文。

🚀 快速上手

首先,请确保你已经安装了 aitoolkit-camopencv-python

pip install aitoolkit-cam opencv-python

本地窗口显示

这是在本地窗口中显示摄像头的最简单方法。代码会在一个名为"实时画面"的窗口中显示视频,直到你按下 'q' 键。

from aitoolkit_cam import Camera

# 使用 'with' 语句自动管理摄像头
try:
    with Camera() as cam:
        print("📹 摄像头已启动, 按 'q' 键退出。")
        # 循环获取并显示每一帧
        for frame in cam:
            # show() 方法会处理显示和按键检测
            if cam.show(frame, window_name="实时画面"):
                break
    print("✅ 演示完成")
except Exception as e:
    print(f"❌ 启动失败: {e}")

Jupyter Notebook / Lab

在Jupyter环境中使用 aitoolkit-cam 同样简单。默认的Jupyter模式会自动显示50帧后停止,防止无限运行和资源泄漏。

from aitoolkit_cam import Camera

# 在Jupyter中,这会自动显示50帧然后停止
with Camera() as cam:
    for frame in cam:
        if cam.show(frame, window_name="Jupyter演示"):
            break

网页流模式

想在浏览器里看视频?只需一个参数即可。

from aitoolkit_cam import Camera
import time

# 启用web模式
with Camera(web_enabled=True) as cam:
    url = cam.get_web_url()
    print(f"🌍 Web服务已启动: {url}")
    print("请在浏览器中打开以上URL。服务将在20秒后自动关闭。")
    
    # 保持程序运行以提供视频流
    time.sleep(20)

print("Web演示结束。")

📚 文档

🤝 贡献

我们欢迎任何形式的贡献!无论是提交bug报告、功能请求还是代码PR,请随时通过 GitHub Issues 与我们联系。

📄 许可

本项目采用 MIT 许可

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aitoolkit_cam-0.4.1.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aitoolkit_cam-0.4.1-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

Details for the file aitoolkit_cam-0.4.1.tar.gz.

File metadata

  • Download URL: aitoolkit_cam-0.4.1.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for aitoolkit_cam-0.4.1.tar.gz
Algorithm Hash digest
SHA256 a9a2c659baa1e1daac11110d19b2b262ea4ec766e9e52ce605d4bb7582c8e212
MD5 550b4d1f31af38645fcc38bbbb8a20d9
BLAKE2b-256 aa57c45173240ab321d4d0b265996dd346e850e669c4f54bc638adc55ebfaacc

See more details on using hashes here.

File details

Details for the file aitoolkit_cam-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: aitoolkit_cam-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 29.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for aitoolkit_cam-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 56c671cc0b726c2dd68c3ba0ba00b5955833a720cd41fdedf34d05b98260cf77
MD5 9607835b319f195670b8528b0917890c
BLAKE2b-256 1281ee98a239156c68152ec8e39a680724a20004008739b265710d3578ab5af5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page