Removed python based webcam support (didn't work well with the raspi), switched instead to external stream (mjpg-streamer being the preferred webcam server)

This commit is contained in:
Gina Häußge committed 2013-01-03 00:39:17 +01:00
1 parent 8dc5e249d5
commit 4e4eed84bb
7 files changed
+67 -124

No files matched your search

+1 -19
View File
@@ -7,7 +7,6 @@ from werkzeug import secure_filename
from printer_webui.printer import Printer, getConnectionOptions
from printer_webui.settings import settings
from printer_webui.webcam import hasWebcamSupport, Webcam
import sys
import os
@@ -28,14 +27,10 @@ if not os.path.isdir(WEBCAM_FOLDER):
app = Flask("printer_webui")
printer = Printer()
if hasWebcamSupport():
webcam = Webcam()
else:
webcam = None
@app.route("/")
def index():
return render_template("index.html")
return render_template("index.html", webcamStream = settings().get("webcam", "stream"))
#~~ Printer state
@@ -261,19 +256,6 @@ def setSettings():
s.save()
return getSettings()
#~~ webcam
@app.route(BASEURL + "webcam/image", methods=["GET"])
def getImage():
if webcam is None:
abort(404)
image = webcam.get()
strIO = StringIO.StringIO()
image.save(strIO, "JPEG", quality=80)
strIO.seek(0)
return send_file(strIO, mimetype="image/jpeg")
#~~ helper functions
def sizeof_fmt(num):
+3
View File
@@ -24,6 +24,9 @@ default_settings = {
"server": {
"host": "0.0.0.0",
"port": 5000
},
"webcam": {
"stream": None
}
}
-8
View File
@@ -97,12 +97,4 @@ table th.gcode_files_action, table td.gcode_files_action {
#webcam_container {
height: 440px;
background-color: #000000;
}
#webcam_placeholder {
height: 440px;
line-height: 440px;
text-align: center;
color: #ffffff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
}
-27
View File
@@ -438,32 +438,6 @@ function DataUpdater(connectionViewModel, printerStateViewModel, temperatureView
}
var dataUpdater = new DataUpdater(connectionViewModel, printerStateViewModel, temperatureViewModel, speedViewModel, terminalViewModel);
function WebcamViewModel() {
var self = this;
self.webcamUpdateInterval = 5000;
self.offlineUrl = "/static/img/webcam-offline.png";
self.url = ko.observable(undefined);
self.enabled = ko.observable(undefined);
self.enabled.subscribe(function(newValue) {
if (newValue) {
self.requestData();
} else {
$("#webcam_image")
}
});
self.requestData = function() {
if (!self.enabled())
return;
self.url(AJAX_BASEURL + "webcam/image?" + (new Date()).getTime());
setTimeout(self.requestData, self.webcamUpdateInterval);
}
}
var webcamViewModel = new WebcamViewModel();
$(function() {
//~~ Print job control
@@ -603,7 +577,6 @@ $(function() {
ko.applyBindings(printerStateViewModel, document.getElementById("jog"));
ko.applyBindings(terminalViewModel, document.getElementById("term"));
ko.applyBindings(speedViewModel, document.getElementById("speed"));
ko.applyBindings(webcamViewModel, document.getElementById("webcam"));
//~~ startup commands
+4 -6
View File
@@ -115,7 +115,7 @@
<li><a href="#jog" data-toggle="tab">Jog</a></li>
<li><a href="#speed" data-toggle="tab">Speed</a></li>
<li><a href="#term" data-toggle="tab">Term</a></li>
<li><a href="#webcam" data-toggle="tab">Webcam</a></li>
{% if webcamStream %}<li><a href="#webcam" data-toggle="tab">Webcam</a></li>{% endif %}
</ul>
<div class="tab-content">
@@ -216,15 +216,13 @@
<button class="btn" type="button" id="terminal-send">Send</button>
</div>
</div>
{% if webcamStream %}
<div class="tab-pane" id="webcam">
<label class="checkbox">
<input type="checkbox" id="webcam_enable" data-bind="checked: enabled"> Enable webcam
</label>
<div id="webcam_container">
<img id="webcam_image" data-bind="attr: { src: url }, visible: enabled()">
<div id="webcam_placeholder" data-bind="visible: !enabled()">Offline</div>
<img id="webcam_image" src="{{ webcamStream }}">
</div>
</div>
{% endif %}
</div>
</div>
</div>
-64
View File
@@ -1,64 +0,0 @@
# coding=utf-8
__author__ = "Gina Häußge <osd@foosel.net>"
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
try:
#Try to find the OpenCV library for video capture.
import cv
except:
cv = None
try:
import VideoCapture as win32vidcap
except:
win32vidcap = None
import PIL
def hasWebcamSupport():
if cv == None and win32vidcap == None:
return False
return True
class Webcam(object):
def __init__(self):
self._cam = None
if cv != None:
self._cam = cv.CreateCameraCapture(-1)
elif win32vidcap != None:
try:
self._cam = win32vidcap.Device()
self._cam.setResolution(640, 480)
except:
pass
def get(self):
if self._cam is None:
return None
if cv is not None:
frame = cv.QueryFrame(self._cam)
image = PIL.Image.fromstring("L", frame.GetSize(), frame.tostring())
return image
elif win32vidcap is not None:
image = self._cam.getImage()
return image
else:
return None
def save(self, filename):
if self._cam is None:
return
if cv is not None:
frame = cv.QueryFrame(self._cam)
cv.SaveImage(filename, frame)
elif win32vidcap is not None:
self._cam.saveSnapshot(filename)
if __name__ == "__main__":
from printer_webui.settings import settings
import os
webcam = Webcam()
webcam.save(os.path.join(settings().settings_dir, "image.png"))