From 5271ae833f6d16e6b79da3cb2895ac75c6aa194f Mon Sep 17 00:00:00 2001 From: albertqu Date: Wed, 16 May 2018 16:48:28 -0700 Subject: [PATCH 01/59] created test.md indicating pull request --- test.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 test.md diff --git a/test.md b/test.md new file mode 100644 index 0000000..e7312e6 --- /dev/null +++ b/test.md @@ -0,0 +1 @@ +**All tests here should be updated** From 7ef2ad85eee028f9dbd8e52f1785ef9be91eb73a Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 17 May 2018 10:29:07 -0700 Subject: [PATCH 02/59] added a dummy file --- __init__.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..88b97b5 --- /dev/null +++ b/__init__.py @@ -0,0 +1,2 @@ +# Test + From e3a993520190c060b2eeeb2e8ab4723a321b3ecc Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 17 May 2018 11:11:52 -0700 Subject: [PATCH 03/59] test gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 894a44c..b3af2ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# markdown +*.md + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] From 0c456a55de16ddee87de4aa5c18a48de2f98cfb4 Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 17 May 2018 11:15:55 -0700 Subject: [PATCH 04/59] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b3af2ca..64e56e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # markdown -*.md +.md # Byte-compiled / optimized / DLL files __pycache__/ From b1d865c71abdc2583c2491b1fa5c2b2c48163579 Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 17 May 2018 11:16:28 -0700 Subject: [PATCH 05/59] let's see --- why.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 why.md diff --git a/why.md b/why.md new file mode 100644 index 0000000..e69de29 From 048f43c630447ff063fcd26b88976b364ad3db6e Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 17 May 2018 11:18:18 -0700 Subject: [PATCH 06/59] finalizing .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 64e56e2..b3af2ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # markdown -.md +*.md # Byte-compiled / optimized / DLL files __pycache__/ From 6ffa542a67379583246e506fe03b668ff933a537 Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 17 May 2018 11:18:53 -0700 Subject: [PATCH 07/59] finalized .gitignore --- test.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test.md diff --git a/test.md b/test.md deleted file mode 100644 index e7312e6..0000000 --- a/test.md +++ /dev/null @@ -1 +0,0 @@ -**All tests here should be updated** From 05f68a56c27290a30f6b0ad11b2d4c536d5a25dc Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 17 May 2018 11:24:03 -0700 Subject: [PATCH 08/59] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0588e8b..8457a88 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,4 @@ This is the bridge settlement project development repository. * test: contains all the most updated customized functional tests, please issue a **pull request** before pushing to test * staging: repo to test the compatibility of all the components before moving into master * individual-dev: names are in the form of $"name-work-version"$, individuals members should make changes in their only subtask repo -* Always issue a **pull request** befor merging any branches! +* Always issue a **pull request** before merging any branches! From 9c8a46e07bebafa6709ef4a93e7b2bf3f58d71fd Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 17 May 2018 11:25:25 -0700 Subject: [PATCH 09/59] delete unnecessary markdown --- why.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 why.md diff --git a/why.md b/why.md deleted file mode 100644 index e69de29..0000000 From 34206553ed2c658af4a16d03d5f5fa8d3c35af82 Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 24 May 2018 17:30:47 -0700 Subject: [PATCH 10/59] albert_ic-first version --- .idea/inspectionProfiles/Project_Default.xml | 15 ++ .idea/vcs.xml | 6 + ImgCollector.py | 106 +++++++++++ RPiCM.py | 175 +++++++++++++++++++ 4 files changed, 302 insertions(+) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/vcs.xml create mode 100644 ImgCollector.py create mode 100644 RPiCM.py diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..280893b --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ImgCollector.py b/ImgCollector.py new file mode 100644 index 0000000..d3f2c5b --- /dev/null +++ b/ImgCollector.py @@ -0,0 +1,106 @@ +import picamera +import os + +class ImgCollector: + + def __init__(self, dir='', ns='img', form='png', raw=False, num=1): + if dir: + if not os.path.exists(dir): + os.mkdir(dir) + if dir[len(dir)-1] != '/': + dir += '/' + + self.name_scheme = dir + ns + '_{0}.' + form + self._dir = dir + self._ns = ns + self._form = form + self._raw = raw + self._num = num + self.counter = 1 + self.init_cam() + + def change_ns(self, ns): + self._ns = ns + self.name_scheme = self._dir + self._ns + '_{0}.' + self._form + + def change_format(self, form): + self._form = form + self.name_scheme = self._dir + self._ns + '_{0}.' + self._form + + def change_dir(self, dir): + self._dir = dir + self.name_scheme = self._dir + self._ns + '_{0}.' + self._form + + def change_num(self, num): + self._num = num + if self._num == 1: + self.capture = self.uni_capture + else: + self.capture = self.multi_capture + + def init_cam(self): + self.cam = picamera.PiCamera() + self.cam.led = False + self.cam.iso = 100 + if self._num == 1: + self.capture = self.uni_capture + else: + self.capture = self.multi_capture + + def shutdown(self): + self.cam.close() + + def uni_capture(self): + self.cam.capture(self.name_scheme.format(self.counter), self._raw) + self.counter += 1 + + def multi_capture(self): + file_list = [self.name_scheme.format("%d_%d" % (self.counter, i)) for i in range(1, self._num+1)] + self.cam.capture_sequence(file_list, self._raw) + self.counter += 1 + + +def main(): + directory = input("Input a directory:\n") + name_pattern = input("Input a name pattern:\n") + pic_format = input("Input a picture format:\n") + raw_image = input("Raw image?[y/n]\n") in ['y', 'yes'] + num_meas = int(input("Number of image samples for one measurement?\n")) + + while True: + try: + ic = ImgCollector(dir=directory, ns=name_pattern, form=pic_format, raw=raw_image, num=num_meas) + break + except: + directory = input("Ill-formated directory, type in another one: ") + + while True: + option = input("Type in an action or h for help:\n") + if option == 'h': + print("m: take measurement\n" + + "r: show raw image status\n" + + "cr: change raw image status\n" + + "cf: change image format\n" + + "cd: change directory\n" + + "cn: change name\n" + + "cm: change number of measurement\n") + elif option == 'm': + ic.capture() + elif option == 'r': + print(ic._raw) + elif option == 'cr': + ic._raw = input("Raw image?[y/n]\n") in ['y', 'yes'] + elif option == 'cf': + ic.change_format(input("Input a picture format:\n")) + elif option == 'cd': + ic.change_dir(input("Input a directory:\n")) + elif option == 'cn': + ic.change_ns(input("Input a name pattern:\n")) + elif option == 'cm': + ic.change_num(int(input("Number of image samples for one measurement?\n"))) + +if __name__ == "__main__": + main() + + + diff --git a/RPiCM.py b/RPiCM.py new file mode 100644 index 0000000..baf3b27 --- /dev/null +++ b/RPiCM.py @@ -0,0 +1,175 @@ +# Author: Alex R. Mead +# Date: May 2016 +# Description: +# This code will run on the Raspberry Pi 2 with Camera Module (RPiCM) to interact with the MacBookPro (MBP). It will +# wait for the MBP to request a measurement, take a measurement, then wait for the MBP to request the latest +# measurement, at which time it will send the measurement to the MBP. + +# Same as the MBP this system is designed to run like finite state machine. + +from __future__ import ( + unicode_literals, + absolute_import, + print_function, + division, + ) + +import sys +import socket +import io +import subprocess +import picamera +import numpy as np +import gc +from time import sleep + +# Constants +#IP = '127.0.0.1' # Testing on a single machine +IP = '0.0.0.0' # Actual run time. +port1 = 1234 +port2 = 2345 +marker = "?" + +MAX_PIXEL_VALUE = 1023 # 2^10 = 1024 +PIXEL_HEIGHT = 1944 +PIXEL_WIDTH = 2592 + +# Takes in the Camera object instantiated at the beginning of the run and takes the desired SS expsoures with it. +def HDRI(SS,camera): + + size = len(SS) + print("Taking %i measurements.\n",size) + names = [] + + # Loop through for each shutter speed requested + for index, shutterSpeed in enumerate(SS): + fileName = str(shutterSpeed) + ".data" + camera.shutter_speed = shutterSpeed + sleep(1) + print(str(camera.shutter_speed)) + camera.capture(fileName,format='jpeg',bayer=True) + names.append(fileName) + + # Return the list of filenames to the calling function. + return names + +def main(): + + STATE = "idle" + RUNNING = [True,0] + + # First declare the camera object and configure it as needed + camera = picamera.PiCamera() + camera.framerate=1 + sleep(1.0) + + camera.led = False + camera.iso = 100 + sleep(10.0) + # This longer sleep is needed so analog_gain and digital_gains settle so when I turn them off in the next step + # they will have settled and not be in their initial 'low' values. + + camera.exposure_mode = 'off' # Fixes analog_gain and digital_gain values + g = camera.awb_gains + camera.aws_mode = 'off' + camera.awb_gains = [1.0,1.0] # typical values 0.9-1.9 according to documentation, I picked these for consistency. + camera.rotation = 180 + sleep(2.0) + + while(RUNNING[0]): + + if("idle" == STATE): + print("We're in idle state waiting to hear from the MacBookPro...") + + # Start up a connection listening for the MBP. + sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) + sock.bind((IP,port1)) + sock.listen(1) + connection, client_address = sock.accept() + + rcv_msg = [] + while True: + data = connection.recv(1) + if marker in data: + rcv_msg.append(data[:data.find(marker)]) + break + rcv_msg.append(data) + + # Check the message received from the MBP, if correct, continue, else exit. + rpl = ''.join(rcv_msg) + if rpl == "True": + print("Now going to acknowledge measurement.") + + # elif used to teminate remotely. + elif rpl == "c": + print("Big John called it for me...") + sys.exit(0) + + # Acknowledge the MBP so it knows a measurement will be taking place. + connection.send("True?") + connection.close() + + # Change state: Continue on and take measurement + STATE ="Measuring" + + elif ("Measuring" == STATE): + print("Engaging the Camera Module to measure the output of the CFS under test...") + # Here is the function call to take the measurement of the CFS inside CUBE2.0 + + # List of the shutter speeds in microseconds to be used + #SS = [1000000, 100000, 10000, 1000, 100, 10]; + SS = [1000000, 100000, 10000]; + + # Take the measurements with the above stated shutter speeds + files = HDRI(SS,camera) + + print("...Measurement taken of CFS.\n") + + # Continue to the next state and wait for MBP to query for the 145 measurements. + STATE = "waitToSend" + + elif("waitToSend" == STATE): + print("Waiting to send to MBP...") + # Setup connection to wait for the request from the MBP + # This maybe a short wait as the MBP may be trying to connect already if the Measurememt was a long time. + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + sock.bind((IP, port2)) + sock.listen(1) + connection, client_address = sock.accept() + + rcv_msg = [] + while True: + data = connection.recv(1) + if marker in data: + rcv_msg.append(data[:data.find(marker)]) + break + rcv_msg.append(data) + + # Check the message received from the MBP, if correct, continue, else exit. + rpl = ''.join(rcv_msg) + if rpl == "True": + print("Send measurement.") + + # Now use the same connection to let the MBP know it can grab the .jpg+RAW + # files and run RPiCM_C.c locally over there, which is MUCH faster. + connection.sendall("True?") + connection.close() + + print("...measurment has been sent.\n") + + # Change state: measurement has been sent, change state back to idle + STATE = "idle" + + # Cycle counter for the finite state machine + RUNNING[1] = RUNNING[1] + 1 + print("Cycle number: " + str(RUNNING[1])) + + print("Little John called it...") + + sys.exit(0) + +if __name__ == "__main__": + main() + From 544d6fd8f9fc58fccb11543b063ce4a667a3975b Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 24 May 2018 17:45:25 -0700 Subject: [PATCH 11/59] name_change --- img_capture.py | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 img_capture.py diff --git a/img_capture.py b/img_capture.py new file mode 100644 index 0000000..b109db2 --- /dev/null +++ b/img_capture.py @@ -0,0 +1,109 @@ +import picamera +import os + +class ImgCollector: + + def __init__(self, dir='', ns='img', form='png', raw=False, num=1): + if dir: + if not os.path.exists(dir): + os.mkdir(dir) + if dir[len(dir)-1] != '/': + dir += '/' + + self.name_scheme = dir + ns + '_{0}.' + form + self._dir = dir + self._ns = ns + self._form = form + self._raw = raw + self._num = num + self.counter = 1 + self.init_cam() + + def change_ns(self, ns): + self._ns = ns + self.name_scheme = self._dir + self._ns + '_{0}.' + self._form + + def change_format(self, form): + self._form = form + self.name_scheme = self._dir + self._ns + '_{0}.' + self._form + + def change_dir(self, dir): + self._dir = dir + self.name_scheme = self._dir + self._ns + '_{0}.' + self._form + + def change_num(self, num): + self._num = num + if self._num == 1: + self.capture = self.uni_capture + else: + self.capture = self.multi_capture + + def init_cam(self): + self.cam = picamera.PiCamera() + self.cam.led = False + self.cam.iso = 100 + if self._num == 1: + self.capture = self.uni_capture + else: + self.capture = self.multi_capture + + def shutdown(self): + self.cam.close() + + def uni_capture(self): + self.cam.capture(self.name_scheme.format(self.counter), bayer=self._raw) + self.counter += 1 + + def multi_capture(self): + file_list = [self.name_scheme.format("%d_%d" % (self.counter, i)) for i in range(1, self._num+1)] + self.cam.capture_sequence(file_list, bayer=self._raw) + self.counter += 1 + + +def main(): + directory = input("Input a directory:\n") + name_pattern = input("Input a name pattern:\n") + pic_format = input("Input a picture format:\n") + raw_image = input("Raw image?[y/n]\n") in ['y', 'yes'] + num_meas = int(input("Number of image samples for one measurement?\n")) + + while True: + try: + ic = ImgCollector(dir=directory, ns=name_pattern, form=pic_format, raw=raw_image, num=num_meas) + break + except: + directory = input("Ill-formated directory, type in another one: ") + + while True: + option = input("Type in an action or h for help:\n") + if option == 'h': + print("m: take measurement\n" + + "r: show raw image status\n" + + "cr: change raw image status\n" + + "cf: change image format\n" + + "cd: change directory\n" + + "cn: change name\n" + + "cm: change number of measurement\n" + + "e: end the program") + elif option == 'm': + ic.capture() + elif option == 'r': + print(ic._raw) + elif option == 'cr': + ic._raw = input("Raw image?[y/n]\n") in ['y', 'yes'] + elif option == 'cf': + ic.change_format(input("Input a picture format:\n")) + elif option == 'cd': + ic.change_dir(input("Input a directory:\n")) + elif option == 'cn': + ic.change_ns(input("Input a name pattern:\n")) + elif option == 'cm': + ic.change_num(int(input("Number of image samples for one measurement?\n"))) + elif option == 'e': + exit(0) + +if __name__ == "__main__": + main() + + + From 46b75bc1b17efec2a48a9538a5fb069010fc8628 Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 24 May 2018 17:48:39 -0700 Subject: [PATCH 12/59] change --- ImgCollector.py | 106 ------------------------------------------------ 1 file changed, 106 deletions(-) delete mode 100644 ImgCollector.py diff --git a/ImgCollector.py b/ImgCollector.py deleted file mode 100644 index d3f2c5b..0000000 --- a/ImgCollector.py +++ /dev/null @@ -1,106 +0,0 @@ -import picamera -import os - -class ImgCollector: - - def __init__(self, dir='', ns='img', form='png', raw=False, num=1): - if dir: - if not os.path.exists(dir): - os.mkdir(dir) - if dir[len(dir)-1] != '/': - dir += '/' - - self.name_scheme = dir + ns + '_{0}.' + form - self._dir = dir - self._ns = ns - self._form = form - self._raw = raw - self._num = num - self.counter = 1 - self.init_cam() - - def change_ns(self, ns): - self._ns = ns - self.name_scheme = self._dir + self._ns + '_{0}.' + self._form - - def change_format(self, form): - self._form = form - self.name_scheme = self._dir + self._ns + '_{0}.' + self._form - - def change_dir(self, dir): - self._dir = dir - self.name_scheme = self._dir + self._ns + '_{0}.' + self._form - - def change_num(self, num): - self._num = num - if self._num == 1: - self.capture = self.uni_capture - else: - self.capture = self.multi_capture - - def init_cam(self): - self.cam = picamera.PiCamera() - self.cam.led = False - self.cam.iso = 100 - if self._num == 1: - self.capture = self.uni_capture - else: - self.capture = self.multi_capture - - def shutdown(self): - self.cam.close() - - def uni_capture(self): - self.cam.capture(self.name_scheme.format(self.counter), self._raw) - self.counter += 1 - - def multi_capture(self): - file_list = [self.name_scheme.format("%d_%d" % (self.counter, i)) for i in range(1, self._num+1)] - self.cam.capture_sequence(file_list, self._raw) - self.counter += 1 - - -def main(): - directory = input("Input a directory:\n") - name_pattern = input("Input a name pattern:\n") - pic_format = input("Input a picture format:\n") - raw_image = input("Raw image?[y/n]\n") in ['y', 'yes'] - num_meas = int(input("Number of image samples for one measurement?\n")) - - while True: - try: - ic = ImgCollector(dir=directory, ns=name_pattern, form=pic_format, raw=raw_image, num=num_meas) - break - except: - directory = input("Ill-formated directory, type in another one: ") - - while True: - option = input("Type in an action or h for help:\n") - if option == 'h': - print("m: take measurement\n" + - "r: show raw image status\n" + - "cr: change raw image status\n" + - "cf: change image format\n" + - "cd: change directory\n" + - "cn: change name\n" + - "cm: change number of measurement\n") - elif option == 'm': - ic.capture() - elif option == 'r': - print(ic._raw) - elif option == 'cr': - ic._raw = input("Raw image?[y/n]\n") in ['y', 'yes'] - elif option == 'cf': - ic.change_format(input("Input a picture format:\n")) - elif option == 'cd': - ic.change_dir(input("Input a directory:\n")) - elif option == 'cn': - ic.change_ns(input("Input a name pattern:\n")) - elif option == 'cm': - ic.change_num(int(input("Number of image samples for one measurement?\n"))) - -if __name__ == "__main__": - main() - - - From 93ca8b557c932dfdba1a1f9358ff3995d7d15e6b Mon Sep 17 00:00:00 2001 From: albertqu Date: Fri, 25 May 2018 00:02:55 -0700 Subject: [PATCH 13/59] structure-change --- RPiCM.py | 1 - img_capture.py | 1 + pi@192.168.3.3 | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 pi@192.168.3.3 diff --git a/RPiCM.py b/RPiCM.py index baf3b27..ca837ac 100644 --- a/RPiCM.py +++ b/RPiCM.py @@ -167,7 +167,6 @@ def main(): print("Cycle number: " + str(RUNNING[1])) print("Little John called it...") - sys.exit(0) if __name__ == "__main__": diff --git a/img_capture.py b/img_capture.py index b109db2..96da7e2 100644 --- a/img_capture.py +++ b/img_capture.py @@ -100,6 +100,7 @@ def main(): elif option == 'cm': ic.change_num(int(input("Number of image samples for one measurement?\n"))) elif option == 'e': + ic.shutdown() exit(0) if __name__ == "__main__": diff --git a/pi@192.168.3.3 b/pi@192.168.3.3 new file mode 100644 index 0000000..d3f2c5b --- /dev/null +++ b/pi@192.168.3.3 @@ -0,0 +1,106 @@ +import picamera +import os + +class ImgCollector: + + def __init__(self, dir='', ns='img', form='png', raw=False, num=1): + if dir: + if not os.path.exists(dir): + os.mkdir(dir) + if dir[len(dir)-1] != '/': + dir += '/' + + self.name_scheme = dir + ns + '_{0}.' + form + self._dir = dir + self._ns = ns + self._form = form + self._raw = raw + self._num = num + self.counter = 1 + self.init_cam() + + def change_ns(self, ns): + self._ns = ns + self.name_scheme = self._dir + self._ns + '_{0}.' + self._form + + def change_format(self, form): + self._form = form + self.name_scheme = self._dir + self._ns + '_{0}.' + self._form + + def change_dir(self, dir): + self._dir = dir + self.name_scheme = self._dir + self._ns + '_{0}.' + self._form + + def change_num(self, num): + self._num = num + if self._num == 1: + self.capture = self.uni_capture + else: + self.capture = self.multi_capture + + def init_cam(self): + self.cam = picamera.PiCamera() + self.cam.led = False + self.cam.iso = 100 + if self._num == 1: + self.capture = self.uni_capture + else: + self.capture = self.multi_capture + + def shutdown(self): + self.cam.close() + + def uni_capture(self): + self.cam.capture(self.name_scheme.format(self.counter), self._raw) + self.counter += 1 + + def multi_capture(self): + file_list = [self.name_scheme.format("%d_%d" % (self.counter, i)) for i in range(1, self._num+1)] + self.cam.capture_sequence(file_list, self._raw) + self.counter += 1 + + +def main(): + directory = input("Input a directory:\n") + name_pattern = input("Input a name pattern:\n") + pic_format = input("Input a picture format:\n") + raw_image = input("Raw image?[y/n]\n") in ['y', 'yes'] + num_meas = int(input("Number of image samples for one measurement?\n")) + + while True: + try: + ic = ImgCollector(dir=directory, ns=name_pattern, form=pic_format, raw=raw_image, num=num_meas) + break + except: + directory = input("Ill-formated directory, type in another one: ") + + while True: + option = input("Type in an action or h for help:\n") + if option == 'h': + print("m: take measurement\n" + + "r: show raw image status\n" + + "cr: change raw image status\n" + + "cf: change image format\n" + + "cd: change directory\n" + + "cn: change name\n" + + "cm: change number of measurement\n") + elif option == 'm': + ic.capture() + elif option == 'r': + print(ic._raw) + elif option == 'cr': + ic._raw = input("Raw image?[y/n]\n") in ['y', 'yes'] + elif option == 'cf': + ic.change_format(input("Input a picture format:\n")) + elif option == 'cd': + ic.change_dir(input("Input a directory:\n")) + elif option == 'cn': + ic.change_ns(input("Input a name pattern:\n")) + elif option == 'cm': + ic.change_num(int(input("Number of image samples for one measurement?\n"))) + +if __name__ == "__main__": + main() + + + From a1fa6c855b9da0e224ec3a599ec55ccd0e830e8e Mon Sep 17 00:00:00 2001 From: albertqu Date: Fri, 25 May 2018 09:36:25 -0700 Subject: [PATCH 14/59] Organized --- RPiCM.py => RPiCam/RPiCM.py | 0 pi@192.168.3.3 => RPiCam/img_capture.py | 10 +++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) rename RPiCM.py => RPiCam/RPiCM.py (100%) rename pi@192.168.3.3 => RPiCam/img_capture.py (92%) diff --git a/RPiCM.py b/RPiCam/RPiCM.py similarity index 100% rename from RPiCM.py rename to RPiCam/RPiCM.py diff --git a/pi@192.168.3.3 b/RPiCam/img_capture.py similarity index 92% rename from pi@192.168.3.3 rename to RPiCam/img_capture.py index d3f2c5b..96da7e2 100644 --- a/pi@192.168.3.3 +++ b/RPiCam/img_capture.py @@ -51,12 +51,12 @@ def shutdown(self): self.cam.close() def uni_capture(self): - self.cam.capture(self.name_scheme.format(self.counter), self._raw) + self.cam.capture(self.name_scheme.format(self.counter), bayer=self._raw) self.counter += 1 def multi_capture(self): file_list = [self.name_scheme.format("%d_%d" % (self.counter, i)) for i in range(1, self._num+1)] - self.cam.capture_sequence(file_list, self._raw) + self.cam.capture_sequence(file_list, bayer=self._raw) self.counter += 1 @@ -83,7 +83,8 @@ def main(): "cf: change image format\n" + "cd: change directory\n" + "cn: change name\n" + - "cm: change number of measurement\n") + "cm: change number of measurement\n" + + "e: end the program") elif option == 'm': ic.capture() elif option == 'r': @@ -98,6 +99,9 @@ def main(): ic.change_ns(input("Input a name pattern:\n")) elif option == 'cm': ic.change_num(int(input("Number of image samples for one measurement?\n"))) + elif option == 'e': + ic.shutdown() + exit(0) if __name__ == "__main__": main() From 2c1daf6fe6454d8c8a8320870632879d5803612d Mon Sep 17 00:00:00 2001 From: albertqu Date: Fri, 25 May 2018 09:37:29 -0700 Subject: [PATCH 15/59] Delete img_capture.py --- img_capture.py | 110 ------------------------------------------------- 1 file changed, 110 deletions(-) delete mode 100644 img_capture.py diff --git a/img_capture.py b/img_capture.py deleted file mode 100644 index 96da7e2..0000000 --- a/img_capture.py +++ /dev/null @@ -1,110 +0,0 @@ -import picamera -import os - -class ImgCollector: - - def __init__(self, dir='', ns='img', form='png', raw=False, num=1): - if dir: - if not os.path.exists(dir): - os.mkdir(dir) - if dir[len(dir)-1] != '/': - dir += '/' - - self.name_scheme = dir + ns + '_{0}.' + form - self._dir = dir - self._ns = ns - self._form = form - self._raw = raw - self._num = num - self.counter = 1 - self.init_cam() - - def change_ns(self, ns): - self._ns = ns - self.name_scheme = self._dir + self._ns + '_{0}.' + self._form - - def change_format(self, form): - self._form = form - self.name_scheme = self._dir + self._ns + '_{0}.' + self._form - - def change_dir(self, dir): - self._dir = dir - self.name_scheme = self._dir + self._ns + '_{0}.' + self._form - - def change_num(self, num): - self._num = num - if self._num == 1: - self.capture = self.uni_capture - else: - self.capture = self.multi_capture - - def init_cam(self): - self.cam = picamera.PiCamera() - self.cam.led = False - self.cam.iso = 100 - if self._num == 1: - self.capture = self.uni_capture - else: - self.capture = self.multi_capture - - def shutdown(self): - self.cam.close() - - def uni_capture(self): - self.cam.capture(self.name_scheme.format(self.counter), bayer=self._raw) - self.counter += 1 - - def multi_capture(self): - file_list = [self.name_scheme.format("%d_%d" % (self.counter, i)) for i in range(1, self._num+1)] - self.cam.capture_sequence(file_list, bayer=self._raw) - self.counter += 1 - - -def main(): - directory = input("Input a directory:\n") - name_pattern = input("Input a name pattern:\n") - pic_format = input("Input a picture format:\n") - raw_image = input("Raw image?[y/n]\n") in ['y', 'yes'] - num_meas = int(input("Number of image samples for one measurement?\n")) - - while True: - try: - ic = ImgCollector(dir=directory, ns=name_pattern, form=pic_format, raw=raw_image, num=num_meas) - break - except: - directory = input("Ill-formated directory, type in another one: ") - - while True: - option = input("Type in an action or h for help:\n") - if option == 'h': - print("m: take measurement\n" + - "r: show raw image status\n" + - "cr: change raw image status\n" + - "cf: change image format\n" + - "cd: change directory\n" + - "cn: change name\n" + - "cm: change number of measurement\n" + - "e: end the program") - elif option == 'm': - ic.capture() - elif option == 'r': - print(ic._raw) - elif option == 'cr': - ic._raw = input("Raw image?[y/n]\n") in ['y', 'yes'] - elif option == 'cf': - ic.change_format(input("Input a picture format:\n")) - elif option == 'cd': - ic.change_dir(input("Input a directory:\n")) - elif option == 'cn': - ic.change_ns(input("Input a name pattern:\n")) - elif option == 'cm': - ic.change_num(int(input("Number of image samples for one measurement?\n"))) - elif option == 'e': - ic.shutdown() - exit(0) - -if __name__ == "__main__": - main() - - - From 09c8c4f6069d62b2997a3ed29c4c99b72b8a4c61 Mon Sep 17 00:00:00 2001 From: albertqu Date: Fri, 25 May 2018 09:38:48 -0700 Subject: [PATCH 16/59] update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b3af2ca..88896d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +IDE file +#.idea + # markdown *.md From ecf3d5b6c3227ad240bdfe8e2b037cba2c769fbf Mon Sep 17 00:00:00 2001 From: albertqu Date: Fri, 25 May 2018 09:41:59 -0700 Subject: [PATCH 17/59] Update .gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 88896d0..e6de56d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -IDE file -#.idea +# IDE file +.idea/ # markdown *.md From d0f412b386a11b2612f87e49ac2c335162a4fb50 Mon Sep 17 00:00:00 2001 From: albertqu Date: Fri, 25 May 2018 09:44:27 -0700 Subject: [PATCH 18/59] delete .idea and changed .gitignore --- .idea/inspectionProfiles/Project_Default.xml | 15 --------------- .idea/vcs.xml | 6 ------ 2 files changed, 21 deletions(-) delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 280893b..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 9b6c854111dfa74de0aea41df9a46052aaeaa7e3 Mon Sep 17 00:00:00 2001 From: albertqu Date: Tue, 29 May 2018 11:04:04 -0700 Subject: [PATCH 19/59] changes --- RPiCam/img_capture.py | 35 +- img_rec_module/__init__.py | 0 img_rec_module/centers.txt | 640 +++++++++++++++++++++++++++++++++++++ img_rec_module/flags.txt | 274 ++++++++++++++++ img_rec_module/img_rec.py | 93 ++++++ 5 files changed, 1035 insertions(+), 7 deletions(-) create mode 100644 img_rec_module/__init__.py create mode 100644 img_rec_module/centers.txt create mode 100644 img_rec_module/flags.txt create mode 100644 img_rec_module/img_rec.py diff --git a/RPiCam/img_capture.py b/RPiCam/img_capture.py index 96da7e2..4f77313 100644 --- a/RPiCam/img_capture.py +++ b/RPiCam/img_capture.py @@ -1,5 +1,8 @@ import picamera import os +import time + +recur = True class ImgCollector: @@ -40,8 +43,10 @@ def change_num(self, num): def init_cam(self): self.cam = picamera.PiCamera() + time.sleep(2) self.cam.led = False self.cam.iso = 100 + time.sleep(3) if self._num == 1: self.capture = self.uni_capture else: @@ -61,11 +66,22 @@ def multi_capture(self): def main(): - directory = input("Input a directory:\n") - name_pattern = input("Input a name pattern:\n") - pic_format = input("Input a picture format:\n") - raw_image = input("Raw image?[y/n]\n") in ['y', 'yes'] - num_meas = int(input("Number of image samples for one measurement?\n")) + prompt = input("Welcome to the RPiCam Module. Type q for quick test or f / [other inputs] for full test.\n") + global recur + if prompt == 'q': + directory = 'quick_test' + name_pattern = 'img' + pic_format = 'png' + raw_image = False + num_meas = 1 + recur = True + else: + directory = input("Input a directory:\n") + name_pattern = input("Input a name pattern:\n") + pic_format = input("Input a picture format:\n") + raw_image = input("Raw image?[y/n]\n") in ['y', 'yes'] + num_meas = int(input("Number of image samples for one measurement?\n")) + recur = False while True: try: @@ -75,6 +91,10 @@ def main(): directory = input("Ill-formated directory, type in another one: ") while True: + if recur: + ic.shutdown() + break + option = input("Type in an action or h for help:\n") if option == 'h': print("m: take measurement\n" + @@ -101,10 +121,11 @@ def main(): ic.change_num(int(input("Number of image samples for one measurement?\n"))) elif option == 'e': ic.shutdown() - exit(0) + break if __name__ == "__main__": - main() + while recur: + main() diff --git a/img_rec_module/__init__.py b/img_rec_module/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/img_rec_module/centers.txt b/img_rec_module/centers.txt new file mode 100644 index 0000000..ea1e64b --- /dev/null +++ b/img_rec_module/centers.txt @@ -0,0 +1,640 @@ +135.5 +134.5 +134.0 +127.5 +131.0 +131.0 +133.5 +131.0 +131.5 +131.5 +129.5 +135.5 +135.5 +126.5 +134.0 +131.5 +132.5 +128.5 +131.5 +134.5 +130.5 +1.0 +132.5 +129.5 +70.5 +131.5 +132.5 +132.0 +132.5 +129.5 +135.5 +129.5 +132.5 +130.5 +131.5 +134.0 +72.0 +67.5 +130.5 +135.0 +132.0 +133.5 +130.5 +129.5 +129.5 +132.0 +130.5 +134.0 +129.5 +136.0 +129.5 +127.5 +133.5 +131.0 +134.0 +131.5 +128.5 +132.0 +132.5 +136.0 +132.0 +133.5 +132.0 +132.5 +132.0 +129.0 +138.5 +133.5 +134.0 +132.5 +132.5 +134.0 +134.5 +131.5 +133.0 +135.5 +132.0 +130.5 +130.5 +128.0 +130.0 +133.0 +132.0 +136.0 +135.5 +132.5 +135.5 +130.5 +136.5 +136.5 +129.5 +129.0 +130.0 +138.5 +135.0 +127.5 +126.5 +135.5 +135.5 +130.5 +127.5 +131.5 +136.5 +134.5 +136.5 +133.5 +133.0 +131.5 +130.0 +136.5 +135.5 +135.0 +134.0 +133.0 +131.5 +130.5 +132.5 +135.5 +133.5 +129.5 +133.0 +136.5 +129.0 +135.5 +133.5 +133.5 +134.0 +129.5 +133.5 +132.0 +134.5 +137.0 +130.5 +129.5 +130.5 +131.5 +133.5 +137.5 +134.5 +130.5 +131.0 +134.0 +137.5 +132.5 +128.0 +129.0 +132.0 +136.5 +129.5 +128.0 +127.5 +128.0 +135.0 +128.5 +129.0 +135.0 +137.5 +136.0 +131.5 +131.0 +130.0 +134.0 +135.5 +133.0 +134.5 +134.0 +133.0 +132.0 +135.0 +132.0 +135.5 +132.5 +130.5 +127.5 +131.5 +131.0 +134.0 +131.0 +129.0 +130.0 +129.0 +129.5 +133.0 +132.0 +127.5 +131.5 +135.0 +134.0 +133.0 +133.0 +130.0 +130.5 +127.5 +133.0 +135.0 +134.0 +135.5 +131.5 +129.5 +128.5 +138.5 +134.0 +132.0 +135.5 +132.0 +128.0 +127.5 +134.5 +130.0 +130.5 +131.0 +129.5 +125.5 +130.0 +130.5 +134.5 +137.5 +129.5 +132.5 +134.0 +131.5 +134.0 +128.5 +131.5 +134.0 +133.5 +134.0 +133.0 +132.5 +130.5 +126.5 +128.5 +130.0 +128.0 +131.5 +131.0 +129.5 +132.5 +131.0 +129.5 +127.5 +135.0 +126.5 +141.5 +132.5 +133.0 +136.0 +131.0 +129.0 +134.5 +130.5 +127.5 +133.0 +133.5 +131.5 +135.5 +134.0 +131.0 +133.5 +133.5 +133.5 +127.5 +132.0 +132.5 +134.5 +132.0 +132.0 +128.0 +132.0 +136.0 +136.0 +132.5 +134.5 +137.0 +131.0 +131.5 +137.0 +130.5 +128.0 +133.0 +129.5 +135.0 +140.0 +130.5 +134.5 +129.0 +136.0 +128.0 +133.5 +136.5 +135.0 +127.5 +131.5 +139.5 +131.5 +128.5 +136.0 +135.0 +131.5 +131.5 +133.5 +127.5 +135.5 +135.5 +128.0 +130.0 +127.5 +128.0 +130.0 +126.5 +142.5 +134.5 +134.5 +124.5 +126.5 +129.5 +131.0 +129.5 +131.5 +127.0 +127.5 +135.0 +134.5 +131.5 +126.0 +130.5 +132.0 +138.0 +131.5 +135.5 +125.0 +133.0 +127.5 +136.5 +131.5 +131.5 +131.0 +124.0 +128.5 +137.5 +133.5 +130.0 +131.0 +129.0 +133.0 +131.0 +125.5 +129.5 +132.0 +129.5 +137.5 +128.5 +130.0 +131.0 +134.5 +130.0 +131.5 +131.5 +136.5 +134.0 +132.0 +136.0 +126.5 +128.0 +133.5 +135.5 +129.0 +133.0 +131.5 +132.0 +129.5 +126.0 +126.0 +130.5 +135.0 +129.0 +131.0 +130.5 +131.5 +135.5 +133.5 +134.0 +131.5 +126.0 +130.0 +131.0 +131.5 +130.5 +133.5 +130.0 +125.0 +126.5 +133.5 +132.0 +129.5 +133.5 +130.5 +132.5 +136.0 +135.0 +130.0 +129.5 +134.0 +135.5 +131.5 +135.5 +135.5 +131.5 +130.0 +130.0 +131.5 +132.0 +129.5 +131.5 +127.5 +136.0 +131.0 +134.5 +135.0 +126.5 +128.0 +131.5 +131.5 +127.0 +130.0 +130.5 +136.5 +130.5 +129.0 +130.0 +130.5 +135.5 +125.5 +130.5 +130.0 +127.5 +132.5 +133.5 +130.0 +127.5 +126.0 +132.0 +127.0 +126.0 +130.5 +127.5 +127.5 +129.5 +131.5 +133.0 +129.5 +127.0 +129.0 +126.5 +130.5 +130.0 +126.5 +128.5 +126.5 +126.5 +127.5 +134.0 +136.5 +129.5 +130.0 +128.5 +130.0 +127.5 +130.5 +135.0 +137.5 +130.0 +129.5 +134.5 +130.5 +127.5 +132.5 +129.0 +132.5 +130.0 +133.5 +127.5 +129.5 +129.0 +124.5 +126.5 +126.0 +128.0 +130.0 +133.0 +129.5 +131.0 +128.5 +132.5 +129.5 +199.5 +133.5 +133.5 +130.0 +127.5 +114.0 +227.5 +113.5 +134.5 +129.5 +130.0 +128.5 +130.0 +132.5 +126.5 +127.5 +129.0 +135.5 +129.5 +126.5 +127.5 +132.5 +127.0 +131.0 +124.5 +132.5 +128.0 +129.5 +135.5 +131.5 +129.0 +131.5 +132.0 +131.5 +130.5 +130.5 +136.5 +135.5 +131.5 +129.0 +130.5 +130.0 +129.0 +130.5 +128.0 +126.5 +133.5 +131.0 +129.0 +128.0 +131.5 +132.5 +128.5 +134.5 +130.0 +127.5 +130.0 +129.5 +131.5 +127.5 +131.0 +129.0 +127.5 +135.5 +128.0 +127.0 +131.0 +131.0 +129.5 +126.0 +128.5 +128.5 +131.0 +126.0 +132.5 +128.0 +130.0 +133.0 +127.5 +128.5 +131.5 +135.5 +133.0 +133.0 +131.0 +132.0 +128.0 +132.0 +130.0 +132.5 +128.5 +127.5 +130.5 +130.0 +131.5 +128.5 +126.5 +132.0 +126.5 +129.5 +128.0 +127.0 +126.5 +133.5 +128.5 +135.5 +133.5 +132.5 +132.0 +132.5 +131.5 +131.0 +131.0 +129.5 +130.5 +127.0 +127.5 +125.0 +129.5 +130.5 +130.5 +132.5 +128.0 +129.5 +126.5 +125.5 +125.0 +131.5 +130.0 +131.5 +128.5 +127.0 +134.0 +129.0 +132.5 +130.0 +129.5 +129.0 +129.0 +126.5 +127.5 +128.0 +125.5 +131.0 +129.5 diff --git a/img_rec_module/flags.txt b/img_rec_module/flags.txt new file mode 100644 index 0000000..b15d479 --- /dev/null +++ b/img_rec_module/flags.txt @@ -0,0 +1,274 @@ +COLOR_BAYER_BG2BGR +COLOR_BAYER_BG2BGRA +COLOR_BAYER_BG2BGR_EA +COLOR_BAYER_BG2BGR_VNG +COLOR_BAYER_BG2GRAY +COLOR_BAYER_BG2RGB +COLOR_BAYER_BG2RGBA +COLOR_BAYER_BG2RGB_EA +COLOR_BAYER_BG2RGB_VNG +COLOR_BAYER_GB2BGR +COLOR_BAYER_GB2BGRA +COLOR_BAYER_GB2BGR_EA +COLOR_BAYER_GB2BGR_VNG +COLOR_BAYER_GB2GRAY +COLOR_BAYER_GB2RGB +COLOR_BAYER_GB2RGBA +COLOR_BAYER_GB2RGB_EA +COLOR_BAYER_GB2RGB_VNG +COLOR_BAYER_GR2BGR +COLOR_BAYER_GR2BGRA +COLOR_BAYER_GR2BGR_EA +COLOR_BAYER_GR2BGR_VNG +COLOR_BAYER_GR2GRAY +COLOR_BAYER_GR2RGB +COLOR_BAYER_GR2RGBA +COLOR_BAYER_GR2RGB_EA +COLOR_BAYER_GR2RGB_VNG +COLOR_BAYER_RG2BGR +COLOR_BAYER_RG2BGRA +COLOR_BAYER_RG2BGR_EA +COLOR_BAYER_RG2BGR_VNG +COLOR_BAYER_RG2GRAY +COLOR_BAYER_RG2RGB +COLOR_BAYER_RG2RGBA +COLOR_BAYER_RG2RGB_EA +COLOR_BAYER_RG2RGB_VNG +COLOR_BGR2BGR555 +COLOR_BGR2BGR565 +COLOR_BGR2BGRA +COLOR_BGR2GRAY +COLOR_BGR2HLS +COLOR_BGR2HLS_FULL +COLOR_BGR2HSV +COLOR_BGR2HSV_FULL +COLOR_BGR2LAB +COLOR_BGR2LUV +COLOR_BGR2Lab +COLOR_BGR2Luv +COLOR_BGR2RGB +COLOR_BGR2RGBA +COLOR_BGR2XYZ +COLOR_BGR2YCR_CB +COLOR_BGR2YCrCb +COLOR_BGR2YUV +COLOR_BGR2YUV_I420 +COLOR_BGR2YUV_IYUV +COLOR_BGR2YUV_YV12 +COLOR_BGR5552BGR +COLOR_BGR5552BGRA +COLOR_BGR5552GRAY +COLOR_BGR5552RGB +COLOR_BGR5552RGBA +COLOR_BGR5652BGR +COLOR_BGR5652BGRA +COLOR_BGR5652GRAY +COLOR_BGR5652RGB +COLOR_BGR5652RGBA +COLOR_BGRA2BGR +COLOR_BGRA2BGR555 +COLOR_BGRA2BGR565 +COLOR_BGRA2GRAY +COLOR_BGRA2RGB +COLOR_BGRA2RGBA +COLOR_BGRA2YUV_I420 +COLOR_BGRA2YUV_IYUV +COLOR_BGRA2YUV_YV12 +COLOR_BayerBG2BGR +COLOR_BayerBG2BGRA +COLOR_BayerBG2BGR_EA +COLOR_BayerBG2BGR_VNG +COLOR_BayerBG2GRAY +COLOR_BayerBG2RGB +COLOR_BayerBG2RGBA +COLOR_BayerBG2RGB_EA +COLOR_BayerBG2RGB_VNG +COLOR_BayerGB2BGR +COLOR_BayerGB2BGRA +COLOR_BayerGB2BGR_EA +COLOR_BayerGB2BGR_VNG +COLOR_BayerGB2GRAY +COLOR_BayerGB2RGB +COLOR_BayerGB2RGBA +COLOR_BayerGB2RGB_EA +COLOR_BayerGB2RGB_VNG +COLOR_BayerGR2BGR +COLOR_BayerGR2BGRA +COLOR_BayerGR2BGR_EA +COLOR_BayerGR2BGR_VNG +COLOR_BayerGR2GRAY +COLOR_BayerGR2RGB +COLOR_BayerGR2RGBA +COLOR_BayerGR2RGB_EA +COLOR_BayerGR2RGB_VNG +COLOR_BayerRG2BGR +COLOR_BayerRG2BGRA +COLOR_BayerRG2BGR_EA +COLOR_BayerRG2BGR_VNG +COLOR_BayerRG2GRAY +COLOR_BayerRG2RGB +COLOR_BayerRG2RGBA +COLOR_BayerRG2RGB_EA +COLOR_BayerRG2RGB_VNG +COLOR_COLORCVT_MAX +COLOR_GRAY2BGR +COLOR_GRAY2BGR555 +COLOR_GRAY2BGR565 +COLOR_GRAY2BGRA +COLOR_GRAY2RGB +COLOR_GRAY2RGBA +COLOR_HLS2BGR +COLOR_HLS2BGR_FULL +COLOR_HLS2RGB +COLOR_HLS2RGB_FULL +COLOR_HSV2BGR +COLOR_HSV2BGR_FULL +COLOR_HSV2RGB +COLOR_HSV2RGB_FULL +COLOR_LAB2BGR +COLOR_LAB2LBGR +COLOR_LAB2LRGB +COLOR_LAB2RGB +COLOR_LBGR2LAB +COLOR_LBGR2LUV +COLOR_LBGR2Lab +COLOR_LBGR2Luv +COLOR_LRGB2LAB +COLOR_LRGB2LUV +COLOR_LRGB2Lab +COLOR_LRGB2Luv +COLOR_LUV2BGR +COLOR_LUV2LBGR +COLOR_LUV2LRGB +COLOR_LUV2RGB +COLOR_Lab2BGR +COLOR_Lab2LBGR +COLOR_Lab2LRGB +COLOR_Lab2RGB +COLOR_Luv2BGR +COLOR_Luv2LBGR +COLOR_Luv2LRGB +COLOR_Luv2RGB +COLOR_M_RGBA2RGBA +COLOR_RGB2BGR +COLOR_RGB2BGR555 +COLOR_RGB2BGR565 +COLOR_RGB2BGRA +COLOR_RGB2GRAY +COLOR_RGB2HLS +COLOR_RGB2HLS_FULL +COLOR_RGB2HSV +COLOR_RGB2HSV_FULL +COLOR_RGB2LAB +COLOR_RGB2LUV +COLOR_RGB2Lab +COLOR_RGB2Luv +COLOR_RGB2RGBA +COLOR_RGB2XYZ +COLOR_RGB2YCR_CB +COLOR_RGB2YCrCb +COLOR_RGB2YUV +COLOR_RGB2YUV_I420 +COLOR_RGB2YUV_IYUV +COLOR_RGB2YUV_YV12 +COLOR_RGBA2BGR +COLOR_RGBA2BGR555 +COLOR_RGBA2BGR565 +COLOR_RGBA2BGRA +COLOR_RGBA2GRAY +COLOR_RGBA2M_RGBA +COLOR_RGBA2RGB +COLOR_RGBA2YUV_I420 +COLOR_RGBA2YUV_IYUV +COLOR_RGBA2YUV_YV12 +COLOR_RGBA2mRGBA +COLOR_XYZ2BGR +COLOR_XYZ2RGB +COLOR_YCR_CB2BGR +COLOR_YCR_CB2RGB +COLOR_YCrCb2BGR +COLOR_YCrCb2RGB +COLOR_YUV2BGR +COLOR_YUV2BGRA_I420 +COLOR_YUV2BGRA_IYUV +COLOR_YUV2BGRA_NV12 +COLOR_YUV2BGRA_NV21 +COLOR_YUV2BGRA_UYNV +COLOR_YUV2BGRA_UYVY +COLOR_YUV2BGRA_Y422 +COLOR_YUV2BGRA_YUNV +COLOR_YUV2BGRA_YUY2 +COLOR_YUV2BGRA_YUYV +COLOR_YUV2BGRA_YV12 +COLOR_YUV2BGRA_YVYU +COLOR_YUV2BGR_I420 +COLOR_YUV2BGR_IYUV +COLOR_YUV2BGR_NV12 +COLOR_YUV2BGR_NV21 +COLOR_YUV2BGR_UYNV +COLOR_YUV2BGR_UYVY +COLOR_YUV2BGR_Y422 +COLOR_YUV2BGR_YUNV +COLOR_YUV2BGR_YUY2 +COLOR_YUV2BGR_YUYV +COLOR_YUV2BGR_YV12 +COLOR_YUV2BGR_YVYU +COLOR_YUV2GRAY_420 +COLOR_YUV2GRAY_I420 +COLOR_YUV2GRAY_IYUV +COLOR_YUV2GRAY_NV12 +COLOR_YUV2GRAY_NV21 +COLOR_YUV2GRAY_UYNV +COLOR_YUV2GRAY_UYVY +COLOR_YUV2GRAY_Y422 +COLOR_YUV2GRAY_YUNV +COLOR_YUV2GRAY_YUY2 +COLOR_YUV2GRAY_YUYV +COLOR_YUV2GRAY_YV12 +COLOR_YUV2GRAY_YVYU +COLOR_YUV2RGB +COLOR_YUV2RGBA_I420 +COLOR_YUV2RGBA_IYUV +COLOR_YUV2RGBA_NV12 +COLOR_YUV2RGBA_NV21 +COLOR_YUV2RGBA_UYNV +COLOR_YUV2RGBA_UYVY +COLOR_YUV2RGBA_Y422 +COLOR_YUV2RGBA_YUNV +COLOR_YUV2RGBA_YUY2 +COLOR_YUV2RGBA_YUYV +COLOR_YUV2RGBA_YV12 +COLOR_YUV2RGBA_YVYU +COLOR_YUV2RGB_I420 +COLOR_YUV2RGB_IYUV +COLOR_YUV2RGB_NV12 +COLOR_YUV2RGB_NV21 +COLOR_YUV2RGB_UYNV +COLOR_YUV2RGB_UYVY +COLOR_YUV2RGB_Y422 +COLOR_YUV2RGB_YUNV +COLOR_YUV2RGB_YUY2 +COLOR_YUV2RGB_YUYV +COLOR_YUV2RGB_YV12 +COLOR_YUV2RGB_YVYU +COLOR_YUV420P2BGR +COLOR_YUV420P2BGRA +COLOR_YUV420P2GRAY +COLOR_YUV420P2RGB +COLOR_YUV420P2RGBA +COLOR_YUV420SP2BGR +COLOR_YUV420SP2BGRA +COLOR_YUV420SP2GRAY +COLOR_YUV420SP2RGB +COLOR_YUV420SP2RGBA +COLOR_YUV420p2BGR +COLOR_YUV420p2BGRA +COLOR_YUV420p2GRAY +COLOR_YUV420p2RGB +COLOR_YUV420p2RGBA +COLOR_YUV420sp2BGR +COLOR_YUV420sp2BGRA +COLOR_YUV420sp2GRAY +COLOR_YUV420sp2RGB +COLOR_YUV420sp2RGBA +COLOR_mRGBA2RGBA diff --git a/img_rec_module/img_rec.py b/img_rec_module/img_rec.py new file mode 100644 index 0000000..3d2894c --- /dev/null +++ b/img_rec_module/img_rec.py @@ -0,0 +1,93 @@ +import cv2 +import numpy as np +import matplotlib.pyplot as plt +import os + +img = cv2.imread("../testpic/png_1_1.png") +print(img.shape) +img[:, :, 0] = 0 +img[:,:, 1] = 0 +cv2.imshow('all', img) +gs = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) +cv2.imshow('gray', gs) + + +def visualize_data(folder, sample, orient, func): + dirs = os.listdir(folder) + for i, f in enumerate(dirs): + img = cv2.imread(f) + interval = int(img.shape[1 if orient == 'h' else 0] / sample) + for j in range(sample): + data = grad_detect(img, j, orient, func) + plt_save_data(data, '../dataplot/data_' + orient + f) + + +def max_entry(img): + max = 0 + for row in img: + temp = max(row) + if temp > max: + max = temp + + +def record_file(vals, fname): + f = open(fname, 'w') + for v in vals: + f.write(str(v) + '\n') + f.close() + + +def rel_lumin(img, r, c): + b = img.item(r, c, 0) + g = img.item(r, c, 1) + r = img.item(r, c, 2) + return 0.2126 * r + 0.7152 * g + 0.0722 * b + + +def grad_detect(img, n, ori, func): + img = np.array(img) + if ori == 'h': + grad = [func(img, n, i+1) - func(img, n, i) for i in range(img.shape[1]-1)] + else: + grad = [func(img, i+1, n) - func(img, i, n) for i in range(img.shape[0]-1)] + return grad + +def max_method(img): + index = [] + s = 0 + for i in range(img.shape[1]): + val = np.argmax(img[:, i]) + index.append(val) + s +=val + return s / len(index) + +def plot_show_data(data): + plt.figure() + plt.plot(data, 'b-') + plt.show() + plt.close() + +def plt_save_data(data, fname): + plt.figure() + plt.plot(data, 'b-') + plt.savefig(fname) + plt.close() + +"""print(sum(centers) / len(centers)) +print(max_method(gs)) +record_file(centers, 'centers.txt') + +while True: + prompt = input("type in an index to draw or q to quit") + if prompt == 'q': + break + else: + plot_i(int(prompt)) + +centers = [] +for i in range(gs.shape[1]): + grad = grad_detect(gs, i, 'v', rel_lumin) + max_v = max(range(len(grad)), key=lambda i: grad[i]) + min_v = min(range(len(grad)), key=lambda i: grad[i]) + centers.append((max_v + min_v) / 2)""" + From 8aa58c9e23dd24ed8ad21d4b075dd7a144c1d29c Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 7 Jun 2018 11:05:36 -0700 Subject: [PATCH 20/59] img_rec --- img_rec_module/img_filter.py | 23 ++++ img_rec_module/img_rec.py | 145 +++++++++++++++------- img_rec_module/sig_proc.py | 229 +++++++++++++++++++++++++++++++++++ testpic/gray.txt | 0 testpic/gray_large.txt | 0 testpic/rel_lumin.txt | 0 testpic/rel_lumin_large.txt | 0 7 files changed, 353 insertions(+), 44 deletions(-) create mode 100644 img_rec_module/img_filter.py create mode 100644 img_rec_module/sig_proc.py create mode 100644 testpic/gray.txt create mode 100644 testpic/gray_large.txt create mode 100644 testpic/rel_lumin.txt create mode 100644 testpic/rel_lumin_large.txt diff --git a/img_rec_module/img_filter.py b/img_rec_module/img_filter.py new file mode 100644 index 0000000..3b8b0dc --- /dev/null +++ b/img_rec_module/img_filter.py @@ -0,0 +1,23 @@ +import cv2 +import numpy as np +from matplotlib import pyplot as plt + +img = cv2.imread('../testpic/img_20_1.png',0) +blur = cv2.GaussianBlur(img,(5,5),0) +cv2.imshow("ok", blur) +img = blur + +laplacian = cv2.Laplacian(img,cv2.CV_64F) +sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) +sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) + +plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray') +plt.title('Original'), plt.xticks([]), plt.yticks([]) +plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray') +plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) +plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray') +plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) +plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray') +plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) + +plt.show() \ No newline at end of file diff --git a/img_rec_module/img_rec.py b/img_rec_module/img_rec.py index 3d2894c..ecda821 100644 --- a/img_rec_module/img_rec.py +++ b/img_rec_module/img_rec.py @@ -3,31 +3,51 @@ import matplotlib.pyplot as plt import os -img = cv2.imread("../testpic/png_1_1.png") -print(img.shape) -img[:, :, 0] = 0 -img[:,:, 1] = 0 -cv2.imshow('all', img) -gs = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) -cv2.imshow('gray', gs) +def identity(img): + return img -def visualize_data(folder, sample, orient, func): + +def grayscale(img): + return cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + + +def grad_detect(img, n, ori, func): + #img = np.array(img) + if ori == 'h': + grad = [func(img, n, i+1) - func(img, n, i) for i in range(img.shape[1]-1)] + else: + grad = [func(img, i+1, n) - func(img, i, n) for i in range(img.shape[0]-1)] + return grad + + +def abs_detect(img, n, ori, func): + if ori == 'h': + return [func(img, n, i) for i in range(img.shape[1])] + else: + return [func(img, i, n) for i in range(img.shape[0])] + + +def visualize_data(folder, oname, sample, orient, func, data_p=grad_detect, img_p=identity): dirs = os.listdir(folder) - for i, f in enumerate(dirs): - img = cv2.imread(f) - interval = int(img.shape[1 if orient == 'h' else 0] / sample) - for j in range(sample): - data = grad_detect(img, j, orient, func) - plt_save_data(data, '../dataplot/data_' + orient + f) + for f in dirs: + try: + img = img_p(cv2.imread(folder + f)) + interval = int(img.shape[1 if orient == 'v' else 0] / sample) + for j in range(sample): + n = j * interval + data = data_p(img, n, orient, func) + plt_save_data(data, oname + 'data_{0}{1}_'.format(orient, n) + f) + except: + print(f) def max_entry(img): - max = 0 + max_e = 0 for row in img: temp = max(row) - if temp > max: - max = temp + if temp > max_e: + max_e = temp def record_file(vals, fname): @@ -44,50 +64,87 @@ def rel_lumin(img, r, c): return 0.2126 * r + 0.7152 * g + 0.0722 * b -def grad_detect(img, n, ori, func): - img = np.array(img) - if ori == 'h': - grad = [func(img, n, i+1) - func(img, n, i) for i in range(img.shape[1]-1)] - else: - grad = [func(img, i+1, n) - func(img, i, n) for i in range(img.shape[0]-1)] - return grad - def max_method(img): index = [] s = 0 for i in range(img.shape[1]): val = np.argmax(img[:, i]) index.append(val) - s +=val + s += val return s / len(index) + def plot_show_data(data): - plt.figure() + plt.figure(figsize=(16, 8)) + #plt.xticks(range(0, img.shape[0], 20), range(0, img.shape[0], 20)) plt.plot(data, 'b-') plt.show() plt.close() + def plt_save_data(data, fname): - plt.figure() + plt.figure(figsize=(16, 8)) plt.plot(data, 'b-') plt.savefig(fname) plt.close() -"""print(sum(centers) / len(centers)) -print(max_method(gs)) -record_file(centers, 'centers.txt') -while True: - prompt = input("type in an index to draw or q to quit") - if prompt == 'q': - break - else: - plot_i(int(prompt)) - -centers = [] -for i in range(gs.shape[1]): - grad = grad_detect(gs, i, 'v', rel_lumin) - max_v = max(range(len(grad)), key=lambda i: grad[i]) - min_v = min(range(len(grad)), key=lambda i: grad[i]) - centers.append((max_v + min_v) / 2)""" +def centroid(img, func): + r = img.shape[0] + c = img.shape[1] + aggr_i = 0 + aggr_j = 0 + aggr = 0 + for i in range(r): + for j in range(c): + lum = func(img, i, j) + aggr_i += lum * i + aggr_j += lum * j + aggr += lum + dim = r * c + return aggr_i / aggr, aggr_j / aggr + # return aggr_i / dim, aggr_j / dim + + +def centroid_test(fname, n, trials, func, img_p=identity): + for i in range(1, n+1): + for j in range(1, trials+1): + cf = fname.format(i, j) + print(cf) + im = img_p(cv2.imread(cf)) + print(centroid(im, func)) + +gray_p = lambda img, r, c: img.item(r, c) + +if __name__ == '__main__': + centroid_test("../testpic/img_{0}_{1}.png", 25, 3, gray_p, img_p=grayscale) + # centroid_test("../testpic/img_{0}_{1}.png", 25, 3, rel_lumin) + + """img = cv2.imread("../testpic/png_1_1.png") + plot_show_data(abs_detect(img, 0, 'v', rel_lumin))""" + + """img = cv2.imread("../testpic/png_1_1.png") + print(img.shape) + cv2.imshow('all', img) + gs = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + cv2.imshow('gray', gs) + print(sum(centers) / len(centers)) + print(max_method(gs)) + record_file(centers, 'centers.txt') + + while True: + prompt = input("type in an index to draw or q to quit") + if prompt == 'q': + break + else: + plot_i(int(prompt)) + + centers = [] + for i in range(gs.shape[1]): + grad = grad_detect(gs, i, 'v', rel_lumin) + max_v = max(range(len(grad)), key=lambda i: grad[i]) + min_v = min(range(len(grad)), key=lambda i: grad[i]) + centers.append((max_v + min_v) / 2)""" + + #visualize_data("../testpic/", "../absdataplot/", 10, 'h', rel_lumin, data_p=abs_detect) diff --git a/img_rec_module/sig_proc.py b/img_rec_module/sig_proc.py new file mode 100644 index 0000000..d1e93db --- /dev/null +++ b/img_rec_module/sig_proc.py @@ -0,0 +1,229 @@ +import cv2 +import numpy as np +import matplotlib.pyplot as plt +from img_rec_module import img_rec +from random import randint +import os + + +def gauss_data_matrix(data): + return np.array([[1, x ** 2, x, 1] for x in data]) + +"""if ori == 'h': + x = np.array(range(img.shape[1])) + y = np.array([img_rec.rel_lumin(img, p, c) for c in x]) +else: + x = np.array(range(img.shape[0])) + y = np.array([img_rec.rel_lumin(img, r, p) for r in x])""" + +def data_matrix(input_data, degree): + # degree is the degree of the polynomial you plan to fit the data with + Data = np.zeros((len(input_data), degree + 1)) + + for k in range(0, degree + 1): + Data[:, k] = (list(map(lambda x: x ** k, input_data))) + + return Data + + +def leastSquares(D, y): + return np.linalg.lstsq(D, y, rcond=None)[0] + + +def poly_curve(params, x_input): + # params contains the coefficients that multiply the polynomial terms, in degree of lowest degree to highest degree + degree = len(params) - 1 + x_range = [x_input[1], x_input[-1]] + x = np.linspace(x_range[0], x_range[1], 1000) + y = x * 0 + + for k in range(0, degree + 1): + coeff = params[k] + y = y + list(map(lambda z: coeff * z ** k, x)) + return x, y + + +def poly_error(params, D_a, y_a): + '''degree=len(params)-1 + y=x_a*0 + + for k in range(0,degree+1): + coeff=params[k] + y=y+list(map(lambda z:coeff*z**k,x_a))''' + y = np.dot(D_a, params) + return np.linalg.norm(y - y_a) ** 2 + + +def MSE(y, y_hat, N): + return np.linalg.norm(y - y_hat) ** 2 / N + + +def improvedCost(x, y, x_test, y_test, start, end): + """Given a set of x and y points training points, + this function calculates polynomial approximations of varying + degrees from start to end. Then it returns the cost, with + the polynomial tested on test points of each degree in an array""" + c = [] + for degree in range(start, end): + # YOUR CODE HERE + D = data_matrix(x, degree) + p = leastSquares(D, y) + D_t = data_matrix(x_test, degree) + y_hat = np.dot(D_t, p) + c.append(MSE(y_test, y_hat, len(x_test))) + return c + + +def OMP(imDims, sparsity, measurements, A): + r = measurements.copy() + indices = [] + + # Threshold to check error. If error is below this value, stop. + THRESHOLD = 0.1 + + # For iterating to recover all signal + i = 0 + + while i < sparsity and np.linalg.norm(r) > THRESHOLD: + # Calculate the correlations + print('%d - ' % i, end="", flush=True) + corrs = A.T.dot(r) + + # Choose highest-correlated pixel location and add to collection + # COMPLETE THE LINE BELOW + best_index = np.argmax(np.abs(corrs)) + indices.append(best_index) + + # Build the matrix made up of selected indices so far + # COMPLETE THE LINE BELOW + Atrunc = A[:, indices] + + # Find orthogonal projection of measurements to subspace + # spanned by recovered codewords + b = measurements + # COMPLETE THE LINE BELOW + xhat = np.linalg.lstsq(Atrunc, b)[0] + + # Find component orthogonal to subspace to use for next measurement + # COMPLETE THE LINE BELOW + r = b - Atrunc.dot(xhat) + + # This is for viewing the recovery process + if i % 10 == 0 or i == sparsity - 1 or np.linalg.norm(r) <= THRESHOLD: + recovered_signal = np.zeros(numPixels) + for j, x in zip(indices, xhat): + recovered_signal[j] = x + Ihat = recovered_signal.reshape(imDims) + plt.title('estimated image') + plt.imshow(Ihat, cmap=plt.cm.gray, interpolation='nearest') + display.clear_output(wait=True) + display.display(plt.gcf()) + + i = i + 1 + + display.clear_output(wait=True) + + # Fill in the recovered signal + recovered_signal = np.zeros(numPixels) + for i, x in zip(indices, xhat): + recovered_signal[i] = x + + return recovered_signal + + +def gauss_reg(x, y): + skip_x = np.array([x[i] for i in range(len(y)) if y[i] != 0]) + y_prime = np.array([y[i] for i in range(len(y)) if y[i] != 0]) + logy = np.log(y_prime) + + sol = leastSquares(gauss_data_matrix(skip_x), logy) + alp, bet, gam, lam = sol + a = np.e ** alp + a *= 10 + c_s = - 1 / (2 * bet) + b = gam * c_s + return a, b, c_s + + +def gauss_mat(shape, a, b1, c_s1, b2, c_s2): + mat = np.zeros(shape) + for r in range(mat.shape[0]): + for c in range(mat.shape[1]): + mat[r, c] = gauss_2d(c, r, a, b1, c_s1, b2, c_s2) + + return mat + + +def gauss_2d(x, y, a, b1, c_s1, b2, c_s2): + return a * np.e ** (- ((x - b1) ** 2 / (2 * c_s1) + (y - b2) ** 2) / (2 * c_s2)) + +def gauss_hat(x, a, b, c_s): + return a * np.e ** (- (x - b) ** 2 / (2 * c_s)) + +img = cv2.imread("../testpic/img_20_1.png") +cv2.imshow("true", img) + + +img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + +dimc = img.shape[1] +dimr = img.shape[0] + +x = np.array(range(dimc)) +#y = np.array([img_rec.rel_lumin(img, 0, c) for c in x]) +y = np.array([img.item(dimr // 2, c) for c in x]) +a1, b1, c_s1 = gauss_reg(x, y) + +x2 = np.array(range(dimr)) +y2 = np.array([img.item(r, dimc // 2) for r in x2]) +a2, b2, c_s2 = gauss_reg(x2, y2) +rem_gauss = gauss_mat(img.shape, (a1+a2) / 2, b1, c_s1, b2, c_s2) +img = img - rem_gauss +cv2.imshow("denoise", img) + +blur = cv2.GaussianBlur(img,(5,5),0) +cv2.imshow("ok", blur) +img = blur + +kernel = np.array([[-1, -1, -1], + [-1, 8, -1], + [-1, -1, -1]]) +kerneled = cv2.filter2D(img, -1, kernel) +cv2.imshow("kerneled", kerneled) + + + +laplacian = cv2.Laplacian(img,cv2.CV_64F) +sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) +sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) +plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray') +plt.title('Original'), plt.xticks([]), plt.yticks([]) +plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray') +plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) +plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray') +plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) +plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray') +plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) +plt.show() + +y_s_x = np.array([sobelx.item(dimr // 2, c) for c in x]) +y_s_y = np.array([sobely.item(r, dimc // 2) for r in x2]) +plt.figure(figsize=(16, 8)) +plt.subplot(211) +plt.plot(y_s_x, 'b-') +plt.ylabel("sobel_x") +plt.subplot(212) +plt.plot(y_s_y, 'b-') +plt.ylabel("sobel_y") +plt.show() +plt.close() + + +y_hat = gauss_hat(x, a1, b1, c_s1) +plt.figure(figsize=(16, 8)) +plt.plot(x, y, 'b-', x, y_hat, 'r-') +plt.show() +plt.close() +plt.figure(figsize=(16,8)) +plt.plot(x, y-y_hat, 'b-') +plt.show() \ No newline at end of file diff --git a/testpic/gray.txt b/testpic/gray.txt new file mode 100644 index 0000000..e69de29 diff --git a/testpic/gray_large.txt b/testpic/gray_large.txt new file mode 100644 index 0000000..e69de29 diff --git a/testpic/rel_lumin.txt b/testpic/rel_lumin.txt new file mode 100644 index 0000000..e69de29 diff --git a/testpic/rel_lumin_large.txt b/testpic/rel_lumin_large.txt new file mode 100644 index 0000000..e69de29 From 610570ce7e9cab727b38cd0c569394b3c14ae52a Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 7 Jun 2018 11:13:22 -0700 Subject: [PATCH 21/59] conflicts resolved --- .DS_Store | Bin 0 -> 12292 bytes absdataplot/.DS_Store | Bin 0 -> 81924 bytes check/.DS_Store | Bin 0 -> 6148 bytes testpic/gray.txt | 150 ++++++++++++++++++++++++++++++++++++ testpic/gray_large.txt | 150 ++++++++++++++++++++++++++++++++++++ testpic/rel_lumin.txt | 150 ++++++++++++++++++++++++++++++++++++ testpic/rel_lumin_large.txt | 150 ++++++++++++++++++++++++++++++++++++ 7 files changed, 600 insertions(+) create mode 100644 .DS_Store create mode 100644 absdataplot/.DS_Store create mode 100644 check/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e1cbb8830762f4f012fe4d07deb30076fe8131e9 GIT binary patch literal 12292 zcmeHNYiu0V6+UNUC$sk09-BCJoLyzZ7Gl5z8^<^<4XhstF^*-|-o$onvdr#`ovCMM z%+9PGCk-;tf)G_z3bd4}ptd|p`=hOZ{%K1a;0L7wsjAfnE$xq@KK`^-5taI+=iZs! z%#O2`T2N(~xzgNo-!t>geSGJf0RZgFD;)r>03guCq$C1VQ~|`QDdP#Oo?UCg7Airy zcF{#?3BU#!7C;A+Qb7n12oTuF2!!b2*!r!YO8|w|u4nz~)?$BJH`4&2SJMl+X4&oS zuVZLSMdj9QLb$40tceaC9U2x#Cbf)djB97qlvHP(GM5G^JDO7$HFaqsW9s>=VWp({ zjI3w!x@@bxy3QI?S)G;1nYun|TAHny#?+*(p0*1El~hfhu*{s@&j(9MQr=R>R2oZL zR0n888mfWaZDfHBV;xs>7Rh*`-N8Qmwc4iLA85V$+U^ha9$u}J>KiWEE{Z2KMKx?~ zR#S7wmNdmaH6>da)lf8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G(&o5G zV!1QNMH0)M)p$qhXP)T^gWjh=4RkY4#9_)T9*IMAVZ}YVmCV0?#}AdXE|G|~T1gs- zsKdQOA*Nsk6G=oJ)~-k*>X5r9_R@|AGnhzX>fpE*6H$kiB9MX^Oe7I?aQw;DwBx}H zCXj*|Oe7I?a9kv@+*yqaq+kYnawqM0FoTICrp{`-BYAsxuIFxhTg{X6|2=m0f7Bjl>~XQ&DxZ|E?eTG0E0^u_@LpZ7cCAiIJICB-zwZD2_@ez} z77zy7V*ObK#0jj=XWHH8e&hA;sF>z?6OGZHUO4ihlm||U?uO0$ZFJ6DgXo^$Xn5mO zqC4OXS5L5m5Up6PFKjoo2Tw$|WX`pjSSrr@N6;%Tx4ef=L^tq;=$!c*(OqeG%Co0L zH|gFdwd7?M(Y@00&Yj?${2ATB+IxMoaqr<1YNvU@-g3M~jP%GU(M^9Be(=aj#01p+ z^ojGQMA!4Yx-(k$y)p6cefm{)^1EYzM=B4|{bslE4tqeq$_Cz0DNZNEJk;Ox3#gW)hcg?j+>`QiuqT8De-c>Y2=ADg9=hTcn&Fbg=U>i$VUPc^$A8;vi#;ybW8Qu}`Rz8NaaSyLiUO=-?&xTwh|(2QL}bZ(5E&pFjM2%ZJZ* z51tKH1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Thu, 7 Jun 2018 11:36:56 -0700 Subject: [PATCH 22/59] Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 064e8ff..fdedbdb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ dataplot/ *.bmp *.gif +# OS +.DS_Store + # IDE file .idea/ From c9b0901d3275e7e08835510be12fa9f0bdc374ef Mon Sep 17 00:00:00 2001 From: albertqu Date: Thu, 7 Jun 2018 11:39:44 -0700 Subject: [PATCH 23/59] clean up repo --- .DS_Store | Bin 12292 -> 0 bytes absdataplot/.DS_Store | Bin 81924 -> 0 bytes check/.DS_Store | Bin 6148 -> 0 bytes 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store delete mode 100644 absdataplot/.DS_Store delete mode 100644 check/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index e1cbb8830762f4f012fe4d07deb30076fe8131e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12292 zcmeHNYiu0V6+UNUC$sk09-BCJoLyzZ7Gl5z8^<^<4XhstF^*-|-o$onvdr#`ovCMM z%+9PGCk-;tf)G_z3bd4}ptd|p`=hOZ{%K1a;0L7wsjAfnE$xq@KK`^-5taI+=iZs! z%#O2`T2N(~xzgNo-!t>geSGJf0RZgFD;)r>03guCq$C1VQ~|`QDdP#Oo?UCg7Airy zcF{#?3BU#!7C;A+Qb7n12oTuF2!!b2*!r!YO8|w|u4nz~)?$BJH`4&2SJMl+X4&oS zuVZLSMdj9QLb$40tceaC9U2x#Cbf)djB97qlvHP(GM5G^JDO7$HFaqsW9s>=VWp({ zjI3w!x@@bxy3QI?S)G;1nYun|TAHny#?+*(p0*1El~hfhu*{s@&j(9MQr=R>R2oZL zR0n888mfWaZDfHBV;xs>7Rh*`-N8Qmwc4iLA85V$+U^ha9$u}J>KiWEE{Z2KMKx?~ zR#S7wmNdmaH6>da)lf8JZemfhw6v}!4LPeyZ-&FGbg&Wk(Rf&TPMA^X0f$Y6-ALgz(LK?`*SMA3V)_6u8fLFi-3`2fo@1o zx$hcLOwMbDB3bMasHAhh7(J%TX;qh$u)vEB^oY@kMdyvBA-C}04PtaMV`j7ThE_ec zQ89a_Xn*vOAiXS{WcNNQTlUC;YS8Ulns?UGQw<8j6sze~6jc%84tN0Z1Unlja5%ye z(o~7UhFM0z+><%d>5XFSK!C+D|i$B2!Dltz`x+%@D2)Ci_I9rEAT38 z!>jQ+?8Y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HH8e&hA;sF>z?6OGZHUO4ihlm||U?uO0$ZFJ6DgXo^$Xn5mO zqC4OXS5L5m5Up6PFKjoo2Tw$|WX`pjSSrr@N6;%Tx4ef=L^tq;=$!c*(OqeG%Co0L zH|gFdwd7?M(Y@00&Yj?${2ATB+IxMoaqr<1YNvU@-g3M~jP%GU(M^9Be(=aj#01p+ z^ojGQMA!4Yx-(k$y)p6cefm{)^1EYzM=B4|{bslE4tqeq$_Cz0DNZNEJk;Ox3#gW)hcg?j+>`QiuqT8De-c>Y2=ADg9=hTcn&Fbg=U>i$VUPc^$A8;vi#;ybW8Qu}`Rz8NaaSyLiUO=-?&xTwh|(2QL}bZ(5E&pFjM2%ZJZ* z51tKH1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Fri, 8 Jun 2018 15:40:20 -0700 Subject: [PATCH 24/59] steady sockets --- img_rec_module/img_rec.py | 4 +- socket_module/pi@192.168.3.3 | 55 +++++++++++++++++++++++ socket_module/rpi_socket.py | 70 ++++++++++++++++++++++++++++++ socket_module/server_socket.py | 79 ++++++++++++++++++++++++++++++++++ 4 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 socket_module/pi@192.168.3.3 create mode 100644 socket_module/rpi_socket.py create mode 100644 socket_module/server_socket.py diff --git a/img_rec_module/img_rec.py b/img_rec_module/img_rec.py index ecda821..e1d95c0 100644 --- a/img_rec_module/img_rec.py +++ b/img_rec_module/img_rec.py @@ -117,7 +117,7 @@ def centroid_test(fname, n, trials, func, img_p=identity): gray_p = lambda img, r, c: img.item(r, c) if __name__ == '__main__': - centroid_test("../testpic/img_{0}_{1}.png", 25, 3, gray_p, img_p=grayscale) + #centroid_test("../testpic/img_{0}_{1}.png", 25, 3, gray_p, img_p=grayscale) # centroid_test("../testpic/img_{0}_{1}.png", 25, 3, rel_lumin) """img = cv2.imread("../testpic/png_1_1.png") @@ -146,5 +146,5 @@ def centroid_test(fname, n, trials, func, img_p=identity): min_v = min(range(len(grad)), key=lambda i: grad[i]) centers.append((max_v + min_v) / 2)""" - #visualize_data("../testpic/", "../absdataplot/", 10, 'h', rel_lumin, data_p=abs_detect) + visualize_data("../testpic/", "../absdataplot/", 10, 'h', rel_lumin, data_p=abs_detect) diff --git a/socket_module/pi@192.168.3.3 b/socket_module/pi@192.168.3.3 new file mode 100644 index 0000000..edf29e0 --- /dev/null +++ b/socket_module/pi@192.168.3.3 @@ -0,0 +1,55 @@ +import socket + + +class SteadySocket: + MAXMSGLEN = 4096 + EOFChar = '!' + + def __init__(self, sockt=None): + if sockt is None: + self.sock = socket.socket() + else: + self.sock = sockt + + def connect(self, host, port): + return self.sock.connect((host, port)) + + def send(self, data, flags=0): + data_sent = 0 + tot_len = len(data) + while data_sent < data: + sent = self.sock.send(data[data_sent:]) + if sent == 0: + raise RuntimeError("Connection interrupted...") + data_sent += sent + + def recv(self): + data_recv = "" + bytes_recv = 0 + while bytes_recv < self.MAXMSGLEN: + msg = str(self.sock.recv(self.MAXMSGLEN - bytes_recv)) + if len(msg) == 0: + return msg + if msg.find(self.EOFChar) != -1: + return msg + data_recv += msg + bytes_recv += len(msg) + return data_recv + + def close(self): + self.sock.close() + + +IP = '192.168.3.4' +port = 8000 + +rpisock = SteadySocket() +while True: + try: + rpisock.connect(IP, port) + msg = input("type a message\n") + rpisock.send(bytes(msg)) + data = rpisock.recv() + print(data) + except: + pass diff --git a/socket_module/rpi_socket.py b/socket_module/rpi_socket.py new file mode 100644 index 0000000..66d350a --- /dev/null +++ b/socket_module/rpi_socket.py @@ -0,0 +1,70 @@ +import socket + + +class SteadySocket: + + MAXMSGLEN = 128 + EOFChar = b'!' + + def __init__(self, sockt=None): + if sockt is None: + self.sock = socket.socket() + else: + self.sock = sockt + + def connect(self, host, port): + self.sock.connect((host, port)) + + def send(self, data, flags=0): + data_sent = 0 + tot_len = len(data) + while data_sent < tot_len: + try: + sent = self.sock.send(data[data_sent:]) + assert sent != 0 + data_sent += sent + except: + raise RuntimeError("Connection Lost!") + + def recv(self): + data_recv = [] + bytes_recv = 0 + count = 0 + while bytes_recv < self.MAXMSGLEN: + msg = self.sock.recv(self.MAXMSGLEN - bytes_recv) + end = msg.find(self.EOFChar) + if end != -1: + data_recv.append(msg[:end]) + break + data_recv.append(msg) + bytes_recv += len(msg) + print(count) + return b''.join(data_recv) + + def close(self): + self.sock.close() + + + +IP = '192.168.3.4' +port = 8000 + +rpisock = SteadySocket() +connected = False +while True: + if not connected: + try: + rpisock.connect(IP, port) + connected = True + msg = input("type a message\n") + rpisock.send(bytes(msg, 'utf-8')) + data = rpisock.recv() + print(data) + except: + pass + else: + print("already connected") + msg = input("type a message\n") + rpisock.send(bytes(msg, 'utf-8')) + data = rpisock.recv() + print(data) diff --git a/socket_module/server_socket.py b/socket_module/server_socket.py new file mode 100644 index 0000000..32e9370 --- /dev/null +++ b/socket_module/server_socket.py @@ -0,0 +1,79 @@ +import socket +import time + + +class SteadySocket: + + MAXMSGLEN = 128 + EOFChar = b'!' + + def __init__(self, sockt=None): + if sockt is None: + self.sock = socket.socket() + else: + self.sock = sockt + + def connect(self, host, port): + self.sock.connect((host, port)) + + def send(self, data, flags=0): + data_sent = 0 + tot_len = len(data) + while data_sent < tot_len: + try: + sent = self.sock.send(data[data_sent:]) + assert sent != 0 + data_sent += sent + except: + raise RuntimeError("Connection Lost!") + + def recv(self): + data_recv = [] + bytes_recv = 0 + count = 0 + while bytes_recv < self.MAXMSGLEN: + msg = self.sock.recv(self.MAXMSGLEN - bytes_recv) + end = msg.find(self.EOFChar) + if end != -1: + data_recv.append(msg[:end]) + break + data_recv.append(msg) + bytes_recv += len(msg) + print(count) + return b''.join(data_recv) + + def close(self): + self.sock.close() + + +ssock = socket.socket() +IP = "192.168.3.4" +port = 8000 +ssock.bind((IP, port)) +print("Now connected to " + IP + ":" + str(port)) +ssock.listen(1) + +conn = None +addr = None +sconn = None +while True: + if conn is None: + conn, addr = ssock.accept() + sconn = SteadySocket(conn) + print(addr) + else: + data = sconn.recv() + if data: + print(data) + if data == b"hi": + sconn.send(b"how are you!") + elif data == b'c': + sconn.close() + break + else: + sconn.send(b"It's good huh?!") + inp = input("value?\n") + if inp == 'e': + sconn.close() + break + From a9ecf95672251b4e52cfe5e5c2fbf554308d522c Mon Sep 17 00:00:00 2001 From: albertqu Date: Mon, 11 Jun 2018 23:22:29 -0700 Subject: [PATCH 25/59] updates --- img_rec_module/sig_proc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/img_rec_module/sig_proc.py b/img_rec_module/sig_proc.py index d1e93db..ab161e5 100644 --- a/img_rec_module/sig_proc.py +++ b/img_rec_module/sig_proc.py @@ -178,7 +178,7 @@ def gauss_hat(x, a, b, c_s): y2 = np.array([img.item(r, dimc // 2) for r in x2]) a2, b2, c_s2 = gauss_reg(x2, y2) rem_gauss = gauss_mat(img.shape, (a1+a2) / 2, b1, c_s1, b2, c_s2) -img = img - rem_gauss +#img = img - rem_gauss cv2.imshow("denoise", img) blur = cv2.GaussianBlur(img,(5,5),0) From 2ad05296c21fb678d215ea0df0d0889ab1211137 Mon Sep 17 00:00:00 2001 From: albertqu Date: Mon, 11 Jun 2018 23:23:43 -0700 Subject: [PATCH 26/59] changes --- test.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 test.sh diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..2af3756 --- /dev/null +++ b/test.sh @@ -0,0 +1,11 @@ +#!/bin/bash +for ip in 192.168.0.{0..255} + do + k=`ping -c 1 $ip | grep 'icmp'` + if [ "$k" > 5 ] + then echo $ip + fi + done + + + From 46c963ceeacd2e51db862358f1e5c8b9b7eba79c Mon Sep 17 00:00:00 2001 From: albertqu Date: Mon, 11 Jun 2018 23:24:35 -0700 Subject: [PATCH 27/59] ip-check shell script --- ip_test.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 ip_test.sh diff --git a/ip_test.sh b/ip_test.sh new file mode 100755 index 0000000..2af3756 --- /dev/null +++ b/ip_test.sh @@ -0,0 +1,11 @@ +#!/bin/bash +for ip in 192.168.0.{0..255} + do + k=`ping -c 1 $ip | grep 'icmp'` + if [ "$k" > 5 ] + then echo $ip + fi + done + + + From 9253db17249ec44f555c157539a014a27ab2ae1c Mon Sep 17 00:00:00 2001 From: albertqu Date: Tue, 12 Jun 2018 09:01:12 -0700 Subject: [PATCH 28/59] shell script --- ip_connected.txt | 1 + ip_test.sh | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 ip_connected.txt diff --git a/ip_connected.txt b/ip_connected.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ip_connected.txt @@ -0,0 +1 @@ + diff --git a/ip_test.sh b/ip_test.sh index 2af3756..36581dd 100755 --- a/ip_test.sh +++ b/ip_test.sh @@ -1,9 +1,12 @@ -#!/bin/bash +#!/bin/bash +touch ip_connected.txt for ip in 192.168.0.{0..255} do k=`ping -c 1 $ip | grep 'icmp'` if [ "$k" > 5 ] - then echo $ip + then + echo $ip + echo $ip >> ip_connected.txt fi done From 301f17c3caf5efcc8e80d6f3c95f4ff49c87443f Mon Sep 17 00:00:00 2001 From: albertqu Date: Tue, 12 Jun 2018 09:19:58 -0700 Subject: [PATCH 29/59] expedite the algorithm --- ip_connected.txt | 6 ++++++ ip_test.sh | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ip_connected.txt b/ip_connected.txt index 8b13789..b42cb27 100644 --- a/ip_connected.txt +++ b/ip_connected.txt @@ -1 +1,7 @@ +192.168.0.0 +192.168.0.1 +192.168.0.2 +192.168.0.3 +192.168.0.1 +192.168.0.13 diff --git a/ip_test.sh b/ip_test.sh index 36581dd..543faff 100755 --- a/ip_test.sh +++ b/ip_test.sh @@ -1,9 +1,10 @@ #!/bin/bash touch ip_connected.txt -for ip in 192.168.0.{0..255} +for ip in 192.168.0.{0..15} do - k=`ping -c 1 $ip | grep 'icmp'` - if [ "$k" > 5 ] + s=`ping -c 1 $ip | grep 'icmp'` + check=`expr "$s" : '64 bytes'` + if [ "$check" -ge 5 ] then echo $ip echo $ip >> ip_connected.txt From a10530e9f4128867f3b62a1e31ff9f5c1b2f9bb0 Mon Sep 17 00:00:00 2001 From: albertqu Date: Tue, 12 Jun 2018 10:16:10 -0700 Subject: [PATCH 30/59] yes --- ip_connected.txt | 3 +++ ip_test.sh | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ip_connected.txt b/ip_connected.txt index b42cb27..90edc97 100644 --- a/ip_connected.txt +++ b/ip_connected.txt @@ -5,3 +5,6 @@ 192.168.0.3 192.168.0.1 192.168.0.13 +10.142.172.115 +10.142.172.116 +10.142.172.118 diff --git a/ip_test.sh b/ip_test.sh index 543faff..c90402d 100755 --- a/ip_test.sh +++ b/ip_test.sh @@ -1,6 +1,6 @@ #!/bin/bash touch ip_connected.txt -for ip in 192.168.0.{0..15} +for ip in 192.168.3.{0..15} do s=`ping -c 1 $ip | grep 'icmp'` check=`expr "$s" : '64 bytes'` From 9441ac9f169b43eaaef2a54e0bcdb99525ea166c Mon Sep 17 00:00:00 2001 From: albertqu Date: Tue, 12 Jun 2018 15:55:05 -0700 Subject: [PATCH 31/59] project setup --- calbridgesensors/calbridgesensors/__init__.py | 0 calbridgesensors/calbridgesensors/settings.py | 120 ++++++++++++++++++ calbridgesensors/calbridgesensors/urls.py | 21 +++ calbridgesensors/calbridgesensors/wsgi.py | 16 +++ calbridgesensors/manage.py | 15 +++ 5 files changed, 172 insertions(+) create mode 100644 calbridgesensors/calbridgesensors/__init__.py create mode 100644 calbridgesensors/calbridgesensors/settings.py create mode 100644 calbridgesensors/calbridgesensors/urls.py create mode 100644 calbridgesensors/calbridgesensors/wsgi.py create mode 100755 calbridgesensors/manage.py diff --git a/calbridgesensors/calbridgesensors/__init__.py b/calbridgesensors/calbridgesensors/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/calbridgesensors/calbridgesensors/settings.py b/calbridgesensors/calbridgesensors/settings.py new file mode 100644 index 0000000..1ea489c --- /dev/null +++ b/calbridgesensors/calbridgesensors/settings.py @@ -0,0 +1,120 @@ +""" +Django settings for calbridgesensors project. + +Generated by 'django-admin startproject' using Django 2.0.3. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '&vuf$!t_6n7_z^0pfj-gdmk2k^8(^4%thu&&i-a)5=na_klw!!' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'calbridgesensors.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'calbridgesensors.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/calbridgesensors/calbridgesensors/urls.py b/calbridgesensors/calbridgesensors/urls.py new file mode 100644 index 0000000..a36e4b2 --- /dev/null +++ b/calbridgesensors/calbridgesensors/urls.py @@ -0,0 +1,21 @@ +"""calbridgesensors URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/calbridgesensors/calbridgesensors/wsgi.py b/calbridgesensors/calbridgesensors/wsgi.py new file mode 100644 index 0000000..cca3138 --- /dev/null +++ b/calbridgesensors/calbridgesensors/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for calbridgesensors project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "calbridgesensors.settings") + +application = get_wsgi_application() diff --git a/calbridgesensors/manage.py b/calbridgesensors/manage.py new file mode 100755 index 0000000..12bb361 --- /dev/null +++ b/calbridgesensors/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "calbridgesensors.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) From e2da9f67117cf329fac3a841193025702088218c Mon Sep 17 00:00:00 2001 From: albertqu Date: Tue, 19 Jun 2018 13:28:43 -0700 Subject: [PATCH 32/59] sensor units --- calbridgesensors/calbridgesensors/settings.py | 3 +- calbridgesensors/calbridgesensors/urls.py | 2 +- calbridgesensors/sensors/__init__.py | 0 calbridgesensors/sensors/admin.py | 3 + calbridgesensors/sensors/apps.py | 5 + .../sensors/migrations/__init__.py | 0 calbridgesensors/sensors/models.py | 41 +++ calbridgesensors/sensors/tests.py | 3 + calbridgesensors/sensors/urls.py | 4 + calbridgesensors/sensors/views.py | 14 + calbridgesensors/templates/base.html | 22 ++ img_rec_module/img_1_1_meas.txt | 24 ++ img_rec_module/img_20_1_meas.txt | 24 ++ img_rec_module/img_20_2_meas.txt | 18 ++ img_rec_module/img_20_3_meas.txt | 43 +++ img_rec_module/sig_proc.py | 274 ++++++++++++++---- 16 files changed, 419 insertions(+), 61 deletions(-) create mode 100644 calbridgesensors/sensors/__init__.py create mode 100644 calbridgesensors/sensors/admin.py create mode 100644 calbridgesensors/sensors/apps.py create mode 100644 calbridgesensors/sensors/migrations/__init__.py create mode 100644 calbridgesensors/sensors/models.py create mode 100644 calbridgesensors/sensors/tests.py create mode 100644 calbridgesensors/sensors/urls.py create mode 100644 calbridgesensors/sensors/views.py create mode 100644 calbridgesensors/templates/base.html create mode 100644 img_rec_module/img_1_1_meas.txt create mode 100644 img_rec_module/img_20_1_meas.txt create mode 100644 img_rec_module/img_20_2_meas.txt create mode 100644 img_rec_module/img_20_3_meas.txt diff --git a/calbridgesensors/calbridgesensors/settings.py b/calbridgesensors/calbridgesensors/settings.py index 1ea489c..7c1a4a0 100644 --- a/calbridgesensors/calbridgesensors/settings.py +++ b/calbridgesensors/calbridgesensors/settings.py @@ -37,6 +37,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + "sensors.apps.SensorsCofig" ] MIDDLEWARE = [ @@ -54,7 +55,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [os.path.join(BASE_DIR, "templates")], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/calbridgesensors/calbridgesensors/urls.py b/calbridgesensors/calbridgesensors/urls.py index a36e4b2..77743d3 100644 --- a/calbridgesensors/calbridgesensors/urls.py +++ b/calbridgesensors/calbridgesensors/urls.py @@ -14,7 +14,7 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, re_path urlpatterns = [ path('admin/', admin.site.urls), diff --git a/calbridgesensors/sensors/__init__.py b/calbridgesensors/sensors/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/calbridgesensors/sensors/admin.py b/calbridgesensors/sensors/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/calbridgesensors/sensors/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/calbridgesensors/sensors/apps.py b/calbridgesensors/sensors/apps.py new file mode 100644 index 0000000..d796eea --- /dev/null +++ b/calbridgesensors/sensors/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class SensorsConfig(AppConfig): + name = 'sensors' diff --git a/calbridgesensors/sensors/migrations/__init__.py b/calbridgesensors/sensors/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/calbridgesensors/sensors/models.py b/calbridgesensors/sensors/models.py new file mode 100644 index 0000000..bf625f8 --- /dev/null +++ b/calbridgesensors/sensors/models.py @@ -0,0 +1,41 @@ +from django.db import models + + + +class Bridge(models.Model): + + name = models.CharField(max_length=40, primary_key=True) + reading = models.OneToOneField(Reading, on_delete=models.PROTECT, help_text="latest sensor reading of the bridge", blank=True, null=True) + anomaly = models.BooleanField(default=False) + broken_times = models.ForeignKey(BridgeLog, on_delete=models.PROTECT) + + class Meta: + ordering = ["name"] + + +class Reading(models.Model): + x = models.DecimalField(max_digits=4, decimal_places=2) + y = models.DecimalField(max_digits=4, decimal_places=2) + z = models.DecimalField(max_digits=4, decimal_places=2) + theta = models.DecimalField(max_digits=4, decimal_places=2) + phi = models.DecimalField(max_digits=4, decimal_places=2) + psi = models.DecimalField(max_digits=4, decimal_places=2) + bridge = models.ForeignKey(Bridge, on_delete=models.CASCADE, unique_for_date="time_taken") + time_taken = models.DateTimeField(auto_now_add=True) + + class Meta: + verbose_name = "Bridge sensor reading" + + +class BridgeLog(models.Model): + DAMAGE = "D" + REPAIR = "R" + LOG_TYPES = ((DAMAGE, "Damage Record"), + (REPAIR, "Repair Record")) + log_type = models.CharField(max_length=1, choices=LOG_TYPES) + log_time = models.DateTimeField(auto_now_add=True, primary_key=True) + bridge = models.ForeignKey(Bridge, on_delete=models.CASCADE, unique_for_date="log_time") + + +class BrokenRecord(models.Model): + bridge = models.OneToOneField(Bridge, on_delete=models.SET_NULL, to_field="name") \ No newline at end of file diff --git a/calbridgesensors/sensors/tests.py b/calbridgesensors/sensors/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/calbridgesensors/sensors/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/calbridgesensors/sensors/urls.py b/calbridgesensors/sensors/urls.py new file mode 100644 index 0000000..7c77335 --- /dev/null +++ b/calbridgesensors/sensors/urls.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from django.urls import path, re_path + +urlpatterns = [] \ No newline at end of file diff --git a/calbridgesensors/sensors/views.py b/calbridgesensors/sensors/views.py new file mode 100644 index 0000000..fe8ede5 --- /dev/null +++ b/calbridgesensors/sensors/views.py @@ -0,0 +1,14 @@ +from django.shortcuts import render +from django.views.generic import TemplateView + + +"""View for home page""" +def home(request): + + # Check broken bridges + return render(request, "home.html", context={}) + + +class BridgeView(TemplateView): + + template_name = "bridge.html" \ No newline at end of file diff --git a/calbridgesensors/templates/base.html b/calbridgesensors/templates/base.html new file mode 100644 index 0000000..c1610a5 --- /dev/null +++ b/calbridgesensors/templates/base.html @@ -0,0 +1,22 @@ + + + + + Cal Bridge Sensors + + + + {% block alert %} +
+
+ {% endblock %} + + {% block content %} + {% endblock %} + + \ No newline at end of file diff --git a/img_rec_module/img_1_1_meas.txt b/img_rec_module/img_1_1_meas.txt new file mode 100644 index 0000000..97ed4c5 --- /dev/null +++ b/img_rec_module/img_1_1_meas.txt @@ -0,0 +1,24 @@ +ksize:(5, 5), sigmax:0 +x: zero_crossing: -1, edge_converge: 384.9492753623189; +y: zero_crossing: 128.7986577181208, edge_converge: 124.79086538461539 +ksize:(7, 7), sigmax:0 +x: zero_crossing: -1, edge_converge: 385.07291666666663; +y: zero_crossing: 129.5, edge_converge: 125.5 +ksize:(9, 9), sigmax:0 +x: zero_crossing: 383.90625, edge_converge: 379.9741379310345; +y: zero_crossing: 129.52727272727273, edge_converge: 130.70366132723112 +ksize:(11, 11), sigmax:0 +x: zero_crossing: -1, edge_converge: 379.9741379310345; +y: zero_crossing: 129.6, edge_converge: 130.70366132723112 +ksize:(13, 13), sigmax:0 +x: zero_crossing: -1, edge_converge: 379.9741379310345; +y: zero_crossing: 129.68627450980392, edge_converge: 130.70366132723112 +ksize:(15, 15), sigmax:0 +x: zero_crossing: 383.6551724137931, edge_converge: 379.9741379310345; +y: zero_crossing: 129.55172413793105, edge_converge: 130.70366132723112 +ksize:(17, 17), sigmax:0 +x: zero_crossing: 383.55172413793105, edge_converge: 379.9741379310345; +y: zero_crossing: 129.5, edge_converge: 130.70366132723112 +ksize:(19, 19), sigmax:0 +x: zero_crossing: 383.90625, edge_converge: 379.9741379310345; +y: zero_crossing: 129.5, edge_converge: 130.70366132723112 diff --git a/img_rec_module/img_20_1_meas.txt b/img_rec_module/img_20_1_meas.txt new file mode 100644 index 0000000..8f3d333 --- /dev/null +++ b/img_rec_module/img_20_1_meas.txt @@ -0,0 +1,24 @@ +ksize:(5, 5), sigmax:0 +x: zero_crossing: 225.33333333333334, edge_converge: 222.40969899665552; +y: zero_crossing: 222.44086021505376, edge_converge: 232.5 +ksize:(7, 7), sigmax:0 +x: zero_crossing: 224.90625, edge_converge: 212.425; +y: zero_crossing: 222.7012987012987, edge_converge: 244.8653846153846 +ksize:(9, 9), sigmax:0 +x: zero_crossing: 224.55172413793105, edge_converge: 225.7096153846154; +y: zero_crossing: 222.8507462686567, edge_converge: 233.3653846153846 +ksize:(11, 11), sigmax:0 +x: zero_crossing: 224.86363636363637, edge_converge: 207.6159420289855; +y: zero_crossing: 223.22413793103448, edge_converge: 215.5216346153846 +ksize:(13, 13), sigmax:0 +x: zero_crossing: 224.8421052631579, edge_converge: 198.0; +y: zero_crossing: 223.37254901960785, edge_converge: 238.5 +ksize:(15, 15), sigmax:0 +x: zero_crossing: 224.8421052631579, edge_converge: 198.0; +y: zero_crossing: 223.33333333333334, edge_converge: 238.5 +ksize:(17, 17), sigmax:0 +x: zero_crossing: 224.8421052631579, edge_converge: 198.0; +y: zero_crossing: 223.46341463414635, edge_converge: 238.5 +ksize:(19, 19), sigmax:0 +x: zero_crossing: 224.56521739130434, edge_converge: 198.0; +y: zero_crossing: 223.57894736842104, edge_converge: 238.5 diff --git a/img_rec_module/img_20_2_meas.txt b/img_rec_module/img_20_2_meas.txt new file mode 100644 index 0000000..e829da1 --- /dev/null +++ b/img_rec_module/img_20_2_meas.txt @@ -0,0 +1,18 @@ +ksize:(5, 5), sigmax:0 +x: zero_crossing: 219.0300751879699, edge_converge: 216.60606060606062; +y: zero_crossing: -1, edge_converge: 231.5486656200942 +ksize:(5, 5), sigmax:1 +x: zero_crossing: 218.97794117647058, edge_converge: 217.825; +y: zero_crossing: -1, edge_converge: 231.5472334682861 +ksize:(7, 7), sigmax:0 +x: zero_crossing: 218.89795918367346, edge_converge: 216.62820512820514; +y: zero_crossing: -1, edge_converge: 231.55 +ksize:(7, 7), sigmax:1 +x: zero_crossing: 219.03100775193798, edge_converge: 216.60606060606062; +y: zero_crossing: -1, edge_converge: 231.5472334682861 +ksize:(9, 9), sigmax:0 +x: zero_crossing: 218.8148148148148, edge_converge: 214.6117886178862; +y: zero_crossing: -1, edge_converge: 246.03571428571428 +ksize:(9, 9), sigmax:1 +x: zero_crossing: 219.03100775193798, edge_converge: 216.60606060606062; +y: zero_crossing: -1, edge_converge: 231.5472334682861 diff --git a/img_rec_module/img_20_3_meas.txt b/img_rec_module/img_20_3_meas.txt new file mode 100644 index 0000000..abf84be --- /dev/null +++ b/img_rec_module/img_20_3_meas.txt @@ -0,0 +1,43 @@ +ksize:(5, 5), sigmax:0 +x: zero_crossing: -1, edge_converge: 228.11759868421052; +y: zero_crossing: 222.4569536423841, edge_converge: 224.60727272727274 +ksize:(5, 5), sigmax:1 +x: zero_crossing: -1, edge_converge: 228.12793522267205; +y: zero_crossing: 222.46504559270517, edge_converge: 224.5452380952381 +ksize:(7, 7), sigmax:0 +x: zero_crossing: -1, edge_converge: 222.77301587301588; +y: zero_crossing: 222.62559241706163, edge_converge: 224.3421052631579 +ksize:(7, 7), sigmax:1 +x: zero_crossing: -1, edge_converge: 228.11759868421052; +y: zero_crossing: 222.43730886850153, edge_converge: 224.5328282828283 +ksize:(9, 9), sigmax:0 +x: zero_crossing: -1, edge_converge: 228.31222222222223; +y: zero_crossing: 222.72103004291844, edge_converge: 208.65 +ksize:(9, 9), sigmax:1 +x: zero_crossing: -1, edge_converge: 228.11759868421052; +y: zero_crossing: 222.43730886850153, edge_converge: 224.5328282828283 + +ksize:(5, 5), sigmax:0 +x: zero_crossing: 225.20987654320987, edge_converge: 219.04166666666669; +y: zero_crossing: 222.6821917808219, edge_converge: 229.85833333333332 +ksize:(7, 7), sigmax:0 +x: zero_crossing: 224.8235294117647, edge_converge: 221.65238095238095; +y: zero_crossing: 222.9, edge_converge: 224.62179487179486 +ksize:(9, 9), sigmax:0 +x: zero_crossing: 224.59375, edge_converge: 221.13636363636363; +y: zero_crossing: 223.02487562189054, edge_converge: 225.125 +ksize:(11, 11), sigmax:0 +x: zero_crossing: 224.74444444444444, edge_converge: 221.13636363636363; +y: zero_crossing: 223.28571428571428, edge_converge: 225.125 +ksize:(13, 13), sigmax:0 +x: zero_crossing: 224.7283950617284, edge_converge: 221.13636363636363; +y: zero_crossing: 223.38888888888889, edge_converge: 225.125 +ksize:(15, 15), sigmax:0 +x: zero_crossing: 224.67441860465115, edge_converge: 221.13636363636363; +y: zero_crossing: 223.3942857142857, edge_converge: 225.125 +ksize:(17, 17), sigmax:0 +x: zero_crossing: 224.67816091954023, edge_converge: 221.13636363636363; +y: zero_crossing: 223.49101796407186, edge_converge: 225.125 +ksize:(19, 19), sigmax:0 +x: zero_crossing: 224.68493150684932, edge_converge: 221.13636363636363; +y: zero_crossing: 223.58641975308643, edge_converge: 225.125 \ No newline at end of file diff --git a/img_rec_module/sig_proc.py b/img_rec_module/sig_proc.py index d1e93db..5629778 100644 --- a/img_rec_module/sig_proc.py +++ b/img_rec_module/sig_proc.py @@ -157,73 +157,229 @@ def gauss_mat(shape, a, b1, c_s1, b2, c_s2): def gauss_2d(x, y, a, b1, c_s1, b2, c_s2): return a * np.e ** (- ((x - b1) ** 2 / (2 * c_s1) + (y - b2) ** 2) / (2 * c_s2)) + def gauss_hat(x, a, b, c_s): return a * np.e ** (- (x - b) ** 2 / (2 * c_s)) -img = cv2.imread("../testpic/img_20_1.png") -cv2.imshow("true", img) - - -img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) - -dimc = img.shape[1] -dimr = img.shape[0] +def max_min(data): + maxi = data[0] + max_ind = 0 + mini = data[0] + min_ind = 0 + for i in range(1, len(data)): + target = data[i] + if target > maxi: + maxi = target + max_ind = i + if target < mini: + mini = target + min_ind = i + return max_ind, min_ind + +def zero_crossing(data): + maxi, mini = max_min(data) + cross = -1 + cross_count = 0 + for j in range(maxi, mini): + y1 = data[j] + x2 = j + 1 + y2 = data[x2] + if check_cross(y1, y2): + cross = root_finding(j, x2, y1, y2) # change to function later + cross_count += 1 + return -1 if cross_count > 1 else cross + + +def root_finding(x1, x2, y1, y2): + return - y1 * (x2 - x1) / (y2 - y1) + x1 + + +def check_cross(a, b): + return a * b < 0 + + +def edge_converge(data): + maxi, mini = max_min(data) + emax = -1 + emin = -1 + maxflag = True + minflag = True + cmax = maxi + cmin = mini + while cmax > 0 and cmin < len(data) - 1 and (maxflag or minflag): + max2 = cmax - 1 + maxy1, maxy2 = data[cmax], data[max2] + min2 = cmin + 1 + miny1, miny2 = data[cmin], data[min2] + if check_cross(maxy1, maxy2) and maxflag: + emax = root_finding(cmax, max2, maxy1, maxy2) + maxflag = False + if check_cross(miny1, miny2) and minflag: + emin = root_finding(cmin, min2, miny1, miny2) + minflag = False + if maxflag: + cmax -= 1 + if minflag: + cmin += 1 + return -1 if (emax == -1 or emin == -1) else (emax + emin) / 2 + +imgn = "img_20_1" +fwrite = open(imgn+"_meas.txt", "w") +cenvalsx = [] +cenvalsy = [] +edgvalsx = [] +edgvalsy = [] +ins = range(5, 20, 2) +end = 15 +ins_e = range(5, end, 2) +imgr = cv2.imread("../testpic/" + imgn + ".png") +cv2.imshow("true", imgr) +dimc = imgr.shape[1] +dimr = imgr.shape[0] x = np.array(range(dimc)) -#y = np.array([img_rec.rel_lumin(img, 0, c) for c in x]) -y = np.array([img.item(dimr // 2, c) for c in x]) -a1, b1, c_s1 = gauss_reg(x, y) - x2 = np.array(range(dimr)) -y2 = np.array([img.item(r, dimc // 2) for r in x2]) -a2, b2, c_s2 = gauss_reg(x2, y2) -rem_gauss = gauss_mat(img.shape, (a1+a2) / 2, b1, c_s1, b2, c_s2) -img = img - rem_gauss -cv2.imshow("denoise", img) - -blur = cv2.GaussianBlur(img,(5,5),0) -cv2.imshow("ok", blur) -img = blur - -kernel = np.array([[-1, -1, -1], - [-1, 8, -1], - [-1, -1, -1]]) -kerneled = cv2.filter2D(img, -1, kernel) -cv2.imshow("kerneled", kerneled) - - - -laplacian = cv2.Laplacian(img,cv2.CV_64F) -sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) -sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) -plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray') -plt.title('Original'), plt.xticks([]), plt.yticks([]) -plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray') -plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) -plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray') -plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) -plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray') -plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) -plt.show() +for i in ins: + sig = 0 + #img = cv2.imread("../testpic/" + imgn + ".png") + #cv2.imshow("true", img) + """img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + x = np.array(range(dimc)) + #y = np.array([img_rec.rel_lumin(img, 0, c) for c in x]) + y = np.array([img.item(dimr // 2, c) for c in x]) + a1, b1, c_s1 = gauss_reg(x, y) + + x2 = np.array(range(dimr)) + y2 = np.array([img.item(r, dimc // 2) for r in x2]) + a2, b2, c_s2 = gauss_reg(x2, y2) + rem_gauss = gauss_mat(img.shape, (a1+a2) / 2, b1, c_s1, b2, c_s2) + #img = img - rem_gauss + cv2.imshow("denoise", img)""" + + gksize = (i, i) + sigmaX = sig + + blur = cv2.GaussianBlur(imgr,gksize,sigmaX) + #cv2.imshow("ok", blur) + img = blur + img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + + kernel = np.array([[-1, -1, -1], + [-1, 8, -1], + [-1, -1, -1]]) + kerneled = cv2.filter2D(img, -1, kernel) + #cv2.imshow("kerneled", kerneled) + + + + laplacian = cv2.Laplacian(img,cv2.CV_64F) + sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=-1) + sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=-1) + """plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray') + plt.title('Original'), plt.xticks([]), plt.yticks([]) + plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray') + plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) + plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray') + plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) + plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray') + plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) + plt.close()""" + #plt.show() + + y_s_x = np.array([sobelx.item(dimr // 2, c) for c in x]) + y_s_y = np.array([sobely.item(r, dimc // 2) for r in x2]) + fname = "ksize:{0}, sigmax:{1}".format(gksize, sigmaX) + fwrite.write(fname) + fwrite.write('\n') + zx = zero_crossing(y_s_x) + cenvalsx.append(zx) + if i < end: + ex = edge_converge(y_s_x) + edgvalsx.append(ex) + zy = zero_crossing(y_s_y) + cenvalsy.append(zy) + if i < end: + ey = edge_converge(y_s_y) + edgvalsy.append(ey) + fwrite.write("x: zero_crossing: {0}, edge_converge: {1}; ".format(zx, ex)) + fwrite.write('\n') + fwrite.write("y: zero_crossing: {0}, edge_converge: {1}\n".format(zy, ey)) + fig = plt.figure(figsize=(16, 8)) + fig.canvas.set_window_title(fname) + plt.subplot(211) + plt.plot(y_s_x, 'b-') + plt.ylabel("sobel_x") + plt.subplot(212) + plt.plot(y_s_y, 'b-') + plt.ylabel("sobel_y") + #plt.show() + plt.savefig(fname + ".png") + + + """y_hat = gauss_hat(x, a1, b1, c_s1) + plt.figure(figsize=(16, 8)) + plt.plot(x, y, 'b-', x, y_hat, 'r-') + plt.show() + plt.close() + plt.figure(figsize=(16,8)) + plt.plot(x, y-y_hat, 'b-') + plt.show()""" -y_s_x = np.array([sobelx.item(dimr // 2, c) for c in x]) -y_s_y = np.array([sobely.item(r, dimc // 2) for r in x2]) -plt.figure(figsize=(16, 8)) -plt.subplot(211) -plt.plot(y_s_x, 'b-') -plt.ylabel("sobel_x") -plt.subplot(212) -plt.plot(y_s_y, 'b-') -plt.ylabel("sobel_y") -plt.show() -plt.close() -y_hat = gauss_hat(x, a1, b1, c_s1) plt.figure(figsize=(16, 8)) -plt.plot(x, y, 'b-', x, y_hat, 'r-') +plt.subplot(2, 1, 1) +plt.plot(ins, cenvalsx, 'b-', ins_e, edgvalsx, 'r-') +plt.legend(['zero crossing', 'edge_converging'], loc="lower left") +plt.ylabel("x_meas") +plt.subplot(2, 1, 2) +plt.plot(ins, cenvalsy, 'b-', ins_e, edgvalsy, 'r-') +plt.legend(['zero crossing', 'edge_converging'], loc="lower left") +plt.ylabel("y_meas") +plt.xlabel("kernel size") plt.show() -plt.close() -plt.figure(figsize=(16,8)) -plt.plot(x, y-y_hat, 'b-') -plt.show() \ No newline at end of file + + +"""This function takes in a list of images and output x, y [pixel] coordinates of the center of the cross hair""" +def center_detect(imgs, sample_int=50): + xsum = 0 + ysum = 0 + num_imgs = len(imgs) + dimr = imgs[0].shape[0] + dimc = imgs[0].shape[1] + for img in imgs: + # Image Processing + gksize = (9, 9) + sigmaX = 0 + img = cv2.GaussianBlur(imgr, gksize, sigmaX) + img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=-1) + sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=-1) + # Gathering Data + nr = sample_int + xs = [] + ys = [] + while nr < dimr: + data_x = sobelx[nr, :, :] + zc_x = zero_crossing(data_x) + ed_x = edge_converge(data_x) + nr += sample_int + if zc_x == -1: + continue + else: + xs.append(zc_x * 0.8 + ed_x * 0.2) + nc = sample_int + while nc < dimc: + data_y = sobely[:, nc, :] + zc_y = zero_crossing(data_y) + ed_y = edge_converge(data_y) + nc += sample_int + if zc_y == -1: + continue + else: + xs.append(zc_y * 0.8 + ed_y * 0.2) + + xsum += sum(xs) / len(xs) + ysum += sum(ys) / len(ys) + + return xsum / num_imgs, ysum / num_imgs \ No newline at end of file From c96ba233f4f52b8bc80ae7aeef3a840039fbfce4 Mon Sep 17 00:00:00 2001 From: albertqu Date: Tue, 19 Jun 2018 13:39:31 -0700 Subject: [PATCH 33/59] sensor units --- img_rec_module/sig_proc.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/img_rec_module/sig_proc.py b/img_rec_module/sig_proc.py index 5629778..5a05064 100644 --- a/img_rec_module/sig_proc.py +++ b/img_rec_module/sig_proc.py @@ -340,8 +340,15 @@ def edge_converge(data): plt.show() -"""This function takes in a list of images and output x, y [pixel] coordinates of the center of the cross hair""" -def center_detect(imgs, sample_int=50): + +def folder_to_imgs(img_name_scheme, num_sample): + """This function takes img files and return cv imgs""" + return [cv2.imread(img_name_scheme.format(i)) for i in range(1, num_sample+1)] + + +def center_detect(img_name_scheme, num_sample, sample_int=50): + """This function takes in a list of images and output x, y [pixel] coordinates of the center of the cross hair""" + imgs = folder_to_imgs(img_name_scheme, num_sample) xsum = 0 ysum = 0 num_imgs = len(imgs) From 2d5692c1be20ccb75784e05008b796652d33e9c4 Mon Sep 17 00:00:00 2001 From: albertqu Date: Wed, 20 Jun 2018 11:21:34 -0700 Subject: [PATCH 34/59] problems fixed --- RPiCam/img_capture.py | 20 +- img_rec_module/img_20_2_meas.txt | 36 +-- img_rec_module/img_20_3_meas.txt | 51 ++-- img_rec_module/sig_proc.py | 321 +++-------------------- img_rec_module/sig_proc_test.py | 419 +++++++++++++++++++++++++++++++ 5 files changed, 503 insertions(+), 344 deletions(-) create mode 100644 img_rec_module/sig_proc_test.py diff --git a/RPiCam/img_capture.py b/RPiCam/img_capture.py index 4f77313..30de8c5 100644 --- a/RPiCam/img_capture.py +++ b/RPiCam/img_capture.py @@ -2,11 +2,9 @@ import os import time -recur = True - class ImgCollector: - def __init__(self, dir='', ns='img', form='png', raw=False, num=1): + def __init__(self, dir='', ns='img', form='png', raw=False, num=1, serialize=True): if dir: if not os.path.exists(dir): os.mkdir(dir) @@ -19,8 +17,18 @@ def __init__(self, dir='', ns='img', form='png', raw=False, num=1): self._form = form self._raw = raw self._num = num - self.counter = 1 self.init_cam() + if serialize: + if os.path.exists("img_log.txt"): + rfile = open("img_log.txt", "r") + self.counter = int(rfile.read()) + else: + rfile = open("img_log.txt", "w") + self.counter = 1 + rfile.close() + else: + self.counter = 1 + def change_ns(self, ns): self._ns = ns @@ -54,6 +62,9 @@ def init_cam(self): def shutdown(self): self.cam.close() + wfile = open("img_log.txt", "w") + wfile.write(str(self.counter)) + wfile.close() def uni_capture(self): self.cam.capture(self.name_scheme.format(self.counter), bayer=self._raw) @@ -124,6 +135,7 @@ def main(): break if __name__ == "__main__": + recur = True while recur: main() diff --git a/img_rec_module/img_20_2_meas.txt b/img_rec_module/img_20_2_meas.txt index e829da1..4e85aab 100644 --- a/img_rec_module/img_20_2_meas.txt +++ b/img_rec_module/img_20_2_meas.txt @@ -1,18 +1,24 @@ ksize:(5, 5), sigmax:0 -x: zero_crossing: 219.0300751879699, edge_converge: 216.60606060606062; -y: zero_crossing: -1, edge_converge: 231.5486656200942 -ksize:(5, 5), sigmax:1 -x: zero_crossing: 218.97794117647058, edge_converge: 217.825; -y: zero_crossing: -1, edge_converge: 231.5472334682861 +x: zero_crossing: -1, edge_converge: 225.58333333333331; +y: zero_crossing: -1, edge_converge: 182.35897435897436 ksize:(7, 7), sigmax:0 -x: zero_crossing: 218.89795918367346, edge_converge: 216.62820512820514; -y: zero_crossing: -1, edge_converge: 231.55 -ksize:(7, 7), sigmax:1 -x: zero_crossing: 219.03100775193798, edge_converge: 216.60606060606062; -y: zero_crossing: -1, edge_converge: 231.5472334682861 +x: zero_crossing: -1, edge_converge: 227.5; +y: zero_crossing: -1, edge_converge: 224.0 ksize:(9, 9), sigmax:0 -x: zero_crossing: 218.8148148148148, edge_converge: 214.6117886178862; -y: zero_crossing: -1, edge_converge: 246.03571428571428 -ksize:(9, 9), sigmax:1 -x: zero_crossing: 219.03100775193798, edge_converge: 216.60606060606062; -y: zero_crossing: -1, edge_converge: 231.5472334682861 +x: zero_crossing: 218.89655172413794, edge_converge: 212.9415292353823; +y: zero_crossing: -1, edge_converge: 232.0 +ksize:(11, 11), sigmax:0 +x: zero_crossing: 218.86363636363637, edge_converge: 266.84375; +y: zero_crossing: -1, edge_converge: -1 +ksize:(13, 13), sigmax:0 +x: zero_crossing: 218.5, edge_converge: 213.0; +y: zero_crossing: -1, edge_converge: -1 +ksize:(15, 15), sigmax:0 +x: zero_crossing: -1, edge_converge: 213.0; +y: zero_crossing: -1, edge_converge: -1 +ksize:(17, 17), sigmax:0 +x: zero_crossing: -1, edge_converge: 213.0; +y: zero_crossing: -1, edge_converge: -1 +ksize:(19, 19), sigmax:0 +x: zero_crossing: -1, edge_converge: 213.0; +y: zero_crossing: 191.76923076923077, edge_converge: -1 diff --git a/img_rec_module/img_20_3_meas.txt b/img_rec_module/img_20_3_meas.txt index abf84be..b228fdb 100644 --- a/img_rec_module/img_20_3_meas.txt +++ b/img_rec_module/img_20_3_meas.txt @@ -1,43 +1,24 @@ ksize:(5, 5), sigmax:0 -x: zero_crossing: -1, edge_converge: 228.11759868421052; -y: zero_crossing: 222.4569536423841, edge_converge: 224.60727272727274 -ksize:(5, 5), sigmax:1 -x: zero_crossing: -1, edge_converge: 228.12793522267205; -y: zero_crossing: 222.46504559270517, edge_converge: 224.5452380952381 +x: zero_crossing: 43.1578947368421, edge_converge: 27.907894736842106; +y: zero_crossing: 222.41739130434783, edge_converge: 224.8991379310345 ksize:(7, 7), sigmax:0 -x: zero_crossing: -1, edge_converge: 222.77301587301588; -y: zero_crossing: 222.62559241706163, edge_converge: 224.3421052631579 -ksize:(7, 7), sigmax:1 -x: zero_crossing: -1, edge_converge: 228.11759868421052; -y: zero_crossing: 222.43730886850153, edge_converge: 224.5328282828283 +x: zero_crossing: -1, edge_converge: 222.0; +y: zero_crossing: 222.53191489361703, edge_converge: 228.6346153846154 ksize:(9, 9), sigmax:0 -x: zero_crossing: -1, edge_converge: 228.31222222222223; -y: zero_crossing: 222.72103004291844, edge_converge: 208.65 -ksize:(9, 9), sigmax:1 -x: zero_crossing: -1, edge_converge: 228.11759868421052; -y: zero_crossing: 222.43730886850153, edge_converge: 224.5328282828283 - -ksize:(5, 5), sigmax:0 -x: zero_crossing: 225.20987654320987, edge_converge: 219.04166666666669; -y: zero_crossing: 222.6821917808219, edge_converge: 229.85833333333332 -ksize:(7, 7), sigmax:0 -x: zero_crossing: 224.8235294117647, edge_converge: 221.65238095238095; -y: zero_crossing: 222.9, edge_converge: 224.62179487179486 -ksize:(9, 9), sigmax:0 -x: zero_crossing: 224.59375, edge_converge: 221.13636363636363; -y: zero_crossing: 223.02487562189054, edge_converge: 225.125 +x: zero_crossing: -1, edge_converge: 225.0; +y: zero_crossing: 222.6338028169014, edge_converge: 213.0 ksize:(11, 11), sigmax:0 -x: zero_crossing: 224.74444444444444, edge_converge: 221.13636363636363; -y: zero_crossing: 223.28571428571428, edge_converge: 225.125 +x: zero_crossing: -1, edge_converge: -1; +y: zero_crossing: 222.75, edge_converge: 291.0 ksize:(13, 13), sigmax:0 -x: zero_crossing: 224.7283950617284, edge_converge: 221.13636363636363; -y: zero_crossing: 223.38888888888889, edge_converge: 225.125 +x: zero_crossing: -1, edge_converge: -1; +y: zero_crossing: 222.79166666666666, edge_converge: 200.0 ksize:(15, 15), sigmax:0 -x: zero_crossing: 224.67441860465115, edge_converge: 221.13636363636363; -y: zero_crossing: 223.3942857142857, edge_converge: 225.125 +x: zero_crossing: -1, edge_converge: -1; +y: zero_crossing: 222.7450980392157, edge_converge: 200.0 ksize:(17, 17), sigmax:0 -x: zero_crossing: 224.67816091954023, edge_converge: 221.13636363636363; -y: zero_crossing: 223.49101796407186, edge_converge: 225.125 +x: zero_crossing: -1, edge_converge: -1; +y: zero_crossing: 222.92105263157896, edge_converge: 200.0 ksize:(19, 19), sigmax:0 -x: zero_crossing: 224.68493150684932, edge_converge: 221.13636363636363; -y: zero_crossing: 223.58641975308643, edge_converge: 225.125 \ No newline at end of file +x: zero_crossing: -1, edge_converge: -1; +y: zero_crossing: 222.9268292682927, edge_converge: 200.0 diff --git a/img_rec_module/sig_proc.py b/img_rec_module/sig_proc.py index 5a05064..8562352 100644 --- a/img_rec_module/sig_proc.py +++ b/img_rec_module/sig_proc.py @@ -1,165 +1,4 @@ import cv2 -import numpy as np -import matplotlib.pyplot as plt -from img_rec_module import img_rec -from random import randint -import os - - -def gauss_data_matrix(data): - return np.array([[1, x ** 2, x, 1] for x in data]) - -"""if ori == 'h': - x = np.array(range(img.shape[1])) - y = np.array([img_rec.rel_lumin(img, p, c) for c in x]) -else: - x = np.array(range(img.shape[0])) - y = np.array([img_rec.rel_lumin(img, r, p) for r in x])""" - -def data_matrix(input_data, degree): - # degree is the degree of the polynomial you plan to fit the data with - Data = np.zeros((len(input_data), degree + 1)) - - for k in range(0, degree + 1): - Data[:, k] = (list(map(lambda x: x ** k, input_data))) - - return Data - - -def leastSquares(D, y): - return np.linalg.lstsq(D, y, rcond=None)[0] - - -def poly_curve(params, x_input): - # params contains the coefficients that multiply the polynomial terms, in degree of lowest degree to highest degree - degree = len(params) - 1 - x_range = [x_input[1], x_input[-1]] - x = np.linspace(x_range[0], x_range[1], 1000) - y = x * 0 - - for k in range(0, degree + 1): - coeff = params[k] - y = y + list(map(lambda z: coeff * z ** k, x)) - return x, y - - -def poly_error(params, D_a, y_a): - '''degree=len(params)-1 - y=x_a*0 - - for k in range(0,degree+1): - coeff=params[k] - y=y+list(map(lambda z:coeff*z**k,x_a))''' - y = np.dot(D_a, params) - return np.linalg.norm(y - y_a) ** 2 - - -def MSE(y, y_hat, N): - return np.linalg.norm(y - y_hat) ** 2 / N - - -def improvedCost(x, y, x_test, y_test, start, end): - """Given a set of x and y points training points, - this function calculates polynomial approximations of varying - degrees from start to end. Then it returns the cost, with - the polynomial tested on test points of each degree in an array""" - c = [] - for degree in range(start, end): - # YOUR CODE HERE - D = data_matrix(x, degree) - p = leastSquares(D, y) - D_t = data_matrix(x_test, degree) - y_hat = np.dot(D_t, p) - c.append(MSE(y_test, y_hat, len(x_test))) - return c - - -def OMP(imDims, sparsity, measurements, A): - r = measurements.copy() - indices = [] - - # Threshold to check error. If error is below this value, stop. - THRESHOLD = 0.1 - - # For iterating to recover all signal - i = 0 - - while i < sparsity and np.linalg.norm(r) > THRESHOLD: - # Calculate the correlations - print('%d - ' % i, end="", flush=True) - corrs = A.T.dot(r) - - # Choose highest-correlated pixel location and add to collection - # COMPLETE THE LINE BELOW - best_index = np.argmax(np.abs(corrs)) - indices.append(best_index) - - # Build the matrix made up of selected indices so far - # COMPLETE THE LINE BELOW - Atrunc = A[:, indices] - - # Find orthogonal projection of measurements to subspace - # spanned by recovered codewords - b = measurements - # COMPLETE THE LINE BELOW - xhat = np.linalg.lstsq(Atrunc, b)[0] - - # Find component orthogonal to subspace to use for next measurement - # COMPLETE THE LINE BELOW - r = b - Atrunc.dot(xhat) - - # This is for viewing the recovery process - if i % 10 == 0 or i == sparsity - 1 or np.linalg.norm(r) <= THRESHOLD: - recovered_signal = np.zeros(numPixels) - for j, x in zip(indices, xhat): - recovered_signal[j] = x - Ihat = recovered_signal.reshape(imDims) - plt.title('estimated image') - plt.imshow(Ihat, cmap=plt.cm.gray, interpolation='nearest') - display.clear_output(wait=True) - display.display(plt.gcf()) - - i = i + 1 - - display.clear_output(wait=True) - - # Fill in the recovered signal - recovered_signal = np.zeros(numPixels) - for i, x in zip(indices, xhat): - recovered_signal[i] = x - - return recovered_signal - - -def gauss_reg(x, y): - skip_x = np.array([x[i] for i in range(len(y)) if y[i] != 0]) - y_prime = np.array([y[i] for i in range(len(y)) if y[i] != 0]) - logy = np.log(y_prime) - - sol = leastSquares(gauss_data_matrix(skip_x), logy) - alp, bet, gam, lam = sol - a = np.e ** alp - a *= 10 - c_s = - 1 / (2 * bet) - b = gam * c_s - return a, b, c_s - - -def gauss_mat(shape, a, b1, c_s1, b2, c_s2): - mat = np.zeros(shape) - for r in range(mat.shape[0]): - for c in range(mat.shape[1]): - mat[r, c] = gauss_2d(c, r, a, b1, c_s1, b2, c_s2) - - return mat - - -def gauss_2d(x, y, a, b1, c_s1, b2, c_s2): - return a * np.e ** (- ((x - b1) ** 2 / (2 * c_s1) + (y - b2) ** 2) / (2 * c_s2)) - - -def gauss_hat(x, a, b, c_s): - return a * np.e ** (- (x - b) ** 2 / (2 * c_s)) def max_min(data): @@ -177,6 +16,7 @@ def max_min(data): min_ind = i return max_ind, min_ind + def zero_crossing(data): maxi, mini = max_min(data) cross = -1 @@ -224,122 +64,6 @@ def edge_converge(data): cmin += 1 return -1 if (emax == -1 or emin == -1) else (emax + emin) / 2 -imgn = "img_20_1" -fwrite = open(imgn+"_meas.txt", "w") -cenvalsx = [] -cenvalsy = [] -edgvalsx = [] -edgvalsy = [] -ins = range(5, 20, 2) -end = 15 -ins_e = range(5, end, 2) -imgr = cv2.imread("../testpic/" + imgn + ".png") -cv2.imshow("true", imgr) -dimc = imgr.shape[1] -dimr = imgr.shape[0] -x = np.array(range(dimc)) -x2 = np.array(range(dimr)) -for i in ins: - sig = 0 - #img = cv2.imread("../testpic/" + imgn + ".png") - #cv2.imshow("true", img) - """img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) - x = np.array(range(dimc)) - #y = np.array([img_rec.rel_lumin(img, 0, c) for c in x]) - y = np.array([img.item(dimr // 2, c) for c in x]) - a1, b1, c_s1 = gauss_reg(x, y) - - x2 = np.array(range(dimr)) - y2 = np.array([img.item(r, dimc // 2) for r in x2]) - a2, b2, c_s2 = gauss_reg(x2, y2) - rem_gauss = gauss_mat(img.shape, (a1+a2) / 2, b1, c_s1, b2, c_s2) - #img = img - rem_gauss - cv2.imshow("denoise", img)""" - - gksize = (i, i) - sigmaX = sig - - blur = cv2.GaussianBlur(imgr,gksize,sigmaX) - #cv2.imshow("ok", blur) - img = blur - img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) - - kernel = np.array([[-1, -1, -1], - [-1, 8, -1], - [-1, -1, -1]]) - kerneled = cv2.filter2D(img, -1, kernel) - #cv2.imshow("kerneled", kerneled) - - - - laplacian = cv2.Laplacian(img,cv2.CV_64F) - sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=-1) - sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=-1) - """plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray') - plt.title('Original'), plt.xticks([]), plt.yticks([]) - plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray') - plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) - plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray') - plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) - plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray') - plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) - plt.close()""" - #plt.show() - - y_s_x = np.array([sobelx.item(dimr // 2, c) for c in x]) - y_s_y = np.array([sobely.item(r, dimc // 2) for r in x2]) - fname = "ksize:{0}, sigmax:{1}".format(gksize, sigmaX) - fwrite.write(fname) - fwrite.write('\n') - zx = zero_crossing(y_s_x) - cenvalsx.append(zx) - if i < end: - ex = edge_converge(y_s_x) - edgvalsx.append(ex) - zy = zero_crossing(y_s_y) - cenvalsy.append(zy) - if i < end: - ey = edge_converge(y_s_y) - edgvalsy.append(ey) - fwrite.write("x: zero_crossing: {0}, edge_converge: {1}; ".format(zx, ex)) - fwrite.write('\n') - fwrite.write("y: zero_crossing: {0}, edge_converge: {1}\n".format(zy, ey)) - fig = plt.figure(figsize=(16, 8)) - fig.canvas.set_window_title(fname) - plt.subplot(211) - plt.plot(y_s_x, 'b-') - plt.ylabel("sobel_x") - plt.subplot(212) - plt.plot(y_s_y, 'b-') - plt.ylabel("sobel_y") - #plt.show() - plt.savefig(fname + ".png") - - - """y_hat = gauss_hat(x, a1, b1, c_s1) - plt.figure(figsize=(16, 8)) - plt.plot(x, y, 'b-', x, y_hat, 'r-') - plt.show() - plt.close() - plt.figure(figsize=(16,8)) - plt.plot(x, y-y_hat, 'b-') - plt.show()""" - - - -plt.figure(figsize=(16, 8)) -plt.subplot(2, 1, 1) -plt.plot(ins, cenvalsx, 'b-', ins_e, edgvalsx, 'r-') -plt.legend(['zero crossing', 'edge_converging'], loc="lower left") -plt.ylabel("x_meas") -plt.subplot(2, 1, 2) -plt.plot(ins, cenvalsy, 'b-', ins_e, edgvalsy, 'r-') -plt.legend(['zero crossing', 'edge_converging'], loc="lower left") -plt.ylabel("y_meas") -plt.xlabel("kernel size") -plt.show() - - def folder_to_imgs(img_name_scheme, num_sample): """This function takes img files and return cv imgs""" @@ -349,14 +73,19 @@ def folder_to_imgs(img_name_scheme, num_sample): def center_detect(img_name_scheme, num_sample, sample_int=50): """This function takes in a list of images and output x, y [pixel] coordinates of the center of the cross hair""" imgs = folder_to_imgs(img_name_scheme, num_sample) - xsum = 0 - ysum = 0 num_imgs = len(imgs) dimr = imgs[0].shape[0] dimc = imgs[0].shape[1] - for img in imgs: + xnum_imgs = num_imgs + ynum_imgs = num_imgs + xsum = 0 + ysum = 0 + zw = 0.5 + ew = 0.5 + gk = 7 + for imgr in imgs: # Image Processing - gksize = (9, 9) + gksize = (gk, gk) sigmaX = 0 img = cv2.GaussianBlur(imgr, gksize, sigmaX) img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) @@ -364,29 +93,41 @@ def center_detect(img_name_scheme, num_sample, sample_int=50): sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=-1) # Gathering Data nr = sample_int + r_thresh = dimr * 2.0 / (sample_int * 3) xs = [] ys = [] while nr < dimr: - data_x = sobelx[nr, :, :] + data_x = sobelx[nr, :] zc_x = zero_crossing(data_x) ed_x = edge_converge(data_x) nr += sample_int if zc_x == -1: continue else: - xs.append(zc_x * 0.8 + ed_x * 0.2) + xs.append(zc_x * zw + ed_x * ew) nc = sample_int + c_thresh = dimc * 2.0 / (sample_int * 3) while nc < dimc: - data_y = sobely[:, nc, :] + data_y = sobely[:, nc] zc_y = zero_crossing(data_y) ed_y = edge_converge(data_y) nc += sample_int if zc_y == -1: continue else: - xs.append(zc_y * 0.8 + ed_y * 0.2) - - xsum += sum(xs) / len(xs) - ysum += sum(ys) / len(ys) - - return xsum / num_imgs, ysum / num_imgs \ No newline at end of file + ys.append(zc_y * zw + ed_y * ew) + + len_xs = len(xs) + len_ys = len(ys) + if len_xs < r_thresh: + xnum_imgs -= 1 + else: + xsum += sum(xs) / len(xs) + if len_ys < c_thresh: + ynum_imgs -= 1 + else: + ysum += sum(ys) / len(ys) + + center_x = -1 if xnum_imgs == 0 else xsum / xnum_imgs + center_y = -1 if ynum_imgs == 0 else ysum / ynum_imgs + return center_x, center_y \ No newline at end of file diff --git a/img_rec_module/sig_proc_test.py b/img_rec_module/sig_proc_test.py new file mode 100644 index 0000000..e62a49d --- /dev/null +++ b/img_rec_module/sig_proc_test.py @@ -0,0 +1,419 @@ +import cv2 +import numpy as np +import matplotlib.pyplot as plt +from img_rec_module import img_rec +from random import randint +import os + + +def gauss_data_matrix(data): + return np.array([[1, x ** 2, x, 1] for x in data]) + +"""if ori == 'h': + x = np.array(range(img.shape[1])) + y = np.array([img_rec.rel_lumin(img, p, c) for c in x]) +else: + x = np.array(range(img.shape[0])) + y = np.array([img_rec.rel_lumin(img, r, p) for r in x])""" + +def data_matrix(input_data, degree): + # degree is the degree of the polynomial you plan to fit the data with + Data = np.zeros((len(input_data), degree + 1)) + + for k in range(0, degree + 1): + Data[:, k] = (list(map(lambda x: x ** k, input_data))) + + return Data + + +def leastSquares(D, y): + return np.linalg.lstsq(D, y, rcond=None)[0] + + +def poly_curve(params, x_input): + # params contains the coefficients that multiply the polynomial terms, in degree of lowest degree to highest degree + degree = len(params) - 1 + x_range = [x_input[1], x_input[-1]] + x = np.linspace(x_range[0], x_range[1], 1000) + y = x * 0 + + for k in range(0, degree + 1): + coeff = params[k] + y = y + list(map(lambda z: coeff * z ** k, x)) + return x, y + + +def poly_error(params, D_a, y_a): + '''degree=len(params)-1 + y=x_a*0 + + for k in range(0,degree+1): + coeff=params[k] + y=y+list(map(lambda z:coeff*z**k,x_a))''' + y = np.dot(D_a, params) + return np.linalg.norm(y - y_a) ** 2 + + +def MSE(y, y_hat, N): + return np.linalg.norm(y - y_hat) ** 2 / N + + +def improvedCost(x, y, x_test, y_test, start, end): + """Given a set of x and y points training points, + this function calculates polynomial approximations of varying + degrees from start to end. Then it returns the cost, with + the polynomial tested on test points of each degree in an array""" + c = [] + for degree in range(start, end): + # YOUR CODE HERE + D = data_matrix(x, degree) + p = leastSquares(D, y) + D_t = data_matrix(x_test, degree) + y_hat = np.dot(D_t, p) + c.append(MSE(y_test, y_hat, len(x_test))) + return c + + +def OMP(imDims, sparsity, measurements, A): + r = measurements.copy() + indices = [] + + # Threshold to check error. If error is below this value, stop. + THRESHOLD = 0.1 + + # For iterating to recover all signal + i = 0 + + while i < sparsity and np.linalg.norm(r) > THRESHOLD: + # Calculate the correlations + print('%d - ' % i, end="", flush=True) + corrs = A.T.dot(r) + + # Choose highest-correlated pixel location and add to collection + # COMPLETE THE LINE BELOW + best_index = np.argmax(np.abs(corrs)) + indices.append(best_index) + + # Build the matrix made up of selected indices so far + # COMPLETE THE LINE BELOW + Atrunc = A[:, indices] + + # Find orthogonal projection of measurements to subspace + # spanned by recovered codewords + b = measurements + # COMPLETE THE LINE BELOW + xhat = np.linalg.lstsq(Atrunc, b)[0] + + # Find component orthogonal to subspace to use for next measurement + # COMPLETE THE LINE BELOW + r = b - Atrunc.dot(xhat) + + # This is for viewing the recovery process + if i % 10 == 0 or i == sparsity - 1 or np.linalg.norm(r) <= THRESHOLD: + recovered_signal = np.zeros(numPixels) + for j, x in zip(indices, xhat): + recovered_signal[j] = x + Ihat = recovered_signal.reshape(imDims) + plt.title('estimated image') + plt.imshow(Ihat, cmap=plt.cm.gray, interpolation='nearest') + display.clear_output(wait=True) + display.display(plt.gcf()) + + i = i + 1 + + display.clear_output(wait=True) + + # Fill in the recovered signal + recovered_signal = np.zeros(numPixels) + for i, x in zip(indices, xhat): + recovered_signal[i] = x + + return recovered_signal + + +def gauss_reg(x, y): + skip_x = np.array([x[i] for i in range(len(y)) if y[i] != 0]) + y_prime = np.array([y[i] for i in range(len(y)) if y[i] != 0]) + logy = np.log(y_prime) + + sol = leastSquares(gauss_data_matrix(skip_x), logy) + alp, bet, gam, lam = sol + a = np.e ** alp + a *= 10 + c_s = - 1 / (2 * bet) + b = gam * c_s + return a, b, c_s + + +def gauss_mat(shape, a, b1, c_s1, b2, c_s2): + mat = np.zeros(shape) + for r in range(mat.shape[0]): + for c in range(mat.shape[1]): + mat[r, c] = gauss_2d(c, r, a, b1, c_s1, b2, c_s2) + + return mat + + +def gauss_2d(x, y, a, b1, c_s1, b2, c_s2): + return a * np.e ** (- ((x - b1) ** 2 / (2 * c_s1) + (y - b2) ** 2) / (2 * c_s2)) + + +def gauss_hat(x, a, b, c_s): + return a * np.e ** (- (x - b) ** 2 / (2 * c_s)) + + +def max_min(data): + maxi = data[0] + max_ind = 0 + mini = data[0] + min_ind = 0 + for i in range(1, len(data)): + target = data[i] + if target > maxi: + maxi = target + max_ind = i + if target < mini: + mini = target + min_ind = i + return max_ind, min_ind + +def zero_crossing(data): + maxi, mini = max_min(data) + cross = -1 + cross_count = 0 + for j in range(maxi, mini): + y1 = data[j] + x2 = j + 1 + y2 = data[x2] + if check_cross(y1, y2): + cross = root_finding(j, x2, y1, y2) # change to function later + cross_count += 1 + return -1 if cross_count > 1 else cross + + +def root_finding(x1, x2, y1, y2): + return - y1 * (x2 - x1) / (y2 - y1) + x1 + + +def check_cross(a, b): + return a * b < 0 + + +def edge_converge(data): + maxi, mini = max_min(data) + emax = -1 + emin = -1 + maxflag = True + minflag = True + cmax = maxi + cmin = mini + while cmax > 0 and cmin < len(data) - 1 and (maxflag or minflag): + max2 = cmax - 1 + maxy1, maxy2 = data[cmax], data[max2] + min2 = cmin + 1 + miny1, miny2 = data[cmin], data[min2] + if check_cross(maxy1, maxy2) and maxflag: + emax = root_finding(cmax, max2, maxy1, maxy2) + maxflag = False + if check_cross(miny1, miny2) and minflag: + emin = root_finding(cmin, min2, miny1, miny2) + minflag = False + if maxflag: + cmax -= 1 + if minflag: + cmin += 1 + return -1 if (emax == -1 or emin == -1) else (emax + emin) / 2 + +def test(): + + imgn = "img_20_3" + fwrite = open(imgn+"_meas.txt", "w") + cenvalsx = [] + cenvalsy = [] + edgvalsx = [] + edgvalsy = [] + ins = range(5, 20, 2) + end = 15 + ins_e = range(5, end, 2) + imgr = cv2.imread("../testpic/" + imgn + ".png") + cv2.imshow("true", imgr) + dimc = imgr.shape[1] + dimr = imgr.shape[0] + x = np.array(range(dimc)) + x2 = np.array(range(dimr)) + for i in ins: + sig = 0 + #img = cv2.imread("../testpic/" + imgn + ".png") + #cv2.imshow("true", img) + """img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + x = np.array(range(dimc)) + #y = np.array([img_rec.rel_lumin(img, 0, c) for c in x]) + y = np.array([img.item(dimr // 2, c) for c in x]) + a1, b1, c_s1 = gauss_reg(x, y) + + x2 = np.array(range(dimr)) + y2 = np.array([img.item(r, dimc // 2) for r in x2]) + a2, b2, c_s2 = gauss_reg(x2, y2) + rem_gauss = gauss_mat(img.shape, (a1+a2) / 2, b1, c_s1, b2, c_s2) + #img = img - rem_gauss + cv2.imshow("denoise", img)""" + + gksize = (i, i) + sigmaX = sig + + blur = cv2.GaussianBlur(imgr,gksize,sigmaX) + #cv2.imshow("ok", blur) + img = blur + img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + + kernel = np.array([[-1, -1, -1], + [-1, 8, -1], + [-1, -1, -1]]) + kerneled = cv2.filter2D(img, -1, kernel) + #cv2.imshow("kerneled", kerneled) + + + + laplacian = cv2.Laplacian(img,cv2.CV_64F) + sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=-1) + sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=-1) + """plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray') + plt.title('Original'), plt.xticks([]), plt.yticks([]) + plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray') + plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) + plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray') + plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) + plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray') + plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) + plt.close()""" + #plt.show() + + y_s_x = np.array([sobelx.item(dimr // 2, c) for c in x]) + y_s_y = np.array([sobely.item(r, dimc // 2) for r in x2]) + fname = "ksize:{0}, sigmax:{1}".format(gksize, sigmaX) + fwrite.write(fname) + fwrite.write('\n') + zx = zero_crossing(y_s_x) + cenvalsx.append(zx) + if i < end: + ex = edge_converge(y_s_x) + edgvalsx.append(ex) + zy = zero_crossing(y_s_y) + cenvalsy.append(zy) + if i < end: + ey = edge_converge(y_s_y) + edgvalsy.append(ey) + fwrite.write("x: zero_crossing: {0}, edge_converge: {1}; ".format(zx, ex)) + fwrite.write('\n') + fwrite.write("y: zero_crossing: {0}, edge_converge: {1}\n".format(zy, ey)) + fig = plt.figure(figsize=(16, 8)) + fig.canvas.set_window_title(fname) + plt.subplot(211) + plt.plot(y_s_x, 'b-') + plt.ylabel("sobel_x") + plt.subplot(212) + plt.plot(y_s_y, 'b-') + plt.ylabel("sobel_y") + #plt.show() + plt.savefig(fname + ".png") + + + """y_hat = gauss_hat(x, a1, b1, c_s1) + plt.figure(figsize=(16, 8)) + plt.plot(x, y, 'b-', x, y_hat, 'r-') + plt.show() + plt.close() + plt.figure(figsize=(16,8)) + plt.plot(x, y-y_hat, 'b-') + plt.show()""" + + + + plt.figure(figsize=(16, 8)) + plt.subplot(2, 1, 1) + plt.plot(ins, cenvalsx, 'b-', ins_e, edgvalsx, 'r-') + plt.legend(['zero crossing', 'edge_converging'], loc="lower left") + plt.ylabel("x_meas") + plt.subplot(2, 1, 2) + plt.plot(ins, cenvalsy, 'b-', ins_e, edgvalsy, 'r-') + plt.legend(['zero crossing', 'edge_converging'], loc="lower left") + plt.ylabel("y_meas") + plt.xlabel("kernel size") + plt.show() + + +def folder_to_imgs(img_name_scheme, num_sample): + """This function takes img files and return cv imgs""" + return [cv2.imread(img_name_scheme.format(i)) for i in range(1, num_sample+1)] + +gk = 7 + +def center_detect(img_name_scheme, num_sample, sample_int=50): + """This function takes in a list of images and output x, y [pixel] coordinates of the center of the cross hair""" + imgs = folder_to_imgs(img_name_scheme, num_sample) + num_imgs = len(imgs) + dimr = imgs[0].shape[0] + dimc = imgs[0].shape[1] + xnum_imgs = num_imgs + ynum_imgs = num_imgs + xsum = 0 + ysum = 0 + zw = 0.5 + ew = 0.5 + for imgr in imgs: + #cv2.imshow("w", imgr) + # Image Processing + gksize = (gk, gk) + sigmaX = 0 + img = cv2.GaussianBlur(imgr, gksize, sigmaX) + img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=-1) + sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=-1) + # Gathering Data + nr = sample_int + r_thresh = dimr * 2.0 / (sample_int * 3) + xs = [] + ys = [] + while nr < dimr: + data_x = sobelx[nr, :] + zc_x = zero_crossing(data_x) + ed_x = edge_converge(data_x) + nr += sample_int + if zc_x == -1: + continue + else: + xs.append(zc_x * zw + ed_x * ew) + nc = sample_int + c_thresh = dimc * 2.0 / (sample_int * 3) + while nc < dimc: + data_y = sobely[:, nc] + zc_y = zero_crossing(data_y) + ed_y = edge_converge(data_y) + nc += sample_int + if zc_y == -1: + continue + else: + ys.append(zc_y * zw + ed_y * ew) + + len_xs = len(xs) + len_ys = len(ys) + if len_xs < r_thresh: + xnum_imgs -= 1 + else: + xsum += sum(xs) / len(xs) + #print(xs) + if len_ys < c_thresh: + ynum_imgs -= 1 + else: + ysum += sum(ys) / len(ys) + #print(ys) + + center_x = -1 if xnum_imgs == 0 else xsum / xnum_imgs + center_y = -1 if ynum_imgs == 0 else ysum / ynum_imgs + return center_x, center_y + +for i in range(1, 26): + print(center_detect("../testpic/img_" + str(i) +"_{0}.png", 3)) +"""plt.figure() +plt.plot([1,2 ,3]) +plt.show()""" \ No newline at end of file From db52da6c8f89c6ac133108f75b30d19fe31a3328 Mon Sep 17 00:00:00 2001 From: albertqu Date: Wed, 20 Jun 2018 11:38:22 -0700 Subject: [PATCH 35/59] fixed sockets --- socket_module/rpi_socket.py | 43 +++++++++++++---------- socket_module/server_socket.py | 64 +++++++++++++++++++--------------- 2 files changed, 60 insertions(+), 47 deletions(-) diff --git a/socket_module/rpi_socket.py b/socket_module/rpi_socket.py index 66d350a..985ab52 100644 --- a/socket_module/rpi_socket.py +++ b/socket_module/rpi_socket.py @@ -16,6 +16,8 @@ def connect(self, host, port): self.sock.connect((host, port)) def send(self, data, flags=0): + if data.find(self.EOFChar == -1): + data += self.EOFChar data_sent = 0 tot_len = len(data) while data_sent < tot_len: @@ -26,6 +28,7 @@ def send(self, data, flags=0): except: raise RuntimeError("Connection Lost!") + def recv(self): data_recv = [] bytes_recv = 0 @@ -45,26 +48,30 @@ def close(self): self.sock.close() +def main(): + IP = '192.168.3.4' + port = 8000 -IP = '192.168.3.4' -port = 8000 - -rpisock = SteadySocket() -connected = False -while True: - if not connected: - try: - rpisock.connect(IP, port) - connected = True + rpisock = SteadySocket() + connected = False + while True: + if not connected: + try: + rpisock.connect(IP, port) + connected = True + msg = input("type a message\n") + rpisock.send(bytes(msg, 'utf-8')) + data = rpisock.recv() + print(data) + except: + pass + else: + print("already connected") msg = input("type a message\n") rpisock.send(bytes(msg, 'utf-8')) data = rpisock.recv() print(data) - except: - pass - else: - print("already connected") - msg = input("type a message\n") - rpisock.send(bytes(msg, 'utf-8')) - data = rpisock.recv() - print(data) + + +if __name__ == "__main__": + main() diff --git a/socket_module/server_socket.py b/socket_module/server_socket.py index 32e9370..49fddb7 100644 --- a/socket_module/server_socket.py +++ b/socket_module/server_socket.py @@ -1,5 +1,4 @@ import socket -import time class SteadySocket: @@ -17,6 +16,8 @@ def connect(self, host, port): self.sock.connect((host, port)) def send(self, data, flags=0): + if data.find(self.EOFChar == -1): + data += self.EOFChar data_sent = 0 tot_len = len(data) while data_sent < tot_len: @@ -27,6 +28,7 @@ def send(self, data, flags=0): except: raise RuntimeError("Connection Lost!") + def recv(self): data_recv = [] bytes_recv = 0 @@ -46,34 +48,38 @@ def close(self): self.sock.close() -ssock = socket.socket() -IP = "192.168.3.4" -port = 8000 -ssock.bind((IP, port)) -print("Now connected to " + IP + ":" + str(port)) -ssock.listen(1) +def main(): + ssock = socket.socket() + IP = "192.168.3.4" + port = 8000 + ssock.bind((IP, port)) + print("Now connected to " + IP + ":" + str(port)) + ssock.listen(1) -conn = None -addr = None -sconn = None -while True: - if conn is None: - conn, addr = ssock.accept() - sconn = SteadySocket(conn) - print(addr) - else: - data = sconn.recv() - if data: - print(data) - if data == b"hi": - sconn.send(b"how are you!") - elif data == b'c': - sconn.close() - break + conn = None + addr = None + sconn = None + while True: + if conn is None: + conn, addr = ssock.accept() + sconn = SteadySocket(conn) + print(addr) else: - sconn.send(b"It's good huh?!") - inp = input("value?\n") - if inp == 'e': - sconn.close() - break + data = sconn.recv() + if data: + print(data) + if data == b"hi": + sconn.send(b"how are you!") + elif data == b'c': + sconn.close() + break + else: + sconn.send(b"It's good huh?!") + inp = input("value?\n") + if inp == 'e': + sconn.close() + break + +if __name__ == "__main__": + main() From b107df5961e0b5158a52f03c23e0b55677457d74 Mon Sep 17 00:00:00 2001 From: albertqu Date: Wed, 20 Jun 2018 11:50:38 -0700 Subject: [PATCH 36/59] keep it clean --- socket_module/pi@192.168.3.3 | 55 ------------------------------------ 1 file changed, 55 deletions(-) delete mode 100644 socket_module/pi@192.168.3.3 diff --git a/socket_module/pi@192.168.3.3 b/socket_module/pi@192.168.3.3 deleted file mode 100644 index edf29e0..0000000 --- a/socket_module/pi@192.168.3.3 +++ /dev/null @@ -1,55 +0,0 @@ -import socket - - -class SteadySocket: - MAXMSGLEN = 4096 - EOFChar = '!' - - def __init__(self, sockt=None): - if sockt is None: - self.sock = socket.socket() - else: - self.sock = sockt - - def connect(self, host, port): - return self.sock.connect((host, port)) - - def send(self, data, flags=0): - data_sent = 0 - tot_len = len(data) - while data_sent < data: - sent = self.sock.send(data[data_sent:]) - if sent == 0: - raise RuntimeError("Connection interrupted...") - data_sent += sent - - def recv(self): - data_recv = "" - bytes_recv = 0 - while bytes_recv < self.MAXMSGLEN: - msg = str(self.sock.recv(self.MAXMSGLEN - bytes_recv)) - if len(msg) == 0: - return msg - if msg.find(self.EOFChar) != -1: - return msg - data_recv += msg - bytes_recv += len(msg) - return data_recv - - def close(self): - self.sock.close() - - -IP = '192.168.3.4' -port = 8000 - -rpisock = SteadySocket() -while True: - try: - rpisock.connect(IP, port) - msg = input("type a message\n") - rpisock.send(bytes(msg)) - data = rpisock.recv() - print(data) - except: - pass From 779bf0ab54160b15c11c171d0237ac078b0fa0c9 Mon Sep 17 00:00:00 2001 From: albertqu Date: Wed, 20 Jun 2018 16:02:59 -0700 Subject: [PATCH 37/59] fixed --- RPiCam/img_capture.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/RPiCam/img_capture.py b/RPiCam/img_capture.py index 30de8c5..23b70b8 100644 --- a/RPiCam/img_capture.py +++ b/RPiCam/img_capture.py @@ -21,7 +21,10 @@ def __init__(self, dir='', ns='img', form='png', raw=False, num=1, serialize=Tru if serialize: if os.path.exists("img_log.txt"): rfile = open("img_log.txt", "r") - self.counter = int(rfile.read()) + try: + self.counter = int(rfile.read()) + except: + self.counter = 1 else: rfile = open("img_log.txt", "w") self.counter = 1 @@ -60,6 +63,12 @@ def init_cam(self): else: self.capture = self.multi_capture + def get_last_meas(self): + if self._num == 1: + return self.name_scheme.format(self.counter - 1) + else: + return self._dir + self._ns + '_%d_{0}.' % (self.counter - 1) + self._form + def shutdown(self): self.cam.close() wfile = open("img_log.txt", "w") From c90acef9a6dfd60f6edaae3ae2b30e3ab17a34fb Mon Sep 17 00:00:00 2001 From: albertqu Date: Mon, 25 Jun 2018 09:50:07 -0700 Subject: [PATCH 38/59] updates for server step 1 --- calbridgesensors/calbridgesensors/settings.py | 13 +++- calbridgesensors/calbridgesensors/urls.py | 7 +- calbridgesensors/sensors/converters.py | 8 +++ .../sensors/migrations/0001_initial.py | 65 +++++++++++++++++++ .../migrations/0002_auto_20180623_0133.py | 17 +++++ .../migrations/0003_auto_20180624_0658.py | 33 ++++++++++ calbridgesensors/sensors/models.py | 37 ++++++++--- calbridgesensors/sensors/urls.py | 13 +++- calbridgesensors/sensors/views.py | 22 +++++-- calbridgesensors/templates/base.html | 55 +++++++++++++++- calbridgesensors/templates/home.html | 10 +++ .../templates/sensors/detail.html | 10 +++ calbridgesensors/templates/sensors/index.html | 10 +++ 13 files changed, 278 insertions(+), 22 deletions(-) create mode 100644 calbridgesensors/sensors/converters.py create mode 100644 calbridgesensors/sensors/migrations/0001_initial.py create mode 100644 calbridgesensors/sensors/migrations/0002_auto_20180623_0133.py create mode 100644 calbridgesensors/sensors/migrations/0003_auto_20180624_0658.py create mode 100644 calbridgesensors/templates/home.html create mode 100644 calbridgesensors/templates/sensors/detail.html create mode 100644 calbridgesensors/templates/sensors/index.html diff --git a/calbridgesensors/calbridgesensors/settings.py b/calbridgesensors/calbridgesensors/settings.py index 7c1a4a0..3aec1ce 100644 --- a/calbridgesensors/calbridgesensors/settings.py +++ b/calbridgesensors/calbridgesensors/settings.py @@ -37,7 +37,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - "sensors.apps.SensorsCofig" + "sensors.apps.SensorsConfig" ] MIDDLEWARE = [ @@ -117,5 +117,14 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.0/howto/static-files/ - STATIC_URL = '/static/' +STATICFILES_DIRS = [ + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + os.path.join(BASE_DIR, 'static/') +] + +# Log in URL dispatchers +LOGIN_URL = 'login' +LOGIN_REDIRECT_URL = 'sensors' +LOGOUT_REDIRECT_URL = 'home' \ No newline at end of file diff --git a/calbridgesensors/calbridgesensors/urls.py b/calbridgesensors/calbridgesensors/urls.py index 77743d3..2474719 100644 --- a/calbridgesensors/calbridgesensors/urls.py +++ b/calbridgesensors/calbridgesensors/urls.py @@ -14,8 +14,13 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path, re_path +from django.views.generic.base import TemplateView +from django.urls import path, include + urlpatterns = [ + path('', TemplateView.as_view(template_name="home.html"), name='home'), path('admin/', admin.site.urls), + path('accounts/', include('django.contrib.auth.urls')), + path('sensors/', include("sensors.urls")) ] diff --git a/calbridgesensors/sensors/converters.py b/calbridgesensors/sensors/converters.py new file mode 100644 index 0000000..a41553e --- /dev/null +++ b/calbridgesensors/sensors/converters.py @@ -0,0 +1,8 @@ +class BridgeNameConverter: + regex = '[/w-]+' + + def to_python(self, value): + return value.replace("-", " ").title() + + def to_url(self, value): + return str(value).replace(" ", "-").lower() \ No newline at end of file diff --git a/calbridgesensors/sensors/migrations/0001_initial.py b/calbridgesensors/sensors/migrations/0001_initial.py new file mode 100644 index 0000000..faceee4 --- /dev/null +++ b/calbridgesensors/sensors/migrations/0001_initial.py @@ -0,0 +1,65 @@ +# Generated by Django 2.0.5 on 2018-06-23 01:15 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Bridge', + fields=[ + ('name', models.CharField(max_length=40, primary_key=True, serialize=False)), + ('anomaly', models.BooleanField(default=False)), + ('validated', models.BooleanField(default=False)), + ], + options={ + 'ordering': ['name'], + }, + ), + migrations.CreateModel( + name='BridgeLog', + fields=[ + ('log_type', models.CharField(choices=[('D', 'Damage Record'), ('R', 'Repair Record')], max_length=1)), + ('log_time', models.DateTimeField(auto_now_add=True, primary_key=True, serialize=False)), + ('bridge', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sensors.Bridge', unique_for_date='log_time')), + ], + options={ + 'ordering': [], + }, + ), + migrations.CreateModel( + name='BrokenFlag', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('bridge', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='sensors.Bridge')), + ('record', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, to='sensors.BridgeLog')), + ], + options={ + 'ordering': [], + }, + ), + migrations.CreateModel( + name='Reading', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('x', models.DecimalField(decimal_places=2, max_digits=4)), + ('y', models.DecimalField(decimal_places=2, max_digits=4)), + ('z', models.DecimalField(decimal_places=2, max_digits=4)), + ('theta', models.DecimalField(decimal_places=2, max_digits=4)), + ('phi', models.DecimalField(decimal_places=2, max_digits=4)), + ('psi', models.DecimalField(decimal_places=2, max_digits=4)), + ('time_taken', models.DateTimeField(auto_now_add=True)), + ('bridge', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sensors.Bridge', unique_for_date='time_taken')), + ], + options={ + 'verbose_name': 'Bridge sensor reading', + }, + ), + ] diff --git a/calbridgesensors/sensors/migrations/0002_auto_20180623_0133.py b/calbridgesensors/sensors/migrations/0002_auto_20180623_0133.py new file mode 100644 index 0000000..d923aed --- /dev/null +++ b/calbridgesensors/sensors/migrations/0002_auto_20180623_0133.py @@ -0,0 +1,17 @@ +# Generated by Django 2.0.5 on 2018-06-23 01:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('sensors', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='reading', + options={'ordering': ['-time_taken'], 'verbose_name': 'Bridge sensor reading'}, + ), + ] diff --git a/calbridgesensors/sensors/migrations/0003_auto_20180624_0658.py b/calbridgesensors/sensors/migrations/0003_auto_20180624_0658.py new file mode 100644 index 0000000..fda13cd --- /dev/null +++ b/calbridgesensors/sensors/migrations/0003_auto_20180624_0658.py @@ -0,0 +1,33 @@ +# Generated by Django 2.0.5 on 2018-06-24 06:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('sensors', '0002_auto_20180623_0133'), + ] + + operations = [ + migrations.AlterModelOptions( + name='bridgelog', + options={'ordering': ['-log_time', 'log_type', 'bridge__name']}, + ), + migrations.AlterModelOptions( + name='brokenflag', + options={'ordering': ['bridge__name']}, + ), + migrations.AlterModelOptions( + name='reading', + options={'ordering': ['bridge__name', '-time_taken'], 'verbose_name': 'Bridge Sensor Reading'}, + ), + migrations.RemoveField( + model_name='bridge', + name='anomaly', + ), + migrations.RemoveField( + model_name='bridge', + name='validated', + ), + ] diff --git a/calbridgesensors/sensors/models.py b/calbridgesensors/sensors/models.py index bf625f8..0c65aba 100644 --- a/calbridgesensors/sensors/models.py +++ b/calbridgesensors/sensors/models.py @@ -1,13 +1,23 @@ from django.db import models - +import re class Bridge(models.Model): - name = models.CharField(max_length=40, primary_key=True) - reading = models.OneToOneField(Reading, on_delete=models.PROTECT, help_text="latest sensor reading of the bridge", blank=True, null=True) - anomaly = models.BooleanField(default=False) - broken_times = models.ForeignKey(BridgeLog, on_delete=models.PROTECT) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + target = r'[^ A-Za-z0-9]' + self.name = str(re.sub(target, " ", self.name)).title() + + def __str__(self): + return self.name + + def latest_reading(self): + return self.reading_set.all()[0] + + def get_damage_records(self): + return self.bridgelog_set.filter(log_type="D") class Meta: ordering = ["name"] @@ -23,8 +33,12 @@ class Reading(models.Model): bridge = models.ForeignKey(Bridge, on_delete=models.CASCADE, unique_for_date="time_taken") time_taken = models.DateTimeField(auto_now_add=True) + def __str__(self): + return "Reading for " + self.bridge.name + class Meta: - verbose_name = "Bridge sensor reading" + verbose_name = "Bridge Sensor Reading" + ordering = ["bridge__name", "-time_taken"] class BridgeLog(models.Model): @@ -36,6 +50,13 @@ class BridgeLog(models.Model): log_time = models.DateTimeField(auto_now_add=True, primary_key=True) bridge = models.ForeignKey(Bridge, on_delete=models.CASCADE, unique_for_date="log_time") + class Meta: + ordering = ["-log_time", "log_type", "bridge__name"] + -class BrokenRecord(models.Model): - bridge = models.OneToOneField(Bridge, on_delete=models.SET_NULL, to_field="name") \ No newline at end of file +class BrokenFlag(models.Model): + bridge = models.OneToOneField(Bridge, on_delete=models.CASCADE) + record = models.OneToOneField(BridgeLog, on_delete=models.PROTECT) + + class Meta: + ordering = ["bridge__name"] \ No newline at end of file diff --git a/calbridgesensors/sensors/urls.py b/calbridgesensors/sensors/urls.py index 7c77335..ee39799 100644 --- a/calbridgesensors/sensors/urls.py +++ b/calbridgesensors/sensors/urls.py @@ -1,4 +1,11 @@ -from django.contrib import admin -from django.urls import path, re_path +from django.urls import path, re_path, register_converter +from .converters import BridgeNameConverter +from . import views -urlpatterns = [] \ No newline at end of file +register_converter(BridgeNameConverter, 'brn') + +urlpatterns = [ + path("", views.SensorsHomeView, "sensors"), + path("/", views.BridgeView.as_view(), "detail"), + path("/update/", views.bridge_update) +] \ No newline at end of file diff --git a/calbridgesensors/sensors/views.py b/calbridgesensors/sensors/views.py index fe8ede5..1f4b14c 100644 --- a/calbridgesensors/sensors/views.py +++ b/calbridgesensors/sensors/views.py @@ -1,14 +1,24 @@ from django.shortcuts import render -from django.views.generic import TemplateView +from django.views.generic import DetailView +from django.http import HttpResponse +from django.views.generic.base import TemplateView +from .models import Bridge, BrokenFlag """View for home page""" -def home(request): +class SensorsHomeView(TemplateView): + template_name = "sensors/index.html" - # Check broken bridges - return render(request, "home.html", context={}) + def get_context_data(self, **kwargs): + broken_bridges = BrokenFlag.objects.all() -class BridgeView(TemplateView): - template_name = "bridge.html" \ No newline at end of file + +class BridgeView(DetailView): + model = Bridge + template_name = "sensors/detail.html" + + +def bridge_update(request, bridge_name): + return HttpResponse("hello") \ No newline at end of file diff --git a/calbridgesensors/templates/base.html b/calbridgesensors/templates/base.html index c1610a5..0117410 100644 --- a/calbridgesensors/templates/base.html +++ b/calbridgesensors/templates/base.html @@ -4,19 +4,70 @@ Cal Bridge Sensors + +
+
  • logout
  • +
  • home
  • +
    + \ No newline at end of file diff --git a/calbridgesensors/templates/home.html b/calbridgesensors/templates/home.html new file mode 100644 index 0000000..676e2df --- /dev/null +++ b/calbridgesensors/templates/home.html @@ -0,0 +1,10 @@ + + + + + Cal Bridge Sensors Home + + + + + \ No newline at end of file diff --git a/calbridgesensors/templates/sensors/detail.html b/calbridgesensors/templates/sensors/detail.html new file mode 100644 index 0000000..566549b --- /dev/null +++ b/calbridgesensors/templates/sensors/detail.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file diff --git a/calbridgesensors/templates/sensors/index.html b/calbridgesensors/templates/sensors/index.html new file mode 100644 index 0000000..566549b --- /dev/null +++ b/calbridgesensors/templates/sensors/index.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file From ba64e38b9747c16c3fac967ab29652711163c3ce Mon Sep 17 00:00:00 2001 From: albertqu Date: Tue, 26 Jun 2018 02:12:31 -0700 Subject: [PATCH 39/59] server update --- calbridgesensors/sensors/admin.py | 2 + calbridgesensors/sensors/converters.py | 2 +- .../migrations/0004_auto_20180626_0607.py | 22 ++++++ calbridgesensors/sensors/models.py | 49 ++++++++++--- .../sensors/templatetags/sensors_filters.py | 10 +++ calbridgesensors/sensors/urls.py | 9 ++- calbridgesensors/sensors/utils.py | 10 +++ calbridgesensors/sensors/views.py | 16 +++-- calbridgesensors/templates/base.html | 33 +++++++-- calbridgesensors/templates/home.html | 68 ++++++++++++++++++- .../templates/registration/login.html | 38 +++++++++++ .../templates/sensors/detail.html | 10 +-- calbridgesensors/templates/sensors/index.html | 34 +++++++--- 13 files changed, 255 insertions(+), 48 deletions(-) create mode 100644 calbridgesensors/sensors/migrations/0004_auto_20180626_0607.py create mode 100644 calbridgesensors/sensors/templatetags/sensors_filters.py create mode 100644 calbridgesensors/sensors/utils.py create mode 100644 calbridgesensors/templates/registration/login.html diff --git a/calbridgesensors/sensors/admin.py b/calbridgesensors/sensors/admin.py index 8c38f3f..d82cac0 100644 --- a/calbridgesensors/sensors/admin.py +++ b/calbridgesensors/sensors/admin.py @@ -1,3 +1,5 @@ from django.contrib import admin +from .models import Bridge # Register your models here. +admin.site.register(Bridge) \ No newline at end of file diff --git a/calbridgesensors/sensors/converters.py b/calbridgesensors/sensors/converters.py index a41553e..ff311d1 100644 --- a/calbridgesensors/sensors/converters.py +++ b/calbridgesensors/sensors/converters.py @@ -1,5 +1,5 @@ class BridgeNameConverter: - regex = '[/w-]+' + regex = '[\w-]+' def to_python(self, value): return value.replace("-", " ").title() diff --git a/calbridgesensors/sensors/migrations/0004_auto_20180626_0607.py b/calbridgesensors/sensors/migrations/0004_auto_20180626_0607.py new file mode 100644 index 0000000..9aead8a --- /dev/null +++ b/calbridgesensors/sensors/migrations/0004_auto_20180626_0607.py @@ -0,0 +1,22 @@ +# Generated by Django 2.0.5 on 2018-06-26 06:07 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('sensors', '0003_auto_20180624_0658'), + ] + + operations = [ + migrations.AlterModelOptions( + name='bridgelog', + options={'ordering': ['bridge__name', 'log_type', '-log_time']}, + ), + migrations.RenameField( + model_name='brokenflag', + old_name='record', + new_name='first_broken_record', + ), + ] diff --git a/calbridgesensors/sensors/models.py b/calbridgesensors/sensors/models.py index 0c65aba..caf5881 100644 --- a/calbridgesensors/sensors/models.py +++ b/calbridgesensors/sensors/models.py @@ -1,14 +1,18 @@ from django.db import models -import re +from .utils import name_validate +from django.utils import timezone class Bridge(models.Model): + # Field: reading name = models.CharField(max_length=40, primary_key=True) + class Meta: + ordering = ["name"] + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - target = r'[^ A-Za-z0-9]' - self.name = str(re.sub(target, " ", self.name)).title() + self.name = name_validate(self.name) def __str__(self): return self.name @@ -19,8 +23,22 @@ def latest_reading(self): def get_damage_records(self): return self.bridgelog_set.filter(log_type="D") - class Meta: - ordering = ["name"] + def get_repair_records(self): + return self.bridgelog_set.filter(log_type="R") + + def is_broken(self): + return self.brokenflag + + def add_reading(self, x, y, z, theta, phi, psi): + return self.reading_set.create(x=x, y=y, z=z, theta=theta, phi=phi, psi=psi, bridge=self) + + def update(self, x, y, z, theta, phi, psi): + old_reading = self.latest_reading() + new_reading = self.add_reading(x, y, z, theta, phi, psi) + + + def mark_broken(self, bridge_log): + self.brokenflag = BrokenFlag(bridge=self, first_broken_record=bridge_log) class Reading(models.Model): @@ -33,13 +51,13 @@ class Reading(models.Model): bridge = models.ForeignKey(Bridge, on_delete=models.CASCADE, unique_for_date="time_taken") time_taken = models.DateTimeField(auto_now_add=True) - def __str__(self): - return "Reading for " + self.bridge.name - class Meta: verbose_name = "Bridge Sensor Reading" ordering = ["bridge__name", "-time_taken"] + def __str__(self): + return "Reading for " + self.bridge.name + class BridgeLog(models.Model): DAMAGE = "D" @@ -51,12 +69,21 @@ class BridgeLog(models.Model): bridge = models.ForeignKey(Bridge, on_delete=models.CASCADE, unique_for_date="log_time") class Meta: - ordering = ["-log_time", "log_type", "bridge__name"] + ordering = ["bridge__name", "log_type", "-log_time"] + + def __str__(self): + return self.get_log_type_display() + " for " + self.bridge.name + + def description(self): + return self.get_log_type_display() + " at " + self.log_time class BrokenFlag(models.Model): bridge = models.OneToOneField(Bridge, on_delete=models.CASCADE) - record = models.OneToOneField(BridgeLog, on_delete=models.PROTECT) + first_broken_record = models.OneToOneField(BridgeLog, on_delete=models.PROTECT) class Meta: - ordering = ["bridge__name"] \ No newline at end of file + ordering = ["bridge__name"] + + def broken_time(self): + return timezone.now() - self.first_broken_record.log_time diff --git a/calbridgesensors/sensors/templatetags/sensors_filters.py b/calbridgesensors/sensors/templatetags/sensors_filters.py new file mode 100644 index 0000000..0fee682 --- /dev/null +++ b/calbridgesensors/sensors/templatetags/sensors_filters.py @@ -0,0 +1,10 @@ +from django import template +from django.template.defaultfilters import stringfilter + +register = template.Library() + + +@stringfilter +@register.filter(name='tourl') +def name_to_url(value): + return value.replace(" ", "-").lower() diff --git a/calbridgesensors/sensors/urls.py b/calbridgesensors/sensors/urls.py index ee39799..58e6d65 100644 --- a/calbridgesensors/sensors/urls.py +++ b/calbridgesensors/sensors/urls.py @@ -4,8 +4,11 @@ register_converter(BridgeNameConverter, 'brn') +app_name = "sensors" + urlpatterns = [ - path("", views.SensorsHomeView, "sensors"), - path("/", views.BridgeView.as_view(), "detail"), - path("/update/", views.bridge_update) + path('', views.SensorsHomeView.as_view(), name='index'), + path('/', views.BridgeView.as_view(), name='detail'), + #re_path(r'^(?P[\w-]+)/$', views.BridgeView.as_view(), name='detail'), + path('/update/', views.bridge_update) ] \ No newline at end of file diff --git a/calbridgesensors/sensors/utils.py b/calbridgesensors/sensors/utils.py new file mode 100644 index 0000000..ab928d4 --- /dev/null +++ b/calbridgesensors/sensors/utils.py @@ -0,0 +1,10 @@ +import re + + +def name_validate(s): + target = r'[^ A-Za-z0-9]' + return re.sub(target, " ", s).title() + + +def check_abnomaly(r1, r2): + return True \ No newline at end of file diff --git a/calbridgesensors/sensors/views.py b/calbridgesensors/sensors/views.py index 1f4b14c..2fee9c3 100644 --- a/calbridgesensors/sensors/views.py +++ b/calbridgesensors/sensors/views.py @@ -1,23 +1,29 @@ from django.shortcuts import render +from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import DetailView from django.http import HttpResponse from django.views.generic.base import TemplateView from .models import Bridge, BrokenFlag -"""View for home page""" -class SensorsHomeView(TemplateView): +class SensorsHomeView(LoginRequiredMixin, TemplateView): + """View for home page""" template_name = "sensors/index.html" + login_url = "/accounts/login/" def get_context_data(self, **kwargs): broken_bridges = BrokenFlag.objects.all() + return {"user": self.request.user, "broken_bridges": broken_bridges, "bridges": Bridge.objects.all()} - - -class BridgeView(DetailView): +class BridgeView(LoginRequiredMixin, DetailView): model = Bridge template_name = "sensors/detail.html" + login_url = "/accounts/login/" + context_object_name = "bridge" + + def get_context_data(self, **kwargs): + return {"user", self.request.user}.update(super().get_context_data(**kwargs)) def bridge_update(request, bridge_name): diff --git a/calbridgesensors/templates/base.html b/calbridgesensors/templates/base.html index 0117410..3202dde 100644 --- a/calbridgesensors/templates/base.html +++ b/calbridgesensors/templates/base.html @@ -51,23 +51,42 @@ color: dodgerblue; } + div.center { + text-align: center; + margin-top: 5%; + margin-bottom: auto; + border-top: 1px solid slategray; + display: flex; + justify-content: center; + } + div.center label { + padding-right: 20px; + margin-top: 10px; + } + + div.center select { + margin-top: 10px; + } - + {% block header %}
    -
  • logout
  • -
  • home
  • + {% if user.is_authenticated %} +
  • logout
  • + {% endif %} +
  • home
  • - + {% endblock %} \ No newline at end of file diff --git a/calbridgesensors/templates/home.html b/calbridgesensors/templates/home.html index 676e2df..30f6e83 100644 --- a/calbridgesensors/templates/home.html +++ b/calbridgesensors/templates/home.html @@ -1,10 +1,72 @@ +{% load static %} - Cal Bridge Sensors Home + Cal Bridge Sensors + - - +{% block content %} +

    Bridge Settlement

    +
    + {% if user.is_authenticated %} +
  • Manage
  • + {% else %} +
  • Log In
  • + {% endif %} +
  • Admin
  • +
    +{% endblock %} \ No newline at end of file diff --git a/calbridgesensors/templates/registration/login.html b/calbridgesensors/templates/registration/login.html new file mode 100644 index 0000000..aff6191 --- /dev/null +++ b/calbridgesensors/templates/registration/login.html @@ -0,0 +1,38 @@ +{% extends "base.html" %} + +{% block content %} + +{% if form.errors %} +

    Your username and password didn't match. Please try again.

    +{% endif %} + +{% if next %} + {% if user.is_authenticated %} +

    Your account doesn't have access to this page. To proceed, + please login with an account that has access.

    + {% else %} +

    Please login to see this page.

    + {% endif %} +{% endif %} + +
    +{% csrf_token %} + + + + + + + + + +
    {{ form.username.label_tag }}{{ form.username }}
    {{ form.password.label_tag }}{{ form.password }}
    + + + +
    + +{# Assumes you setup the password_reset view in your URLconf #} +

    Lost password?

    + +{% endblock %} \ No newline at end of file diff --git a/calbridgesensors/templates/sensors/detail.html b/calbridgesensors/templates/sensors/detail.html index 566549b..b65a6cb 100644 --- a/calbridgesensors/templates/sensors/detail.html +++ b/calbridgesensors/templates/sensors/detail.html @@ -1,10 +1,2 @@ - - - - - Title - - +{% extends 'base.html' %} - - \ No newline at end of file diff --git a/calbridgesensors/templates/sensors/index.html b/calbridgesensors/templates/sensors/index.html index 566549b..2275dc4 100644 --- a/calbridgesensors/templates/sensors/index.html +++ b/calbridgesensors/templates/sensors/index.html @@ -1,10 +1,26 @@ - - - - - Title - - +{% extends "base.html" %} +{% load sensors_filters %} - - \ No newline at end of file +{% block alert %} +
    + {% if broken_bridges %} + {% for bb in broken_bridges %} +
  • bb.bridge
  • +
  • bb.broken_time
  • + {% endfor %} + {% else %} +

    All Bridges Are Healthy

    + {% endif %} +
    +{% endblock %} + +{% block content %} +
    + + +
    +{% endblock %} \ No newline at end of file From ca6adf19bd0052d103e2ef3d9ad0056794f5bc76 Mon Sep 17 00:00:00 2001 From: albertqu Date: Tue, 26 Jun 2018 05:56:57 -0700 Subject: [PATCH 40/59] server-v-1.0 finished --- calbridgesensors/sensors/admin.py | 6 +- calbridgesensors/sensors/models.py | 1 - calbridgesensors/sensors/urls.py | 2 +- calbridgesensors/sensors/views.py | 19 +- calbridgesensors/templates/base.html | 59 +++++ calbridgesensors/templates/home.html | 8 - .../templates/sensors/detail.html | 56 ++++ calbridgesensors/templates/sensors/index.html | 6 +- img_rec_module/img_1_1new_meas.txt | 24 ++ img_rec_module/img_2_1new_meas.txt | 24 ++ img_rec_module/img_3_1new_meas.txt | 24 ++ .../meas/img_19_3/img_19_3_(240, 320).txt | 24 ++ .../meas/img_1_1/img_1_1_(600, 960).txt | 24 ++ .../meas/img_20_1/img_20_1_(240, 320).txt | 24 ++ .../meas/img_20_1/img_20_1_(900, 1400).txt | 0 .../meas/img_2_1/img_2_1_(200, 500).txt | 24 ++ .../meas/img_2_1/img_2_1_(400, 700).txt | 24 ++ .../meas/img_2_1/img_2_1_(800, 900).txt | 24 ++ .../meas/img_2_1/img_2_1_(900, 1700).txt | 24 ++ .../meas/img_2_1/img_2_1_(900, 900).txt | 24 ++ .../meas/img_2_4/img_2_4_(1400, 900).txt | 0 .../meas/img_2_4/img_2_4_(600, 960).txt | 24 ++ .../meas/img_2_4/img_2_4_(900, 1400).txt | 24 ++ .../meas/img_3_3/img_3_3_(240, 320).txt | 24 ++ .../meas/img_3_3/img_3_3_new_(600, 960).txt | 24 ++ .../meas/img_4_1/img_4_1_(240, 320).txt | 0 .../meas/img_4_1/img_4_1_(500, 1200).txt | 0 .../meas/img_5_1/img_5_1_(240, 320).txt | 24 ++ .../meas/img_5_1/img_5_1_(900, 1400).txt | 0 .../meas/img_9_1/img_9_1_(240, 320).txt | 24 ++ img_rec_module/sig_proc_test.py | 247 ++++++++++++------ 31 files changed, 710 insertions(+), 102 deletions(-) create mode 100644 img_rec_module/img_1_1new_meas.txt create mode 100644 img_rec_module/img_2_1new_meas.txt create mode 100644 img_rec_module/img_3_1new_meas.txt create mode 100644 img_rec_module/meas/img_19_3/img_19_3_(240, 320).txt create mode 100644 img_rec_module/meas/img_1_1/img_1_1_(600, 960).txt create mode 100644 img_rec_module/meas/img_20_1/img_20_1_(240, 320).txt create mode 100644 img_rec_module/meas/img_20_1/img_20_1_(900, 1400).txt create mode 100644 img_rec_module/meas/img_2_1/img_2_1_(200, 500).txt create mode 100644 img_rec_module/meas/img_2_1/img_2_1_(400, 700).txt create mode 100644 img_rec_module/meas/img_2_1/img_2_1_(800, 900).txt create mode 100644 img_rec_module/meas/img_2_1/img_2_1_(900, 1700).txt create mode 100644 img_rec_module/meas/img_2_1/img_2_1_(900, 900).txt create mode 100644 img_rec_module/meas/img_2_4/img_2_4_(1400, 900).txt create mode 100644 img_rec_module/meas/img_2_4/img_2_4_(600, 960).txt create mode 100644 img_rec_module/meas/img_2_4/img_2_4_(900, 1400).txt create mode 100644 img_rec_module/meas/img_3_3/img_3_3_(240, 320).txt create mode 100644 img_rec_module/meas/img_3_3/img_3_3_new_(600, 960).txt create mode 100644 img_rec_module/meas/img_4_1/img_4_1_(240, 320).txt create mode 100644 img_rec_module/meas/img_4_1/img_4_1_(500, 1200).txt create mode 100644 img_rec_module/meas/img_5_1/img_5_1_(240, 320).txt create mode 100644 img_rec_module/meas/img_5_1/img_5_1_(900, 1400).txt create mode 100644 img_rec_module/meas/img_9_1/img_9_1_(240, 320).txt diff --git a/calbridgesensors/sensors/admin.py b/calbridgesensors/sensors/admin.py index d82cac0..ca58d9b 100644 --- a/calbridgesensors/sensors/admin.py +++ b/calbridgesensors/sensors/admin.py @@ -1,5 +1,7 @@ from django.contrib import admin -from .models import Bridge +from .models import Bridge, BridgeLog, BrokenFlag # Register your models here. -admin.site.register(Bridge) \ No newline at end of file +admin.site.register(Bridge) +admin.site.register(BridgeLog) +admin.site.register(BrokenFlag) \ No newline at end of file diff --git a/calbridgesensors/sensors/models.py b/calbridgesensors/sensors/models.py index caf5881..6f118f3 100644 --- a/calbridgesensors/sensors/models.py +++ b/calbridgesensors/sensors/models.py @@ -36,7 +36,6 @@ def update(self, x, y, z, theta, phi, psi): old_reading = self.latest_reading() new_reading = self.add_reading(x, y, z, theta, phi, psi) - def mark_broken(self, bridge_log): self.brokenflag = BrokenFlag(bridge=self, first_broken_record=bridge_log) diff --git a/calbridgesensors/sensors/urls.py b/calbridgesensors/sensors/urls.py index 58e6d65..881559d 100644 --- a/calbridgesensors/sensors/urls.py +++ b/calbridgesensors/sensors/urls.py @@ -8,7 +8,7 @@ urlpatterns = [ path('', views.SensorsHomeView.as_view(), name='index'), - path('/', views.BridgeView.as_view(), name='detail'), + path('/', views.bridge_view, name='detail'), #re_path(r'^(?P[\w-]+)/$', views.BridgeView.as_view(), name='detail'), path('/update/', views.bridge_update) ] \ No newline at end of file diff --git a/calbridgesensors/sensors/views.py b/calbridgesensors/sensors/views.py index 2fee9c3..1813427 100644 --- a/calbridgesensors/sensors/views.py +++ b/calbridgesensors/sensors/views.py @@ -1,5 +1,6 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.auth.decorators import login_required from django.views.generic import DetailView from django.http import HttpResponse from django.views.generic.base import TemplateView @@ -16,14 +17,26 @@ def get_context_data(self, **kwargs): return {"user": self.request.user, "broken_bridges": broken_bridges, "bridges": Bridge.objects.all()} -class BridgeView(LoginRequiredMixin, DetailView): +"""class BridgeView(LoginRequiredMixin, DetailView): model = Bridge template_name = "sensors/detail.html" login_url = "/accounts/login/" context_object_name = "bridge" def get_context_data(self, **kwargs): - return {"user", self.request.user}.update(super().get_context_data(**kwargs)) + return {"user": self.request.user}.update(super().get_context_data(**kwargs))""" + + +@login_required(login_url='/accounts/login/') +def bridge_view(request, pk): + bridge = get_object_or_404(Bridge, pk=pk) + context = {"user": request.user, + "damage_recs": bridge.get_damage_records(), + "repair_recs": bridge.get_repair_records(), + "bridge": bridge, + "reading": bridge.latest_reading() + } + return render(request, "sensors/detail.html", context=context) def bridge_update(request, bridge_name): diff --git a/calbridgesensors/templates/base.html b/calbridgesensors/templates/base.html index 3202dde..9d2690d 100644 --- a/calbridgesensors/templates/base.html +++ b/calbridgesensors/templates/base.html @@ -69,6 +69,65 @@ margin-top: 10px; } + .dropitem { + float: none; + color: black; + padding: 12px 16px; + text-decoration: none; + display: block; + text-align: left; + } + + .dropmenu { + display: none; + position: absolute; + background-color: aliceblue; + min-width: 160px; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + z-index: 1; + } + + .dropdown .dropbtn { + font-size: 16px; + border: none; + outline: none; + color: black; + padding: 14px 16px; + background-color: aliceblue; + border-radius: 10px; + list-style: none; + font-family: inherit; + margin: 0; + } + + .dropdown:hover .dropmenu { + display: block; + } + + li.setview { + background-color: aliceblue; + margin: auto 30px auto 30px; + list-style: none; + border-radius: 10px; + padding: 10px 20px; + width: 110px; + height: 20px; + } + + .bar { + display: table; + margin: 20px; + } + + .bar li { + float: left; + } + + .dropdown { + float: left; + display: block; + } + diff --git a/calbridgesensors/templates/home.html b/calbridgesensors/templates/home.html index 30f6e83..75b327a 100644 --- a/calbridgesensors/templates/home.html +++ b/calbridgesensors/templates/home.html @@ -46,14 +46,6 @@ display: flex; justify-content: center; } - - li.setview { - background-color: aliceblue; - margin: auto 30px auto 30px; - list-style: none; - border-radius: 10px; - padding: 10px 20px; - } diff --git a/calbridgesensors/templates/sensors/detail.html b/calbridgesensors/templates/sensors/detail.html index b65a6cb..1456a7e 100644 --- a/calbridgesensors/templates/sensors/detail.html +++ b/calbridgesensors/templates/sensors/detail.html @@ -1,2 +1,58 @@ {% extends 'base.html' %} +{% block content %} +
      +
    • Bridge Name
    • +
    • Bridge reading x
    • +
    • Bridge reading y
    • +
    • Broken Record
    • +
    • Repair Record
    • +
    +
    +
      +
    • {{ bridge.name }}
    • + {% if reading %} +
    • {{ reading.x }}
    • +
    • {{ reading.y }}
    • + {% else %} +
    • {{ 0.0 }}
    • +
    • {{ 0.0 }}
    • + {% endif %} + + {% if damage_recs %} + + {% else %} +
    • No Damages
    • + {% endif %} + + {% if repair_recs %} + + {% else %} +
    • No Repairs
    • + {% endif %} +
    +{% endblock %} \ No newline at end of file diff --git a/calbridgesensors/templates/sensors/index.html b/calbridgesensors/templates/sensors/index.html index 2275dc4..d99b195 100644 --- a/calbridgesensors/templates/sensors/index.html +++ b/calbridgesensors/templates/sensors/index.html @@ -4,9 +4,10 @@ {% block alert %}
    {% if broken_bridges %} +

    Bridge In Danger!

    {% for bb in broken_bridges %} -
  • bb.bridge
  • -
  • bb.broken_time
  • +
  • {{ bb.bridge }}
  • +
  • Time broken: {{ bb.broken_time }}
  • {% endfor %} {% else %}

    All Bridges Are Healthy

    @@ -18,6 +19,7 @@

    All Bridges Are Healthy