Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Complete model #11

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Next Next commit
train code skeletal done
  • Loading branch information
Arvinth-s committed Jan 12, 2021
commit c0a75f37f7c95e0adadb980cb0d23c58e61adbe3
3 changes: 1 addition & 2 deletions Automated Dataset/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
clearCommand = ["--folder", "/store_00020001/DCIM/100CANON",
"--delete-all-files", "-R"]
clearCommand = ["--folder", "/store_00020001/DCIM/100CANON", "--delete-all-files", "-R"]
triggerCommand = ["--trigger-capture"]
downloadCommand = ["--get-all-files"]

Expand Down
13 changes: 7 additions & 6 deletions Automated Dataset/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pygame
from pygame.locals import *

# noinspection PyUnresolvedReferences
from sh import gphoto2 as gp

Expand All @@ -14,20 +15,20 @@


def killGphoto2Process():
p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
p = subprocess.Popen(["ps", "-A"], stdout=subprocess.PIPE)
out, err = p.communicate()

for line in out.splitlines():
if b'gvfsd-gphoto2' in line:
if b"gvfsd-gphoto2" in line:
pid = int(line.split(None, 1)[0])
os.kill(pid, signal.SIGKILL)


def createSaveFolder(save_location):
try:
os.makedirs(save_location)
with open("/home/syzygianinfern0/sambashare/timestamp.txt", 'w') as handler:
handler.write('/'.join(save_location.split('/')[4:6]))
with open("/home/syzygianinfern0/sambashare/timestamp.txt", "w") as handler:
handler.write("/".join(save_location.split("/")[4:6]))
print("Timstamp is ready")
except:
print("Failed to create new directory.")
Expand Down Expand Up @@ -57,7 +58,7 @@ def main():
pygame.init()
pygame.font.init()
display = pygame.display.set_mode((320, 240))
pygame.display.set_caption('Thermal Cam')
pygame.display.set_caption("Thermal Cam")
pygame.mouse.set_visible(True)
while True:
for event in pygame.event.get():
Expand Down Expand Up @@ -85,7 +86,7 @@ def main():
exit()


if __name__ == '__main__':
if __name__ == "__main__":
picID = "Cannon200DShots"
shot_time = datetime.now().strftime("%Y-%m-%d %H-%M-%S")

Expand Down
6 changes: 3 additions & 3 deletions Automated Dataset/namer/files_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
string2 = ""
string3 = ""

for folder in glob.glob('./Dataset/*Cannon*'):
for folder in glob.glob("./Dataset/*Cannon*"):
for filename in glob.glob(os.path.join(folder, "*small*long*.JPG")):
string1 = filename
for filename in glob.glob(os.path.join(folder, "*small*short*.JPG")):
Expand All @@ -23,7 +23,7 @@
myFile.write(data)

data = ""
for folder in glob.glob('./Dataset/*Cannon*'):
for folder in glob.glob("./Dataset/*Cannon*"):
for filename in glob.glob(os.path.join(folder, "*raw*long*.CR3")):
string1 = filename
for filename in glob.glob(os.path.join(folder, "*raw*short*.CR3")):
Expand All @@ -38,7 +38,7 @@
myFile.write(data)

data = ""
for folder in glob.glob('./Dataset/*Cannon*'):
for folder in glob.glob("./Dataset/*Cannon*"):
for filename in glob.glob(os.path.join(folder, "*raw*long*.JPG")):
string1 = filename
for filename in glob.glob(os.path.join(folder, "*raw*short*.JPG")):
Expand Down
51 changes: 28 additions & 23 deletions Automated Dataset/thermal_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

class ThermalCamera:
def __init__(self):
self.port = '22'
self.uname = 'pi'
self.passd = 'ni6ga2rd'
self.ip = '192.168.43.185'
self.port = "22"
self.uname = "pi"
self.passd = "ni6ga2rd"
self.ip = "192.168.43.185"
self.pi_ssh = paramiko.SSHClient()
self.connect_ssh()

Expand All @@ -18,37 +18,42 @@ def connect_ssh(self):

def trigger_camera(self):
stdin, stdout, stderr = self.pi_ssh.exec_command(
"(sleep 2; echo a) | '/home/pi/darkSight/Dark-Sight/Thermal Camera Libs/pimoroni/examples/fbuf'")
"(sleep 2; echo a) | '/home/pi/darkSight/Dark-Sight/Thermal Camera Libs/pimoroni/examples/fbuf'"
)
print(stdout.read())
self.txt2jpg()

