Skip to content

Commit

Permalink
v2.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
wzyy2 committed Jan 12, 2015
1 parent 133b85d commit a08797b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
7 changes: 6 additions & 1 deletion optional-app/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
Here is app you can choose to install or no.<br>
How to install depends on app.
How to install depends on app.<br>


# webcam #

![image](http://blog.iotwrt.com/wp-content/uploads/2015/01/webcam.png)
3 changes: 2 additions & 1 deletion optional-app/webcam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

sudo apt-get install python-opencv

注意设备权限!

因为使用的过程中出现了usb速度或者其他硬件原因导致的读取失败,大小被限制在320*240.
11 changes: 6 additions & 5 deletions optional-app/webcam/django/html/webcam.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
if(data['msg'] != 'ok') {
$("#dialog").html("Open failed");
$("#dialog").dialog({
modal: true,
modal: false,
closeText: '<span class="glyphicon glyphicon-play"></span>',
buttons: {
Ok: function() {
Expand All @@ -30,6 +30,7 @@
}
});
}
$("#surface").attr('src', "temp.jpg?t=" + Math.random());
});
});
$("#close").click( function(){
Expand All @@ -50,7 +51,7 @@
});
});
$("#refresh").click( function(){
$("#surface").attr('src',$("#surface").attr('src'));
$("#surface").attr('src', "temp.jpg?t=" + Math.random() );
});
});
</script>
Expand All @@ -69,7 +70,7 @@ <h1>

{% block content %}
<div class="row">
<div class="col-md-12" style="margin-bottom:20px;">
<center>
<span>Port:</span>
<input type="text" id="camera_port" style="margin-left:5px;" value="0">
<span style="margin-left:20px;">Control:</span>
Expand All @@ -78,11 +79,11 @@ <h1>
<button class="btn btn-primary" id="close"><span class="glyphicon glyphicon-pause"></span></button>
<button class="btn btn-primary" id="refresh"><span class="glyphicon glyphicon-refresh"></span></button>
</div>
</div>
</center>
</div>
<div class="row">
<center>
<img id="surface" src="temp.jpg"></img>
<img id="surface" src="temp.jpg" style="margin-top: 60px;"></img>
</center>
</div>

Expand Down
46 changes: 37 additions & 9 deletions optional-app/webcam/django/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from PiApp.models import *

from PIL import Image
import cv2
import cv2,os
import cv2.cv as cv

try:
pisettings_instance = PiSettings.objects.get(id =1)
Expand All @@ -15,6 +16,7 @@

html_source_header = "application/webcam/django/html/"
static_source_header = "static/webcam/django/static/"
cwd = os.getcwd() + '/App/webcam/'
camera = None

def index(request):
Expand All @@ -23,27 +25,53 @@ def index(request):
return HttpResponse(t.render(c))

def image(request):
global camera
http = HttpResponse(mimetype='image/jpeg')
if camera != None:
retval, im = camera.read()
img = Image.open('/home/ubuntu/PiBox/App/webcam/django/static/img/pi_logo.png')
img.save(http,'png')
retval, img = camera.read()
cv2.imwrite(cwd + "django/tmp/tmp.jpg" , img)
ret_img = Image.open(cwd + "django/tmp/tmp.jpg")
# img.save(http,'png')
# img = Image.frombytes("RGB", (size_x, size_y), im)
# img.save(http,'jpg')
ret_img.save(http,'JPEG')
return http

def open_camera(request):
global camera
try:
if request.method == 'GET':
camera_port = int(request.GET['camera_port'])
camera = cv2.VideoCapture(camera_port)
if camera == None:
camera = cv2.VideoCapture(camera_port)
camera.set(cv.CV_CAP_PROP_FRAME_WIDTH,320)
camera.set(cv.CV_CAP_PROP_FRAME_HEIGHT,240)
camera.set(cv.CV_CAP_PROP_FPS,1)
retval, img = camera.read() #light led
return HttpResponse(simplejson.dumps({'msg':'ok'}))
except:
return HttpResponse(simplejson.dumps({'msg':'fail'}))

def close_camera(request):
global camera
# del(camera)
return HttpResponse(simplejson.dumps({'msg':'ok'}))
del(camera)
return HttpResponse(simplejson.dumps({'msg':'ok'}))


# CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds.
# CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
# CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file
# CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
# CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
# CV_CAP_PROP_FPS Frame rate.
# CV_CAP_PROP_FOURCC 4-character code of codec.
# CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
# CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
# CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
# CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
# CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
# CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
# CV_CAP_PROP_HUE Hue of the image (only for cameras).
# CV_CAP_PROP_GAIN Gain of the image (only for cameras).
# CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
# CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
# CV_CAP_PROP_WHITE_BALANCE Currently unsupported
# CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)

0 comments on commit a08797b

Please sign in to comment.