Nexclap

Sports Clothing Image Recognition

A project I worked on early last year involved taking an image of sports clothing and matching the image to the actual product on Amazon. It would be cool to see if someone could add extra features to this such that the program could retrieve the product from other clothing sites as well and filter for the cheapest ones. The video shows the current status of the project and the github link is here: https://github.com/akhily1/Sports-Apparel-Matching


Genie Index/Optimal Split (Given a list of possible split values)

This code (without recursion) determines the optimal vertical split for a group of data (list of coordinates titled numbers) that minimizes total variance/Euclidean distance between the data points on either side of the split.

import math numbers = [(1,1), (2,2), (3,3), (4,4), (5,5), (4,3), (4,10), (5,5), (6,2), (1,7), (4,3), (5,8)] xvalues = [] yvalues = [] #create x and y lists for x in numbers: xvalues.append(x[0]) for y in numbers: yvalues.append(y[1]) #sort the values based on x-value relative to split variances = [] for split in range(0,6,1): greaterthanx = [] lessthanx = [] greaterthany = [] lessthany = [] greaterthan = [] lessthan = [] for a in numbers: if a[0] < split: lessthan.append(a) lessthanx.append(a[0]) lessthany.append(a[1]) elif a[0] > split: greaterthan.append(a) greaterthanx.append(a[0]) greaterthany.append(a[1]) #calculate coordinates of centroid if len(greaterthanx)>0: avgx1 = (sum(greaterthanx))/(len(greaterthanx)) avgy1 = (sum(greaterthany))/(len(greaterthany)) else: avgx1 == 0 avgy1 == 0 if len(lessthanx)>0: avgx2 = (sum(lessthanx))/(len(lessthanx)) avgy2 = (sum(lessthany))/(len(lessthany)) else: avgx1 == 0 avgy1 == 0 #calculate Euclidean distances from each point to the centroid, then find variance distancesgreater = [] distancesless = [] for j in greaterthan: x1 = abs(j[0] - avgx1) y1 = abs(j[1] - avgy1) distgreater = math.sqrt((int(x1))^2 + (int(y1))^2) distancesgreater.append(distgreater) distgreater = 0 for k in lessthan: x2 = abs(k[0] - avgx2) y2 = abs(k[1] - avgy2) distless = math.sqrt((int(x2))^2+(int(y2))^2) distancesless.append(distless) distless = 0 variance1 = sum(distancesgreater) variance2 = sum(distancesless) totvariance = variance1 + variance2 variances.append(totvariance) greaterthanx = [] lessthanx = [] greaterthany = [] lessthany = [] greaterthan = [] lessthan = [] minvariance = min(variances) a = variances.index(minvariance) print("Your optimal split occurs at x = " + str(a))

Fractions

this adds,subtracts,multiplies,divides fractions and returns the fraction

class Fraction: '''represents fractions''' def __init__(self,num,denom): self.num=num self.denom=denom '''Fraction(num,denom) -> Fraction creates the fraction object representing num/denom''' if denom == 0: # raise an error if the denominator is zero raise ZeroDivisionError def __str__(self): lst=[] if self.num == 0: return "0" if self.num<0: neg=-self.num for i in range(1,neg+1): if self.num/i==self.num//i and self.denom/i==self.denom//i: lst.append(-1*i) minimum=min(lst) smplfiednum=self.num//minimum smplfieddenom=self.denom//minimum return str(smplfiednum)+'/'+str(smplfieddenom) elif self.num>0: for n in range(1,self.num+1): if self.num/n==self.num//n and self.denom/n==self.denom//n: lst.append(n) maximum=max(lst) smplfiednum=self.num//maximum smplfieddenom=self.denom//maximum return str(smplfiednum)+'/'+str(smplfieddenom) def __float__(self): return self.num/self.denom def add(self, other): newdenom = self.denom*other.denom newnum = (self.num*other.denom)+(other.num*self.denom) #self.denom=newdenom #self.num=newnum return Fraction(newnum, newdenom) def sub(self, other): newdenom = self.denom*other.denom newnum = (self.num*other.denom)-(other.num*self.denom) #self.denom=newdenom #self.num=newnum return Fraction(newnum,newdenom) def mul(self, other): newdenom = self.denom*other.denom newnum = self.num*other.num #self.denom=newdenom #self.num=newnum return Fraction(newnum,newdenom) def div(self, other): newdenom = self.denom*other.num newnum = self.num*other.denom #self.denom=newdenom #self.num=newnum return Fraction(newnum,newdenom) def eq(self,other): if self.denom/other.denom==self.num/other.num: return True else: return False # examples #getting p p = Fraction(3,6) print(p) # should print 1/2 q = Fraction(10,-60) print(q) # should print -1/6 r = Fraction(-24,-48) print(r) # should also print 1/2 x=float(p) print(x) # should print 0.5 ### if implementing "normal" arithmetic methods print(p.add(q)) # should print 1/3, since 1/2 + (-1/6) = 1/3 print(p.sub(q)) # should print 2/3, since 1/2 - (-1/6) = 2/3 print(p.sub(p)) # should print 0/1, since p-p is 0 print(p.mul(q)) # should print -1/12 print(p.div(q)) # should print -3/1 print(p.eq(r)) # should print True print(p.eq(q)) # should print False
Announcements
  • Test Announcement from Nexclap

    Test message from nexclap - please ignore

    2023-02-13

  • Test message

    Test message from nexclap - please ignore

    2023-02-11

  • Test message

    Test message from nexclap - please ignore

    2023-02-11

  • View all