def getFingerValues(self, finger, countoflines, blona): fingerlenghts = [] top = finger.toppoint down = finger.halfpoint rightfingercontour = v2.getPartOfContour(self.contourmap[finger.rightpoint], self.contourmap[finger.toppoint], self.contour) leftfingercontour = v2.getPartOfContour(self.contourmap[finger.leftpoint], self.contourmap[finger.toppoint], self.contour) if blona: cv.line(self.img, finger.leftpoint, finger.shortestleftpoint, [145,0,255], 5) cv.line(self.img2, finger.leftpoint, finger.shortestleftpoint, [145,0,255], 5) fingerlenghts.append(v2.EuclideanDistance(finger.leftpoint, finger.shortestleftpoint)) cv.line(self.img, top, down, [255,0,0], 5) cv.line(self.img2, top, down, [255,0,0], 5) fingerlenghts.append(v2.EuclideanDistance(top, down)) f = v2.getFunctionFromPoints(top, down) x = self.getPointsOnLine(top,down,f,countoflines,100) for i in x: cv.circle(self.img,i,10,[150,0,0],-1) cv.circle(self.img2,i,10,[150,0,0],-1) rafunc = v2.findRightAngleFunction(f, i) rightpoint, addedr = v2.getPreciseCrossPointFuncionAndContour(rafunc,i,rightfingercontour) leftpoint, addedl = v2.getPreciseCrossPointFuncionAndContour(rafunc,i,leftfingercontour) #cv.circle(self.img,rightpoint,10,[50,0,0],-1) #cv.circle(self.img,leftpoint,10,[200,0,0],-1) cv.line(self.img, rightpoint, leftpoint, [0,150,0], 5) cv.line(self.img2, rightpoint, leftpoint, [0,150,0], 5) cv.line(self.img, addedr, addedl, [0,250,0], 5) cv.line(self.img2, addedr, addedl, [0,250,0], 5) fingerlenghts.append(v2.EuclideanDistance(addedr, addedl)) return fingerlenghts
def findMainDefectsV2(contour, hull, img): defects = [] startpos = hull[0][0] for i in range(1,len(hull)+1): endpos = hull[i%len(hull)][0] hullfunc = v2.getFunctionFromPoints(tuple(contour[startpos][0]),tuple(contour[endpos][0])) partofcontour = v2.getPartOfContour(startpos,endpos,contour) dist, defectpoint = v2.getDistanceBeetwenFunctionAndContour(hullfunc,partofcontour) defects.append([endpos,startpos,mapContour[defectpoint],dist]) cv.circle(img,defectpoint,5,[255,255,255],-1) startpos = endpos maindefects = [] for i in defects: s,e,f,d = i start = tuple(contour[s][0]) end = tuple(contour[e][0]) far = tuple(contour[f][0]) #print(d) if d > 30 and d < 3000 and v2.EuclideanDistance(start,end) > 50: maindefects = [i] + maindefects #cv.circle(img,start,15,[110,80,240],-1) cv.circle(img,far,30,[0,255,0],-1) #cv.circle(img,end,15,[70,50,190],-1) if v2.EuclideanDistance(start,end) > 50: cv.circle(img,start,15,[110,80,240],-1) #cv.circle(img,far,30,[0,255,0],-1) cv.circle(img,end,15,[70,50,190],-1) #print("maindefects",maindefects) return maindefects