Update app.py
Browse files
app.py
CHANGED
|
@@ -590,13 +590,18 @@ def getAreasPerimeter(green2,img,number,num1,num2,flag,finalColorArray,color=[0,
|
|
| 590 |
|
| 591 |
return appended
|
| 592 |
|
|
|
|
| 593 |
def FillDictionary(green2,SimilarAreaDictionary,img,number,num1,num2,flag,finalColorArray,rgbcolor=[0,0,0],color=[0,0,0]):
|
| 594 |
#fills dictionary with key areas and number of occurences
|
| 595 |
print('wttttt')
|
| 596 |
areas_Perimeters=sorted(getAreasPerimeter(green2,img,number,num1,num2,flag,finalColorArray,color) )
|
| 597 |
print(areas_Perimeters)
|
| 598 |
indices=[]
|
|
|
|
|
|
|
|
|
|
| 599 |
for i in range(len(areas_Perimeters)):
|
|
|
|
| 600 |
# colorRGB=hexRGB(color)
|
| 601 |
item1 = areas_Perimeters[i][0]
|
| 602 |
width1 = areas_Perimeters[i][1]
|
|
@@ -609,11 +614,12 @@ def FillDictionary(green2,SimilarAreaDictionary,img,number,num1,num2,flag,finalC
|
|
| 609 |
areaPerimeterMax= round(item1,1) + 0.3
|
| 610 |
# print (areaMin, areaMax)
|
| 611 |
if color != [0,0,0]: #colored images
|
| 612 |
-
mydata=[round(item1,1),width1,height1,0, 1,0,[rgbcolor[0],rgbcolor[1],rgbcolor[2]],
|
| 613 |
-
|
|
|
|
| 614 |
else:
|
| 615 |
# print('??')
|
| 616 |
-
mydata=[round(item1,1),width1,height1,0, 1,0 ,
|
| 617 |
|
| 618 |
# if (( round(item1,1) in SimilarAreaDictionary['Rounded'].values) or (areaMin in SimilarAreaDictionary['Rounded'].values )or (areaMax in SimilarAreaDictionary['Rounded'].values )):
|
| 619 |
|
|
@@ -643,19 +649,28 @@ def FillDictionary(green2,SimilarAreaDictionary,img,number,num1,num2,flag,finalC
|
|
| 643 |
if (SimilarAreaDictionary['Width'].loc[i] <=widthMax and SimilarAreaDictionary['Width'].loc[i] >= widthMin) and (SimilarAreaDictionary['Height'].loc[i] <= heightMax and SimilarAreaDictionary['Height'].loc[i] >= heightMin ) or (SimilarAreaDictionary['Width'].loc[i] <=heightMax and SimilarAreaDictionary['Width'].loc[i] >= heightMin) and (SimilarAreaDictionary['Height'].loc[i] <= widthMax and SimilarAreaDictionary['Height'].loc[i] >= widthMin ) :
|
| 644 |
checkifColorExists=1 #found and incremented
|
| 645 |
SimilarAreaDictionary['Occurences'].loc[i]+=1
|
| 646 |
-
SimilarAreaDictionary['R'].loc[i] =
|
| 647 |
-
SimilarAreaDictionary['G'].loc[i] =
|
| 648 |
-
SimilarAreaDictionary['B'].loc[i] =
|
|
|
|
|
|
|
| 649 |
|
| 650 |
if checkifColorExists==0: #couldnt find the color , doesnt exist so add it
|
| 651 |
SimilarAreaDictionary.loc[len(SimilarAreaDictionary)] =mydata
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 655 |
|
| 656 |
return SimilarAreaDictionary
|
| 657 |
|
| 658 |
|
|
|
|
|
|
|
| 659 |
def drawAllContours(green2,img,number,finalColorArray,num1,num2,flag):
|
| 660 |
# colors=[color,color1,color2,color3,color4,color5,color6,color7]
|
| 661 |
# img=np.array(img)
|
|
@@ -834,7 +849,7 @@ def drawAllContours(green2,img,number,finalColorArray,num1,num2,flag):
|
|
| 834 |
SimilarAreaDictionary['TotalArea'].loc[i]+=areaa
|
| 835 |
SimilarAreaDictionary['Area'].loc[i]=areaa
|
| 836 |
passed=1
|
| 837 |
-
cv2.drawContours(imgArea1, [contour], 0, ( int(SimilarAreaDictionary['B'].loc[i]), int(SimilarAreaDictionary['G'].loc[i]),
|
| 838 |
cv2.putText(imgtransparent1,'Area= '+str(areaa) + ' m', (x+50,y-10) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
| 839 |
cv2.drawContours(imgArea1, [contour], 0, (0, 0, 255), 4)
|
| 840 |
elif flag=='perimeter':
|
|
|
|
| 590 |
|
| 591 |
return appended
|
| 592 |
|
| 593 |
+
|
| 594 |
def FillDictionary(green2,SimilarAreaDictionary,img,number,num1,num2,flag,finalColorArray,rgbcolor=[0,0,0],color=[0,0,0]):
|
| 595 |
#fills dictionary with key areas and number of occurences
|
| 596 |
print('wttttt')
|
| 597 |
areas_Perimeters=sorted(getAreasPerimeter(green2,img,number,num1,num2,flag,finalColorArray,color) )
|
| 598 |
print(areas_Perimeters)
|
| 599 |
indices=[]
|
| 600 |
+
colorRanges=[[255,153,153],[51,255,51],[201,56,147],[255,0,0],[255,0,255],[0,102,204],[102,0,102],[153,0,76],[200,92,135],[52,161,99],[235,250,24],[40,30,170],[98,149,63],[100,30,179],[200,55,67],[150,80,200],[0,102,102],[250,28,191],[101,27,101],[230,150,76],[3,65,127],[114,39,39],[250,36,100],[180,30,40],[10,250,60],[140,30,253],[114,58,245],[47,255,255]]
|
| 601 |
+
print(colorRanges[0])
|
| 602 |
+
print(colorRanges[0][0],colorRanges[0][1], colorRanges[0][2])
|
| 603 |
for i in range(len(areas_Perimeters)):
|
| 604 |
+
print(colorRanges)
|
| 605 |
# colorRGB=hexRGB(color)
|
| 606 |
item1 = areas_Perimeters[i][0]
|
| 607 |
width1 = areas_Perimeters[i][1]
|
|
|
|
| 614 |
areaPerimeterMax= round(item1,1) + 0.3
|
| 615 |
# print (areaMin, areaMax)
|
| 616 |
if color != [0,0,0]: #colored images
|
| 617 |
+
mydata=[round(item1,1),width1,height1,0, 1,0,[rgbcolor[0],rgbcolor[1],rgbcolor[2] ],0,0,0]
|
| 618 |
+
# mydata=[round(item1,1),width1,height1,0, 1,0,[rgbcolor[0],rgbcolor[1],rgbcolor[2] ],colorRanges[0][2],colorRanges[0][1],colorRanges[0][0]]
|
| 619 |
+
# colorRanges.pop(0)
|
| 620 |
else:
|
| 621 |
# print('??')
|
| 622 |
+
mydata=[round(item1,1),width1,height1,0, 1,0 ,0,0,0]
|
| 623 |
|
| 624 |
# if (( round(item1,1) in SimilarAreaDictionary['Rounded'].values) or (areaMin in SimilarAreaDictionary['Rounded'].values )or (areaMax in SimilarAreaDictionary['Rounded'].values )):
|
| 625 |
|
|
|
|
| 649 |
if (SimilarAreaDictionary['Width'].loc[i] <=widthMax and SimilarAreaDictionary['Width'].loc[i] >= widthMin) and (SimilarAreaDictionary['Height'].loc[i] <= heightMax and SimilarAreaDictionary['Height'].loc[i] >= heightMin ) or (SimilarAreaDictionary['Width'].loc[i] <=heightMax and SimilarAreaDictionary['Width'].loc[i] >= heightMin) and (SimilarAreaDictionary['Height'].loc[i] <= widthMax and SimilarAreaDictionary['Height'].loc[i] >= widthMin ) :
|
| 650 |
checkifColorExists=1 #found and incremented
|
| 651 |
SimilarAreaDictionary['Occurences'].loc[i]+=1
|
| 652 |
+
# SimilarAreaDictionary['R'].loc[i] =colorRanges[0][2]
|
| 653 |
+
# SimilarAreaDictionary['G'].loc[i] =colorRanges[0][1]
|
| 654 |
+
# SimilarAreaDictionary['B'].loc[i] = colorRanges[0][0]
|
| 655 |
+
|
| 656 |
+
# colorRanges.pop(0)
|
| 657 |
|
| 658 |
if checkifColorExists==0: #couldnt find the color , doesnt exist so add it
|
| 659 |
SimilarAreaDictionary.loc[len(SimilarAreaDictionary)] =mydata
|
| 660 |
+
|
| 661 |
+
for i in range(len(SimilarAreaDictionary)):
|
| 662 |
+
SimilarAreaDictionary.loc[i, "R"] = colorRanges[i][0]
|
| 663 |
+
SimilarAreaDictionary.loc[i, "G"] = colorRanges[i][1]
|
| 664 |
+
SimilarAreaDictionary.loc[i, "B"] = colorRanges[i][2]
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
|
| 668 |
|
| 669 |
return SimilarAreaDictionary
|
| 670 |
|
| 671 |
|
| 672 |
+
|
| 673 |
+
|
| 674 |
def drawAllContours(green2,img,number,finalColorArray,num1,num2,flag):
|
| 675 |
# colors=[color,color1,color2,color3,color4,color5,color6,color7]
|
| 676 |
# img=np.array(img)
|
|
|
|
| 849 |
SimilarAreaDictionary['TotalArea'].loc[i]+=areaa
|
| 850 |
SimilarAreaDictionary['Area'].loc[i]=areaa
|
| 851 |
passed=1
|
| 852 |
+
cv2.drawContours(imgArea1, [contour], 0, ( int(SimilarAreaDictionary['B'].loc[i]), int(SimilarAreaDictionary['G'].loc[i]), int(SimilarAreaDictionary['R'].loc[i])), -1)
|
| 853 |
cv2.putText(imgtransparent1,'Area= '+str(areaa) + ' m', (x+50,y-10) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
| 854 |
cv2.drawContours(imgArea1, [contour], 0, (0, 0, 255), 4)
|
| 855 |
elif flag=='perimeter':
|