Upload files to "/"
This commit is contained in:
commit
8963cf3710
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@ -0,0 +1,26 @@
|
||||
# Perustuu viralliseen Python-kuvaan
|
||||
FROM python:3.10-slim
|
||||
|
||||
# Työhakemiston asettaminen
|
||||
WORKDIR /app
|
||||
|
||||
# Asenna tarvittavat riippuvuudet
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libgl1-mesa-glx \
|
||||
libglib2.0-0 \
|
||||
&& apt-get clean
|
||||
|
||||
# Kopioi sovelluksen tiedostot
|
||||
COPY requirements.txt requirements.txt
|
||||
COPY app.py app.py
|
||||
|
||||
# Asenna Python-paketit
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Avaa portti 5000
|
||||
EXPOSE 5000
|
||||
|
||||
# Käynnistä Flask-sovellus
|
||||
CMD ["gunicorn", "-w", "1", "-b", "0.0.0.0:5000", "--timeout", "120", "app:app"]
|
||||
|
||||
|
102
README.me
Normal file
102
README.me
Normal file
@ -0,0 +1,102 @@
|
||||
# Live Webcam Stream Flaskilla ja OpenCV:llä
|
||||
|
||||
Tämä projekti tarjoaa yksinkertaisen verkkosovelluksen, joka suoratoistaa reaaliaikaista videota verkkokamerasta käyttäen Flaskia ja OpenCV:tä. Sovellus pitää kameran jatkuvasti päällä ja palvelee videolähetystä yhdistetyille asiakkaille.
|
||||
|
||||
---
|
||||
|
||||
## Ominaisuudet
|
||||
- Suoratoistaa reaaliaikaista videota verkkokamerasta verkkoselaimeen.
|
||||
- Flask-hoitaa HTTP-pyynnöt.
|
||||
- OpenCV käytetään videon kaappaamiseen ja kehysten käsittelyyn.
|
||||
- Säikeistys varmistaa, että kamera pysyy päällä riippumatta asiakkaan toiminnasta.
|
||||
|
||||
---
|
||||
|
||||
## Vaatimukset
|
||||
- Python 3.8 tai uudempi
|
||||
- Flask
|
||||
- OpenCV
|
||||
|
||||
---
|
||||
|
||||
## Asennus ja käyttöönotto
|
||||
|
||||
### 1. Kloonaa repositorio
|
||||
Kloonaa tämä repositorio Gitea-palvelimellesi tai paikalliselle koneellesi:
|
||||
```bash
|
||||
git clone <repository-url>
|
||||
cd <repository-folder>
|
||||
```
|
||||
|
||||
### 2. Asenna riippuvuudet
|
||||
Suosittelemme käyttämään Python-virtuaaliympäristöä:
|
||||
```bash
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
pip install flask opencv-python
|
||||
```
|
||||
|
||||
### 3. Käynnistä sovellus
|
||||
Käynnistä Flask-sovellus paikallisesti:
|
||||
```bash
|
||||
python app.py
|
||||
```
|
||||
|
||||
Avaa sovellus selaimessasi osoitteessa:
|
||||
```
|
||||
http://localhost:5000
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Dockerin käyttö
|
||||
|
||||
### 1. Luo Docker-image
|
||||
Luo Docker-image mukana toimitetusta `Dockerfile`-tiedostosta:
|
||||
```bash
|
||||
sudo docker build -t webcam .
|
||||
```
|
||||
|
||||
### 2. Käynnistä Docker-kontti
|
||||
Käynnistä kontti kameran käyttöoikeudella:
|
||||
```bash
|
||||
sudo docker run -it --rm -p 5001:5000 --device /dev/video0 webcam
|
||||
```
|
||||
|
||||
Avaa sovellus selaimessasi osoitteessa:
|
||||
```
|
||||
http://<docker-isäntä-ip>:5001
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Tiedostorakenne
|
||||
```
|
||||
.
|
||||
├── app.py # Pääasiallinen Flask-sovellus
|
||||
├── Dockerfile # Docker-konfiguraatio
|
||||
├── README.md # Projektin dokumentaatio
|
||||
└── requirements.txt # Python-riippuvuudet
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Vianetsintä
|
||||
|
||||
### Verkkokameraa ei löydy
|
||||
Varmista, että verkkokamera on oikein liitetty ja käytettävissä. Jos käytät Dockeria, varmista, että `--device /dev/video0`-lippu on mukana.
|
||||
|
||||
### Suorituskykyongelmat
|
||||
Jos suoratoisto pätkii, harkitse resoluution alentamista OpenCV:n `VideoCapture`-asetuksista.
|
||||
|
||||
---
|
||||
|
||||
## Osallistuminen
|
||||
Voit vapaasti haarauttaa tämän repositorion ja lähettää pull requesteja parantaaksesi projektia.
|
||||
|
||||
---
|
||||
|
||||
## Lisenssi
|
||||
Tämä projekti on lisensoitu MIT-lisenssillä.
|
||||
|
||||
|
39
app.py
Normal file
39
app.py
Normal file
@ -0,0 +1,39 @@
|
||||
import cv2
|
||||
from flask import Flask, Response
|
||||
import threading
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Kamera ja kehykset globaalina
|
||||
camera = cv2.VideoCapture(0)
|
||||
current_frame = None
|
||||
|
||||
def capture_frames():
|
||||
global camera, current_frame
|
||||
while True:
|
||||
success, frame = camera.read()
|
||||
if success:
|
||||
current_frame = cv2.imencode('.jpg', frame)[1].tobytes()
|
||||
|
||||
# Käynnistä taustasäie kameran pitämiseksi päällä
|
||||
frame_thread = threading.Thread(target=capture_frames, daemon=True)
|
||||
frame_thread.start()
|
||||
|
||||
def generate_frames():
|
||||
global current_frame
|
||||
while True:
|
||||
if current_frame is not None:
|
||||
yield (b'--frame\r\n'
|
||||
b'Content-Type: image/jpeg\r\n\r\n' + current_frame + b'\r\n')
|
||||
|
||||
@app.route('/video_feed')
|
||||
def video_feed():
|
||||
return Response(generate_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return "<h1>Live Stream</h1><img src='/video_feed' width='640'>"
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
flask
|
||||
opencv-python-headless
|
||||
gunicorn
|
Loading…
x
Reference in New Issue
Block a user