Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import cv2
import numpy as np
def HoldLister(count, imgLink):
holds = []
for i in range(0,54):
imgLink, count, img = ImageLinkSorter(count, imgLink)
holds.append(cv2.imread(img, cv2.IMREAD_GRAYSCALE))
return holds
def ImageLinkSorter(count, imgLink):
imgLink = list(imgLink)
imgLink = NumRemover(imgLink)
count += 1
imgLink.insert(23, str(count))
img = ""
for i in imgLink:
img += i
return imgLink, count, img
def NumRemover(text):
for i in text:
if i.isdigit():
text.remove(i)
for i in text:
if i.isdigit():
NumChecker(text)
return(text)
def HoldFinder(climbImg, holds, count, imgLink):
validHolds = []
for hold in holds:
result = cv2.matchTemplate(climbImg, hold, cv2.TM_CCOEFF_NORMED)
threshold = 0.9
locations = np.where(result >= threshold)
locations = list(zip(*locations[::-1]))
if locations != []:
imgLink, count, img = ImageLinkSorter(count, imgLink)
validHolds.append(img)
else:
count += 1
for location in locations:
top_left = location
bottom_right = (top_left[0] + hold.shape[1], top_left[1] + hold.shape[0])
cv2.rectangle(climbImg, top_left, bottom_right, (0, 255, 0), 2)
return validHolds
def ImgRecMain(picOfClimb):
climbImg = cv2.imread(picOfClimb, cv2.IMREAD_GRAYSCALE)
holds = HoldLister(0, r"D:\Disso\HoldPics\Hold_0.jpeg")
validHolds = HoldFinder(climbImg, holds, 0, r"D:\Disso\HoldPics\Hold_0.jpeg")#May need to change file path for program to function properly.
#Unhash these lines to display the image with the holds identified to the screen
#cv2.namedWindow("Climbing wall with detected holds", cv2.WINDOW_NORMAL)
#cv2.imshow("Climbing wall with detected holds", climbImg)
#cv2.waitKey(0)
#cv2.destroyAllWindows()
return validHolds
#ImgRecMain(r"D:\Disso\ClimbPics\Climb_26.jpeg")
#ImgRecMain(r"D:\Disso\ClimbPics\Climb_22.jpeg")