Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
34d14de
print test
charlie-killian Mar 27, 2022
0d660cf
test print
charlie-killian Mar 27, 2022
777fccd
new changed
charlie-killian Apr 15, 2022
7fb1dd1
Prints estimated distance from aruco marker
charlie-killian May 1, 2022
8269477
python screenshot for aruco
charlie-killian Aug 12, 2022
96ed55c
8/12/22 update--
charlie-killian Aug 12, 2022
a75da6e
aruce
Adi-M02 Aug 12, 2022
0463947
Merge branch 'aruco' of https://github.com/roboticsatiowa/control-res…
Adi-M02 Aug 12, 2022
3f8bca4
working screenshot
charlie-killian Aug 12, 2022
9af7485
Merge branch 'aruco' of https://github.com/roboticsatiowa/control-res…
charlie-killian Aug 12, 2022
ba7a94f
WORKING!!!
charlie-killian Aug 12, 2022
cdfedc7
working
Adi-M02 Aug 12, 2022
9ad306b
Merge branch 'aruco' of https://github.com/roboticsatiowa/control-res…
Adi-M02 Aug 12, 2022
6b9d66b
clean up
charlie-killian Aug 12, 2022
c758fce
Merge branch 'aruco' of https://github.com/roboticsatiowa/control-res…
charlie-killian Aug 12, 2022
8683221
working
Adi-M02 Aug 12, 2022
78f6314
Merge branch 'aruco' of https://github.com/roboticsatiowa/control-res…
Adi-M02 Aug 12, 2022
13f537e
semi working screen recording
Adi-M02 Aug 12, 2022
dd3142a
working screen record(not polished)
Adi-M02 Aug 12, 2022
5dc3704
basestation aruco working
Aug 13, 2022
52e9005
test
charlie-killian Sep 16, 2022
059b4e8
test
charlie-killian Aug 18, 2023
49bf026
Delete ..screenshot2022-0812_10-50-02-108548.png-TVGc
charlie-killian Aug 18, 2023
b000858
cleanup
charlie-killian Aug 20, 2023
82af71b
more cleanup
charlie-killian Aug 20, 2023
2398cc6
more cleanup
charlie-killian Aug 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/control-research.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Recording.avi
Binary file not shown.
Binary file added Recording.mov
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import cv2
import mediapipe as mp
import time

cap = cv2.VideoCapture(0) #main videp camera

# https://google.github.io/mediapipe/solutions/hands.html
# Database of manually annotated pictures of hands and has inbuilt functions

mpHands = mp.solutions.hands
hands = mpHands.Hands()
mpDraw = mp.solutions.drawing_utils

pTime = 0
cTime = 0

while True:
success, img = cap.read()

imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = hands.process(imgRGB)
# print(results.multi_hand_landmarks)

if results.multi_hand_landmarks:
for handLms in results.multi_hand_landmarks:
mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS)

cTime = time.time()
fps = 1/(cTime - pTime)
pTime = cTime

cv2.putText(img,str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3, (255, 0, 255), 3)

# 20:00 in video "Advanced Computer Vision with Python"

cv2.imshow("Image", img)
cv2.waitKey(1)
1 change: 1 addition & 0 deletions aruco_marker_detection/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ def identify_markers():
if __name__ == "__main__":
generate_markers()
identify_markers()
print('test')
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added aruco_marker_detection/positioning/IMG_0064.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions aruco_marker_detection/positioning/aruco_2023.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import os
import sys
import cv2
import numpy as np

print("OpenCV version:", cv2.__version__)
print("Current working directory:", os.getcwd())
print(sys.executable)
# conda: /Users/charliekillian/anaconda3/bin/python



class Aruco():
def __init__(self, camera_calibration_parameters, dict):
self.cv_file = cv2.FileStorage(camera_calibration_parameters, cv2.FILE_STORAGE_READ)
self.mtx = self.cv_file.getNode('K').mat()
self.dist = self.cv_file.getNode('D').mat()
self.cv_file.release()
self.aruco_dictionary = cv2.aruco.getPredefinedDictionary(dict)
self.aruco_parameters = cv2.aruco.DetectorParameters()

def get_aruco_dictionary(self, dict):
return cv2.aruco.Dictionary_get(dict)

def detect(self, frame):
# (corners, marker_ids, rejected) = cv2.aruco.detectMarkers(
# frame, self.aruco_dictionary, parameters=self.aruco_parameters,
# cameraMatrix=self.mtx, distCoefs=self.dist)

corners, marker_ids, rejected = cv2.aruco.detectMarkers(frame, self.aruco_dictionary, parameters=self.aruco_parameters)

if corners:
aruco_perimeter = cv2.arcLength(corners[0][0], True) #added 4-28-22 by CK
print("ARC LENGTH: ", aruco_perimeter)
print("Corners: ", corners)
# calculate_distance(aruco_perimeter, 12)
focal_length = 12
pixel_height = aruco_perimeter
distance_mm = (focal_length * 50 * 1080) / (pixel_height*11)
distance_cm = distance_mm / 10
print("Distance: ", distance_cm)

if marker_ids is not None:

# Draw a square around detected markers in the video frame

cv2.aruco.drawDetectedMarkers(frame, corners, marker_ids)
print("Marker ID: ", marker_ids)

# Get the rotation and translation vectors
# print('test1')
rvecs, tvecs, obj_points = cv2.aruco.estimatePoseSingleMarkers(
corners,
self.aruco_marker_side_length,
self.mtx,
self.dist)


def start_webcam(self):
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if ret:
frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
self.detect(frame) # Call the detect method here
cv2.imshow('Input', frame)

c = cv2.waitKey(1)
if c == 27:
break

cap.release()
cv2.destroyAllWindows()

if __name__ == '__main__':
dict = cv2.aruco.DICT_4X4_50
# calibration_parameters_path = 'calibration_chessboard.yaml'
calibration_parameters_path = 'calibration_chessboard.yaml'

arUco = Aruco(calibration_parameters_path, dict)
arUco.start_webcam()

155 changes: 155 additions & 0 deletions aruco_marker_detection/positioning/aruco_id_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
from __future__ import print_function # Python 2/3 compatibility
import cv2 # Import the OpenCV library
import numpy as np # Import Numpy library
import pathlib
import os
from datetime import datetime
# from scipy.spatial.transform import Rotation as R
# import math # Math library
# from argparse import ArgumentParser #added by CK by 4-28-22 while debugging 'argparse not defined'
import pyautogui
# Side length of the ArUco marker in meters
now = datetime.now()
currentTime = now.strftime("%D:%H:%M,%S")
print(currentTime)
new_dir = pathlib.Path("aruco_images" + currentTime)
new_dir.mkdir(parents = True, exist_ok = True)
aruco_dictionary_name = "DICT_ARUCO_ORIGINAL"
ARUCO_DICT = {
"DICT_4X4_50": cv2.aruco.DICT_4X4_50
}
aruco_marker_side_length = 0.0500

# Calibration parameters yaml file
camera_calibration_parameters_filename = 'calibration_chessboard.yaml'

def main():

#Setting up screen recording

# Specify resolution
resolution = tuple(pyautogui.size())

# Specify video codec
codec = cv2.VideoWriter_fourcc(*"XVID")

#1 Specify name of Output file
#2 #filename = "Recording.mov"

#3 Specify frames rate. We can choose any
#4 value and experiment with it
fps = 1


#8 Creating a VideoWriter object
#9 # out = cv2.VideoWriter(filename, codec, fps, resolution)

#11 Create an Empty window
#cv2.namedWindow("Live", cv2.WINDOW_NORMAL)

#13 Resize this window
# cv2.resizeWindow("Live", 480, 270)
cv_file = cv2.FileStorage(
camera_calibration_parameters_filename, cv2.FILE_STORAGE_READ)
mtx = cv_file.getNode('K').mat()
dst = cv_file.getNode('D').mat()
this_aruco_dictionary = cv2.aruco.Dictionary_get(ARUCO_DICT["DICT_4X4_50"]) # Changed to working dictionary, formerly aruco_dictionary_name
this_aruco_parameters = cv2.aruco.DetectorParameters_create()

while True:
# Take screenshot using PyAutoGUI
img = pyautogui.screenshot()

# Convert the screenshot to a numpy array
frame = np.array(img)

# Convert it from BGR(Blue, Green, Red) to
# RGB(Red, Green, Blue)

frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
(corners, marker_ids, rejected) = cv2.aruco.detectMarkers(
frame, this_aruco_dictionary, parameters=this_aruco_parameters)


if marker_ids is not None:

print("Marker ID: ", str(marker_ids[0][0]))
path = "aruco_images" + currentTime
cv2.imwrite(os.path.join(path, "Marker_ID_"+str(marker_ids[0][0])+".jpg"), frame)

else:
print(marker_ids)
continue
marker_ids = None
# Write it to the output file
#out.write(frame)

# Optional: Display the recording screen
#cv2.imshow('Live', frame)

# Stop recording when we press 'q'
if cv2.waitKey(1) == ord('q'):
break

# Release the Video writer
out.release()

# Destroy all windows
cv2.destroyAllWindows()
"""
Main method of the program.
"""
# Check that we have a valid ArUco marker
# if ARUCO_DICT.get(aruco_dictionary_name, None) is None:
# print("[INFO] ArUCo tag of '{}' is not supported".format(
# args["type"]))
# sys.exit(0)

# Load the camera parameters from the saved file
'''
cv_file = cv2.FileStorage(
camera_calibration_parameters_filename, cv2.FILE_STORAGE_READ)
mtx = cv_file.getNode('K').mat()
dst = cv_file.getNode('D').mat()
cv_file.release()

# Load the ArUco dictionary
print("[INFO] detecting '{}' markers...".format(
'DICT_4x4_50'))
this_aruco_dictionary = cv2.aruco.Dictionary_get(ARUCO_DICT["DICT_4X4_50"]) # Changed to working dictionary, formerly aruco_dictionary_name
this_aruco_parameters = cv2.aruco.DetectorParameters_create()

# Start the video stream
cap = cv2.VideoCapture(0)

while(True):

# Capture frame-by-frame
# This method returns True/False as well
# as the video frame.
ret, frame = cap.read()

# Detect ArUco markers in the video frame
(corners, marker_ids, rejected) = cv2.aruco.detectMarkers(
frame, this_aruco_dictionary, parameters=this_aruco_parameters,
cameraMatrix=mtx, distCoeff=dst)


# Check that at least one ArUco marker was detected
if marker_ids is not None:
print("Marker ID: ", marker_ids)

# Display the resulting frame
#cv2.imshow('frame',frame)

screenshot(marker_ids)
'''






if __name__ == '__main__':
print(__doc__)
main()
Loading