Skip to content

Instantly share code, notes, and snippets.

@toandaominh1997
Created December 6, 2019 03:36
Show Gist options
  • Save toandaominh1997/9e721d55be16658ff4fe9b72ebc42ad9 to your computer and use it in GitHub Desktop.
Save toandaominh1997/9e721d55be16658ff4fe9b72ebc42ad9 to your computer and use it in GitHub Desktop.
import numpy
import numpy as np
from PIL import Image
from PyV4L2Camera.camera import Camera
from PyV4L2Camera.controls import ControlIDs
camera = Camera('/dev/video0', 1280, 720)
controls = camera.get_controls()
for control in controls:
print(control.name)
camera.set_control_value(ControlIDs.BRIGHTNESS, 48)
import cv2
import time
while(True):
start = time.time()
frame = camera.get_frame()
# Decode the image
pil_image = Image.frombytes('RGB', (camera.width, camera.height), frame, 'raw', 'RGB')
img = cv2.cvtColor(numpy.asarray(pil_image), cv2.COLOR_RGB2BGR)
cv2.imshow('Opencv', img)
total_time = time.time() - start
print("FPS: {}".format(1/total_time))
camera.close()
"""
sudo apt-get install libv4l-dev
pip install PyV4L2Camera
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment