Änderungen

Aus Hackerspace Ffm
Wechseln zu: Navigation, Suche

OpenCV mit Python

1.524 Byte hinzugefügt, 17:35, 24. Mär. 2019
/* Testen der Kamera unter Python-OpenCV */
cv.destroyAllWindows()
</pre>
 
Es sollte das Videobild in Graustufen angezeigt werden, im aktiven Kamerabildfenster "ESC" drücken, um das Program ordentlich zu beenden.
 
== RAW-Zugriff auf die Raspberry Pi Kamera ==
Mit dem folgenden Skript kann ohne V4L2-Treiber auf die Raspberry Pi Kamera zugegriffen werden. Evtl. ermöglicht das auch feinere Einstellungsmöglichkeiten der Kamera wie z.B. Belichtungszeit etc.
<pre>
# OpenCV camera test special for Raspberry Pi
# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import numpy as np
 
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
camera.rotation = 0
rawCapture = PiRGBArray(camera, size=camera.resolution)
 
# allow the camera to warmup
time.sleep(1)
 
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# grab the raw NumPy array representing the image, then initialize the timestamp
# and occupied/unoccupied text
image = frame.array
# show the frame
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow("Hit ESC to end", gray.astype(np.uint8))
# clear the stream in preparation for the next frame
rawCapture.truncate(0)
 
# if the `q` or ESC key was pressed, break from the loop
key = cv2.waitKey(1) & 0xFF
if key == ord("q") or key == 27:
break
 
cv2.destroyAllWindows()
camera.close()
</pre>
Es sollte das Videobild in Graustufen angezeigt werden, im aktiven Kamerabildfenster "ESC" drücken, um das Program ordentlich zu beenden.
1.932
Bearbeitungen