异步网络摄像机/视频/图像/截图库。

acapture的Python项目详细描述


https://github.com/aieater/python_acapture

acapture(异步捕获python库)

说明

acapture是一个实时的python相机/视频捕获库。 当python应用程序实现视频、网络摄像机和屏幕截图捕获时,它的fps速度太慢,性能也很差。 另外,python是非事件驱动的体系结构,总是存在i/o阻塞问题,这将阻碍并行性。

acapture(asynchronuscapture)库提供异步视频/摄像机捕获实现,可以解决阻塞和性能问题。

acapture库是有用的,而不是opencv视频捕获api。

opencv有阻塞问题。

import cv2
cap = cv2.VideoCapture(0)
check,frame = cap.read() # blocking!! and depends on camera FPS.

acapture库可以解决实时应用程序中的阻塞问题。

import acapture
cap = acapture.open(0)
check,frame = cap.read() # non-blocking

另请参阅“pyglview”软件包。

由于cv2.waitkey(1),opencv3呈现程序太慢。 如果想提高性能,应该使用opencv4+或“pyglview”包。

https://github.com/aieater/python_glview.git

这个包支持最快的opengl直接查看器和opencv渲染器。 如果您的环境不支持opengl,它将自动切换到cpu渲染器(opencv),也可以使用远程桌面(xserver),如vnc。

开始

ubuntu16.04上的基本库
Libraryinstallation
Camerasudo apt install -y libv4l-dev libdc1394-22 libdc1394-22-dev v4l-utils
Videosudo apt install -y ffmpeg libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libfaac-dev libmp3lame-dev mplayer
MacOSX上的基本库
Libraryinstallation
Brew/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Camera-
Videobrew install ffmpeg mplayer
python包依赖项
VersionLibraryinstallation
v3.x/v4.xOpenCVpip3 install opencv-python
v4.xmsspip3 install mss
v1.1x.xnumpypip3 install numpy
v1.9.xpygamepip3 install pygame
v3.7.xconfigparserpip3 install configparser

最后,安装孔盖。

pip3 install acapture

示例

视频流(异步)

import acapture
import cv2

cap = acapture.open("test.mp4")
while True:
    check,frame = cap.read() # non-blocking
    if check:
        frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
        cv2.imshow("test",frame)
        cv2.waitKey(1)

视频帧(异步)

cap = acapture.open("test.mp4",frame_capture=True)

相机流(异步)

import acapture
import cv2

cap = acapture.open(0) # /dev/video0
while True:
    check,frame = cap.read() # non-blocking
    if check:
        frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
        cv2.imshow("test",frame)
        cv2.waitKey(1)

截图流(同步)

import acapture
import cv2

cap = acapture.open(-1)
while True:
    check,frame = cap.read() # blocking
    if check:
        frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
        cv2.imshow("test",frame)
        cv2.waitKey(1)

目录图像(同步)

import acapture
import cv2

cap = acapture.open("images/")
while True:
    check,frame = cap.read() # blocking
    if check:
        frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
        cv2.imshow("test",frame)
        cv2.waitKey(1)

单位图像(预加载)

import acapture
import cv2

cap = acapture.open("images/test.jpg")
while True:
    check,frame = cap.read()
    if check:
        frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
        cv2.imshow("test",frame)
        cv2.waitKey(1)

将视频提取到jpg图像。

import acapture

acapture.extract_video2images("test.mp4",format="jpg",quality=2)

原料药
VersionFunctionRequiredDescription
v1.0open(f,**kargs)fOpen stream. [-1=>screenshot], [0=>camera0], [1=>camera1], [dirpath=>images], [path=>image],[path=>video]
v1.0extract_video2images(path,**kargs)pathExtract video to images.
v1.0camera_info()Display camera information on Ubuntu.
v1.0compress_images2video(path,**kargs)pathMake video from images.
v1.0extract_video2audio(f)pathExtract audio file as mp3.
v1.0join_audio_with_video(vf,af)vf, afJoin video file and audio file.

另请参阅“pyglview”软件包。

OpenCV3渲染器太慢。 如果想提高性能,应该使用opencv4或pyglview包。

https://github.com/aieater/python_glview.git

这个包支持最快的opengl查看器和opencv渲染器。 如果您的环境不支持opengl,它将自动切换到cpu渲染器(opencv),也可以使用远程桌面(xserver),如vnc。

acapture+pyglview+webcamera示例。

import cv2
import acapture
import pyglview
viewer = pyglview.Viewer()
cap = acapture.open(0) # Camera 0,  /dev/video0
def loop():
    check,frame = cap.read() # non-blocking
    frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
    if check:
        viewer.set_image(frame)
viewer.set_loop(loop)
viewer.start()

支持60fps的Logicool C922 1280x720(HD)。 这种相机设备和opengl直接渲染器是最佳实践。 Logicool Brio 90fps相机也不错!,但有点贵。

许可证

这个项目是在麻省理工学院的许可下授权的-请参见LICENSE文件了解详细信息

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JAVAutil。整数java的扫描器键盘输入   java通知运行后立即崩溃   java如何在一个只能由类修改而不能由其实例修改的类中生成静态变量?   数据库Java字段猜测   返回值周围的java括号为什么?   java Android更新通讯录中的联系人   一个消费者正在读取数据   java是否可以通过编程方式为蓝牙配对设置pin?   java Spring引导和buildResponseEntity()   java为什么序列化可以在没有实现可序列化的情况下工作   Java同步无助于相互排斥   twitter Java Twitter4J未在推文下显示源标签   为什么Javasocket不支持中断处理?