concurrent-videocapture
Opencv VideoCapture that runs concurrently in a thread for faster processing
Installation
You can install concurrent_videocapture from pip using
pip install concurrent_videocapture
or using
pip install git+https://github.com/charlielito/concurrent-videocapture
Usage
It follows the same api than cv2.VideoCapture, so the change in code is minimal. The following example just opens the Camera 0 and shows the image in a cv2 window while simulating a heavy image processing function with time.sleep.
import cv2
import time
from concurrent_videocapture import ConcurrentVideoCapture
# Use it a the standard cv2.VideoCapture Class
cap = ConcurrentVideoCapture(0)
while True:
init = time.time()
grabbed, frame = cap.read()
# Simulate heavy image processing function
time.sleep(0.3)
if not grabbed:
break
cv2.imshow("video", frame)
key = cv2.waitKey(1)
if key == 27: # ESC
break
fps = 1/(time.time() - init)
print('Fps: {}'.format(fps))
cap.release()
Additional parameters
Sometimes it is useful to perform some preprocessing to the image in the thread where the camera is read. For that we can use in the constructor the parameter transform_fn, which is a function that is applied to each frame. The flag return_rgb is for converting each frame to RGB since opencv by default returns the frames in GBR format. The next example will flip horizontally the image and return it as RGB:
import cv2
from concurrent_videocapture import ConcurrentVideoCapture
cap = ConcurrentVideoCapture(0, transform_fn=lambda image:cv2.flip(image, 1), return_rgb=True)
while True:
grabbed, frame = cap.read()
if not grabbed:
break
cv2.imshow("video", frame)
key = cv2.waitKey(1)
if key == 27: # ESC
break
cap.release()
Metadata
Release files for concurrent-videocapture 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| concurrent_videocapture-0.0.2.tar.gz | 3.5 kB | Without provenance | Details for concurrent_videocapture-0.0.2.tar.gz |
Release files / concurrent_videocapture-0.0.2.tar.gz
| Download URL | concurrent_videocapture-0.0.2.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0dbdbb79711b60c008babd82fb23041a82274f6fb2076b0d8ec3f9f9238d4ccd
|
|
BLAKE2b-256 checksum How to use checksums |
23db4c268b8b90cf34eabbdc6fa0f4eacd31734d21d194ebff45c1f13f2cc0a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|
Security for concurrent-videocapture 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.