Spaces:
Sleeping
Sleeping
Update pilecaps_adr.py
Browse files- pilecaps_adr.py +89 -45
pilecaps_adr.py
CHANGED
|
@@ -18,6 +18,7 @@ import cv2
|
|
| 18 |
from matplotlib import pyplot as plt
|
| 19 |
#from pdf2image import convert_from_path
|
| 20 |
import math
|
|
|
|
| 21 |
import pandas as pd
|
| 22 |
import random
|
| 23 |
# import imutils
|
|
@@ -292,8 +293,7 @@ def DetectColor(img,color=0):
|
|
| 292 |
|
| 293 |
detectedColors=cv2.cvtColor(detectedColors,cv2.COLOR_HSV2BGR)
|
| 294 |
detectedColors=cv2.medianBlur(detectedColors,7)
|
| 295 |
-
|
| 296 |
-
|
| 297 |
return mask, detectedColors, color
|
| 298 |
|
| 299 |
|
|
@@ -487,7 +487,7 @@ def findContoursFullImage(green2,img,number,finalColorArray,ratioarea,ratioperim
|
|
| 487 |
return contourss
|
| 488 |
else:
|
| 489 |
mask, detectedColors, rgbcolor =DetectColor(img,color)
|
| 490 |
-
print(rgbcolor)
|
| 491 |
|
| 492 |
pil_image=Image.fromarray(mask)
|
| 493 |
|
|
@@ -547,7 +547,6 @@ def getAreasPerimeter(green2,img,number,ratioarea,ratioperim,flag,finalColorArra
|
|
| 547 |
perimeter1 = cv2.arcLength(approx, True)
|
| 548 |
# approx = cv2.approxPolyDP(contourss[contour][0], 0.01* perimeter, True)
|
| 549 |
# area1 = cv2.contourArea(approx)
|
| 550 |
-
|
| 551 |
x, y , width, height = cv2.boundingRect(contourss[contour][0])
|
| 552 |
|
| 553 |
angleR,widthR ,heightR= StraightenImage(contourss[contour][0],img)
|
|
@@ -561,7 +560,7 @@ def getAreasPerimeter(green2,img,number,ratioarea,ratioperim,flag,finalColorArra
|
|
| 561 |
# print('numss')
|
| 562 |
# if flag=='area':
|
| 563 |
# addedMargin=area1+perimeter1*2
|
| 564 |
-
areaa=round(area1* ratioarea ,
|
| 565 |
appended.append([areaa,width,height])
|
| 566 |
|
| 567 |
#else:
|
|
@@ -573,13 +572,14 @@ def getAreasPerimeter(green2,img,number,ratioarea,ratioperim,flag,finalColorArra
|
|
| 573 |
|
| 574 |
def FillDictionary(green2,SimilarAreaDictionary,img,number,ratioarea,ratioperim,flag,finalColorArray,rgbcolor=[0,0,0],color=[0,0,0]):
|
| 575 |
#fills dictionary with key areas and number of occurences
|
| 576 |
-
print('wttttt')
|
| 577 |
areas_Perimeters=sorted(getAreasPerimeter(green2,img,number,ratioarea,ratioperim,flag,finalColorArray,color) )
|
| 578 |
|
| 579 |
indices=[]
|
| 580 |
-
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],[18,236,206],[225,105,29],[189,65,121],[206,204,48],[126,7,247],[3,168,251]]
|
| 581 |
-
|
| 582 |
-
|
|
|
|
|
|
|
| 583 |
colorsUsed=[]
|
| 584 |
for i in range(len(areas_Perimeters)):
|
| 585 |
|
|
@@ -641,21 +641,54 @@ def FillDictionary(green2,SimilarAreaDictionary,img,number,ratioarea,ratioperim,
|
|
| 641 |
SimilarAreaDictionary.loc[len(SimilarAreaDictionary)] =mydata
|
| 642 |
# s= SimilarAreaDictionary
|
| 643 |
for i in range(len(SimilarAreaDictionary)):
|
| 644 |
-
SimilarAreaDictionary['
|
| 645 |
SimilarAreaDictionary['G'].loc[i] =colorRanges[i][1]
|
| 646 |
-
SimilarAreaDictionary['
|
| 647 |
colorsUsed.append(colorRanges[i])
|
| 648 |
|
| 649 |
|
| 650 |
return SimilarAreaDictionary, colorsUsed , areas_Perimeters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 651 |
def drawAllContours(img,number,finalColorArray,ratioarea,ratioperim,flag , path,pdfpath):
|
| 652 |
green2=allpreSteps(img)
|
| 653 |
doc = fitz.open('dropbox_plans/1.0/'+path)
|
| 654 |
-
page = doc[0]
|
| 655 |
-
page.set_rotation(
|
| 656 |
pix=page.get_pixmap()
|
| 657 |
-
|
| 658 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 659 |
areasinImage=[]
|
| 660 |
totaldf=pd.DataFrame()
|
| 661 |
imgArea1= img.copy()
|
|
@@ -709,7 +742,7 @@ def drawAllContours(img,number,finalColorArray,ratioarea,ratioperim,flag , path,
|
|
| 709 |
|
| 710 |
box = cv2.boxPoints(rect)
|
| 711 |
box = box.astype('int')
|
| 712 |
-
print(box)
|
| 713 |
|
| 714 |
x, y , width, height = cv2.boundingRect(contourss[contour][0])
|
| 715 |
perimeter = cv2.arcLength(contourss[contour][0], True)
|
|
@@ -728,7 +761,7 @@ def drawAllContours(img,number,finalColorArray,ratioarea,ratioperim,flag , path,
|
|
| 728 |
allpoints.append(shape)
|
| 729 |
# print(x,y,width,height)
|
| 730 |
# print(allpoints)
|
| 731 |
-
print(shape)
|
| 732 |
if (angleR != 90.0 and angleR != -90.0 and angleR != 0.0 and angleR != -0.0 ): #inclined b ay degree
|
| 733 |
width=widthR
|
| 734 |
height=heightR
|
|
@@ -778,6 +811,7 @@ def drawAllContours(img,number,finalColorArray,ratioarea,ratioperim,flag , path,
|
|
| 778 |
# print(index)
|
| 779 |
# cv2.drawContours(imgArea1, [contour], 0, (int(rgbcolor[2]), int(rgbcolor[1]), int(rgbcolor[0])), -1)
|
| 780 |
cv2.drawContours(imgArea1, [contourss[contour][0]], 0, ( int(SimilarAreaDictionary['B'].loc[i]), int(SimilarAreaDictionary['G'].loc[i]), int(SimilarAreaDictionary['R'].loc[i])), -1)
|
|
|
|
| 781 |
annot = page.add_polygon_annot( points=shape ) # 'Polygon'
|
| 782 |
annot.set_border(width=0.3, dashes=[2])
|
| 783 |
annot.set_colors( fill=( int(SimilarAreaDictionary['R'].loc[i])/255 , int(SimilarAreaDictionary['G'].loc[i])/255 , int(SimilarAreaDictionary['B'].loc[i])/255 ) )
|
|
@@ -786,6 +820,7 @@ def drawAllContours(img,number,finalColorArray,ratioarea,ratioperim,flag , path,
|
|
| 786 |
annot.set_info(content='Area='+str(areaa)+' m2' +'\n \nPerimeter='+str(perimeterr)+' m',subject='ADR Team')#,title='uuum')
|
| 787 |
# annot.set_line_ends(fitz.PDF_ANNOT_LE_DIAMOND, fitz.PDF_ANNOT_LE_CIRCLE)
|
| 788 |
annot.update()
|
|
|
|
| 789 |
cv2.putText(imgtransparent1,'Area= '+str(area1) , (x+50,y-10) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
| 790 |
# cv2.putText(imgtransparent1,'Width= '+str(width) , (x+50,y-10) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
| 791 |
# cv2.putText(imgtransparent1,'Length= '+str(height) , (x+50,y-20) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
|
@@ -795,10 +830,10 @@ def drawAllContours(img,number,finalColorArray,ratioarea,ratioperim,flag , path,
|
|
| 795 |
cv2.putText(imgPerimeter1,'Area: '+str(areaa)+' m2', (x+50,y-40) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
| 796 |
|
| 797 |
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
|
| 803 |
print(SimilarAreaDictionary)
|
| 804 |
# display(totaldf)
|
|
@@ -821,14 +856,20 @@ def drawAllContours(img,number,finalColorArray,ratioarea,ratioperim,flag , path,
|
|
| 821 |
x, y , width, height = cv2.boundingRect(contourss[contour][0])
|
| 822 |
# approxo = cv2.approxPolyDP(contourss[contour],0.1*cv2.arcLength(contourss[contour],True),True)
|
| 823 |
# approx = cv2.approxPolyDP(contourss[contour][0], 0.005 * perimeter, True)
|
| 824 |
-
|
| 825 |
-
area1 = cv2.contourArea(
|
| 826 |
approx = cv2.approxPolyDP(contourss[contour][0], 0.01 * perimeter, True) #0.0009
|
| 827 |
perimeter1 = cv2.arcLength(approx, True)
|
| 828 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 829 |
x1, y1 = point[0]
|
|
|
|
| 830 |
shape.append([int(x1*ratio),int(y1*ratio)])
|
| 831 |
-
|
| 832 |
if (angleR != 90.0 and angleR != -90.0 and angleR != 0.0 and angleR != -0.0 ): #inclined b ay degree
|
| 833 |
width=widthR
|
| 834 |
height=heightR
|
|
@@ -867,17 +908,19 @@ def drawAllContours(img,number,finalColorArray,ratioarea,ratioperim,flag , path,
|
|
| 867 |
|
| 868 |
passed=1
|
| 869 |
cv2.drawContours(imgArea1, [contourss[contour][0]], 0, ( int(SimilarAreaDictionary['B'].loc[i]), int(SimilarAreaDictionary['G'].loc[i]), int(SimilarAreaDictionary['R'].loc[i])), -1)
|
| 870 |
-
|
| 871 |
annot = page.add_polygon_annot( points=shape ) # 'Polygon'
|
|
|
|
| 872 |
annot.set_border(width=0.3, dashes=[2])
|
| 873 |
-
annot.set_colors( fill=( int(SimilarAreaDictionary['
|
| 874 |
# annot.set_colors( fill=(1,0,1) )
|
| 875 |
annot.set_opacity(0.5)
|
| 876 |
annot.set_info(content='Area='+str(areaa)+' m2' +'\n \nPerimeter='+str(perimeterr)+' m',subject='ADR Team')#,title='uuum')
|
| 877 |
# annot.set_line_ends(fitz.PDF_ANNOT_LE_DIAMOND, fitz.PDF_ANNOT_LE_CIRCLE)
|
| 878 |
annot.update()
|
| 879 |
-
|
| 880 |
-
cv2.putText(imgtransparent1,'
|
|
|
|
| 881 |
|
| 882 |
alpha = 0.4 # Transparency factor.
|
| 883 |
image_new1 = cv2.addWeighted(imgArea1, alpha, imgtransparent1, 1 - alpha, 0)
|
|
@@ -886,6 +929,7 @@ def drawAllContours(img,number,finalColorArray,ratioarea,ratioperim,flag , path,
|
|
| 886 |
print(SimilarAreaDictionary)
|
| 887 |
|
| 888 |
# annotationsSave
|
|
|
|
| 889 |
pdflink= db.dropbox_upload_file(doc=doc,pdfname=path,pdfpath=pdfpath)
|
| 890 |
dbx=db.dropbox_connect()
|
| 891 |
md, res =dbx.files_download(path= pdfpath+path)
|
|
@@ -1375,6 +1419,7 @@ def mapnametoLegend(McTName):
|
|
| 1375 |
row0=['MC_T Name','Qty','Unit']
|
| 1376 |
worksheetS.update_row(1,row0)
|
| 1377 |
|
|
|
|
| 1378 |
for i in range(len(McTName)):
|
| 1379 |
allgbnames=''
|
| 1380 |
item=''
|
|
@@ -1418,21 +1463,21 @@ def mapnametoLegend(McTName):
|
|
| 1418 |
# guessednames=guessednames[3:]
|
| 1419 |
print('gg',guessednames)
|
| 1420 |
for m in McTName[i][1]:
|
| 1421 |
-
|
| 1422 |
-
|
| 1423 |
-
|
| 1424 |
-
|
| 1425 |
-
|
| 1426 |
-
|
| 1427 |
-
|
| 1428 |
-
|
| 1429 |
-
|
| 1430 |
-
|
| 1431 |
-
|
| 1432 |
-
|
| 1433 |
-
|
| 1434 |
-
|
| 1435 |
-
|
| 1436 |
else:
|
| 1437 |
if McTName[i][1].startswith('text1'):
|
| 1438 |
name=McTName[i][1].removeprefix('text1')
|
|
@@ -1535,7 +1580,6 @@ def mapnametoLegend(McTName):
|
|
| 1535 |
spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_key, body=body2).execute()
|
| 1536 |
return summaryId,guessednamesfinal
|
| 1537 |
|
| 1538 |
-
|
| 1539 |
# print(x,xarea)
|
| 1540 |
def getguessnames(gc,ws):
|
| 1541 |
guessednamesfinal=[]
|
|
|
|
| 18 |
from matplotlib import pyplot as plt
|
| 19 |
#from pdf2image import convert_from_path
|
| 20 |
import math
|
| 21 |
+
from math import sin, cos, radians
|
| 22 |
import pandas as pd
|
| 23 |
import random
|
| 24 |
# import imutils
|
|
|
|
| 293 |
|
| 294 |
detectedColors=cv2.cvtColor(detectedColors,cv2.COLOR_HSV2BGR)
|
| 295 |
detectedColors=cv2.medianBlur(detectedColors,7)
|
| 296 |
+
cv2.imwrite('det.png',detectedColors)
|
|
|
|
| 297 |
return mask, detectedColors, color
|
| 298 |
|
| 299 |
|
|
|
|
| 487 |
return contourss
|
| 488 |
else:
|
| 489 |
mask, detectedColors, rgbcolor =DetectColor(img,color)
|
| 490 |
+
# print(rgbcolor)
|
| 491 |
|
| 492 |
pil_image=Image.fromarray(mask)
|
| 493 |
|
|
|
|
| 547 |
perimeter1 = cv2.arcLength(approx, True)
|
| 548 |
# approx = cv2.approxPolyDP(contourss[contour][0], 0.01* perimeter, True)
|
| 549 |
# area1 = cv2.contourArea(approx)
|
|
|
|
| 550 |
x, y , width, height = cv2.boundingRect(contourss[contour][0])
|
| 551 |
|
| 552 |
angleR,widthR ,heightR= StraightenImage(contourss[contour][0],img)
|
|
|
|
| 560 |
# print('numss')
|
| 561 |
# if flag=='area':
|
| 562 |
# addedMargin=area1+perimeter1*2
|
| 563 |
+
areaa=round(area1* ratioarea , 2) # true value of area of any shape/ area px value of same shape
|
| 564 |
appended.append([areaa,width,height])
|
| 565 |
|
| 566 |
#else:
|
|
|
|
| 572 |
|
| 573 |
def FillDictionary(green2,SimilarAreaDictionary,img,number,ratioarea,ratioperim,flag,finalColorArray,rgbcolor=[0,0,0],color=[0,0,0]):
|
| 574 |
#fills dictionary with key areas and number of occurences
|
|
|
|
| 575 |
areas_Perimeters=sorted(getAreasPerimeter(green2,img,number,ratioarea,ratioperim,flag,finalColorArray,color) )
|
| 576 |
|
| 577 |
indices=[]
|
| 578 |
+
# 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],[18,236,206],[225,105,29],[189,65,121],[206,204,48],[126,7,247],[3,168,251]]
|
| 579 |
+
|
| 580 |
+
colorRanges=[[255,0,0],[0,0,255],[0,255,255],[0,64,0],[255,204,0],[255,128,64],[255,0,128],[255,128,192],[128,128,255],[128,64,0],[0,255,0],[179,106,179],[115,52,179],[0,128,192],[128,0,128],[128,0,0],[0,128,255],[255,182,128],[255,0,255],[0,0,128],[0,128,64],[255,255,0],[128,0,64],[203,203,106],[128,255,166],[255,128,0],[255,98,98],[90,105,138],[114,10,72],[36,82,78],[225,105,29],[108,62,40],[11,35,75],[42,176,203],[255,153,153],[129,74,138],[99,123,137],[159,179,30]]
|
| 581 |
+
# print(colorRanges[0])
|
| 582 |
+
# print(colorRanges[0][0],colorRanges[0][1], colorRanges[0][2])
|
| 583 |
colorsUsed=[]
|
| 584 |
for i in range(len(areas_Perimeters)):
|
| 585 |
|
|
|
|
| 641 |
SimilarAreaDictionary.loc[len(SimilarAreaDictionary)] =mydata
|
| 642 |
# s= SimilarAreaDictionary
|
| 643 |
for i in range(len(SimilarAreaDictionary)):
|
| 644 |
+
SimilarAreaDictionary['B'].loc[i] =colorRanges[i][0]
|
| 645 |
SimilarAreaDictionary['G'].loc[i] =colorRanges[i][1]
|
| 646 |
+
SimilarAreaDictionary['R'].loc[i] = colorRanges[i][2]
|
| 647 |
colorsUsed.append(colorRanges[i])
|
| 648 |
|
| 649 |
|
| 650 |
return SimilarAreaDictionary, colorsUsed , areas_Perimeters
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
|
| 654 |
+
def rotate_point(point, angle, center_point=(0, 0)):
|
| 655 |
+
"""Rotates a point around center_point(origin by default)
|
| 656 |
+
Angle is in degrees.
|
| 657 |
+
Rotation is counter-clockwise
|
| 658 |
+
"""
|
| 659 |
+
angle_rad = radians(angle % 360)
|
| 660 |
+
# Shift the point so that center_point becomes the origin
|
| 661 |
+
new_point = (point[0] - center_point[0], point[1] - center_point[1])
|
| 662 |
+
new_point = (new_point[0] * cos(angle_rad) - new_point[1] * sin(angle_rad),
|
| 663 |
+
new_point[0] * sin(angle_rad) + new_point[1] * cos(angle_rad))
|
| 664 |
+
# Reverse the shifting we have done
|
| 665 |
+
new_point = (new_point[0] + center_point[0], new_point[1] + center_point[1])
|
| 666 |
+
return new_point
|
| 667 |
+
|
| 668 |
+
def rotate_polygon(polygon, angle, center_point=(0, 0)):
|
| 669 |
+
"""Rotates the given polygon which consists of corners represented as (x,y)
|
| 670 |
+
around center_point (origin by default)
|
| 671 |
+
Rotation is counter-clockwise
|
| 672 |
+
Angle is in degrees
|
| 673 |
+
"""
|
| 674 |
+
rotated_polygon = []
|
| 675 |
+
for corner in polygon:
|
| 676 |
+
rotated_corner = rotate_point(corner, angle, center_point)
|
| 677 |
+
rotated_polygon.append(rotated_corner)
|
| 678 |
+
return rotated_polygon
|
| 679 |
+
|
| 680 |
def drawAllContours(img,number,finalColorArray,ratioarea,ratioperim,flag , path,pdfpath):
|
| 681 |
green2=allpreSteps(img)
|
| 682 |
doc = fitz.open('dropbox_plans/1.0/'+path)
|
| 683 |
+
page = doc[0]
|
| 684 |
+
# page.set_rotation(270)
|
| 685 |
pix=page.get_pixmap()
|
| 686 |
+
print('SHAPPEE',img.shape)
|
| 687 |
+
# if img.shape[0] > img.shape[1]:
|
| 688 |
+
ratio = pix.width / img.shape[1]
|
| 689 |
+
# ratio0 = img.shape[1] * pix.width
|
| 690 |
+
# ratio= pix.height /img.shape[0]
|
| 691 |
+
|
| 692 |
areasinImage=[]
|
| 693 |
totaldf=pd.DataFrame()
|
| 694 |
imgArea1= img.copy()
|
|
|
|
| 742 |
|
| 743 |
box = cv2.boxPoints(rect)
|
| 744 |
box = box.astype('int')
|
| 745 |
+
# print(box)
|
| 746 |
|
| 747 |
x, y , width, height = cv2.boundingRect(contourss[contour][0])
|
| 748 |
perimeter = cv2.arcLength(contourss[contour][0], True)
|
|
|
|
| 761 |
allpoints.append(shape)
|
| 762 |
# print(x,y,width,height)
|
| 763 |
# print(allpoints)
|
| 764 |
+
# print(shape)
|
| 765 |
if (angleR != 90.0 and angleR != -90.0 and angleR != 0.0 and angleR != -0.0 ): #inclined b ay degree
|
| 766 |
width=widthR
|
| 767 |
height=heightR
|
|
|
|
| 811 |
# print(index)
|
| 812 |
# cv2.drawContours(imgArea1, [contour], 0, (int(rgbcolor[2]), int(rgbcolor[1]), int(rgbcolor[0])), -1)
|
| 813 |
cv2.drawContours(imgArea1, [contourss[contour][0]], 0, ( int(SimilarAreaDictionary['B'].loc[i]), int(SimilarAreaDictionary['G'].loc[i]), int(SimilarAreaDictionary['R'].loc[i])), -1)
|
| 814 |
+
|
| 815 |
annot = page.add_polygon_annot( points=shape ) # 'Polygon'
|
| 816 |
annot.set_border(width=0.3, dashes=[2])
|
| 817 |
annot.set_colors( fill=( int(SimilarAreaDictionary['R'].loc[i])/255 , int(SimilarAreaDictionary['G'].loc[i])/255 , int(SimilarAreaDictionary['B'].loc[i])/255 ) )
|
|
|
|
| 820 |
annot.set_info(content='Area='+str(areaa)+' m2' +'\n \nPerimeter='+str(perimeterr)+' m',subject='ADR Team')#,title='uuum')
|
| 821 |
# annot.set_line_ends(fitz.PDF_ANNOT_LE_DIAMOND, fitz.PDF_ANNOT_LE_CIRCLE)
|
| 822 |
annot.update()
|
| 823 |
+
|
| 824 |
cv2.putText(imgtransparent1,'Area= '+str(area1) , (x+50,y-10) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
| 825 |
# cv2.putText(imgtransparent1,'Width= '+str(width) , (x+50,y-10) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
| 826 |
# cv2.putText(imgtransparent1,'Length= '+str(height) , (x+50,y-20) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
|
|
|
| 830 |
cv2.putText(imgPerimeter1,'Area: '+str(areaa)+' m2', (x+50,y-40) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
| 831 |
|
| 832 |
|
| 833 |
+
for i,row in SimilarAreaDictionary.iterrows():
|
| 834 |
+
# print(row)
|
| 835 |
+
if row[5] not in areasinImage: # column of area
|
| 836 |
+
SimilarAreaDictionary = SimilarAreaDictionary.drop(SimilarAreaDictionary.loc[SimilarAreaDictionary.index==i].index)
|
| 837 |
|
| 838 |
print(SimilarAreaDictionary)
|
| 839 |
# display(totaldf)
|
|
|
|
| 856 |
x, y , width, height = cv2.boundingRect(contourss[contour][0])
|
| 857 |
# approxo = cv2.approxPolyDP(contourss[contour],0.1*cv2.arcLength(contourss[contour],True),True)
|
| 858 |
# approx = cv2.approxPolyDP(contourss[contour][0], 0.005 * perimeter, True)
|
| 859 |
+
approxa = cv2.approxPolyDP(contourssA[contour][0], 0.0002* perimeter, True)
|
| 860 |
+
area1 = cv2.contourArea(approxa)
|
| 861 |
approx = cv2.approxPolyDP(contourss[contour][0], 0.01 * perimeter, True) #0.0009
|
| 862 |
perimeter1 = cv2.arcLength(approx, True)
|
| 863 |
+
M = cv2.moments(contourssA[contour][0])
|
| 864 |
+
if M['m00'] != 0:
|
| 865 |
+
cx = int(M['m10']/M['m00'])
|
| 866 |
+
cy = int(M['m01']/M['m00'])
|
| 867 |
+
|
| 868 |
+
for point in approxa:
|
| 869 |
x1, y1 = point[0]
|
| 870 |
+
|
| 871 |
shape.append([int(x1*ratio),int(y1*ratio)])
|
| 872 |
+
# shape=rotate_polygon(shape, 90)
|
| 873 |
if (angleR != 90.0 and angleR != -90.0 and angleR != 0.0 and angleR != -0.0 ): #inclined b ay degree
|
| 874 |
width=widthR
|
| 875 |
height=heightR
|
|
|
|
| 908 |
|
| 909 |
passed=1
|
| 910 |
cv2.drawContours(imgArea1, [contourss[contour][0]], 0, ( int(SimilarAreaDictionary['B'].loc[i]), int(SimilarAreaDictionary['G'].loc[i]), int(SimilarAreaDictionary['R'].loc[i])), -1)
|
| 911 |
+
|
| 912 |
annot = page.add_polygon_annot( points=shape ) # 'Polygon'
|
| 913 |
+
|
| 914 |
annot.set_border(width=0.3, dashes=[2])
|
| 915 |
+
annot.set_colors( fill=( int(SimilarAreaDictionary['R'].loc[i])/255 , int(SimilarAreaDictionary['G'].loc[i])/255 , int(SimilarAreaDictionary['B'].loc[i])/255 ) )
|
| 916 |
# annot.set_colors( fill=(1,0,1) )
|
| 917 |
annot.set_opacity(0.5)
|
| 918 |
annot.set_info(content='Area='+str(areaa)+' m2' +'\n \nPerimeter='+str(perimeterr)+' m',subject='ADR Team')#,title='uuum')
|
| 919 |
# annot.set_line_ends(fitz.PDF_ANNOT_LE_DIAMOND, fitz.PDF_ANNOT_LE_CIRCLE)
|
| 920 |
annot.update()
|
| 921 |
+
|
| 922 |
+
cv2.putText(imgtransparent1,'Area: '+str(areaa)+' m2' , (x+50,y-10) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
| 923 |
+
cv2.putText(imgtransparent1,'Perimeter: '+str(perimeterr)+' m' , (x+50,y-40) ,cv2.FONT_HERSHEY_SIMPLEX, 0.6, (50, 50, 255), 2)
|
| 924 |
|
| 925 |
alpha = 0.4 # Transparency factor.
|
| 926 |
image_new1 = cv2.addWeighted(imgArea1, alpha, imgtransparent1, 1 - alpha, 0)
|
|
|
|
| 929 |
print(SimilarAreaDictionary)
|
| 930 |
|
| 931 |
# annotationsSave
|
| 932 |
+
|
| 933 |
pdflink= db.dropbox_upload_file(doc=doc,pdfname=path,pdfpath=pdfpath)
|
| 934 |
dbx=db.dropbox_connect()
|
| 935 |
md, res =dbx.files_download(path= pdfpath+path)
|
|
|
|
| 1419 |
row0=['MC_T Name','Qty','Unit']
|
| 1420 |
worksheetS.update_row(1,row0)
|
| 1421 |
|
| 1422 |
+
|
| 1423 |
for i in range(len(McTName)):
|
| 1424 |
allgbnames=''
|
| 1425 |
item=''
|
|
|
|
| 1463 |
# guessednames=guessednames[3:]
|
| 1464 |
print('gg',guessednames)
|
| 1465 |
for m in McTName[i][1]:
|
| 1466 |
+
if m:
|
| 1467 |
+
if m.startswith('text1'):
|
| 1468 |
+
name=m.removeprefix('text1')
|
| 1469 |
+
allgbnames+= name +' +'
|
| 1470 |
+
indices = [o for o, x in enumerate(guessednames) if x == name]
|
| 1471 |
+
print(indices)
|
| 1472 |
+
# roww=worksheetw.find(str(name))
|
| 1473 |
+
# print(roww)
|
| 1474 |
+
for j in range(len(indices)):
|
| 1475 |
+
# print('kjjjj',roww[j])
|
| 1476 |
+
ar+=float(worksheetw.cell((indices[j]+1 ,rowvalue)).value)
|
| 1477 |
+
else:
|
| 1478 |
+
item+=m + ' ,'
|
| 1479 |
+
print(item)
|
| 1480 |
+
n= McTName[i][0] + ' ( '+ allgbnames[:-2] +' , ' + item[:-1] + ' ) '
|
| 1481 |
else:
|
| 1482 |
if McTName[i][1].startswith('text1'):
|
| 1483 |
name=McTName[i][1].removeprefix('text1')
|
|
|
|
| 1580 |
spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_key, body=body2).execute()
|
| 1581 |
return summaryId,guessednamesfinal
|
| 1582 |
|
|
|
|
| 1583 |
# print(x,xarea)
|
| 1584 |
def getguessnames(gc,ws):
|
| 1585 |
guessednamesfinal=[]
|