Skip to content

Instantly share code, notes, and snippets.

@OndraZizka
Last active August 3, 2022 01:41
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save OndraZizka/0e08e3931dcc587db92ce0723d7f23e8 to your computer and use it in GitHub Desktop.
Save OndraZizka/0e08e3931dcc587db92ce0723d7f23e8 to your computer and use it in GitHub Desktop.
OpenCV, Python, camera, Raspberry Pi
# sudo apt-get install python-picamera
import picamera
from time import sleep
camera = picamera.PiCamera()
camera.capture('image.jpg')
camera.start_preview()
camera.vflip = True
camera.hflip = True
camera.brightness = 60
camera.start_recording('video.h264')
sleep(5)
camera.stop_recording()
sudo raspi-config
raspistill -o fotka.jpg
raspistill -vf -hf -w 1920 –h 1080 -o fotka2.jpg
# ms bitrate framerate
raspivid -t 10000 -o video2.h264 –b3500000 –f 15
# sudo modprobe bcm2835-v4l2
import cv2
import os
os.system('sudo modprobe bcm2835-v4l2')
cap = cv2.VideoCapture(0)
cap.set(3, 480) #sirka videa
cap.set(4, 320) #vyska videa
cap.read() #adjustace svetla
while(True):
ret, frame = cap.read()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
import cv2
cap = cv2.VideoCapture(0) # Inicializace
cap.read() # Adjustace svetla
while(True):
ret, frame = cap.read()
cv2.imshow('Fotka',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release() # uvolneni kamery
cv2.destroyAllWindows() # zavreni vsech vytvorenych oken
import time
import picamera
frames = [15,25,30,40,50,60,60,60,60]
xres = [2592,1920,1600,1280,1024,800,640,480,320]
yres = [1944,1080,900,720,600,600,480,320,240]
j = 0
while (j < len(xres)):
with picamera.PiCamera() as camera:
camera.resolution = (xres[j], yres[j])
camera.start_preview()
time.sleep(2) # autoexpozice
start = time.time()
cesta = '/run/shm/image%03d.jpg' #/run/shm je RAMdisk
camera.capture_sequence((cesta % i for i in range(frames[j])), use_video_port=True)
print('%d %dx%d: Vyfoceno %d snimku pri %.2ffps' \
%(j+1, xres[j], yres[j], frames[j], (frames[j]/(time.time() - start)) ))
camera.stop_preview()
j = j + 1
sudo apt install -y python-opencv
python
>
import cv2
cam_port = 0 #cislo portu kamery
cap = cv2.VideoCapture(cam_port)
cap.read() #adjustace svetla
img_name = "fotka.png"
ret, img = cap.read() #vlastni foceni
cv2.imwrite(img_name, img)
cap.release()
# Ctrl+D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment