Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
391 changes: 178 additions & 213 deletions .idea/workspace.xml

Large diffs are not rendered by default.

34 changes: 21 additions & 13 deletions Arjun:Josh Sliding window.py
Original file line number Diff line number Diff line change
@@ -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()
63 changes: 63 additions & 0 deletions data-collector.py
Original file line number Diff line number Diff line change
@@ -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"
40 changes: 40 additions & 0 deletions detect.py
Original file line number Diff line number Diff line change
@@ -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)
Binary file added output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions sql1.py
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -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()