diff --git a/.gitignore b/.gitignore index cf4e265..747fae6 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,7 @@ dev.env #_pycache __pycache__/ +#image_files +*.jpg +*.jpeg +*.png diff --git a/README.md b/README.md index bebd740..653cdc0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Create your own live stream from a Raspberry Pi using the Pi camera module. Buil The Pi streams the output of the camera module over the web via Flask. Devices connected to the same network would be able to access the camera stream via ``` - + ``` ## Screenshots @@ -24,12 +24,12 @@ The Pi streams the output of the camera module over the web via Flask. Devices c Install the following dependencies to create camera stream. ``` -sudo apt-get update +sudo apt-get update sudo apt-get upgrade sudo apt-get install libatlas-base-dev sudo apt-get install libjasper-dev -sudo apt-get install libqtgui4 +sudo apt-get install libqtgui4 sudo apt-get install libqt4-test sudo apt-get install libhdf5-dev @@ -39,10 +39,9 @@ sudo pip3 install opencv-contrib-python sudo pip3 install imutils sudo pip3 install opencv-python - ``` -Note: This installation of opencv may take a while depending on your pi model. +Note: This installation of opencv may take a while depending on your pi model. OpenCV alternate installation (in the event of failed opencv builds): @@ -79,7 +78,7 @@ Go the end of the and add the following (from above): sudo python3 /home/pi/pi-camera-stream-flask/main.py ``` -This would cause the following terminal command to auto-start each time the Raspberry Pi boots up. This in effect creates a headless setup - which would be accessed via SSH. +This would cause the following terminal command to auto-start each time the Raspberry Pi boots up. This in effect creates a headless setup - which would be accessed via SSH. Note: make sure SSH is enabled. ## More Projects / Next Steps diff --git a/camera.py b/camera.py index 6992fa0..7f30692 100644 --- a/camera.py +++ b/camera.py @@ -2,16 +2,19 @@ #Date: 27.09.20 #Desc: This scrtipt script.. -import cv2 +import cv2 as cv from imutils.video.pivideostream import PiVideoStream import imutils import time +from datetime import datetime import numpy as np class VideoCamera(object): - def __init__(self, flip = False): - self.vs = PiVideoStream().start() - self.flip = flip + def __init__(self, flip = False, file_type = ".jpg", photo_string= "stream_photo"): + self.vs = PiVideoStream(resolution=(1920, 1080), framerate=30).start() + self.flip = flip # Flip frame vertically + self.file_type = file_type # image type i.e. .jpg + self.photo_string = photo_string # Name to save the photo time.sleep(2.0) def __del__(self): @@ -24,5 +27,13 @@ class VideoCamera(object): def get_frame(self): frame = self.flip_if_needed(self.vs.read()) - ret, jpeg = cv2.imencode('.jpg', frame) - return jpeg.tobytes() \ No newline at end of file + ret, jpeg = cv.imencode(self.file_type, frame) + self.previous_frame = jpeg + return jpeg.tobytes() + + # Take a photo, called by camera button + def take_picture(self): + frame = self.flip_if_needed(self.vs.read()) + ret, image = cv.imencode(self.file_type, frame) + today_date = datetime.now().strftime("%m%d%Y-%H%M%S") # get current time + cv.imwrite(str(self.photo_string + "_" + today_date + self.file_type), frame) diff --git a/main.py b/main.py index 91547d5..5ccfe87 100644 --- a/main.py +++ b/main.py @@ -5,8 +5,6 @@ # import the necessary packages from flask import Flask, render_template, Response, request from camera import VideoCamera -import time -import threading import os pi_camera = VideoCamera(flip=False) # flip pi camera if upside down. @@ -30,9 +28,12 @@ def video_feed(): return Response(gen(pi_camera), mimetype='multipart/x-mixed-replace; boundary=frame') +# Take a photo when pressing camera button +@app.route('/picture') +def take_picture(): + pi_camera.take_picture() + return "None" + if __name__ == '__main__': app.run(host='0.0.0.0', debug=False) - - - diff --git a/templates/index.html b/templates/index.html index 2c7aaf3..b7dc167 100644 --- a/templates/index.html +++ b/templates/index.html @@ -25,7 +25,7 @@ body { text-align: center; padding: 14px 16px; text-decoration: none; - font-size: 17px; + font-size: 17px; } .navbar a:hover { @@ -43,7 +43,7 @@ body { } -.camera-movement{ +.camera-movement{ float: none; position: absolute; top: 50%; @@ -60,7 +60,7 @@ i.fa { border-radius: 60px; box-shadow: 0px 0px 2px #888; padding: 0.5em 0.6em; - + } @@ -79,12 +79,12 @@ button { overflow: hidden; outline:none; } - + //CSS .camera-bg { - position: fixed; - top: 0; - left: 0; + position: fixed; + top: 0; + left: 0; /* Preserve aspet ratio */ min-width: 100%; @@ -132,11 +132,11 @@ body {
- +
@@ -144,20 +144,29 @@ body { + + - + + + -