Created
April 30, 2017 15:51
-
-
Save GeorgEncinas/66f48a222b12aab3aa070881deac41c5 to your computer and use it in GitHub Desktop.
Chameleon Eyes
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
# Method to save image, acquired from a web camera connected to a raspberry | |
# The idea is to save images with motion sensor and take an instant photograph in a forest | |
def __init__(self): | |
self.gps = self.getGPS() | |
self.config = { | |
.... config firebase | |
} | |
self.firebase = self.connect() | |
self.db = self.firebase.database() | |
self.db.child("list-img") | |
self.storage = self.firebase.storage() | |
self.pi = PiCamera() | |
self.dispatcher = EventDispatcher() | |
self.directoryToSave = os.path.join(self.getSaveDir(), 'images') | |
def saveImage(self): | |
gen = self.getSerialName() | |
serial_name = "%s_%s" % (gen[0], gen[1]) | |
file_name = '%s_%f_%f.jpg' % (serial_name, self.gps[0], self.gps[1]) | |
path_to_firebase = 'images/%s' % file_name | |
path_to_local = os.path.join(self.directoryToSave, file_name) | |
data = {"filename": path_to_firebase, | |
"date": gen[0], | |
"time": gen[2], | |
"latitude": self.gps[0], | |
"longitude": self.gps[1] | |
} | |
try: | |
self.pi.exportImage(path_to_local); | |
r = self.storage.child("images/%s.jpg" % path_to_firebase).put(path_to_local) | |
print r | |
results = self.db.child().push(data) | |
print "Console: %s to firebase" % results | |
except ValueError: | |
print "Console: Firebase offline..." |
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
# This code is responsible for reading the image and save it in another location and then be synchronized with the database in the cloud | |
import cv2 | |
class PiCamera(): | |
def __init__(self): | |
self.cap = cv2.VideoCapture(0) | |
self.img = (False, None) | |
def readImage(self): | |
return self.cap.read() | |
def exportImage(self, name="/home/pi/instant.jpg"): | |
self.img = self.readImage() | |
if self.img[0] is not False: | |
cv2.imwrite(name, self.img[1], [cv2.IMWRITE_JPEG_QUALITY, 90]) | |
print "Console: Save %s" % (name) | |
else: | |
print "Console: Error: no img is saved" % (name) |
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
# Highlight moving objects, the idea is to process in a server the detection of animals using K-Means (in progress) | |
while (1): | |
_, frame2 = video.read() | |
if(i%3==0): | |
frame1 = cv2.resize(frame1, (400, 300)) | |
frame2 = cv2.resize(frame2, (400, 300)) | |
res1, frame = procesar(frame1, frame2) | |
mat_puntos = map_out(res1, frame) | |
res = get_submats(mat_puntos, frame2, frame2) | |
cv2.imshow("fondo", res1) | |
cv2.imshow("original", frame2) | |
frame1 = frame2 | |
i += 1 | |
k = cv2.waitKey(30) & 0xFF | |
if k == 27: | |
break | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment