def compute_algo_circumference(): # Time measurement start = time.clock() # Read lidars datas lidarsSet.read_datas_files() # Plot raw datas lidarsSet.plot_raw_datas() # Compute raw datas into merged datas lidarsSet.compute_raw_datas() # Remove outliers if len(utility.mergedPointsXY) > constants.min_points: #utility.remove_outliers() # Compute contour contour.contour() cust_print("Circumference computed in: " + str(time.clock() - start) + ' sec.') # Show the plots if constants.disp_charts: cust_print('\nClose all figures to continue...\n') plt.show(block=True) else: cust_print( ' Not enough data point have been read in the expected area!')
def createAlgsList(self): # First we populate the list of algorithms with those created # extending GeoAlgorithm directly (those that execute GDAL # using the console) self.preloadedAlgs = [nearblack(), information(), warp(), translate(), rgb2pct(), pct2rgb(), merge(), buildvrt(), polygonize(), gdaladdo(), ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(), sieve(), fillnodata(), ExtractProjection(), gdal2xyz(), hillshade(), slope(), aspect(), tri(), tpi(), roughness(), ColorRelief(), GridInvDist(), GridAverage(), GridNearest(), GridDataMetrics(), gdaltindex(), gdalcalc(), rasterize_over(), # ----- OGR tools ----- OgrInfo(), Ogr2Ogr(), Ogr2OgrClip(), Ogr2OgrClipExtent(), Ogr2OgrToPostGis(), Ogr2OgrToPostGisList(), Ogr2OgrPointsOnLines(), Ogr2OgrBuffer(), Ogr2OgrDissolve(), Ogr2OgrOneSideBuffer(), Ogr2OgrTableToPostGisList(), OgrSql(), ] # And then we add those that are created as python scripts folder = self.scriptsFolder() if os.path.exists(folder): for descriptionFile in os.listdir(folder): if descriptionFile.endswith('py'): try: fullpath = os.path.join(self.scriptsFolder(), descriptionFile) alg = GdalScriptAlgorithm(fullpath) self.preloadedAlgs.append(alg) except WrongScriptException as e: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
def createAlgsList(self): # First we populate the list of algorithms with those created # extending GeoAlgorithm directly (those that execute GDAL # using the console) self.preloadedAlgs = [nearblack(), information(), warp(), translate(), rgb2pct(), pct2rgb(), merge(), polygonize(), gdaladdo(), ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(), sieve(), fillnodata(), ExtractProjection(), gdal2xyz(), hillshade(), slope(), aspect(), tri(), tpi(), roughness(), ColorRelief(), GridInvDist(), GridAverage(), GridNearest(), GridDataMetrics(), # ----- OGR tools ----- OgrInfo(), Ogr2Ogr(), OgrSql(), ] # And then we add those that are created as python scripts folder = self.scriptsFolder() if os.path.exists(folder): for descriptionFile in os.listdir(folder): if descriptionFile.endswith('py'): try: fullpath = os.path.join(self.scriptsFolder(), descriptionFile) alg = GdalScriptAlgorithm(fullpath) self.preloadedAlgs.append(alg) except WrongScriptException, e: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
def __find_contours(self, img, thresh): #1 src = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 2 src = cv2.GaussianBlur(src, (5, 5), 0) # Set threshold and maxValue #thresh = 200 maxValue = 255 # 3 th, dst = cv2.threshold(src, thresh, maxValue, cv2.THRESH_BINARY) # 4 edges = cv2.Canny(dst, 0, 75, apertureSize=5) # 5 dst, conts, hierarchy = cv2.findContours(dst, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) contours = [] print hierarchy[0] for x in xrange(0, len(conts), 1): a_contour = contour(conts[x], hierarchy[0][x][0], hierarchy[0][x][1], hierarchy[0][x][2], hierarchy[0][x][3]) contours.append(a_contour) return contours
def __find_contours(self, image, thresh): contours = [] #opencv functies die uit de mee gegeven afbeelding contouren en hun hierarchy haalt, zie SAD voor details #find contours returned een lijst met contouren, een contour is een lijst met punten. #find contours geeft ook een lijst met een hierarchy, een hierarchy is een lijst waarbij de index over een komt met het #bijbehorende contour in de hierarchy staan de previous(de vorige contour met de zelfde parrent), de next(het volgende contour met de zelfde parrent), de parrent(welk countour om de contour heen zit) en de child(wat is het eerste contour in ddeze contour) #all deze getallen verwijzen naar een index van dit desbetrevvende contour. wenneer een dergelijk veld leeg is is de waarde -1 #structuur hierarchy: [Next, Previous, First_Child, Parent] src = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) src = cv2.GaussianBlur(src, (5, 5), 0) maxValue = 255 th, dst = cv2.threshold(src, thresh, maxValue, cv2.THRESH_BINARY) edges = cv2.Canny(dst, 0, 75, apertureSize=5) dst, conts, hierarchy = cv2.findContours(dst, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) for index in xrange(0, len(conts) - 1, 1): cont = contour(conts[index]) j = hierarchy[0][index][2] #j is de index van de parrent if j > -1: #oftewel als er een parrent is cont.add_child(j) while hierarchy[0][j][ 0] > -1: #oftewel while er een next child is j = hierarchy[0][j][ 2] #j is nu index van de volgende child cont.add_child(j) contours.append(cont) return contours
def createAlgsList(self): # First we populate the list of algorithms with those created # extending GeoAlgorithm directly (those that execute GDAL # using the console) self.preloadedAlgs = [ nearblack(), information(), warp(), translate(), rgb2pct(), pct2rgb(), merge(), buildvrt(), polygonize(), gdaladdo(), ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(), sieve(), fillnodata(), ExtractProjection(), gdal2xyz(), hillshade(), slope(), aspect(), tri(), tpi(), roughness(), ColorRelief(), GridInvDist(), GridAverage(), GridNearest(), GridDataMetrics(), gdaltindex(), gdalcalc(), rasterize_over(), retile(), gdal2tiles(), # ----- OGR tools ----- OgrInfo(), Ogr2Ogr(), Ogr2OgrClip(), Ogr2OgrClipExtent(), Ogr2OgrToPostGis(), Ogr2OgrToPostGisList(), Ogr2OgrPointsOnLines(), Ogr2OgrBuffer(), Ogr2OgrDissolve(), Ogr2OgrOneSideBuffer(), Ogr2OgrTableToPostGisList(), OgrSql(), ]
import h5py import contour import math h5file = h5py.File('ng__t.h5') temp = h5file['image']['data'][0].T[::-1] contours = contour.contour(temp, [310., 1550.]) print("full: %d" % reduce( lambda x, y: x + y, [len(l) for c in contours.values() for l in c.lines])) f = open('temp_full.svg', 'w') f.write(contour.svg(temp.shape[0], temp.shape[1], contours)) f.close() for theta in [5, 10, 15, 20]: threshold = math.cos(theta * math.pi / 180.0) simple_contours = contour.simplify(contours, threshold) print(u"%02d\u00b0: %d" % (theta, reduce(lambda x, y: x + y, [len(l) for c in simple_contours.values() for l in c.lines]))) f = open('temp_%02d.svg' % theta, 'w') f.write(contour.svg(temp.shape[0], temp.shape[1], simple_contours)) f.close()
def contour_at(self, f, lvl): # Find a point on f at lvl e0 = f.edge if e0.has_level(lvl): pass elif e0.next.has_level(lvl): e0 = e0.next pX0 = e0.at_level(lvl) c = contour(pX0) walking = True forward = True currEdge = e0.twin switch = True while walking: if switch: e1 = currEdge.next e2 = e1.next switch = False else: e1 = currEdge.prev e2 = e1.prev switch = True if forward: if e1.has_level(lvl): pXc = e1.at_level(lvl) if e1.twin != None and e1.twin.next != None: currEdge = e1.twin else: forward = False switch = False currEdge = e0 elif e2.has_level(lvl): pXc = e2.at_level(lvl) if e2.twin != None and e2.twin.next != None: currEdge = e2.twin else: forward = False switch = False currEdge = e0 if e1 == e0 or e2 == e0: walking = False c.append(pXc) else: if e1.has_level(lvl): pXc = e1.at_level(lvl) if e1.twin != None: currEdge = e1.twin else: walking = False elif e2.has_level(lvl): pXc = e2.at_level(lvl) if e2.twin != None: currEdge = e2.twin else: walking = False c.prepend(pXc) c.complete(forward) return c
import h5py import contour import math h5file=h5py.File('ng__t.h5') temp=h5file['image']['data'][0].T[::-1] contours=contour.contour(temp,[310.,1550.]) print("full: %d"%reduce(lambda x,y: x+y,[len(l) for c in contours.values() for l in c.lines])) f=open('temp_full.svg','w') f.write(contour.svg(temp.shape[0],temp.shape[1],contours)) f.close() for theta in [5,10,15,20]: threshold=math.cos(theta*math.pi/180.0) simple_contours=contour.simplify(contours,threshold) print(u"%02d\u00b0: %d"%(theta,reduce(lambda x,y: x+y,[len(l) for c in simple_contours.values() for l in c.lines]))) f=open('temp_%02d.svg'%theta,'w') f.write(contour.svg(temp.shape[0],temp.shape[1],simple_contours)) f.close()