diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b1509c0..ff62e0e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,76 +1,41 @@ + + + + + + + + + + + + + + + + + - - - - + + + - - + - - + + + + - - + + + + + + + + + + + + + + + + + + - + @@ -214,109 +232,56 @@ + + + + + + 1602968734911 + + + 1603573161082 + + + 1604177889397 + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - file://$PROJECT_DIR$/apriltag_test.py - 9 - - - file://$PROJECT_DIR$/video_detect.py - 14 - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + \ No newline at end of file diff --git a/Arjun:Josh Sliding window.py b/Arjun:Josh Sliding window.py index 9e92711..0da3927 100644 --- a/Arjun:Josh Sliding window.py +++ b/Arjun:Josh Sliding window.py @@ -1,30 +1,38 @@ import apriltag import cv2 +import os import numpy as np -#gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) +# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) - # slide a window across the image -def reader(img): - tagList = [] +# slide a window across the image +def reader(detector, img, file_name): + tag_list = [] global img2 for y in range(0, img.shape[0], 350): for x in range(0, img.shape[1], 350): - - result, img2 = detector.detect(img[y:y + 450, x:x + 450], return_image = True) - if ((len(result) != 0) and result not in tagList): - tagList.append(result) - print(result) - cv2.imwrite("output.jpg",img2) + result, img2 = detector.detect(img[y:y + 450, x:x + 450], return_image=True) + if (len(result) != 0) and any(result) not in tag_list: + tag_list.append(result) + print(result) + cv2.imwrite("Outputs/"+file_name+".output.jpg", img2) +def compareTag(apriltag, tagList): + for tag in tagList: + if apriltag["tag_family"] == tag["tag_family"] and apriltag["tag_id"] == tag["tag_id"]: + return True + return False if __name__ == '__main__': cap = cv2.VideoCapture(0) - detector = apriltag.Detector() - img = cv2.imread("data/Track 10-22/90_0.png", cv2.IMREAD_GRAYSCALE) - reader(img) + det = apriltag.Detector() + directory = "data/Track 10-22/" + for file in os.listdir(directory): + print(file) + img = cv2.imread(directory+file, cv2.IMREAD_GRAYSCALE) + reader(det, img, file) cap.release() cv2.destroyAllWindows() diff --git a/data-collector.py b/data-collector.py new file mode 100644 index 0000000..fee6c84 --- /dev/null +++ b/data-collector.py @@ -0,0 +1,63 @@ +import mysql.connector +import datetime +import os +import cv2 +from PIL import Image +from PIL.ExifTags import TAGS, GPSTAGS + + +# insert sighting into sighting table +def insert_sighting(cursor, cnx, turtle_tag_id, latitude, longitude, drone_image, + timestamp): # no sighting_id bc AI field + insert_stmt = ("""INSERT INTO sighting (turtle_tag_id, latitude, longitude, drone_image, timestamp) + VALUES (%s,%s,%s,%s,%s)""") # parameters are always %s + data = (turtle_tag_id, latitude, longitude, drone_image, timestamp) + # update db with new data + cursor.execute(insert_stmt, data) + cnx.commit() + return + + +def get_exif(filename): + exif = Image.open(filename)._getexif() + if exif is not None: + for key, value in exif.items(): + name = TAGS.get(key, key) + exif[name] = exif.pop(key) + print(exif.keys()) + + +def get_timestamp(path): + t = os.path.getmtime(path) + if (t): + return datetime.datetime.fromtimestamp(t) + else: + print("No timestamp available") + return None + + +def load_images_from_folder(folder): + images = [] + for filename in os.listdir(folder): + img = cv2.imread(os.path.join(folder, filename)) + if img is not None: + images.append(img) + return images + + +def connect_to_db(host, user, pw, db): + return mysql.connector.connect(host=host, user=user, password=pw, database=db) + + +if __name__ == '__main__': + # DB credentials + host = "dct-turtle-uav.cojdookdlkis.us-east-1.rds.amazonaws.com" # AWS RDB endpoint + user = "admin" + password = "DukeConservationTech1!" + database = "dct_turtle_uav_db" + + # establish DB connection + # cnx = connect_to_db(host, user, password, database) + + # test get exif + path = "/Users/josephnagy/Desktop/test.jpg" diff --git a/detect.py b/detect.py new file mode 100644 index 0000000..73d3244 --- /dev/null +++ b/detect.py @@ -0,0 +1,40 @@ +import apriltag +import cv2 +import os +import numpy as np + + +# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + + +# slide a window across the image +def reader(detector, img, file_name): + tag_list = [] + global img2 + + for y in range(0, img.shape[0], 350): + for x in range(0, img.shape[1], 350): + result, img2 = detector.detect(img[y:y + 450, x:x + 450], return_image=True) + print(result) + if (len(result) != 0) and all(result) not in tag_list: + tag_list.append(result) + cv2.imwrite("Outputs/"+file_name+".output.jpg", img2) + return tag_list + + +if __name__ == '__main__': +# cap = cv2.VideoCapture(0) + fail = [] + detector = apriltag.Detector() + directory = "data/Track 10-22/" + for f in os.listdir(directory): + file = directory+f + print(file) + img = cv2.imread(file, cv2.IMREAD_GRAYSCALE) + tag_list = reader(detector, img, file) + print(tag_list) + if len(tag_list) == 0: + fail.append(file) + # cap.release() + cv2.destroyAllWindows() + print(fail) diff --git a/output.png b/output.png new file mode 100644 index 0000000..01d944e Binary files /dev/null and b/output.png differ diff --git a/sql1.py b/sql1.py new file mode 100644 index 0000000..372b571 --- /dev/null +++ b/sql1.py @@ -0,0 +1,14 @@ +import mysql.connector + +if __name__ == "__main__": + database = mysql.connector.connect( + host="dct-turtle-uav.cojdookdlkis.us-east-1.rds.amazonaws.com", + user="admin", + password="DukeConservationTech1!" + ) + mycursor = database.cursor() + sqlCommand = "" + value = "" + mycursor.execute(sqlCommand, value) + database.commit() + print(database) \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..e2072f4 --- /dev/null +++ b/test.py @@ -0,0 +1,17 @@ +import cv2 +import apriltag + +if __name__ == '__main__': + cap = cv2.VideoCapture(0) + detector = apriltag.Detector() + directory = "data/Track 10-22/" + file = directory+"30_3.png" + img = cv2.imread(file, cv2.IMREAD_GRAYSCALE) + size = (int(img.shape[1]*0.5), int(img.shape[0]*0.5)) + output = cv2.resize(img, size) + thresh = cv2.adaptiveThreshold(output, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2) + #test, thresh = cv2.threshold(output, 75, 255, cv2.ADAPTIVE_THRESH_MEAN_C) + cv2.imwrite("output_1.png", thresh) + detector.detect(thresh, return_image=True) + cap.release() + cv2.destroyAllWindows() \ No newline at end of file