Why does this code render no objects on the screen? - object

Did I mess up something somewhere? If i put a putsxy in the same box, it renders a string just fine, but for some reason this code hates objects. What this code is supposed to do is render a set of randomly positioned 't's on the screen, and this works fine without objects. However, when I add objects, nothing renders. What am I doing wrong? Help is much appreciated. Code is as follows:
-------------------------------
-- Asterix v0.0.3 --
-- Copyright 2013 WilliamTDR. --
-------------------------------
-- prerequestities --
require "actions" -- button input
require "math" -- random numbers
-- Global Variables --
local player = {
health = 20, -- player health
foodparts = 12, -- portions of food until the food level depletes by one
food = 40, -- player food
x = 50, -- player x position
y = 50, -- player y position
roomx = 0, -- x value of room player is in
roomy = 0 -- y value of room player is in
}
local object = {
x = 30,
y = 30,
roomx = 0,
roomy = 0,
name = "Unknown Object",
touchingplayer = false,
symbol = "u"
}
local objects = {}
function object:new (o)
o = o or {} -- create object if user does not provide one
setmetatable(o, self)
self.__index = self
return o
end
function player.refresh()
-- reset player values
player.food = 40
player.health = 20
player.foodparts = 12
player.x = 50
player.y = 50
player.roomx = 0
roomy = 0
end
function player.die()
rb.lcd_clear_display() -- clear the display
rb.lcd_putsxy(1, 7, "You have died!")
rb.lcd_putsxy(1, 45, "Respawning in 3...")
rb.lcd_update()
rb.sleep(rb.HZ) -- sleep for one second
rb.lcd_putsxy(1, 45, "Respawning in 2...")
rb.lcd_update()
rb.sleep(rb.HZ)
rb.lcd_putsxy(1, 45, "Respawning in 1...")
rb.lcd_update()
rb.sleep(rb.HZ)
player.refresh()
render()
end
function renderobjects()
for _,object in ipairs(objects) do
if player.roomx == object.roomx and player.roomy == object.roomy then
rb.putsxy(object.x, object.y, object.symbol)
end
end
rb.lcd_update()
end
function createnewobjects()
obj1 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj2 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj3 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj4 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj5 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj6 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj7 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj8 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj9 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj10 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj11 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj12 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj13 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj14 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj15 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj16 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj17 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj18 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj19 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
obj20 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
table.insert(obj1, objects)
table.insert(obj2, objects)
table.insert(obj3, objects)
table.insert(obj4, objects)
table.insert(obj5, objects)
table.insert(obj6, objects)
table.insert(obj7, objects)
table.insert(obj8, objects)
table.insert(obj9, objects)
table.insert(obj10, objects)
table.insert(obj11, objects)
table.insert(obj12, objects)
table.insert(obj13, objects)
table.insert(obj14, objects)
table.insert(obj15, objects)
table.insert(obj16, objects)
table.insert(obj17, objects)
table.insert(obj18, objects)
table.insert(obj19, objects)
table.insert(obj20, objects)
end
function checks()
if player.foodparts < 1 then
player.foodparts = 12
player.food = player.food - 1
end
if player.food < 1 then
player.health = player.health - 1
end
if player.health < 1 then
player.die()
end
if player.x < 1 then
player.roomx = player.roomx + 1
createnewobjects()
player.x = 92
end
if player.x > 93 then
player.roomx = player.roomx - 1
createnewobjects()
player.x = 4
end
if player.y < 1 then
player.roomy = player.roomy + 1
createnewobjects()
player.y = 92
end
if player.y > 93 then
player.roomy = player.roomy - 1
renderobjects()
player.y = 4
end
end
function render()
checks()
rb.lcd_set_background(0, 255, 0) -- background is black
rb.lcd_set_foreground(-1, 0, 0) -- foreground is white
rb.lcd_clear_display()
rb.lcd_fillrect(5, 3, (player.health * 2), 2)
rb.lcd_set_foreground(88, 2, 2)
rb.lcd_fillrect(45, 3, player.food, 2)
rb.lcd_set_foreground(125, 125, 0)
rb.lcd_putsxy(player.x, player.y, "*")
renderobjects()
rb.lcd_update()
end
function LoadGame()
render()
while true do
button = rb.get_plugin_action(0)
if button == 182 then
player.x = player.x - 1
player.foodparts = player.foodparts - 1
render()
elseif button == 183 then
player.x = player.x + 1
player.foodparts = player.foodparts - 1
render()
elseif button == 180 then
player.y = player.y - 1
player.foodparts = player.foodparts - 1
render()
elseif button == 181 then
player.y = player.y + 1
player.foodparts = player.foodparts - 1
render()
elseif button == 186 then
player.x = player.x - 4
player.foodparts = player.foodparts - 4
LoadGame()
elseif button == 187 then
player.x = player.x + 4
player.foodparts = player.foodparts - 4
LoadGame()
elseif button == 184 then
player.y = player.y - 4
player.foodparts = player.foodparts - 4
LoadGame()
elseif button == 185 then
player.y = player.y + 4
player.foodparts = player.foodparts - 4
LoadGame()
elseif button == 191 then
ShowMainMenu() -- start the program by displaying the main menu of the script.
end
end
end
function ShowMainMenu()
mainmenu = {"New Game", "Load Game", "About MCRE", "Exit"}
while true do
s = rb.do_menu("Asterix v0.0.1", mainmenu, nil, false)
if s == 0 then LoadGame()
elseif s == 1 then rb.splash(3 * rb.HZ, "No maps found! Create one first.")
elseif s == 2 then rb.splash(5 * rb.HZ, "Game ©2013 WilliamTDR. Version 0.0.1, build 4. Minecraft is a registered trademark of Notch Development AB.")
elseif s == 3 then os.exit()
elseif s == -2 then os.exit()
else rb.splash(2 * rb.HZ, "Whoops: Unexpected Button press!" .. s)
end
end
end
ShowMainMenu() -- start the program by displaying the main menu of the script.

