Did you know you can directly decompress an archive using Scilab?
Here is an example that downloads an archive using http_get, decompresses it, and displays its contents (images) in an uicontrol.
Download
We first download the archive. This example is based on a zip
file but many other formats are managed.
// URL of a zip file
zipUrl = "https://gitlab.com/scilab/forge/scicv/-/archive/0.6.2/scicv-0.6.2.zip?path=data/images";
// Download the zip file
mprintf("Downloading archive file... ");
zipFile = http_get(zipUrl, "output_images.zip");
mprintf("DONE\n");
Decompress
Then we extract its contents in a specific directory:
// Extract the archive and return the list of extracted element path
mprintf("Decompressing archive... ");
extracted = decompress("output_images.zip", "output_dir");
// Keep only files from the decompressed extracted element list
names = fileparts(extracted, 'fname');
fileIdx = find(names <> "");
files = extracted(fileIdx);
filenames = names(fileIdx);
mprintf("%d files extracted.\n", size(files, "*"));
Display
And finally, we display the extracted images in a uicontrol
based GUI:
// Create the main figure
f = figure("name", "Image browser", "background", -2, "axes_size", [700, 350], "tag", "main_figure", "toolbar_visible", "off", "menubar_visible", "off");
// Display selectable file list
uicontrol(f, "style", "listbox", "string", filenames, "userdata", files, "position", [20, 20, 200, 300], "callback", "image_changes_cb");
// Add a label above the file list
uicontrol(f, "style", "text", "string", " Extracted images:", "BackgroundColor", [1,1,1], "position", [20, 325, 200, 20], "FontWeight", "bold");
// Display the image after clicking on the image name
uicontrol(f, "style", "image", "BackgroundColor", [1,1,1], "horizontalalignment", "center", "verticalalignment", "middle", "Position", [250, 20, 400, 300], "tag", "image_zone");
// Defines the callback function called when clicking on a filename
function image_changes_cb()
selectedFile = gcbo().userdata(gcbo().value);
set("image_zone", "String", selectedFile);
set("main_figure", "info_message", pathconvert(selectedFile));
endfunction
Feel free to use this example as a basis for your own demo