@staticmethod
def txt2jpg():
file = open('/home/syzygianinfern0/sambashare/timestamp.txt', 'r')
file = open("/home/syzygianinfern0/sambashare/timestamp.txt", "r")
filename = file.read().strip()
file.close()
file = open('/home/syzygianinfern0/sambashare/' + filename + '/jpg_temp.txt', 'r')
file = open(
"/home/syzygianinfern0/sambashare/" + filename + "/jpg_temp.txt", "r"
)

while (not file):
file = open('/home/syzygianinfern0/sambashare/' + filename + '/jpg_temp.txt', 'r')
while not file:
file = open(
"/home/syzygianinfern0/sambashare/" + filename + "/jpg_temp.txt", "r"
)

string = ""
for each in file:
string += each
color = list(string.strip().split('#'))
ir = list(color[0].strip().split('\n'))
ig = list(color[1].strip().split('\n'))
ib = list(color[2].strip().split('\n'))
color = list(string.strip().split("#"))
ir = list(color[0].strip().split("\n"))
ig = list(color[1].strip().split("\n"))
ib = list(color[2].strip().split("\n"))
irr = []
igg = []
ibb = []
img = []
for r in ir:
irr.append(list(map(int, r.strip().split('\t'))))
irr.append(list(map(int, r.strip().split("\t"))))
for g in ig:
igg.append(list(map(int, g.strip().split('\t'))))
igg.append(list(map(int, g.strip().split("\t"))))
for b in ib:
ibb.append(list(map(int, b.strip().split('\t'))))
ibb.append(list(map(int, b.strip().split("\t"))))

img.append(irr)
img.append(igg)
Expand All @@ -62,33 +67,33 @@ def txt2jpg():

print(img.shape)
img = img / 255
direc = '/home/syzygianinfern0/sambashare/' + filename
direc = "/home/syzygianinfern0/sambashare/" + filename

plt.imsave(direc + '/jpg_temp.jpg', img)
plt.imsave(direc + "/jpg_temp.jpg", img)
file.close()

file = open('/home/syzygianinfern0/sambashare/' + filename + '/temp.txt', 'r')
file = open("/home/syzygianinfern0/sambashare/" + filename + "/temp.txt", "r")

string = ""
for each in file:
string += each
tem_row = list(string.strip().split('\n'))
tem_row = list(string.strip().split("\n"))
temp = []
for col in tem_row:
temp.append(list(map(float, col.strip().split('\t'))))
temp.append(list(map(float, col.strip().split("\t"))))
temp = np.array(temp)

temp = np.flipud(temp)
temp = np.fliplr(temp)

temp = temp / 255
plt.imsave(direc + '/temp.jpg', temp)
plt.imsave(direc + "/temp.jpg", temp)


def main():
camera = ThermalCamera()
camera.trigger_camera()


if __name__ == '__main__':
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions Automated Dataset/utils/trigger_pygame.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def main():
pygame.init()
pygame.font.init()
display = pygame.display.set_mode((320, 240))
pygame.display.set_caption('Thermal Cam')
pygame.display.set_caption("Thermal Cam")
pygame.mouse.set_visible(True)
wait()


if __name__ == '__main__':
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions Comms Over LAN/Archives/Video Capture Over TCP/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

context = zmq.Context()
footage_socket = context.socket(zmq.SUB)
footage_socket.bind('tcp://*:5555')
footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode(''))
footage_socket.bind("tcp://*:5555")
footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode(""))

while True:
try:
Expand Down
4 changes: 2 additions & 2 deletions Comms Over LAN/Archives/Video Capture Over TCP/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

context = zmq.Context()
footage_socket = context.socket(zmq.PUB)
footage_socket.connect('tcp://192.168.43.156:5555')
footage_socket.connect("tcp://192.168.43.156:5555")

camera = cv2.VideoCapture(2) # init the camera

while True:
try:
grabbed, frame = camera.read() # grab the current frame
frame = cv2.resize(frame, (640, 480)) # resize the frame
encoded, buffer = cv2.imencode('.jpg', frame)
encoded, buffer = cv2.imencode(".jpg", frame)
jpg_as_text = base64.b64encode(buffer)
footage_socket.send(jpg_as_text)

Expand Down
54 changes: 31 additions & 23 deletions Comms Over LAN/Archives/thermal_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def read(self, length=1024):
def read_until(self, data):
""" Read data into the buffer until we have data """
while data not in self.buff:
self.buff += self.conn.recv(1024).decode('ascii')
self.buff += self.conn.recv(1024).decode("ascii")

pos = self.buff.find(data)
rval = self.buff[:pos + len(data)]
self.buff = self.buff[pos + len(data):]
rval = self.buff[: pos + len(data)]
self.buff = self.buff[pos + len(data) :]

