<jupyter_start><jupyter_text>def open_img(filepath):        img=cv2.imread(filepath)  התמונה    mark=cv2.circle(img, (int(df['x'].iloc[0]),int(df['y'].iloc[0])),10,(0,0,255),5)    mark1=cv2.circle(mark, (int(df['x'].iloc[1]),int(df['y'].iloc[1])),10,(0,0,255),5)    mark2=cv2.circle(mark1, (int(df['x'].iloc[2]),int(df['y'].iloc[2])),10,(0,0,255),5)    mark3=cv2.circle(mark2, (int(df['x'].iloc[3]),int(df['y'].iloc[3])),10,(0,0,255),5)    mark4=cv2.circle(mark3, (int(df['x'].iloc[4]),int(df['y'].iloc[4])),10,(0,0,255),5)    mark5=cv2.circle(mark4, (int(df['x'].iloc[5]),int(df['y'].iloc[5])),10,(0,0,255),5)    resize = ResizeWithAspectRatio(mark5, width=900)  התמונה מוקטנת            cv2.imshow("Image number {}".format(filepath), resize)    cv2.cv2.waitKey(0)  משך זמן הצגת תמונה-0 אין סוף      cv2.destroyAllWindows()<jupyter_code># שלבי פעולה
#1 מגדירים פונקציה שמקטינה תמונה תוך שמירה על הפורפורציות
#2 מגדירים פונקציה שמקבלת שם תמונה ודאטהפריים
# בתוך הפונקציה יש הגדרה של קורדינטות
# קריאה לתמונה ציור מעגלים וקווים ע"פ הקורדינטות
# הקטנת התמונה באופן פורפורצינאלי בעזרת פונקציית ההקטנה שכבר הוגדרה
#1
# פונקציה שמגדירה איך להקטין תמונה תוך שמירה על פורפורציות
def ResizeWithAspectRatio(image, width=None, height=None, inter=cv2.INTER_AREA):
    dim = None
    (h, w) = image.shape[:2]

    if width is None and height is None:
        return image
    if width is None:
        r = height / float(h)
        dim = (int(w * r), height)
    else:
        r = width / float(w)
        dim = (width, int(h * r))

    return cv2.resize(image, dim, interpolation=inter)
def open_img(filepath, df):
    
    snout=(int(df['x'].iloc[0]),int(df['y'].iloc[0]))
    vent=(int(df['x'].iloc[1]),int(df['y'].iloc[1]))
    reye=(int(df['x'].iloc[2]),int(df['y'].iloc[2]))
    leye=(int(df['x'].iloc[3]),int(df['y'].iloc[3]))
    rleg=(int(df['x'].iloc[4]),int(df['y'].iloc[4]))
    lleg=(int(df['x'].iloc[5]),int(df['y'].iloc[5]))

    img=cv2.imread(filepath) # התמונה
    mark=cv2.circle(img, snout,10,(0,0,255),4)
    mark1=cv2.circle(mark, vent,10,(0,0,255),4)
    mark2=cv2.circle(mark1, reye,10,(0,0,255),4)
    mark3=cv2.circle(mark2, leye,10,(0,0,255),4)
    mark4=cv2.circle(mark3, rleg,10,(0,0,255),4)
    mark5=cv2.circle(mark4, lleg,10,(0,0,255),4)
    snout_ventline=cv2.line(mark5, snout, vent, (0,0,255), 3)
    eyeline=cv2.line(mark5, reye, leye, (0,0,255), 3)
    legline=cv2.line(mark5, rleg, lleg, (0,0,255), 3)
    resize = ResizeWithAspectRatio(mark5, width=900) # התמונה מוקטנת
    

    
    cv2.imshow("Image number {}".format(filepath), resize)
    cv2.cv2.waitKey(0) # משך זמן הצגת תמונה-0 אין סוף  
    cv2.destroyAllWindows() # 
# קריאה לפונקציה תוך הזנת שם הקובץ ומאיזה דטאהפריים לקחת אותו
open_img(os.path.join(path,df['frog_id'].iloc[0],df['fig_name'].iloc[0]), df)
# Image directory
directory = r'C:\Users\Chen\Frog ID\frog on prosses'
# Change the current directory 
# to specified directory 
os.chdir(directory)
# saveing the procssed image in the frog on prosses - directory
def save_img(filepath, df):
    
    snout=(int(df['x'].iloc[0]),int(df['y'].iloc[0]))
    vent=(int(df['x'].iloc[1]),int(df['y'].iloc[1]))
    reye=(int(df['x'].iloc[2]),int(df['y'].iloc[2]))
    leye=(int(df['x'].iloc[3]),int(df['y'].iloc[3]))
    rleg=(int(df['x'].iloc[4]),int(df['y'].iloc[4]))
    lleg=(int(df['x'].iloc[5]),int(df['y'].iloc[5]))

    img=cv2.imread(filepath) # התמונה
    mark=cv2.circle(img, snout,10,(0,0,255),4)
    mark1=cv2.circle(mark, vent,10,(0,0,255),4)
    mark2=cv2.circle(mark1, reye,10,(0,0,255),4)
    mark3=cv2.circle(mark2, leye,10,(0,0,255),4)
    mark4=cv2.circle(mark3, rleg,10,(0,0,255),4)
    mark5=cv2.circle(mark4, lleg,10,(0,0,255),4)
    snout_ventline=cv2.line(mark5, snout, vent, (0,0,255), 3)
    eyeline=cv2.line(mark5, reye, leye, (0,0,255), 3)
    legline=cv2.line(mark5, rleg, lleg, (0,0,255), 3)
    resize = ResizeWithAspectRatio(mark5, width=900) # התמונה מוקטנת
    

    
    cv2.imwrite('C:\\Users\\Chen\\Frog ID\\frog on prosses\\f1.jpg', resize)
    
save_img(os.path.join(path,df['frog_id'].iloc[0],df['fig_name'].iloc[0]), df)
# Let's load the image 
image = cv2.imread('C:\\Users\\Chen\\Frog ID\\frog on prosses\\f1.jpg')
cv2.waitKey(0)

# Grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Find Canny edges
edged = cv2.Canny(gray, 30, 200)
cv2.waitKey(0)

# Finding Contours
# Use a copy of the image e.g. edged.0copy()
# since findContours alters the image

cnts, hierarchy = cv2.findContours(edged,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) 
#contours, hierarchy = cv2.findContours(edged,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)


cv2.imshow('Canny Edges After Contouring', edged)
cv2.waitKey(0)

print("Number of Contours found = " + str(len(cnts)))

# Draw all contours
# -1 signifies drawing all contours
cv2.drawContours(image, cnts, -1, (0, 255, 0), 3)

cv2.imshow('Contours', image)
cv2.waitKey(0)
cv2.destroyAllWindows()

import imutils
cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)<jupyter_output><empty_output><jupyter_text>cnts<jupyter_code># find contours in thresholded image, then grab the largest
c = max(cnts, key=cv2.contourArea)
left = tuple(c[c[:, :, 0].argmin()][0])
right = tuple(c[c[:, :, 0].argmax()][0])
top = tuple(c[c[:, :, 1].argmin()][0])
bottom = tuple(c[c[:, :, 1].argmax()][0])
# draw the outline of the object, then draw each of the
# extreme points, where the left-most is red, right-most
# is green, top-most is blue, and bottom-most is teal
cv2.drawContours(image, [c], -1, (0, 255, 255), 2)
cv2.circle(image, left, 8, (0, 0, 255), -1)
cv2.circle(image, right, 8, (0, 255, 0), -1)
cv2.circle(image, top, 8, (255, 0, 0), -1)
cv2.circle(image, bottom, 8, (255, 255, 0), -1)
# show the output image
cv2.imshow("Image", image)
cv2.waitKey(0)
 
smallest = min(cnts, key=lambda x: x[1].any())[0]
smallest

