Profil von Thomas Boor auf LinkedIn anzeigen

Thomas Boor


UNIX-Systemprogrammierung


[Home]   [Impressum]   [Kontakt]   [CV (curriculum vitae) ]   [Veröffentlichungen]   [Vermittler für IT-Freelancer]
[IMS Infos]   [IT Infos]   [Internet-Tips]   [Info-Pages & Service-URLs]   [Downloads]   [Internet Radio]   [Aphorismen & Zitate]

Takt-Bilder auf einem Linux-Rechner (z.B. raspian) mit einem Python-Script mit einem Digital-Fotoapparat aufnehmen, Zeitraffer-Film daraus machen

(Still images captured under linux using python gphoto, made a movy out of the images)

  • Installation der notwendigen Pakete, hier unter ubuntu:
    apt-get install libgphoto2 libgphoto2-dev gphoto2 digikam python-pip python-dev
  • Mit dem Python Installer pip gphoto2 installieren:
    pip install gphoto2
  • Bild(er) aufnehmen:
    python capture-image.py
    Das python-file capture-image.py liegt zusammen mit anderen examples im Verzeichnis /usr/local/share/python-gphoto2/examples/
    capture-image.py:
    #!/usr/bin/env python
    
    # python-gphoto2 - Python interface to libgphoto2
    # http://github.com/jim-easterbrook/python-gphoto2
    # Copyright (C) 2015  Jim Easterbrook  jim@jim-easterbrook.me.uk
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program.  If not, see .
    
    from __future__ import print_function
    
    import logging
    import os
    import subprocess
    import sys
    
    import gphoto2 as gp
    
    def main():
        logging.basicConfig(
            format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
        gp.check_result(gp.use_python_logging())
        context = gp.gp_context_new()
        camera = gp.check_result(gp.gp_camera_new())
        gp.check_result(gp.gp_camera_init(camera, context))
        print('Capturing image')
        file_path = gp.check_result(gp.gp_camera_capture(
            camera, gp.GP_CAPTURE_IMAGE, context))
        print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
        target = os.path.join('/tmp', file_path.name)
        print('Copying image to', target)
        camera_file = gp.check_result(gp.gp_camera_file_get(
                camera, file_path.folder, file_path.name,
                gp.GP_FILE_TYPE_NORMAL, context))
        gp.check_result(gp.gp_file_save(camera_file, target))
        subprocess.call(['xdg-open', target])
        gp.check_result(gp.gp_camera_exit(camera, context))
        return 0
    
    if __name__ == "__main__":
        sys.exit(main())
        
  • Aus den vorliegenden jpgs (die von 'python capture-image.py' ge-captured wurden) einen kleinen mpeg4-Film erzeugen:
    avconv -i *JPG -b:v 1000k mov.mp4



Wenn nur eine webcam verfügbar ist, hilft opencv bei der Aufnahme.
Beispiel eines frame-grabbers mit direkter Ausgabe in einm GUI-Fenster:
#!/usr/bin/env python

import cv2
import sys

cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(0)

while True:

    # Capture frame-by-frame
    ret, frame = video_capture.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = faceCascade.detectMultiScale(
                        gray,
                        scaleFactor=1.1,
                        minNeighbors=5,
                        minSize=(30, 30),
                        flags=cv2.cv.CV_HAAR_SCALE_IMAGE
            )

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # Display the resulting frame
    cv2.imshow('Video', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
webcam farme grabbing with python and opencv


Hier noch: Standbild einer webcam mit python und opencv als File abspeichern
import cv2
 
# Camera 0 is the integrated web cam on my netbook
camera_port = 0
 
#Number of frames to throw away while the camera adjusts to light levels
ramp_frames = 30
 
# Now we can initialize the camera capture object with the cv2.VideoCapture class.
# All it needs is the index to a camera port.
camera = cv2.VideoCapture(camera_port)
 
# Captures a single image from the camera and returns it in PIL format
def get_image():
 # read is the easiest way to get a full image out of a VideoCapture object.
 retval, im = camera.read()
 return im
 
# Ramp the camera - these frames will be discarded and are only used to allow v4l2
# to adjust light levels, if necessary
for i in xrange(ramp_frames):
 temp = get_image()
print("Taking image...")
# Take the actual image we want to keep
camera_capture = get_image()
file = "/home/codeplasma/test_image.png"
# A nice feature of the imwrite method is that it will automatically choose the
# correct format based on the file extension you provide. Convenient!
cv2.imwrite(file, camera_capture)
 
# You'll want to release the camera, otherwise you won't be able to create a new
# capture object until your script exits
del(camera)


Sitemap
Home  |  Kontakt  |  CV (curriculum vitae)  |  Veröffentlichungen  |  IMS Infos  |  IT Infos  |  Info-Pages & Service-URLs DiffServ / QoS in IPv4 und IPv6
Internet Radio  |  Vermittler für IT-Freelancer  |  musical essentials (en)  |  youtube links  |  Aphorismen und Zitate  |  Latein für Smalltalker  |  Downloads  |  Impressum
[fun] [Lyrik] [Limmericks] [MatheGimmicks] [Bauernregeln] [Witze] [(my) blog]
CV in deutsch CV in english
DUCATI Panigale V4


sponsored links

Für Büro Elsenfeld:

Eigene Wetter-Messung und -Aufzeichung: wunderground.com: IELSEN5
Weather Underground PWS IELSEN5 Weather Underground PWS IELSEN5IELSEN5
Weather Underground PWS IELSEN5


accu


klein-windkraftanlagen.com/
klein-windkraftanlagen.com/technik/stromspeicher

http://windempowerment.org/
Savonius Windmill historical information