return rval

Expand All @@ -44,11 +44,13 @@ def close(self):

class ThermalCamera:
def __init__(self):
self.port = '22'
self.uname = 'pi'
self.passd = 'ni6ga2rd'
self.ip = '192.168.0.109'
self.pi_ssh = ParallelSSHClient(hosts=[self.ip], user=self.uname, password=self.passd)
self.port = "22"
self.uname = "pi"
self.passd = "ni6ga2rd"
self.ip = "192.168.0.109"
self.pi_ssh = ParallelSSHClient(
hosts=[self.ip], user=self.uname, password=self.passd
)
self.connect_ssh()

def connect_ssh(self):
Expand All @@ -63,7 +65,9 @@ def trigger_camera(self):
# _, _, err = self.pi_ssh.exec_command('tmux send -t two "timeout 4 ~/bin/fbuf" ENTER', get_pty=True)
# _ = self.pi_ssh.exec_command('tmux new-session -d "timeout 4 ~/bin/fbuf"')

self.pi_ssh.run_command(command='tmux new-session -d "~/test | nc 192.168.0.104 2000"')
self.pi_ssh.run_command(
command='tmux new-session -d "~/test | nc 192.168.0.104 2000"'
)

# self.revive_cam()
# err = err.readlines()
Expand All @@ -75,10 +79,10 @@ def revive_cam(self):


def stdout2arr(string):
tem_row = list(string.strip().split('\n'))
tem_row = list(string.strip().split("\n"))
temp = []
for col in tem_row:
temp.append(list(map(float, col.strip().split(' '))))
temp.append(list(map(float, col.strip().split(" "))))
temp = np.array(temp, dtype=np.float32)

# temp = np.flipud(temp)
Expand All @@ -88,42 +92,46 @@ def stdout2arr(string):


def arr2heatmap(arr):
heatmap = cv2.normalize(arr, dst=None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U)
heatmap = cv2.normalize(
arr, dst=None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U
)
heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET)
return heatmap


def read(op):
nc = Netcat('192.168.0.104', 1234)
nc = Netcat("192.168.0.104", 1234)
cam = ThermalCamera()
cam.trigger_camera()

nc.listen()
_ = nc.read_until('End')
_ = nc.read_until("End")

while True:
try:
data = nc.read_until('End')
data = data[data.find('Subpage:') + 11:-4]
data = nc.read_until("End")
data = data[data.find("Subpage:") + 11 : -4]
op = stdout2arr(data)
except Exception as e:
print(e)


def main():
nc = Netcat('192.168.0.104', 2000)
nc = Netcat("192.168.0.104", 2000)
cam = ThermalCamera()
cam.trigger_camera()

nc.listen()
_ = nc.read_until('End')
thermal = 'Thermal Feed'
_ = nc.read_until("End")
thermal = "Thermal Feed"
cv2.namedWindow(thermal, cv2.WINDOW_NORMAL)

while True:
try:
tick = time.time()

data = nc.read_until('End')
data = data[data.find('Subpage:') + 11:-4]
data = nc.read_until("End")
data = data[data.find("Subpage:") + 11 : -4]
proc = stdout2arr(data)

tock = time.time()
Expand All @@ -133,13 +141,13 @@ def main():
heatmap = arr2heatmap(vis)
cv2.imshow(thermal, heatmap)
ch = cv2.waitKey(1)
if ch == ord('q'):
if ch == ord("q"):
break
except Exception as e:
print(e)
# cam.revive_cam()


if __name__ == '__main__':
if __name__ == "__main__":
main()
cv2.destroyAllWindows()
6 changes: 3 additions & 3 deletions Comms Over LAN/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ def print_arr(arr):
def arr2heatmap(arr):

# ax = cv2.applyColorMap( (arr * cv2.getTrackbarPos("Scale", "Trackbar")/122).astype('uint8'), cv2.COLORMAP_JET)
ax = cv2.applyColorMap( (arr * 2.245).astype('uint8'), cv2.COLORMAP_JET)
ax = cv2.applyColorMap((arr * 2.245).astype("uint8"), cv2.COLORMAP_JET)

return ax


def thermal_process():
global op_thermal
nc = Netcat("192.168.0.104", 1234)
Expand All @@ -134,7 +135,7 @@ def thermal_process():
op_thermal[:] = list(np.concatenate(stdout2arr(data)))
# print(op)
except Exception as e:
#cam.revive_cam()
# cam.revive_cam()
print(e)
print("Consider restarting PI!!!!!")

Expand Down Expand Up @@ -188,4 +189,3 @@ def nothing(nil):
picam = PiCamera()

main()

Loading