Update app.py
Browse files
app.py
CHANGED
|
@@ -980,7 +980,7 @@ def createGoogleSheet():
|
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
-
def legendGoogleSheets(path,SimilarAreaDictionary,colorsUsed):
|
| 984 |
|
| 985 |
########
|
| 986 |
# legendTitle=getTitle(path)
|
|
@@ -1083,10 +1083,10 @@ def legendGoogleSheets(path,SimilarAreaDictionary,colorsUsed):
|
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
-
def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag):
|
| 1087 |
|
| 1088 |
imgPerimeter1,image_new1,Df2,colorsUsed=drawAllContours(plan,green2,img,number,finalColorArray,num1,num2,flag)
|
| 1089 |
-
gc,spreadsheet_service,spreadsheetId ,spreadsheet_url =legendGoogleSheets(plan,Df2,colorsUsed)
|
| 1090 |
# x = path.split("/")
|
| 1091 |
# x=x.pop()
|
| 1092 |
Df2=Df2.T
|
|
@@ -1108,7 +1108,7 @@ def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag):
|
|
| 1108 |
|
| 1109 |
return Df2, imgPerimeter1,image_new1 , spreadsheet_url
|
| 1110 |
|
| 1111 |
-
def PickColorContours(plan,dp,img,radioButton,radioButton1, color,color1,color2,color3,color4,color5,color6,color7,color8,num1=0,num2=0):
|
| 1112 |
print(type(img))
|
| 1113 |
green2=allpreSteps(img)
|
| 1114 |
|
|
@@ -1139,15 +1139,15 @@ def PickColorContours(plan,dp,img,radioButton,radioButton1, color,color1,color2,
|
|
| 1139 |
else:
|
| 1140 |
if radioButton=="Measure Full Image":
|
| 1141 |
if radioButton1=='Area':
|
| 1142 |
-
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url =MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'area')
|
| 1143 |
else:
|
| 1144 |
-
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'perimeter')
|
| 1145 |
|
| 1146 |
else:
|
| 1147 |
if radioButton1=='Area':
|
| 1148 |
-
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'area')
|
| 1149 |
else:
|
| 1150 |
-
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'perimeter')
|
| 1151 |
|
| 1152 |
Dictionary=Dictionary.T
|
| 1153 |
# s=s.to_html()
|
|
@@ -1159,7 +1159,7 @@ def PickColorContours(plan,dp,img,radioButton,radioButton1, color,color1,color2,
|
|
| 1159 |
|
| 1160 |
''' General measurement function'''
|
| 1161 |
def getMeasurement(plan,SaveOP,check1, dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1=0,num2=0):
|
| 1162 |
-
|
| 1163 |
if plan==None:
|
| 1164 |
area,perim,df=None,None,None
|
| 1165 |
elif 'foundation' in plan:
|
|
@@ -1177,16 +1177,16 @@ def getMeasurement(plan,SaveOP,check1, dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,i
|
|
| 1177 |
|
| 1178 |
|
| 1179 |
if num1!=0 and num2!=0:
|
| 1180 |
-
imgPerimeter1,Dictionary , spreadsheet_url = PickColorContours(plan1,dp,img,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1,num2)
|
| 1181 |
imgPerimeter1= cv2.cvtColor(imgPerimeter1, cv2.COLOR_RGB2BGR)
|
| 1182 |
if SaveOP:
|
| 1183 |
pushToDropbox(plan,imgPerimeter1,Dictionary)
|
| 1184 |
if check1:
|
| 1185 |
exportToExcel(plan,Dictionary)
|
| 1186 |
-
return imgPerimeter1,Dictionary
|
| 1187 |
# return imgPerimeter1,Dictionary , gr.HTML.update( """Click <a href=%s> on this Google Sheet </a> to continue to the Legend.""" %spreadsheet_url)
|
| 1188 |
else:
|
| 1189 |
-
area=PickColorContours(plan1,dp,img,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12)
|
| 1190 |
area = cv2.cvtColor(area, cv2.COLOR_BGR2RGB)
|
| 1191 |
# if SaveOP:
|
| 1192 |
# pushToDropbox(plan, area)
|
|
@@ -1234,8 +1234,8 @@ def saveExcel(Dictionary,plan):
|
|
| 1234 |
# with gr.Accordion("User Guide "):
|
| 1235 |
# gr.Markdown("Please read this before you use this tool. \n Note : The algorithm is based on detecting shapes from the plan. Some shapes such as tables and textboxes containing information about the plan may be seen as a shape and inserted into the algorithm as well. To avoid this, please clean up the plan before you choose to measure it by erasing them or drawing a white rectangle above them using any external tool. \n Please note that the pdfs inserted in this tab should be pile caps only.\n The tool is divided into two main parts:\n * First Part (until the measure button) \n - You will find three dropdowns. Choose the name of the project you want to measure, along with the project part, and the project section. \n - Then choose whether this project contains levels or not. If you wish to measure all of the plan choose Measure full image. If you wish to measure certain regions of the plan or divide the plan into regions please choose Measure Specific regions. \n - If you choose Measure specific regions, please draw shapes around the desired regions on Bluebeam or any external tool before choosing to measure this plan. \n Also, you should insert the colors in rgb format (Red-Green-Blue) of the levels. \n The output of the first part will be in the unit pixels. To convert the measurements into a metric unit. Please refer to the the second part for detailed information. \n * Second part (Unit Conversion - This occurs once only) \n - Choose one of the shapes of the measured plan (preferably the largest shape) and measure it in Bluebeam. \n - In the first field labeled Real value, please enter the value you obtained from the measurement you made on Bluebeam. \n - In the second field labeled Pixel value, enter the pixel value of the same shape in which you measured that is shown in the output of the first part. \n - The unit in which the conversion will be into. \n This creates a ratio so that the conversion would be as accurate as possible. You can think of this as the scale check logic in Bluebeam. \n Outputs:\n The first output is an image of the plan measured and color sorted. \n The second output is a representation of the Legend exported.\n The column named MC-Template Name is empty for you to enter the MC-T name. \n The column named Area is the area measured of one of the shape.\n The column named Occurences is the number of count of this shape - This is just to make sure every shape was seen correctly and thus summed later correctly.\n The column named Total Area contains the summed areas of each shape \n The column named Unit refers to the unit in which the conversion was made to.")
|
| 1236 |
with gr.Blocks(css="#search {background: green}") as mainBlock:
|
| 1237 |
-
spreadsheetId,spreadsheet_service,gc=createGoogleSheet()
|
| 1238 |
-
spreadsheet_url = "https://docs.google.com/spreadsheets/d/%s" % spreadsheetId
|
| 1239 |
with gr.Tab("Main UI"):
|
| 1240 |
with gr.Row():
|
| 1241 |
# with gr.Column():
|
|
@@ -1305,7 +1305,7 @@ with gr.Blocks(css="#search {background: green}") as mainBlock:
|
|
| 1305 |
# btn1.click(fn=PickColorContours, inputs=[dp,in1,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11], outputs=out1)
|
| 1306 |
#secoond part
|
| 1307 |
# btn.click(fn=PickColorContours, inputs=[dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,num1,num2], outputs=outputs1)
|
| 1308 |
-
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])
|
| 1309 |
project.change(fn=update_dropdown, inputs=[project], outputs=drop)
|
| 1310 |
|
| 1311 |
mainBlock.launch(debug=True,enable_queue=True)
|
|
|
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
+
def legendGoogleSheets(path,SimilarAreaDictionary,colorsUsed, spreadsheetId,spreadsheet_service,gc):
|
| 984 |
|
| 985 |
########
|
| 986 |
# legendTitle=getTitle(path)
|
|
|
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
+
def MainFunc( spreadsheetId,spreadsheet_service,gc,plan,green2,img,dp,finalColorArray,number,num1,num2,flag):
|
| 1087 |
|
| 1088 |
imgPerimeter1,image_new1,Df2,colorsUsed=drawAllContours(plan,green2,img,number,finalColorArray,num1,num2,flag)
|
| 1089 |
+
gc,spreadsheet_service,spreadsheetId ,spreadsheet_url =legendGoogleSheets(plan,Df2,colorsUsed, spreadsheetId,spreadsheet_service,gc)
|
| 1090 |
# x = path.split("/")
|
| 1091 |
# x=x.pop()
|
| 1092 |
Df2=Df2.T
|
|
|
|
| 1108 |
|
| 1109 |
return Df2, imgPerimeter1,image_new1 , spreadsheet_url
|
| 1110 |
|
| 1111 |
+
def PickColorContours( spreadsheetId,spreadsheet_service,gc,plan,dp,img,radioButton,radioButton1, color,color1,color2,color3,color4,color5,color6,color7,color8,num1=0,num2=0):
|
| 1112 |
print(type(img))
|
| 1113 |
green2=allpreSteps(img)
|
| 1114 |
|
|
|
|
| 1139 |
else:
|
| 1140 |
if radioButton=="Measure Full Image":
|
| 1141 |
if radioButton1=='Area':
|
| 1142 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url =MainFunc( spreadsheetId,spreadsheet_service,gc,plan,green2,img,dp,finalColorArray,0,num1,num2,'area')
|
| 1143 |
else:
|
| 1144 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc( spreadsheetId,spreadsheet_service,gc,plan,green2,img,dp,finalColorArray,0,num1,num2,'perimeter')
|
| 1145 |
|
| 1146 |
else:
|
| 1147 |
if radioButton1=='Area':
|
| 1148 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc( spreadsheetId,spreadsheet_service,gc,plan,green2,img,dp,finalColorArray,220,num1,num2,'area')
|
| 1149 |
else:
|
| 1150 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc( spreadsheetId,spreadsheet_service,gc,plan,green2,img,dp,finalColorArray,220,num1,num2,'perimeter')
|
| 1151 |
|
| 1152 |
Dictionary=Dictionary.T
|
| 1153 |
# s=s.to_html()
|
|
|
|
| 1159 |
|
| 1160 |
''' General measurement function'''
|
| 1161 |
def getMeasurement(plan,SaveOP,check1, dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1=0,num2=0):
|
| 1162 |
+
spreadsheetId,spreadsheet_service,gc=createGoogleSheet()
|
| 1163 |
if plan==None:
|
| 1164 |
area,perim,df=None,None,None
|
| 1165 |
elif 'foundation' in plan:
|
|
|
|
| 1177 |
|
| 1178 |
|
| 1179 |
if num1!=0 and num2!=0:
|
| 1180 |
+
imgPerimeter1,Dictionary , spreadsheet_url = PickColorContours( spreadsheetId,spreadsheet_service,gc,plan1,dp,img,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1,num2)
|
| 1181 |
imgPerimeter1= cv2.cvtColor(imgPerimeter1, cv2.COLOR_RGB2BGR)
|
| 1182 |
if SaveOP:
|
| 1183 |
pushToDropbox(plan,imgPerimeter1,Dictionary)
|
| 1184 |
if check1:
|
| 1185 |
exportToExcel(plan,Dictionary)
|
| 1186 |
+
return imgPerimeter1,Dictionary , spreadsheet_url
|
| 1187 |
# return imgPerimeter1,Dictionary , gr.HTML.update( """Click <a href=%s> on this Google Sheet </a> to continue to the Legend.""" %spreadsheet_url)
|
| 1188 |
else:
|
| 1189 |
+
area=PickColorContours( spreadsheetId,spreadsheet_service,gc,plan1,dp,img,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12)
|
| 1190 |
area = cv2.cvtColor(area, cv2.COLOR_BGR2RGB)
|
| 1191 |
# if SaveOP:
|
| 1192 |
# pushToDropbox(plan, area)
|
|
|
|
| 1234 |
# with gr.Accordion("User Guide "):
|
| 1235 |
# gr.Markdown("Please read this before you use this tool. \n Note : The algorithm is based on detecting shapes from the plan. Some shapes such as tables and textboxes containing information about the plan may be seen as a shape and inserted into the algorithm as well. To avoid this, please clean up the plan before you choose to measure it by erasing them or drawing a white rectangle above them using any external tool. \n Please note that the pdfs inserted in this tab should be pile caps only.\n The tool is divided into two main parts:\n * First Part (until the measure button) \n - You will find three dropdowns. Choose the name of the project you want to measure, along with the project part, and the project section. \n - Then choose whether this project contains levels or not. If you wish to measure all of the plan choose Measure full image. If you wish to measure certain regions of the plan or divide the plan into regions please choose Measure Specific regions. \n - If you choose Measure specific regions, please draw shapes around the desired regions on Bluebeam or any external tool before choosing to measure this plan. \n Also, you should insert the colors in rgb format (Red-Green-Blue) of the levels. \n The output of the first part will be in the unit pixels. To convert the measurements into a metric unit. Please refer to the the second part for detailed information. \n * Second part (Unit Conversion - This occurs once only) \n - Choose one of the shapes of the measured plan (preferably the largest shape) and measure it in Bluebeam. \n - In the first field labeled Real value, please enter the value you obtained from the measurement you made on Bluebeam. \n - In the second field labeled Pixel value, enter the pixel value of the same shape in which you measured that is shown in the output of the first part. \n - The unit in which the conversion will be into. \n This creates a ratio so that the conversion would be as accurate as possible. You can think of this as the scale check logic in Bluebeam. \n Outputs:\n The first output is an image of the plan measured and color sorted. \n The second output is a representation of the Legend exported.\n The column named MC-Template Name is empty for you to enter the MC-T name. \n The column named Area is the area measured of one of the shape.\n The column named Occurences is the number of count of this shape - This is just to make sure every shape was seen correctly and thus summed later correctly.\n The column named Total Area contains the summed areas of each shape \n The column named Unit refers to the unit in which the conversion was made to.")
|
| 1236 |
with gr.Blocks(css="#search {background: green}") as mainBlock:
|
| 1237 |
+
# spreadsheetId,spreadsheet_service,gc=createGoogleSheet()
|
| 1238 |
+
# spreadsheet_url = "https://docs.google.com/spreadsheets/d/%s" % spreadsheetId
|
| 1239 |
with gr.Tab("Main UI"):
|
| 1240 |
with gr.Row():
|
| 1241 |
# with gr.Column():
|
|
|
|
| 1305 |
# btn1.click(fn=PickColorContours, inputs=[dp,in1,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11], outputs=out1)
|
| 1306 |
#secoond part
|
| 1307 |
# btn.click(fn=PickColorContours, inputs=[dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,num1,num2], outputs=outputs1)
|
| 1308 |
+
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])
|
| 1309 |
project.change(fn=update_dropdown, inputs=[project], outputs=drop)
|
| 1310 |
|
| 1311 |
mainBlock.launch(debug=True,enable_queue=True)
|