You need to swap the order of the arguments to table.insert -- it should be
table.insert(objects, obj1)
not
table.insert(obj1, objects)
You can also use
setmetatable(objects,{__index=table})
objects:insert(obj1)
-- etc.

Related

How to change color of mark on topoplot interactively?

I want to create interactive line- and topoplot depending on menu. I figured out how to make red the line chosen in menu, but it doesn't work for topoplot marks (black circles inside topoplot). I can change it manually (cmap[][4] = RGB{N0f8}(1.0,0.0,0.0)), but how to do that interactively?
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), resolution = (1500, 700))
ax = Axis(f[1:3, 1], xlabel = "Time [s]", ylabel = "Voltage amplitude [µV]")
N = 1:length(pos) #1:4
hidespines!(ax, :t, :r)
GLMakie.xlims!(-0.3, 1.2)
hlines!(0, color = :gray, linewidth = 1)
vlines!(0, color = :gray, linewidth = 1)
times = range(-0.3, length=size(dat_e,2), step=1 ./ 128)
lines = Dict()
for i in N
mean_trial = mean(dat_e[i,:,:],dims=2)[:,1]
line = lines!(times, mean_trial, color = "black")
lines[i] = line
end
hidedecorations!(ax, label = false, ticks = false, ticklabels = false)
topo_axis = Axis(f[2, 2], width = 178, height = 178, aspect = DataAspect())
Makie.xlims!(low = -0.2, high = 1.2)
Makie.ylims!(low = -0.2, high = 1.2)
topoMatrix = eegHeadMatrix(pos[N], (0.5, 0.5), 0.5)
cmap = Observable(collect(ColorScheme(range(colorant"black", colorant"black", length=30))))
#cmap[][4] = RGB{N0f8}(1.0,0.0,0.0)
topo = eeg_topoplot!(topo_axis, N, # averaging all trial of 30 participants on Xth msec
raw.ch_names[1:30];
positions=pos, # produced automatically from ch_names
interpolation=NullInterpolator(),
enlarge=1,
#colorrange = (0, 1), # add the 0 for the white-first color
colormap = cmap[],
label_text=false)
hidedecorations!(current_axis())
hidespines!(current_axis())
num_prev = 0
menu = Menu(f[3, 2], options = raw.ch_names[1:30], default = nothing)#, default = "second")
on(menu.selection) do selected
if selected != nothing
num = findall(x->x==menu.selection[], raw.ch_names[1:30])[]
if num_prev != 0
lines[num_prev].color = "black"
cmap[][num] = RGB{N0f8}(1.0,0.0,0.0)
end
lines[num].color = "red"
cmap[][num] = RGB{N0f8}(1.0,0.0,0.0)
num_prev = num
end
end
notify(menu.selection)
#print(cmap[])
f
We solved this by putting this string at the end of the menu.selection section:
notify(lines)
It works, because lines() automatically creates Observable.

Why am i not getting any visualisation Vpython?

I am trying to simulate some planets and their moons around the sun but not getting scene opened up.`from vpython import*
def open_scene(breedte, hoogte):
global open_venster
c = canvas(width=breedte, height=hoogte, background=color.black)
c.center = vector(0,0,0)
c.range = breedte
c.autozoom = True
c.autoscale = False
c.userzoom = True
c.userspin = False
c.userpan = False
return c
open_scene(400, 400)
def solarsystem(n, dt):
He = planets_from_file("planeten.txt")
planets = []
sun = sphere(pos = vector(0,0,0), radius = He[0].straal_v_hemellichaam, color = kleuromzetting(He[0].kleur))
earth = sphere(pos = vector(-He[3].straal_vd_baan, 0, 0), radius= He[3].straal_v_hemellichaam*50, texture= textures.earth)
moon = sphere(pos = vector(-He[4].straal_vd_baan,0,0), radius = He[4].straal_v_hemellichaam, color = kleuromzetting(He[4].kleur))
mercurius = sphere(pos = vector(-He[1].straal_vd_baan,0,0), radius = He[1].straal_v_hemellichaam, color = kleuromzetting(He[1].kleur))
venus = sphere(pos = vector(-He[2].straal_vd_baan,0,0), radius = He[2].straal_v_hemellichaam, color = kleuromzetting(He[2].kleur))
mars = sphere(pos = vector(-He[5].straal_vd_baan,0,0), radius = He[5].straal_v_hemellichaam, color = kleuromzetting(He[5].kleur))
phobos = sphere(pos = vector(-He[6].straal_vd_baan-He[5].straal_vd_baan,0,0), radius = He[6].straal_v_hemellichaam, color = kleuromzetting(He[6].kleur))
deimos = sphere(pos = vector(-He[7].straal_vd_baan-He[5].straal_vd_baan,0,0), radius = He[7].straal_v_hemellichaam, color = kleuromzetting(He[7].kleur))
jupiter = sphere(pos = vector(-He[8].straal_vd_baan,0,0), radius = He[8].straal_v_hemellichaam, color = kleuromzetting(He[8].kleur))
io = sphere(pos = vector(-He[9].straal_vd_baan-He[8].straal_vd_baan,0,0), radius = He[9].straal_v_hemellichaam, color = kleuromzetting(He[9].kleur))
europa = sphere(pos = vector(-He[10].straal_vd_baan-He[8].straal_vd_baan,0,0), radius = He[10].straal_v_hemellichaam, color = kleuromzetting(He[10].kleur))
ganymede = sphere(pos = vector(-He[11].straal_vd_baan-He[8].straal_vd_baan,0,0), radius = He[11].straal_v_hemellichaam, color = kleuromzetting(He[11].kleur))
callisto = sphere(pos = vector(-He[12].straal_vd_baan-He[8].straal_vd_baan,0,0), radius = He[12].straal_v_hemellichaam, color = kleuromzetting(He[12].kleur))
sun.velocity = vector(0, 0, 0)
earth.velocity = He[3].snelheid
moon.velocity = He[4].snelheid
mercury.velocity = He[1].snelheid
venus.velocity = He[2].snelheid
mars.velocity =He[5].snelheid
phobos.velocity = He[6].snelheid
deimos.velocity = He[7].snelheid
jupiter.velocity = He[8].snelheid
io.velocity = He[9].snelheid
europa.velocity = He[10].snelheid
ganymede.velocity = He[11].snelheid
callisto.velocity = He[12].snelheid
sun.massa = He[0].massa
earth.massa = He[3].massa
moon.massa = He[4].massa
mercury.massa = He[1].massa
venus.massa = He[2].massa
mars.massa =He[5].massa
phobos.massa = He[6].massa
deimos.massa = He[7].massa
jupiter.massa = He[8].massa
io.massa = He[9].massa
europa.massa = He[10].massa
ganymede.massa = He[11].massa
callisto.massa = He[12].massa
planets.extend((sun, earth, moon, mercurius, venus, mars, phobos, jupiter, io, europa, ganymede, calisto))
while True:
sleep(0.02)
for planet in planets:
a = calc_gravitational_acceleration(planet.massa, planet.pos)
planet.velocity -= a*dt
planet.pos += planet.velocity * dt`

How to automatically resize and centre tkinter window

I have an issues with window resizing in tkinter when a user variable is displayed. As the program takes in the name of a team and display's it later in the program, having a set size for the display window will not work as it needs to be adaptive. I have got code for centring the window, but is there a way to automatically set the size of the window?
Current Look:
team_2 = t2_entry.get()
top_2.withdraw()
confirm_screen = Toplevel(master)
w = 160 + len(team_2) + len(team_1)
h = 50
ws = confirm_screen.winfo_screenwidth()
hs = confirm_screen.winfo_screenheight()
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
confirm_screen.geometry('%dx%d+%d+%d' % (w, h, x, y))
t1_name = Label(confirm_screen, text = "Team 1: " + team_1).grid(row = 1, column = 1)
t2_name = Label(confirm_screen, text="Team 2: " + team_2).grid(row = 1, column = 2)
confirm_button = Button(confirm_screen, text = "Submit", width = 10, command = team_name_1).grid(row = 4, column = 1)
redo = Button(confirm_screen, text="Redo", width=10, command= lambda: [start_team1(), clear()]).grid(row=4, column=2)
Attempts 1:
team_2 = t2_entry.get()
top_2.withdraw()
confirm_screen = Toplevel(master)
w = 160 + len(team_2) + len(team_1)
h = 50
ws = confirm_screen.winfo_screenwidth()
hs = confirm_screen.winfo_screenheight()
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
confirm_screen.geometry('%dx%d+%d+%d' % (w, h, x, y))
t1_name = Label(confirm_screen, text = "Team 1: " + team_1).grid(row = 1, column = 1)
t2_name = Label(confirm_screen, text="Team 2: " + team_2).grid(row = 1, column = 2)
confirm_button = Button(confirm_screen, text = "Submit", width = 10, command = team_name_1).grid(row = 4, column = 1)
redo = Button(confirm_screen, text="Redo", width=10, command= lambda: [start_team1(), clear()]).grid(row=4, column=2)
Attempt 2:
team_2 = t2_entry.get()
top_2.withdraw()
confirm_screen = Toplevel(master)
w = confirm_screen.winfo_width
h = confirm_screen.winfo_height
ws = confirm_screen.winfo_screenwidth()
hs = confirm_screen.winfo_screenheight()
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
confirm_screen.geometry('%dx%d+%d+%d' % (w, h, x, y))
t1_name = Label(confirm_screen, text = "Team 1: " + team_1).grid(row = 1, column = 1)
t2_name = Label(confirm_screen, text="Team 2: " + team_2).grid(row = 1, column = 2)
confirm_button = Button(confirm_screen, text = "Submit", width = 10, command = team_name_1).grid(row = 4, column = 1)
redo = Button(confirm_screen, text="Redo", width=10, command= lambda: [start_team1(), clear()]).grid(row=4, column=2)
I think this is what you are after:
from tkinter import *
confirm_screen = Tk()
t1_name = Label(confirm_screen, text = "Team 1: " + "team_1").grid(row = 1, column = 1)
t2_name = Label(confirm_screen, text="Team 2: " + "team_2").grid(row = 1, column = 2)
confirm_button = Button(confirm_screen, text = "Submit", width = 10, command = None).grid(row = 4, column = 1)
redo = Button(confirm_screen, text="Redo", width=10, command= lambda: [start_team1(), clear()]).grid(row=4, column=2)
# You need to update the display so that the widgets are actually displayed on the screen.
# Otherwise `w` and `h` will both = 1
confirm_screen.update()
w = confirm_screen.winfo_width()
h = confirm_screen.winfo_height()
ws = confirm_screen.winfo_screenwidth()
hs = confirm_screen.winfo_screenheight()
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
confirm_screen.geometry('+%d+%d' % (x, y))
You have to first place all of the widgets and then calculate where the window should go. Also there is no need to always include the size of the window when using <tkinter.Tk>.geometry(...).

tkinter sliders are stuck together

I'm having trouble separating these 2 sliders. They seem to be tracking together, but the variables seem to no be unique, and I can't figure out why. Can anyone help?
import tkinter as tk
sBoard = tk.Tk()
sBoard.geometry("800x400")
ch1_Frame = tk.LabelFrame(sBoard, text = "CH 1", bd = 5)
ch1_val = 0
ch1 = tk.Scale(ch1_Frame, variable = ch1_val, from_ =100, to = 0, showvalue = 0, width = 25, length = 200)
ch1.pack()
button1 = tk.Button(ch1_Frame, text = "Power")
button1.pack()
ch1_Frame.place(x=25, y=50)
ch2_Frame = tk.LabelFrame(sBoard, text = "CH 2", bd = 5)
ch2_val = 0
ch2 = tk.Scale(ch2_Frame, variable = ch2_val, from_ =100, to = 0, showvalue = 0, width = 25, length = 200)
ch2.pack()
button2 = tk.Button(ch2_Frame, text = "Power")
button2.pack()
ch2_Frame.place(x=150, y=50)
sBoard.mainloop()
The variable must be one of the tkinter variable types, for example an IntVar:
ch1_val = tk.IntVar()
ch1 = tk.Scale(ch1_Frame, variable = ch1_val, from_ =100, to = 0, showvalue = 0, width = 25, length = 200)
ch1.pack()

How to get real Landsat image conrers

How I can get actual coordinates of Landsat image corners (see image to understand) ?
From metadata file (..._MTL.txt) I can get coordinates of red corners, but I need to get coordinates of green corners.
I work with GeoTIFF files using GDAL.
I need to get correct latitude and longitude of green points.
Can I do it using python3?
Thanks for help
Metadata file
GROUP = L1_METADATA_FILE
GROUP = METADATA_FILE_INFO
ORIGIN = "Image courtesy of the U.S. Geological Survey"
REQUEST_ID = "9991103150002_00325"
PRODUCT_CREATION_TIME = 2011-03-16T20:14:24Z
STATION_ID = "EDC"
LANDSAT5_XBAND = "1"
GROUND_STATION = "IKR"
LPS_PROCESSOR_NUMBER = 0
DATEHOUR_CONTACT_PERIOD = "1016604"
SUBINTERVAL_NUMBER = "01"
END_GROUP = METADATA_FILE_INFO
GROUP = PRODUCT_METADATA
PRODUCT_TYPE = "L1T"
ELEVATION_SOURCE = "GLS2000"
PROCESSING_SOFTWARE = "LPGS_11.3.0"
EPHEMERIS_TYPE = "DEFINITIVE"
SPACECRAFT_ID = "Landsat5"
SENSOR_ID = "TM"
SENSOR_MODE = "BUMPER"
ACQUISITION_DATE = 2010-06-15
SCENE_CENTER_SCAN_TIME = 04:57:44.2830500Z
WRS_PATH = 145
STARTING_ROW = 26
ENDING_ROW = 26
BAND_COMBINATION = "1234567"
PRODUCT_UL_CORNER_LAT = 49.8314223
PRODUCT_UL_CORNER_LON = 84.0018859
PRODUCT_UR_CORNER_LAT = 49.8694055
PRODUCT_UR_CORNER_LON = 87.4313889
PRODUCT_LL_CORNER_LAT = 47.8261840
PRODUCT_LL_CORNER_LON = 84.1192898
PRODUCT_LR_CORNER_LAT = 47.8615913
PRODUCT_LR_CORNER_LON = 87.4144676
PRODUCT_UL_CORNER_MAPX = 284400.000
PRODUCT_UL_CORNER_MAPY = 5524200.000
PRODUCT_UR_CORNER_MAPX = 531000.000
PRODUCT_UR_CORNER_MAPY = 5524200.000
PRODUCT_LL_CORNER_MAPX = 284400.000
PRODUCT_LL_CORNER_MAPY = 5301000.000
PRODUCT_LR_CORNER_MAPX = 531000.000
PRODUCT_LR_CORNER_MAPY = 5301000.000
PRODUCT_SAMPLES_REF = 8221
PRODUCT_LINES_REF = 7441
PRODUCT_SAMPLES_THM = 4111
PRODUCT_LINES_THM = 3721
BAND1_FILE_NAME = "L5145026_02620100615_B10.TIF"
BAND2_FILE_NAME = "L5145026_02620100615_B20.TIF"
BAND3_FILE_NAME = "L5145026_02620100615_B30.TIF"
BAND4_FILE_NAME = "L5145026_02620100615_B40.TIF"
BAND5_FILE_NAME = "L5145026_02620100615_B50.TIF"
BAND6_FILE_NAME = "L5145026_02620100615_B60.TIF"
BAND7_FILE_NAME = "L5145026_02620100615_B70.TIF"
GCP_FILE_NAME = "L5145026_02620100615_GCP.txt"
METADATA_L1_FILE_NAME = "L5145026_02620100615_MTL.txt"
CPF_FILE_NAME = "L5CPF20100401_20100630_09"
END_GROUP = PRODUCT_METADATA
GROUP = MIN_MAX_RADIANCE
LMAX_BAND1 = 193.000
LMIN_BAND1 = -1.520
LMAX_BAND2 = 365.000
LMIN_BAND2 = -2.840
LMAX_BAND3 = 264.000
LMIN_BAND3 = -1.170
LMAX_BAND4 = 221.000
LMIN_BAND4 = -1.510
LMAX_BAND5 = 30.200
LMIN_BAND5 = -0.370
LMAX_BAND6 = 15.303
LMIN_BAND6 = 1.238
LMAX_BAND7 = 16.500
LMIN_BAND7 = -0.150
END_GROUP = MIN_MAX_RADIANCE
GROUP = MIN_MAX_PIXEL_VALUE
QCALMAX_BAND1 = 255.0
QCALMIN_BAND1 = 1.0
QCALMAX_BAND2 = 255.0
QCALMIN_BAND2 = 1.0
QCALMAX_BAND3 = 255.0
QCALMIN_BAND3 = 1.0
QCALMAX_BAND4 = 255.0
QCALMIN_BAND4 = 1.0
QCALMAX_BAND5 = 255.0
QCALMIN_BAND5 = 1.0
QCALMAX_BAND6 = 255.0
QCALMIN_BAND6 = 1.0
QCALMAX_BAND7 = 255.0
QCALMIN_BAND7 = 1.0
END_GROUP = MIN_MAX_PIXEL_VALUE
GROUP = PRODUCT_PARAMETERS
CORRECTION_METHOD_GAIN_BAND1 = "CPF"
CORRECTION_METHOD_GAIN_BAND2 = "CPF"
CORRECTION_METHOD_GAIN_BAND3 = "CPF"
CORRECTION_METHOD_GAIN_BAND4 = "CPF"
CORRECTION_METHOD_GAIN_BAND5 = "CPF"
CORRECTION_METHOD_GAIN_BAND6 = "IC"
CORRECTION_METHOD_GAIN_BAND7 = "CPF"
CORRECTION_METHOD_BIAS = "IC"
SUN_AZIMUTH = 141.2669762
SUN_ELEVATION = 59.9909680
OUTPUT_FORMAT = "GEOTIFF"
END_GROUP = PRODUCT_PARAMETERS
GROUP = CORRECTIONS_APPLIED
STRIPING_BAND1 = "NONE"
STRIPING_BAND2 = "NONE"
STRIPING_BAND3 = "NONE"
STRIPING_BAND4 = "NONE"
STRIPING_BAND5 = "NONE"
STRIPING_BAND6 = "NONE"
STRIPING_BAND7 = "NONE"
BANDING = "N"
COHERENT_NOISE = "N"
MEMORY_EFFECT = "Y"
SCAN_CORRELATED_SHIFT = "Y"
INOPERABLE_DETECTORS = "N"
DROPPED_LINES = "N"
END_GROUP = CORRECTIONS_APPLIED
GROUP = PROJECTION_PARAMETERS
REFERENCE_DATUM = "WGS84"
REFERENCE_ELLIPSOID = "WGS84"
GRID_CELL_SIZE_THM = 60.000
GRID_CELL_SIZE_REF = 30.000
ORIENTATION = "NUP"
RESAMPLING_OPTION = "CC"
MAP_PROJECTION = "UTM"
END_GROUP = PROJECTION_PARAMETERS
GROUP = UTM_PARAMETERS
ZONE_NUMBER = 45
END_GROUP = UTM_PARAMETERS
END_GROUP = L1_METADATA_FILE
END
You might first find the contour with the biggest area. Then try some algorithm to find the points you want. It seems that the satellite picture in the image is not a perfect rectangle, so you can't fit a rectangle on it using OpenCV's built-in methods.
You should try something like that:
import cv2
import numpy as np
img = cv2.imread('z_edited.jpg')
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(imgray, (11, 11), 0)
ret, thresh = cv2.threshold(blurred, 27, 255, 0)
cnts, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
max_area = 0
max_area_index = 0
for i, cnt in enumerate(cnts):
area = cv2.contourArea(cnt)
if area > max_area:
max_area = area
max_area_index = i
x_min = np.min(cnts[max_area_index][:, 0, 0])
x_max = np.max(cnts[max_area_index][:, 0, 0])
y_min = np.min(cnts[max_area_index][:, 0, 1])
y_max = np.max(cnts[max_area_index][:, 0, 1])
(x_left, y_left) = (x_min, cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 0] == x_min)), 0, 1])
(x_right, y_right) = (x_max, cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 0] == x_max)), 0, 1])
(x_down, y_down) = (cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 1] == y_max)), 0, 0], y_max)
(x_top, y_top) = (cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 1] == y_min)), 0, 0], y_min)
cv2.circle(img, (x_left, y_left), 10, (0, 0, 255), thickness=8)
cv2.circle(img, (x_right, y_right), 10, (0, 0, 255), thickness=8)
cv2.circle(img, (x_down, y_down), 10, (0, 0, 255), thickness=8)
cv2.circle(img, (x_top, y_top), 10, (0, 0, 255), thickness=8)
# cv2.drawContours(img, cnts, max_area_index, (0, 255, 0), 2)
cv2.namedWindow('s', cv2.WINDOW_NORMAL)
cv2.imshow('s', img)
cv2.waitKey(0)
And the result looks like:
Using this code you can find the coordinates of the corners of the satellite picture inside the image(red points).
Also need to say I have assumed that your satellite picture background is completely black(the image you have uploaded, has a thin gray strip around the whole image).

Resources