- #!/usr/bin/python
- #python -m CGIHTTPServer
- import sys
- sys.path.append('.')
- from Adafruit_AMG88xx import Adafruit_AMG88xx
- #import pygame
- import os
- import math
- import time
- import numpy as np
- from scipy.interpolate import griddata
- from colour import Color
- #low range of the sensor (this will be blue on the screen)
- MINTEMP = 15
- #high range of the sensor (this will be red on the screen)
- MAXTEMP = 30
- #how many color values we can have
- COLORDEPTH = 1024
- #sys.stdout.write("Content-type: text/html \r\n\r\n")
- #sys.stdout.write("<!doctype html><html><head><title>Hello CGI</title></head>")
- #sys.stdout.write("<body>")
- sys.stdout.write("Content-type: image/svg+xml \r\n\r\n")
- #initialize the sensor
- sensor = Adafruit_AMG88xx()
- points = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)]
- grid_x, grid_y = np.mgrid[0:7:32j, 0:7:32j]
- #sensor is an 8x8 grid so lets do a square
- height = 240
- width = 240
- #the list of colors we can choose from
- blue = Color("indigo")
- colors = list(blue.range_to(Color("red"), COLORDEPTH))
- #create the array of colors
- colors = [(int(c.red * 255), int(c.green * 255), int(c.blue * 255)) for c in colors]
- displayPixelWidth = width / 30
- displayPixelHeight = height / 30
- #some utility functions
- def constrain(val, min_val, max_val):
- return min(max_val, max(min_val, val))
- def map(x, in_min, in_max, out_min, out_max):
- return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
- #let the sensor initialize
- time.sleep(.1)
- #read the pixels
- pixels = sensor.readPixels()
- pixels = [map(p, MINTEMP, MAXTEMP, 0, COLORDEPTH - 1) for p in pixels]
- #perdorm interpolation
- bicubic = griddata(points, pixels, (grid_x, grid_y), method='cubic')
- print("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"240\" height=\"240\" id=\"yourimage\" >")
- #draw everything
- for ix, row in enumerate(bicubic):
- for jx, pixel in enumerate(row):
- theColor=colors[constrain(int(pixel), 0, COLORDEPTH- 1)]
- theX=(displayPixelHeight * ix)
- theY=(displayPixelWidth * jx)
- dispColor=str(theColor[0])+","+str(theColor[1])+","+str(theColor[2]);
- #print("dispColor="+dispColor);
- #print("theColor["+str(theColor)+"] "+str(theX)+","+str(theY)+" ")
- print("<rect x=\""+str(theX)+"\" y=\""+str(theY)+"\" width=\"8\" height=\"8\" style=\"fill:rgb("+dispColor+");\"/>")
- #pygame.draw.rect(lcd, colors[constrain(int(pixel), 0, COLORDEPTH- 1)], (displayPixelHeight * ix, displayPixelWidth * jx, displayPixelHeight, #displayPixelWidth))
- #print("</svg>")
- sys.stdout.write("</svg>")
- #python -m CGIHTTPServer # run from command line
- #index.html
- #<head>
- # <nometa http-equiv="refresh" content="2" />
- #</head>
- #<img src="./cgi-bin/cam.py" id="yourimage">
- #<script>
- #window.setInterval(function()
- #{
- # document.getElementById('yourimage').src = "./cgi-bin/cam.py?random="+new Date().getTime();
- #},5000);
- #</script>
- #</body>
IR Camera Server
Posted by Anonymous on Sun 8th Apr 2018 00:20
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.