Update app.py
Browse files
app.py
CHANGED
|
@@ -604,6 +604,7 @@ def FillDictionary(green2,SimilarAreaDictionary,img,number,num1,num2,flag,finalC
|
|
| 604 |
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]]
|
| 605 |
print(colorRanges[0])
|
| 606 |
print(colorRanges[0][0],colorRanges[0][1], colorRanges[0][2])
|
|
|
|
| 607 |
for i in range(len(areas_Perimeters)):
|
| 608 |
print(colorRanges)
|
| 609 |
# colorRGB=hexRGB(color)
|
|
@@ -669,15 +670,15 @@ def FillDictionary(green2,SimilarAreaDictionary,img,number,num1,num2,flag,finalC
|
|
| 669 |
# x='#%02x%02x%02x' % (colorRanges[i])
|
| 670 |
# xx='#%02x%02x%02x' % ( colorRanges[i][0] , colorRanges[i][1] , colorRanges[i][2] )
|
| 671 |
# print( xx)
|
| 672 |
-
|
| 673 |
-
s=( SimilarAreaDictionary.style.apply(
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
# '#%02x%02x%02x' % (colorRanges[i])
|
| 678 |
|
| 679 |
|
| 680 |
-
return SimilarAreaDictionary,
|
| 681 |
|
| 682 |
|
| 683 |
|
|
@@ -714,7 +715,7 @@ def drawAllContours(plan,green2,img,number,finalColorArray,num1,num2,flag):
|
|
| 714 |
counter+=1
|
| 715 |
|
| 716 |
contourss,rgbcolor,invertedmask=findContoursFullImage(green2,maskDone,number,finalColorArray,num1,num2,flag,eachcolor)
|
| 717 |
-
SimilarAreaDictionary ,
|
| 718 |
|
| 719 |
a = SimilarAreaDictionary.to_numpy()
|
| 720 |
|
|
@@ -821,7 +822,7 @@ def drawAllContours(plan,green2,img,number,finalColorArray,num1,num2,flag):
|
|
| 821 |
SimilarAreaDictionary= pd.DataFrame(columns=['Rounded','Width','Height','Perimeter','Occurences','Total Perimeter','Color','R','G','B'])
|
| 822 |
contourss=findContoursFullImage(green2,img,number,finalColorArray,num1,num2,flag)
|
| 823 |
|
| 824 |
-
SimilarAreaDictionary ,
|
| 825 |
|
| 826 |
for contour in contourss:
|
| 827 |
|
|
@@ -895,7 +896,7 @@ def drawAllContours(plan,green2,img,number,finalColorArray,num1,num2,flag):
|
|
| 895 |
|
| 896 |
# apdf.write('b.pdf')
|
| 897 |
# annotationsDraw
|
| 898 |
-
return imgPerimeter1,image_new1,SimilarAreaDictionary ,
|
| 899 |
# drawAllContours(img,0,[],1.11,25579,'area') #,[190,47,250] ,[47,251,255] ,[80,240,15],[253,163,40]
|
| 900 |
# imgPerimeter1,image_new1,Dictionary=drawAllContours(img,220,[47,251,255],[251,163,47],1.105,27233.5,'area')
|
| 901 |
###############################################
|
|
@@ -1071,12 +1072,12 @@ def legendGoogleSheets(SimilarAreaDictionary,colorsUsed):
|
|
| 1071 |
print(spreadsheet_url)
|
| 1072 |
|
| 1073 |
return gc,spreadsheet_service,spreadsheetId
|
| 1074 |
-
|
| 1075 |
|
| 1076 |
|
| 1077 |
def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag):
|
| 1078 |
|
| 1079 |
-
imgPerimeter1,image_new1,Df2,
|
| 1080 |
# x = path.split("/")
|
| 1081 |
# x=x.pop()
|
| 1082 |
Df2=Df2.T
|
|
@@ -1095,7 +1096,8 @@ def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag):
|
|
| 1095 |
Df2=Df2.reindex(['MC-Template-Name','Perimeter', 'Occurences', 'Total Perimeter','Color', 'Unit'])
|
| 1096 |
|
| 1097 |
# display(Df2)
|
| 1098 |
-
|
|
|
|
| 1099 |
|
| 1100 |
def PickColorContours(plan,dp,img,radioButton,radioButton1, color,color1,color2,color3,color4,color5,color6,color7,color8,num1=0,num2=0):
|
| 1101 |
print(type(img))
|
|
@@ -1113,30 +1115,30 @@ def PickColorContours(plan,dp,img,radioButton,radioButton1, color,color1,color2,
|
|
| 1113 |
if radioButton=="Measure Full Image" :
|
| 1114 |
|
| 1115 |
if radioButton1=='Area':
|
| 1116 |
-
imgPerimeter1,image_new1,df ,
|
| 1117 |
return image_new1
|
| 1118 |
else:
|
| 1119 |
-
imgPerimeter1,image_new1,df ,
|
| 1120 |
return imgPerimeter1
|
| 1121 |
else:
|
| 1122 |
if radioButton1=='Area':
|
| 1123 |
-
imgPerimeter1,image_new1,df ,
|
| 1124 |
return image_new1
|
| 1125 |
else:
|
| 1126 |
-
imgPerimeter1,image_new1,df ,
|
| 1127 |
return imgPerimeter1
|
| 1128 |
else:
|
| 1129 |
if radioButton=="Measure Full Image":
|
| 1130 |
if radioButton1=='Area':
|
| 1131 |
-
Dictionary, imgPerimeter1,image_new1 ,
|
| 1132 |
else:
|
| 1133 |
-
Dictionary, imgPerimeter1,image_new1 ,
|
| 1134 |
|
| 1135 |
else:
|
| 1136 |
if radioButton1=='Area':
|
| 1137 |
-
Dictionary, imgPerimeter1,image_new1,
|
| 1138 |
else:
|
| 1139 |
-
Dictionary, imgPerimeter1,image_new1,
|
| 1140 |
|
| 1141 |
Dictionary=Dictionary.T
|
| 1142 |
s=s.to_html()
|
|
@@ -1166,13 +1168,13 @@ def getMeasurement(plan,SaveOP,check1, dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,i
|
|
| 1166 |
|
| 1167 |
|
| 1168 |
if num1!=0 and num2!=0:
|
| 1169 |
-
imgPerimeter1,Dictionary ,
|
| 1170 |
imgPerimeter1= cv2.cvtColor(imgPerimeter1, cv2.COLOR_RGB2BGR)
|
| 1171 |
if SaveOP:
|
| 1172 |
pushToDropbox(plan,imgPerimeter1,Dictionary)
|
| 1173 |
if check1:
|
| 1174 |
exportToExcel(plan,Dictionary)
|
| 1175 |
-
return imgPerimeter1,Dictionary ,
|
| 1176 |
else:
|
| 1177 |
area=PickColorContours(plan1,dp,img,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12)
|
| 1178 |
area = cv2.cvtColor(area, cv2.COLOR_BGR2RGB)
|
|
|
|
| 604 |
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]]
|
| 605 |
print(colorRanges[0])
|
| 606 |
print(colorRanges[0][0],colorRanges[0][1], colorRanges[0][2])
|
| 607 |
+
colorsUsed=[]
|
| 608 |
for i in range(len(areas_Perimeters)):
|
| 609 |
print(colorRanges)
|
| 610 |
# colorRGB=hexRGB(color)
|
|
|
|
| 670 |
# x='#%02x%02x%02x' % (colorRanges[i])
|
| 671 |
# xx='#%02x%02x%02x' % ( colorRanges[i][0] , colorRanges[i][1] , colorRanges[i][2] )
|
| 672 |
# print( xx)
|
| 673 |
+
colorsUsed.append(colorRanges[i])
|
| 674 |
+
# s=( SimilarAreaDictionary.style.apply(
|
| 675 |
+
# lambda col: ['background-color: %s' % ('#%02x%02x%02x' % ( colorRanges[i][0] , colorRanges[i][1] , colorRanges[i][2] )) for i in range(len(SimilarAreaDictionary))],
|
| 676 |
+
# subset=['Color']
|
| 677 |
+
# ) )
|
| 678 |
# '#%02x%02x%02x' % (colorRanges[i])
|
| 679 |
|
| 680 |
|
| 681 |
+
return SimilarAreaDictionary, colorsUsed
|
| 682 |
|
| 683 |
|
| 684 |
|
|
|
|
| 715 |
counter+=1
|
| 716 |
|
| 717 |
contourss,rgbcolor,invertedmask=findContoursFullImage(green2,maskDone,number,finalColorArray,num1,num2,flag,eachcolor)
|
| 718 |
+
SimilarAreaDictionary ,colorsUsed= FillDictionary(green2,SimilarAreaDictionary,maskDone,number,num1,num2,flag,finalColorArray,rgbcolor,eachcolor)
|
| 719 |
|
| 720 |
a = SimilarAreaDictionary.to_numpy()
|
| 721 |
|
|
|
|
| 822 |
SimilarAreaDictionary= pd.DataFrame(columns=['Rounded','Width','Height','Perimeter','Occurences','Total Perimeter','Color','R','G','B'])
|
| 823 |
contourss=findContoursFullImage(green2,img,number,finalColorArray,num1,num2,flag)
|
| 824 |
|
| 825 |
+
SimilarAreaDictionary , colorsUsed= FillDictionary(green2,SimilarAreaDictionary,img,number,num1,num2,flag,finalColorArray)
|
| 826 |
|
| 827 |
for contour in contourss:
|
| 828 |
|
|
|
|
| 896 |
|
| 897 |
# apdf.write('b.pdf')
|
| 898 |
# annotationsDraw
|
| 899 |
+
return imgPerimeter1,image_new1,SimilarAreaDictionary , colorsUsed
|
| 900 |
# drawAllContours(img,0,[],1.11,25579,'area') #,[190,47,250] ,[47,251,255] ,[80,240,15],[253,163,40]
|
| 901 |
# imgPerimeter1,image_new1,Dictionary=drawAllContours(img,220,[47,251,255],[251,163,47],1.105,27233.5,'area')
|
| 902 |
###############################################
|
|
|
|
| 1072 |
print(spreadsheet_url)
|
| 1073 |
|
| 1074 |
return gc,spreadsheet_service,spreadsheetId
|
| 1075 |
+
|
| 1076 |
|
| 1077 |
|
| 1078 |
def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag):
|
| 1079 |
|
| 1080 |
+
imgPerimeter1,image_new1,Df2,colorsUsed=drawAllContours(plan,green2,img,number,finalColorArray,num1,num2,flag)
|
| 1081 |
# x = path.split("/")
|
| 1082 |
# x=x.pop()
|
| 1083 |
Df2=Df2.T
|
|
|
|
| 1096 |
Df2=Df2.reindex(['MC-Template-Name','Perimeter', 'Occurences', 'Total Perimeter','Color', 'Unit'])
|
| 1097 |
|
| 1098 |
# display(Df2)
|
| 1099 |
+
gc,spreadsheet_service,spreadsheetId=legendGoogleSheets(Df2,colorsUsed)
|
| 1100 |
+
return Df2, imgPerimeter1,image_new1
|
| 1101 |
|
| 1102 |
def PickColorContours(plan,dp,img,radioButton,radioButton1, color,color1,color2,color3,color4,color5,color6,color7,color8,num1=0,num2=0):
|
| 1103 |
print(type(img))
|
|
|
|
| 1115 |
if radioButton=="Measure Full Image" :
|
| 1116 |
|
| 1117 |
if radioButton1=='Area':
|
| 1118 |
+
imgPerimeter1,image_new1,df ,colorsUsed =drawAllContours(plan,green2,img,0,finalColorArray,num1,num2,'area')
|
| 1119 |
return image_new1
|
| 1120 |
else:
|
| 1121 |
+
imgPerimeter1,image_new1,df ,colorsUsed =drawAllContours(plan,green2,img,0,finalColorArray,num1,num2,'perimeter')
|
| 1122 |
return imgPerimeter1
|
| 1123 |
else:
|
| 1124 |
if radioButton1=='Area':
|
| 1125 |
+
imgPerimeter1,image_new1,df ,colorsUsed =drawAllContours(plan,green2,img,220,finalColorArray,num1,num2,'area') #rgbValue
|
| 1126 |
return image_new1
|
| 1127 |
else:
|
| 1128 |
+
imgPerimeter1,image_new1,df ,colorsUsed =drawAllContours(plan,green2,img,220,finalColorArray,num1,num2,'perimeter') #rgbValue
|
| 1129 |
return imgPerimeter1
|
| 1130 |
else:
|
| 1131 |
if radioButton=="Measure Full Image":
|
| 1132 |
if radioButton1=='Area':
|
| 1133 |
+
Dictionary, imgPerimeter1,image_new1 ,colorsUsed =MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'area')
|
| 1134 |
else:
|
| 1135 |
+
Dictionary, imgPerimeter1,image_new1 ,colorsUsed =MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'perimeter')
|
| 1136 |
|
| 1137 |
else:
|
| 1138 |
if radioButton1=='Area':
|
| 1139 |
+
Dictionary, imgPerimeter1,image_new1,colorsUsed =MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'area')
|
| 1140 |
else:
|
| 1141 |
+
Dictionary, imgPerimeter1,image_new1,colorsUsed =MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'perimeter')
|
| 1142 |
|
| 1143 |
Dictionary=Dictionary.T
|
| 1144 |
s=s.to_html()
|
|
|
|
| 1168 |
|
| 1169 |
|
| 1170 |
if num1!=0 and num2!=0:
|
| 1171 |
+
imgPerimeter1,Dictionary , colorsUsed= PickColorContours(plan1,dp,img,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1,num2)
|
| 1172 |
imgPerimeter1= cv2.cvtColor(imgPerimeter1, cv2.COLOR_RGB2BGR)
|
| 1173 |
if SaveOP:
|
| 1174 |
pushToDropbox(plan,imgPerimeter1,Dictionary)
|
| 1175 |
if check1:
|
| 1176 |
exportToExcel(plan,Dictionary)
|
| 1177 |
+
return imgPerimeter1,Dictionary , colorsUsed
|
| 1178 |
else:
|
| 1179 |
area=PickColorContours(plan1,dp,img,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12)
|
| 1180 |
area = cv2.cvtColor(area, cv2.COLOR_BGR2RGB)
|