Marthee commited on
Commit
1e39b35
·
1 Parent(s): 8b454b3

Update pixelconversion.py

Browse files
Files changed (1) hide show
  1. pixelconversion.py +12 -8
pixelconversion.py CHANGED
@@ -17,10 +17,12 @@ from PIL import Image
17
  import numpy as np
18
  import cv2
19
  import db
 
20
 
21
  """### Open PDF and draw a rectangle on it using Fitz"""
22
- def openDrawPDF(path):
23
- doc = fitz.open(path)
 
24
  page = doc[0]
25
  pix = page.get_pixmap() # render page to an image
26
  pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
@@ -61,9 +63,9 @@ def openDrawPDF(path):
61
  rotate=90
62
 
63
  if page.rotation !=0:
64
- page.draw_rect([shape[3][0]-20,shape[3][1]-20,shape[1][0]+20,shape[1][1]+20], color = (75/255,0,130/255), width = 1,fill=(75/255,0,130/255),fill_opacity=0.9 )
65
  else:
66
- page.draw_rect([shape[0][0]-20,shape[0][1]-20,shape[2][0]+20,shape[2][1]+20], color = (75/255,0,130/255), width = 1,fill=(75/255,0,130/255),fill_opacity=0.9 )
67
 
68
  text = """Scale Document"""
69
  annot1=page.add_freetext_annot(rectText, text, fontsize=45, fontname='helv', border_color=(1,1,1), text_color=(1,1,1), rotate= page.rotation, align=1)
@@ -104,11 +106,13 @@ def DetectColor(img,color=0):
104
 
105
  """### For backend - calc area and perim"""
106
 
107
- def getAreaPerimeter(pdfpath, plan):
108
- dbx=db.dropbox_connect()
109
- md, res =dbx.files_download(path= pdfpath+plan)
110
  data = res.content
111
  doc=fitz.open("pdf", data)
 
 
112
  for page in doc:
113
  pix = page.get_pixmap(dpi=300) # render page to an image
114
  pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
@@ -116,7 +120,7 @@ def getAreaPerimeter(pdfpath, plan):
116
  print(img.shape)
117
  img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
118
  mask=DetectColor(img,color=(73,0,130)) #detect colored rect drawn on the pdf
119
- cv2.imwrite('maskk.png',mask)
120
  contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
121
  for contour in contours:
122
  area = cv2.contourArea(contour)
 
17
  import numpy as np
18
  import cv2
19
  import db
20
+ import tsadropboxretrieval
21
 
22
  """### Open PDF and draw a rectangle on it using Fitz"""
23
+ def openDrawPDF(data):
24
+
25
+ doc=fitz.open("pdf", data)
26
  page = doc[0]
27
  pix = page.get_pixmap() # render page to an image
28
  pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
 
63
  rotate=90
64
 
65
  if page.rotation !=0:
66
+ page.draw_rect([shape[3][0]-20,shape[3][1]-20,shape[1][0]+20,shape[1][1]+20], color = (75/255,0,130/255), width = 1,fill=(75/255,0,130/255),fill_opacity=0.95 )
67
  else:
68
+ page.draw_rect([shape[0][0]-20,shape[0][1]-20,shape[2][0]+20,shape[2][1]+20], color = (75/255,0,130/255), width = 1,fill=(75/255,0,130/255),fill_opacity=0.95 )
69
 
70
  text = """Scale Document"""
71
  annot1=page.add_freetext_annot(rectText, text, fontsize=45, fontname='helv', border_color=(1,1,1), text_color=(1,1,1), rotate= page.rotation, align=1)
 
106
 
107
  """### For backend - calc area and perim"""
108
 
109
+ def getAreaPerimeter(path,name):
110
+ dbxTeam=tsadropboxretrieval.ADR_Access_DropboxTeam('user')
111
+ md, res =dbxTeam.files_download(path= path+name)
112
  data = res.content
113
  doc=fitz.open("pdf", data)
114
+ area=0
115
+ perimeter=0
116
  for page in doc:
117
  pix = page.get_pixmap(dpi=300) # render page to an image
118
  pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
 
120
  print(img.shape)
121
  img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
122
  mask=DetectColor(img,color=(73,0,130)) #detect colored rect drawn on the pdf
123
+ # cv2.imwrite('maskk.png',mask)
124
  contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
125
  for contour in contours:
126
  area = cv2.contourArea(contour)