def circle(latlng_origin=None, pid_origin=None, radius=15): """ Returns a validator function for a Panorama. which Returns True if the Panorama is inside a circle of the radius r around the center point latlng_0. :param latlng_0: tuple (lat, lng) - center GPS :param r: float - radius in meters :return: validator(panorama) - given Panorama it returns True if the Panorama is inside the circle """ if latlng_origin: (easting, northing, z_number, z_letter) = utm.from_latlon(latlng_origin[0], latlng_origin[1]) elif pid_origin: latlng_origin = Panorama(pid_origin).getGPS() (easting, northing, z_number, z_letter) = utm.from_latlon(latlng_origin[0], latlng_origin[1]) else: raise ValueError( "One of the arguments 'latlang_origin' or 'pid_origin' must be given." ) def isClose(p): ll = p.getGPS() (est, nth, zn, zl) = utm.from_latlon(ll[0], ll[1], force_zone_number=z_number) x, y = est - easting, nth - northing d = sqrt(x**2 + y**2) return d < radius return isClose
def box(latlng_origin=None, pid_origin=None, width=15, height=15): """ Returns a validator function of Panorama that returns True is the Panorama is inside a box of the size w,h around center point latlng_0. :param latlng_origin: tuple (lat, lng) - center GPS :param w: float - width in meters :param h: float - height in meters :return: validator(Panorama) - given a Panorama it returns True if the panorama is inside the box """ if latlng_origin: (easting, northing, z_number, z_letter) = utm.from_latlon(latlng_origin[0], latlng_origin[1]) elif pid_origin: latlng_origin = Panorama(pid_origin).getGPS() (easting, northing, z_number, z_letter) = utm.from_latlon(latlng_origin[0], latlng_origin[1]) else: raise ValueError( "One of the arguments 'latlang_origin' or 'pid_origin' must be given." ) def isClose(p): ll = p.getGPS() (est, nth, zn, zl) = utm.from_latlon(ll[0], ll[1], force_zone_number=z_number) x, y = est - easting, nth - northing return abs(x) < w / 2 and abs(y) < h / 2 return isClose
def __init__(self, latlng=None, pano_id=None, validator=None, root='myData', label='myCity', zoom=5, images=False, depth=False, time=True, skip=False): if not latlng and not pano_id: raise ValueError('start point (latlng or pano_id) not given') loger.info('___ Crawler starting ___') self.dir = os.path.join(root, label) self.fname = os.path.join(root, label, 'db.pickle') self.fname_bck = self.fname + '.bck' self.zoom = zoom if isinstance(zoom, list) else [zoom] # zoom must be a list self.start_id = pano_id self.start_latlng = latlng self.inArea = validator self.db = Database() self.threads = self.n_thr * [None] # thread vector allocation self.exit_flag = False # flag for signaling threads self.images = images self.depth = depth self.time = time if not os.path.exists(self.dir): # create dir os.makedirs(self.dir) if os.path.exists(self.fname): # resume existing crawler db if not self.load(self.fname): self.load(self.fname_bck) # roll back to backup else: # new crawler db p = Panorama(self.start_id, self.start_latlng) self.db.enqueue(p.pano_id) # starting panorama into a queue
def worker(self, id): loger.debug('Starting thread %d' % (id, )) while not self.exit_flag: #loger.debug('Tread %d dequeue'%(id,)) pano_id = self.db.dequeue() loger.debug('Tread %d dequeued, id: %s' % (id, pano_id)) if self.db.isSentinel(pano_id): self.db.task_done() break try: p = Panorama(pano_id) self.savePano(p, self.zoom) self.visitPano(p) except Exception as e: msg = 'Thread %d - %s:%s' % (id, type(e).__name__, str(e)) loger.error(msg) finally: self.db.task_done() loger.debug('Exiting thread %d' % (id, ))
def run(self): logger.info('starting skyline panorama') Panorama(getpid()).start() while 1: sleep(100)
from panorama import Panorama import imutils import cv2 imageA = cv2.imread('secondPic1.jpg') imageB = cv2.imread('secondPic2.jpg') img1 = imutils.resize(imageA, width=400) img2 = imutils.resize(imageB, width=400) panorama = Panorama() (result, matched_points) = panorama.image_stitch([img1, img2], match_status=True) cv2.imshow("Keypoint Matches", matched_points) cv2.imshow("Result", result) cv2.imwrite("Matched_points1.jpg", matched_points) cv2.imwrite("Panorama_image1.jpg", result) cv2.waitKey(0) cv2.destroyAllWindows()
def parse(args): # Info command if args.info: # pano_id has priority over latlng print Panorama(pano_id=args.panoid, latlng=args.latlng) return # Show command if args.show: Panorama(pano_id=args.panoid).getImage(2).show() return # Setting up loger fdir = os.path.join(args.root, args.label) if not os.path.exists(fdir): os.makedirs(fdir) l_fmt = '%(asctime)s %(levelname)s [%(filename)s:%(lineno)s - %(funcName)10s() ]: %(message)s' # format l_dfmt = '%m/%d/%Y %I:%M:%S %p' # date format l_fname = os.path.join(args.root, args.label, 'crawler.log') # filepath logging.basicConfig(filename=l_fname, format=l_fmt, datefmt=l_dfmt) # Filename for command restore fname = os.path.join(args.root, args.label, 'crawlerArgs.pickle') # Handling resuem command a existing crawler if args.resume: with open(fname) as f: args = pickle.load(f) print '\nResuming command:' print args.cmds + '\n' else: if os.path.exists(fname): msg = '\n"%s" already crawled. Use "resume" (see --help) to continue crawling.' % ( args.label, ) raise AssertionError(msg) # Create area validator for crawler if args.circle: if args.latlng: pvalid = validator.circle(latlng_origin=args.latlng, radius=args.r) else: pvalid = validator.circle(pid_origin=args.panoid, radius=args.r) elif args.box: if args.latlng: pvalid = validator.box(latlng_origin=args.latlng, width=args.w, height=args.h) else: pvalid = validator.box(pid_origin=args.pid, width=args.w, height=args.h) # pvalid = validator.box(a.latlng, a.w, a.h) elif args.gpsbox: pvalid = validator.gpsbox(args.topleft, args.btmright) else: raise NotImplementedError('Unknown validator') with open(fname, 'w') as f: pickle.dump(args, f) launch(args, pvalid)