Update app.py
Browse files
app.py
CHANGED
|
@@ -978,7 +978,7 @@ def createGoogleSheet():
|
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
-
def legendGoogleSheets(path,SimilarAreaDictionary,colorsUsed
|
| 982 |
|
| 983 |
########
|
| 984 |
# legendTitle=getTitle(path)
|
|
@@ -1081,10 +1081,10 @@ def legendGoogleSheets(path,SimilarAreaDictionary,colorsUsed,spreadsheetId,sprea
|
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
-
def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag
|
| 1085 |
|
| 1086 |
imgPerimeter1,image_new1,Df2,colorsUsed=drawAllContours(plan,green2,img,number,finalColorArray,num1,num2,flag)
|
| 1087 |
-
gc,spreadsheet_service,spreadsheetId ,spreadsheet_url =legendGoogleSheets(plan,Df2,colorsUsed
|
| 1088 |
# x = path.split("/")
|
| 1089 |
# x=x.pop()
|
| 1090 |
Df2=Df2.T
|
|
@@ -1106,7 +1106,7 @@ def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag,spreadshee
|
|
| 1106 |
|
| 1107 |
return Df2, imgPerimeter1,image_new1 , spreadsheet_url
|
| 1108 |
|
| 1109 |
-
def PickColorContours(
|
| 1110 |
print(type(img))
|
| 1111 |
green2=allpreSteps(img)
|
| 1112 |
|
|
@@ -1137,15 +1137,15 @@ def PickColorContours(spreadsheetId,spreadsheet_service,gc,plan,dp,img,radioButt
|
|
| 1137 |
else:
|
| 1138 |
if radioButton=="Measure Full Image":
|
| 1139 |
if radioButton1=='Area':
|
| 1140 |
-
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url =MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'area'
|
| 1141 |
else:
|
| 1142 |
-
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'perimeter'
|
| 1143 |
|
| 1144 |
else:
|
| 1145 |
if radioButton1=='Area':
|
| 1146 |
-
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'area'
|
| 1147 |
else:
|
| 1148 |
-
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'perimeter'
|
| 1149 |
|
| 1150 |
Dictionary=Dictionary.T
|
| 1151 |
# s=s.to_html()
|
|
@@ -1156,7 +1156,7 @@ def PickColorContours(spreadsheetId,spreadsheet_service,gc,plan,dp,img,radioButt
|
|
| 1156 |
return imgPerimeter1,Dictionary ,spreadsheet_url
|
| 1157 |
|
| 1158 |
''' General measurement function'''
|
| 1159 |
-
def getMeasurement(
|
| 1160 |
|
| 1161 |
if plan==None:
|
| 1162 |
area,perim,df=None,None,None
|
|
@@ -1175,7 +1175,7 @@ def getMeasurement(spreadsheetId,spreadsheet_service,gc,plan,SaveOP,check1, dp,i
|
|
| 1175 |
|
| 1176 |
|
| 1177 |
if num1!=0 and num2!=0:
|
| 1178 |
-
imgPerimeter1,Dictionary , spreadsheet_url = PickColorContours(
|
| 1179 |
imgPerimeter1= cv2.cvtColor(imgPerimeter1, cv2.COLOR_RGB2BGR)
|
| 1180 |
if SaveOP:
|
| 1181 |
pushToDropbox(plan,imgPerimeter1,Dictionary)
|
|
@@ -1183,7 +1183,7 @@ def getMeasurement(spreadsheetId,spreadsheet_service,gc,plan,SaveOP,check1, dp,i
|
|
| 1183 |
exportToExcel(plan,Dictionary)
|
| 1184 |
return imgPerimeter1,Dictionary
|
| 1185 |
else:
|
| 1186 |
-
area=PickColorContours(
|
| 1187 |
area = cv2.cvtColor(area, cv2.COLOR_BGR2RGB)
|
| 1188 |
# if SaveOP:
|
| 1189 |
# pushToDropbox(plan, area)
|
|
@@ -1293,13 +1293,13 @@ with gr.Blocks(css="#search {background: orangered}") as mainBlock:
|
|
| 1293 |
buttonSaveDf=gr.Button("Save dataframe")
|
| 1294 |
|
| 1295 |
# getMeasurement(plan,SaveOP) #drop, check
|
| 1296 |
-
show_button.click(fn=getMeasurement, inputs=[
|
| 1297 |
buttonSaveDf.click(fn=saveExcel,inputs=[out2,project])
|
| 1298 |
# clr_btn.click(fn=clear,outputs=[project,radio_button,check,drop])
|
| 1299 |
# btn1.click(fn=PickColorContours, inputs=[dp,in1,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11], outputs=out1)
|
| 1300 |
#secoond part
|
| 1301 |
# btn.click(fn=PickColorContours, inputs=[dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,num1,num2], outputs=outputs1)
|
| 1302 |
-
btn.click(fn=getMeasurement, inputs=[
|
| 1303 |
project.change(fn=update_dropdown, inputs=[project], outputs=drop)
|
| 1304 |
|
| 1305 |
mainBlock.launch(debug=True,enable_queue=True)
|
|
|
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
+
def legendGoogleSheets(path,SimilarAreaDictionary,colorsUsed):
|
| 982 |
|
| 983 |
########
|
| 984 |
# legendTitle=getTitle(path)
|
|
|
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
+
def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag):
|
| 1085 |
|
| 1086 |
imgPerimeter1,image_new1,Df2,colorsUsed=drawAllContours(plan,green2,img,number,finalColorArray,num1,num2,flag)
|
| 1087 |
+
gc,spreadsheet_service,spreadsheetId ,spreadsheet_url =legendGoogleSheets(plan,Df2,colorsUsed)
|
| 1088 |
# x = path.split("/")
|
| 1089 |
# x=x.pop()
|
| 1090 |
Df2=Df2.T
|
|
|
|
| 1106 |
|
| 1107 |
return Df2, imgPerimeter1,image_new1 , spreadsheet_url
|
| 1108 |
|
| 1109 |
+
def PickColorContours(plan,dp,img,radioButton,radioButton1, color,color1,color2,color3,color4,color5,color6,color7,color8,num1=0,num2=0):
|
| 1110 |
print(type(img))
|
| 1111 |
green2=allpreSteps(img)
|
| 1112 |
|
|
|
|
| 1137 |
else:
|
| 1138 |
if radioButton=="Measure Full Image":
|
| 1139 |
if radioButton1=='Area':
|
| 1140 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url =MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'area')
|
| 1141 |
else:
|
| 1142 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'perimeter')
|
| 1143 |
|
| 1144 |
else:
|
| 1145 |
if radioButton1=='Area':
|
| 1146 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'area')
|
| 1147 |
else:
|
| 1148 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'perimeter')
|
| 1149 |
|
| 1150 |
Dictionary=Dictionary.T
|
| 1151 |
# s=s.to_html()
|
|
|
|
| 1156 |
return imgPerimeter1,Dictionary ,spreadsheet_url
|
| 1157 |
|
| 1158 |
''' General measurement function'''
|
| 1159 |
+
def getMeasurement(plan,SaveOP,check1, dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1=0,num2=0):
|
| 1160 |
|
| 1161 |
if plan==None:
|
| 1162 |
area,perim,df=None,None,None
|
|
|
|
| 1175 |
|
| 1176 |
|
| 1177 |
if num1!=0 and num2!=0:
|
| 1178 |
+
imgPerimeter1,Dictionary , spreadsheet_url = PickColorContours(plan1,dp,img,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1,num2)
|
| 1179 |
imgPerimeter1= cv2.cvtColor(imgPerimeter1, cv2.COLOR_RGB2BGR)
|
| 1180 |
if SaveOP:
|
| 1181 |
pushToDropbox(plan,imgPerimeter1,Dictionary)
|
|
|
|
| 1183 |
exportToExcel(plan,Dictionary)
|
| 1184 |
return imgPerimeter1,Dictionary
|
| 1185 |
else:
|
| 1186 |
+
area=PickColorContours(plan1,dp,img,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12)
|
| 1187 |
area = cv2.cvtColor(area, cv2.COLOR_BGR2RGB)
|
| 1188 |
# if SaveOP:
|
| 1189 |
# pushToDropbox(plan, area)
|
|
|
|
| 1293 |
buttonSaveDf=gr.Button("Save dataframe")
|
| 1294 |
|
| 1295 |
# getMeasurement(plan,SaveOP) #drop, check
|
| 1296 |
+
show_button.click(fn=getMeasurement, inputs=[drop, check ,check1, dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12],outputs=img1)
|
| 1297 |
buttonSaveDf.click(fn=saveExcel,inputs=[out2,project])
|
| 1298 |
# clr_btn.click(fn=clear,outputs=[project,radio_button,check,drop])
|
| 1299 |
# btn1.click(fn=PickColorContours, inputs=[dp,in1,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11], outputs=out1)
|
| 1300 |
#secoond part
|
| 1301 |
# btn.click(fn=PickColorContours, inputs=[dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,num1,num2], outputs=outputs1)
|
| 1302 |
+
btn.click(fn=getMeasurement, inputs=[drop, check,check1 ,dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1,num2],outputs=[out1,out2,out3])
|
| 1303 |
project.change(fn=update_dropdown, inputs=[project], outputs=drop)
|
| 1304 |
|
| 1305 |
mainBlock.launch(debug=True,enable_queue=True)
|