First, forgive me if this sounds like a stupid question for something impossible to do. But, I'm currently trying to simulate a scene where a quadcopter moves through a field that is georeferenced. This georeference comes from a GEOTiff image that I exported from QGIS. This image is 992x622 pixels in size and each pixel area should represent an 8x8m [pixel] area on the world map with a WGS84 Coordinate Reference System (CRS).
I'm using CoppeliaSim v4.10 on Linux Fedora 42. This is part of my PhD research, so forgive me again if it may soudn stupid. I'm trying to create a nice visually and "ground truth"-based PhD thesis that's not just another theoretical piece of work.
What I already tried:
- Force CoppeliaSim through a lua script to create a 7,936m by 4,976m cuboid and apply the image texture to it. This resulted in a huge black image that not fiddling with the color settings fixed
- Resample the image using GIMP a lot to have close to 125x78px, but that made no sense and the image was simply unusable
- Create 40 1,000m by 1,000m tiles and arranged then in a 5x8[rows,cols] grid, sliced the images to have 125x125px each and composed a 40 tiled grid with each of the 40 sliced images in the correct cuboid to form the whole georeferenced image. This resulted in 5x8 huge floor cuboid with 40 textures that seemed fairly zoomed in, so that the pixels were shown individually, again...unusable
To create 40 tiles in a 5x8 grid:
Code: Select all
#lua
sim = require 'sim'
-- Grid configuration
rows = 5 -- Y direction (south → north)
cols = 8 -- X direction (west → east)
-- Tile size in meters
tileSizeX = 1000.0
tileSizeY = 1000.0
tileSizeZ = 0.1
for r = 0, rows-1 do
for c = 0, cols-1 do
-- 1 = cuboid primitive
h = sim.createPrimitiveShape(1, {tileSizeX, tileSizeY, tileSizeZ})
-- Center positions so grid starts at (0,0) and grows in +X,+Y
xCenter = 0.5 * tileSizeX + c * tileSizeX -- 500, 1500, 2500, ...
yCenter = 0.5 * tileSizeY + r * tileSizeY -- 500, 1500, 2500, ...
zCenter = 0.0
-- Place relative to world (-1 = world frame)
sim.setObjectPosition(h, -1, {xCenter, yCenter, zCenter})
-- Give a clear alias: tile_r<row>_c<col>
alias = string.format('tile_r%d_c%d', r, c)
sim.setObjectAlias(h, alias)
-- Make ambient/diffuse color white so textures show correctly later
sim.setObjectColor(h, 0, sim.colorcomponent_ambient_diffuse, {1, 1, 1})
end
end
print('Created 40 tiles (5 rows x 8 cols) of 1000x1000x0.1 m.')
Code: Select all
#lua
-- slice_8x5.lua
-- Usage: lua slice_8x5.lua input.png output_dir
local input = arg[1]
local outdir = arg[2]
if not input or not outdir then
print("Usage: lua slice_8x5.lua input.png output_dir")
os.exit(1)
end
-- Image is 992x622, 8 m/px, tiles 125x125 px
local W, H = 992, 622
local tile = 125
-- Make output dir
os.execute("mkdir -p '" .. outdir .. "'")
local rows = 5 -- ceil(622/125)
local cols = 8 -- ceil(992/125)
for r = 0, rows - 1 do
for c = 0, cols - 1 do
local x0 = c * tile
local y0 = r * tile
if x0 >= W or y0 >= H then
goto continue
end
local x1 = math.min(x0 + tile, W)
local y1 = math.min(y0 + tile, H)
local w = x1 - x0
local h = y1 - y0
local fname = string.format("%s/tile_r%d_c%d.png", outdir, r, c)
local cmd = string.format("magick '%s' -crop %dx%d+%d+%d +repage '%s'", input, w, h, x0, y0, fname)
print(cmd)
os.execute(cmd)
::continue::
end
end
Caio Guimarães.