New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

acapture

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acapture

Async web camera/video/images/screenshot capturing library.

  • 1.2.6
  • PyPI
  • Socket score

Maintainers
1

https://github.com/aieater/python_acapture

acapture (async capture python library)

Description

acapture is a python camera/video capturing library for realtime. When python apps implement video, web camera and screenshot capturing, it is too slow FPS and suffering with that performance. In addition, python is non event driven architecture and always be I/O blocking problem, and that will be imped parallelism.

acapture(AsynchronusCapture) library provides async video/camera capturing implementation and can solve that blocking and performance problems.

acapture library is useful instead of OpenCV VideoCapture API.

OpenCV has blocking problem.
import cv2
cap = cv2.VideoCapture(0)
check,frame = cap.read() # blocking!! and depends on camera FPS.
acapture library can solve that blocking problem in realtime apps.
import acapture
cap = acapture.open(0)
check,frame = cap.read() # non-blocking

Also see 'pyglview' package.

OpenCV3 renderer is too slow due to cv2.waitKey(1). If you want to more performance, you should use OpenCV4+ or 'pyglview' package.

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

This package is supported fastest OpenGL direct viewer and OpenCV renderer both. If your environment was not supported OpenGL, it will be switched to CPU renderer(OpenCV) automatically and also available remote desktop(Xserver) like VNC.

Getting Started

Base libraries on 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
Base libraries on MacOSX
Libraryinstallation
Brew/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Camera-
Videobrew install ffmpeg mplayer
Python package dependencies
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
Finally, install acapture.
pip3 install acapture

Examples

Video stream (Async)
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)
Video frames (Async)
cap = acapture.open("test.mp4",frame_capture=True)
Camera stream (Async)
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)
Screenshot stream (Sync)
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)
Directory images (Sync)
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)
Unit image (Preloaded)
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)
Extract video to jpg images.
import acapture

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

APIs
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.

Also see 'pyglview' package.

OpenCV3 renderer is too slow. If you want to more performance, you should use OpenCV4 or pyglview package.

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

This package is supported fastest OpenGL viewer and OpenCV renderer both. If your environment was not supported OpenGL, it will be switched to CPU renderer(OpenCV) automatically and also available remote desktop(Xserver) like VNC.

acapture + pyglview + webcamera example.
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()

Logicool C922 1280x720(HD) is supported 60FPS. This camera device and OpenGL direct renderer is best practice. Logicool BRIO 90FPS camera is also good!, but little bit expensive.

License

This project is licensed under the MIT License - see the LICENSE file for details

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc