Last active
April 2, 2018 07:06
-
-
Save arms22/e62e682089fe428b1de8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import numpy as np | |
import cv2 | |
from GridEye import GridEye | |
myeye = GridEye() | |
temp_min = 20. | |
temp_max = 30. | |
img_edge = 256 | |
img = np.zeros((img_edge, img_edge * 2, 3), np.uint8) | |
# np.set_printoptions(precision=1) | |
while(True): | |
# print 'Thermistor Temp:', myeye.thermistorTemp() | |
pixel = np.array(myeye.pixelOut()) | |
pixel.resize((8, 8)) | |
temp_min = temp_min * 0.9 + pixel.min() * 0.1 | |
temp_max = temp_max * 0.9 + pixel.max() * 0.1 | |
if temp_max < 30: | |
temp_max = 30 | |
# print 'Pixel Out(Temp):' | |
# print pixel | |
pixel = pixel.clip(temp_min, temp_max) | |
pixel = (pixel - temp_min) / (temp_max - temp_min) * 255.0 | |
pixel = pixel.astype(np.uint8) | |
# print 'Pixel Out(0-255):' | |
# print pixel | |
pixel = cv2.applyColorMap(pixel, cv2.COLORMAP_JET) | |
# 左側にコピー | |
roi = img[:, :img_edge] | |
cv2.resize(pixel, roi.shape[0:2], roi, | |
interpolation=cv2.INTER_CUBIC) | |
# 右側にコピー | |
roi = img[:, img_edge:] | |
cv2.resize(pixel, roi.shape[0:2], roi, | |
interpolation=cv2.INTER_NEAREST) | |
cv2.imshow('GridEyeView', img) | |
if cv2.waitKey(100) == 27: # ESC | |
break | |
cv2.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import smbus | |
class GridEye: | |
__REG_FPSC = 0x02 | |
__REG_TOOL = 0x0E | |
__REG_PIXL = 0x80 | |
def __init__(self, address=0x68): | |
self.i2c = smbus.SMBus(1) # 0 for Raspberry Pi Model B(256MB) | |
self.address = address | |
self.i2c.write_byte_data(self.address, self.__REG_FPSC, 0x00) | |
def thermistorTemp(self): | |
result = self.i2c.read_word_data(self.address, self.__REG_TOOL) | |
if(result > 2047): | |
result = result - 2048 | |
result = -result | |
return result * 0.0625 | |
def pixelOut(self): | |
out = [] | |
for x in xrange(0, 64): | |
temp = self.i2c.read_word_data( | |
self.address, self.__REG_PIXL + (x * 2)) | |
if(temp > 2047): | |
temp = temp - 4096 | |
out.append(temp * 0.25) | |
return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment