forked from AgriVision/pisstv
-
Notifications
You must be signed in to change notification settings - Fork 9
/
sstvcatch.py
71 lines (61 loc) · 1.93 KB
/
sstvcatch.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# Gerrit Polder, PA3BYA, Januari 2014
# Endless loop, wait for Image change, then transmits image data
# on 144.5 MHz using SSTV
import time
import subprocess
import StringIO
from PIL import Image, ImageFont, ImageDraw
mycallsign = "MYCALL" # ham radio callsign
threshold = 10
sensitivity = 400
DEBUG = True
font = ImageFont.load_default()
font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf", 24)
# Capture an image
def captureImage():
command = "raspistill -w %s -h %s -t 1 -e png -o -" % (320, 256)
imageData = StringIO.StringIO()
imageData.write(subprocess.check_output(command, shell=True))
imageData.seek(0)
image = Image.open(imageData)
buffer = image.load()
imageData.close()
return image, buffer
# transmit image in sstv
def transmitImage(im):
draw = ImageDraw.Draw(im)
localtime = time.strftime("%b %d %Y %H:%M:%S", time.localtime(time.time()) )
draw.text((10, 10), mycallsign , (0,0,0), font=font)
draw.text((10, 220), localtime, (0,0,0), font=font)
im.save("/tmp/image.png")
command = "./pisstvpp -pm1 -r22050 /tmp/image.png"
subprocess.call(command, shell=True)
command = "sudo ./pifm_sstv /tmp/image.png.wav"
subprocess.call(command, shell=True)
command = "rm /tmp/image.png*"
subprocess.call(command, shell=True)
# grab initial image
img, buf = captureImage()
# loop forever
while (True):
if (DEBUG):
print(time.strftime("%b %d %Y %H:%M:%S", time.localtime(time.time()) ))
# grab comparison image
imgnew, bufnew = captureImage()
# Count changed pixels
changedPixels = 0
for x in xrange(0, 320):
for y in xrange(0, 256):
# Just check red channel as it's dominant for PiCam NoIR
pixdiff = abs(buf[x,y][0] - bufnew[x,y][0])
if pixdiff > threshold:
changedPixels += 1
if (DEBUG):
print(changedPixels)
# Transmit an image if pixels changed
if changedPixels > sensitivity:
# Swap comparison buffers
img = imgnew
buf = bufnew
transmitImage(img.copy())