diff --git a/Camera/RTSPCameraOne.py b/Camera/RTSPCameraOne.py new file mode 100644 index 0000000000000000000000000000000000000000..4eac4bad37f62e998319c4c03b36e56abd5bf32d --- /dev/null +++ b/Camera/RTSPCameraOne.py @@ -0,0 +1,41 @@ +import sys +import vlc +import pygame + +#IP Address of camera 1 +#Port 554 +stream = "rtsp://192.168.1.10:554/user=admin&password=&channel=1&stream=0.sdp" + +pygame.init() +screen = pygame.display.set_mode((640,360)) + +print "Using %s renderer" % pygame.display.get_driver() +print 'Playing: %s' % stream + +# Create instane of VLC and create reference to movie. +vlcInstance = vlc.Instance() +media = vlcInstance.media_new(stream, ":network-caching=300") + +# Create new instance of vlc player +player = vlcInstance.media_player_new() + +# Pass pygame window id to vlc player, so it can render its contents there. +win_id = pygame.display.get_wm_info()['window'] +if sys.platform == "linux2": # for Linux using the X Server + player.set_xwindow(win_id) +elif sys.platform == "win32": # for Windows + player.set_hwnd(win_id) + +# Load movie into vlc player instance +player.set_media(media) +player.video_set_format("RV32", 1280, 720, 0); + +# Start movie playback +player.play() + +while player.get_state() != vlc.State.Ended: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + sys.exit(0) + + diff --git a/Camera/RTSPCameraTwo.py b/Camera/RTSPCameraTwo.py new file mode 100644 index 0000000000000000000000000000000000000000..c31abddb9577168e980c3696345084213fdd3596 --- /dev/null +++ b/Camera/RTSPCameraTwo.py @@ -0,0 +1,41 @@ +import sys +import vlc +import pygame + +#IP Address of camera 2 +#Port 554 +stream = "rtsp://192.168.1.11:554/user=admin&password=&channel=1&stream=0.sdp" + +pygame.init() +screen = pygame.display.set_mode((640,360)) + +print "Using %s renderer" % pygame.display.get_driver() +print 'Playing: %s' % stream + +# Create instane of VLC and create reference to movie. +vlcInstance = vlc.Instance() +media = vlcInstance.media_new(stream, ":network-caching=300") + +# Create new instance of vlc player +player = vlcInstance.media_player_new() + +# Pass pygame window id to vlc player, so it can render its contents there. +win_id = pygame.display.get_wm_info()['window'] +if sys.platform == "linux2": # for Linux using the X Server + player.set_xwindow(win_id) +elif sys.platform == "win32": # for Windows + player.set_hwnd(win_id) + +# Load movie into vlc player instance +player.set_media(media) +player.video_set_format("RV32", 1280, 720, 0); + +# Start movie playback +player.play() + +while player.get_state() != vlc.State.Ended: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + sys.exit(0) + + diff --git a/baseStationCode/Static Map API/00000006.png b/baseStationCode/Static Map API/00000006.png new file mode 100644 index 0000000000000000000000000000000000000000..ecd49d812d4601097f54c500b67df8f719a9b53f Binary files /dev/null and b/baseStationCode/Static Map API/00000006.png differ diff --git a/baseStationCode/Static Map API/MercatorProjection.pyc b/baseStationCode/Static Map API/MercatorProjection.pyc index 202154569d4cd9a5f56479397ae457806bfc8e98..aa4daae49d1c8c253278584604818a376132c74a 100644 Binary files a/baseStationCode/Static Map API/MercatorProjection.pyc and b/baseStationCode/Static Map API/MercatorProjection.pyc differ diff --git a/baseStationCode/Static Map API/createCachedImage.py b/baseStationCode/Static Map API/createCachedImage.py index 8cd544d1521bac2823e071d99c4bb5dce86bb3ab..06d87227c2cc22aae6eb688b812f30fe0024f149 100644 --- a/baseStationCode/Static Map API/createCachedImage.py +++ b/baseStationCode/Static Map API/createCachedImage.py @@ -2,6 +2,8 @@ import MercatorProjection import urllib import pygame as pg import io +import os +from math import ceil try: # Python2 from urllib2 import urlopen @@ -13,19 +15,6 @@ except ImportError: # initialize pygame pg.init() -# create url -# can change variables to center on certain locations -# size maxes out at 640x640 for free version -# -90 < latitude < 90 -180 < longitude < 180 -def getUrl(latitude, longitude, zoom, horizontal, vertical): - apikey = "AIzaSyA4it7lRdo5H0mhPlRMM4n2CltZpFnnF4s"; - query = "https://maps.googleapis.com/maps/api/staticmap?" - query += "center=%s,%s&" % (latitude,longitude) - query += "zoom=%s&" % zoom - query += "size=%sx%s&" % (horizontal,vertical) - query += apikey - return query - """ # on a webpage right click on the image you want and use Copy image URL image_url2 = getUrl(corners['S'], corners['E'], 15, 640, 640) @@ -40,47 +29,84 @@ urllib.urlretrieve(image_url4, "00000004.png") urllib.urlretrieve(image_url5, "00000005.png") """ -""" -# center is (x,y) -# scale is how big it is -> -# 1 = 1280x1280 -def createCache(longitude, latitude, scale): - whiteScreen(scale * 640, scale * 640) - for(i in range(scale)): - for(j in range(4)): - image = pg.image.load(str(i + j)) -""" +# create url +# can change variables to center on certain locations +# size maxes out at 640x640 for free version +# -90 < latitude < 90 -180 < longitude < 180 +def getUrl(latitude, longitude, zoom, horizontal, vertical): + apikey = "AIzaSyA4it7lRdo5H0mhPlRMM4n2CltZpFnnF4s"; + query = "https://maps.googleapis.com/maps/api/staticmap?" + query += "center=%s,%s&" % (latitude,longitude) + query += "zoom=%s&" % zoom + query += "size=%sx%s&" % (horizontal,vertical) + query += apikey + return query -# finds the coordinates of the edges -# can use these coordinates to find ratio of pixel to change in degrees -centerPoint = MercatorProjection.G_LatLng(40, -80) -corners = MercatorProjection.getCorners(centerPoint, 15, 640, 640) -cornersB = MercatorProjection.getCorners(centerPoint, 15, 1280, 1280) -print corners -print cornersB - -# create an 1920 by 1080 white screen and put the image on that screen -# (r, g, b) color tuple, values 0 to 255 -white = (255, 255, 255) -screen = pg.display.set_mode((1920,1080), pg.RESIZABLE ) -screen.fill(white) - -def draw(image_file,x,y): +# # center is (x,y) +# # scale is how big it is -> +# # 1 = 1280x1280 +# def createCache(longitude, latitude, scale): +# # horizontal, vertical = (scale+1)*640 +# # screen = whiteScreen(horizontal,vertical) +# for(i in range(scale)): +# for(j in range(4)): +# image = pg.image.load(str(i + j)) + +def draw(image_file,x,y,screen): # load the image from a file or stream image = pg.image.load(image_file) # draw image, position the image ulc at x=0, y=0 screen.blit(image, (x, y)) -draw("00000004.png", 640, 0) # northeast -draw("00000005.png", 0, 0) # northwest -draw("00000003.png", 0, 640) # southwest -draw("00000002.png", 640, 640) # southeast +# create centered fullscreen whitescreen image +def whiteScreen(): + os.environ['SDL_VIDEO_CENTERED'] = '1' + white = (255, 255, 255) + screen = pg.display.set_mode() + screen.fill(white) + return screen +# finds the coordinates of the edges +# can use these coordinates to find ratio of pixel to change in degrees +def findCorners(latitude, longitude, zoom, horizontal, vertical): + centerPoint = MercatorProjection.G_LatLng(latitude, longitude) + corners = MercatorProjection.getCorners(centerPoint, zoom, horizontal, vertical) + return corners + +# get the display information +info = pg.display.Info() +scale = ceil(max(info.current_w, info.current_h) / 640) +print scale +# print "horizontal = %s, vertical = %s" % (info.current_w, info.current_h) + +# can use this the corners with varying sizes to find lat and long for +# various pixel coordinates -> use those coords to query another segment of the map +# from the API. +cornersB = findCorners(40,-80, 15, 1280, 1280) +screen = whiteScreen(); +bleh = findCorners(40,-80,15,1920,640) +longitude = bleh['E'] +latitude = bleh['N'] +print longitude +print latitude +image_url6 = getUrl(latitude, longitude, 15, 640, 640) +urllib.urlretrieve(image_url6, "00000006.png") + + +draw("00000004.png", 640, 0,screen) # northeast +draw("00000005.png", 0, 0,screen) # northwest +draw("00000003.png", 0, 640,screen) # southwest +draw("00000002.png", 640, 640,screen) # southeast +draw("00000006.png",1280,0,screen) + +# saves the combined image +# might not be useful in the end # pg.image.save(screen, "combined.png") # nothing gets displayed until one updates the screen pg.display.flip() + while True: for event in pg.event.get(): if event.type == pg.QUIT: @@ -88,9 +114,10 @@ while True: raise SystemExit if event.type == pg.MOUSEBUTTONDOWN: pixCoord = pg.mouse.get_pos() # get_pos returns tuple - longitude = cornersB['N'] + pixCoord[1] * (cornersB['N'] - cornersB['S']) / 1280 - latitude = cornersB['E'] + pixCoord[0] * (cornersB['E'] - cornersB['W']) / 1280 - print "%s,%s" % (longitude,latitude) + print pixCoord[1] * (cornersB['N'] - cornersB['S']) / info.current_h + longitude = cornersB['W'] + pixCoord[0] * (cornersB['E'] - cornersB['W']) / 1280 + latitude = cornersB['N'] + pixCoord[1] * (cornersB['N'] - cornersB['S']) / 1280 + print "latitude = %s, longitude = %s" % (latitude, longitude)