#df = pd.DataFrame.from_records(data)
cnts_df = pd.DataFrame.from_records(cnts)
cnts_df.head(-5)
cnts_df.to_csv('C:\\Users\\Chen\\Frog ID\\Frog data\\cnts_df.csv',index=True)
#https://github.com/jrosebr1/imutils/blob/master/demos/sorting_contours.py
#https://gist.github.com/divyaprabha123/bfa1e44ebdfc6b578fd9715818f07aec
#https://github.com/jrosebr1/imutils
from imutils import contours
cnts= imutils.grab_contours(cnts)

#cnts = imutils.grab_contours(cnts)
def prediction(self, image):
        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        image = cv2.GaussianBlur(image, (21, 21), 0)
        if self.avg is None:
            self.avg = image.copy().astype(float)
        cv2.accumulateWeighted(image, self.avg, 0.5)
        frameDelta = cv2.absdiff(image, cv2.convertScaleAbs(self.avg))
        thresh = cv2.threshold(
                frameDelta, DELTA_THRESH, 255,
                cv2.THRESH_BINARY)[1]
        thresh = cv2.dilate(thresh, None, iterations=2)
        cnts = cv2.findContours(
                thresh.copy(), cv2.RETR_EXTERNAL,
                cv2.CHAIN_APPROX_SIMPLE)
        cnts = imutils.grab_contours(cnts)
        self.avg = image.copy().astype(float)
        return cnts 
0
imutils.contours.sort_contours(contours)
cv2.__version__
df['fig_name'].unique()
df149=df[df['fig_name']=='0000-149.jpg']
open_img(os.path.join(path,df149['frog_id'].iloc[0],df149['fig_name'].iloc[0]), df149)
import math
#A function that measures an angle between 2 lines:

def dot(vA, vB):
    return vA[0]*vB[0]+vA[1]*vB[1]

def ang(lineA, lineB):
    # Get nicer vector form
    vA = [(lineA[0][0]-lineA[1][0]), (lineA[0][1]-lineA[1][1])]
    vB = [(lineB[0][0]-lineB[1][0]), (lineB[0][1]-lineB[1][1])]
    # Get dot prod
    dot_prod = dot(vA, vB)
    # Get magnitudes
    magA = dot(vA, vA)**0.5
    magB = dot(vB, vB)**0.5
    # Get cosine value
    cos_ = dot_prod/magA/magB
    # Get angle in radians and then convert to degrees
    angle = math.acos(dot_prod/magB/magA)
    # Basically doing angle <- angle mod 360
    ang_deg = math.degrees(angle)%360

    if ang_deg-180>=0:
        # As in if statement
        return 360 - ang_deg
    else: 

        return ang_deg
# 6 points are defined :
def comput_ang(df):
#change to float
    snout=(float(df['x'].iloc[0]),float(df['y'].iloc[0]))
    vent=(float(df['x'].iloc[1]),float(df['y'].iloc[1]))
    reye=(float(df['x'].iloc[2]),float(df['y'].iloc[2]))
    leye=(float(df['x'].iloc[3]),float(df['y'].iloc[3]))
    rleg=(float(df['x'].iloc[4]),float(df['y'].iloc[4]))
    lleg=(float(df['x'].iloc[5]),float(df['y'].iloc[5]))

    snout_ventline=(snout, vent)
    eyeline=(reye, leye)
    legline=(rleg, lleg)
    return snout_ventline, eyeline, legline
ventline149, eyeline149, legline149 = comput_ang(df149)
ang(ventline149, eyeline149)
ang(ventline149, legline149)
image=cv2.imread(os.path.join(path,df['frog_id'].iloc[25],df['fig_name'].iloc[25]))
cv2.imwrite()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19521012200632626, 'fraction_numerical': 0.06348847718029824, 'mean_word_length': 4.417992656058751, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '178573', 'license': 'MIT', 'n_tokens_mistral': 4310, 'n_tokens_neox': 4063, 'n_words': 634, 'path': 'Frog marks on image & findcontors.ipynb', 'repo_name': 'wildlifeai/pepeketua_zooniverse', 'size': '8852'}