~alanbell/+junk/camcontrol

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
# -*- coding:utf-8 -*-
#printing out stuff like:
#  <area shap="rect" alt="North West" coords="0,0,200,150" href="#" title="North West">

print """<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script language="javascript">
function camgoto(x,y)
{
 $.get('camcontrol.py?gox=' + x + '&goy=' + y);
}
</script>

</head>
<body>
<h1>Camera Control</h1>
<p>Click anywhere on the image to centre (roughly) that bit of the image.</p>
<a style="float:right;" href="http://www.amazon.co.uk/gp/product/B00432J56G/ref=as_li_ss_il?ie=UTF8&amp;camp=1634&amp;creative=19450&amp;creativeASIN=B00432J56G&amp;linkCode=as2&amp;tag=theopesou-21"><img src="http://ws.assoc-amazon.co.uk/widgets/q?_encoding=UTF8&amp;ASIN=B00432J56G&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=GB&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=theopesou-21" alt="" border="0" /><br/>The thing I bought (with evil affiliate code)</a> 

<img style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.co.uk/e/ir?t=theopesou-21&amp;l=as2&amp;o=2&amp;a=B00432J56G" alt="" width="1" height="1" border="0" />


<p>This is based on a £35 wireless pan and tilt camera, but with a bit of python running on a separate web server
to control it. The mjpeg video stream is direct from the camera and it has a clickable imagemap overlay
which chops up the image into 40px squares. Clicking a square requests a simple web service running on
a computer close to the camera which starts the camera moving and stops it again after a fraction of a second
multiplied by the number of pixels it needs to move. The camera itself has no absolute or relative positioning,
it is just done by careful timing of the start and stop signals.</p>
<p>The camera can move in diagonal directions, it would be nice to get it to smoothly move to a new location smoothly
first by panning and tilting, then the rest of the way on one axis. Might be nice to have something round the
outside of the image to allow you to move double the distance, at the moment you can move a half frame in one click
would be nice to be able to go a whole frame away.</p>
<p>The camera stream has a maximum of 4 concurrent viewers, a few more if I
drop the resolution to 320x200. For lots of viewers I would use ffmpeg to reencode from mjpeg to something else
on the fly and possibly pass it to a streaming server of some kind, the overlay control should work
just as it is over a multicast video stream. In reality, if you are expecting more than a couple of concurrent
viewers they are going to argue over control too much.</p>

<img src="http://guest:guest@ubingo.libertus.co.uk:9090/videostream.cgi" usemap="#navmap"/>
<map name="navmap">"""

for x in range(0,640,40):
  for y in range(0,480,40):
    print '  <area shape="rect" alt="%d,%d" title="%d,%d" coords="%d,%d,%d,%d" onclick="camgoto(%d,%d)">' % (x-320,y-240,x-320,y-240,x,y,x+40,y+40,x-320,240-y)


print """</map>
</body>
</html>"""