Viewing progress of MovieWriter file for animation plots - animation

I am doing simulations which can take several hours to finish and I am using matplotlib.animation's MovieWriter to handle the details of writing plots of the data to a movie file. I am simply following the example script, http://matplotlib.org/examples/animation/moviewriter.html.
Is it possible to open the movie while it is being written to? I would like to check the progress of the simulation? Maybe I need to use a video format which can operate on incomplete data stream.
I know an easy alternative is to use savefig simply save an image to file, but I was wondering if it is possible to "check" on the progress of the movie by making some simple changes.
When I try to open the movie while (on MacOS) I get an error basically saying that the format cannot be understood. Once fully written the file open with no problems.

Related

Isolate OpenSCAD view

I occasionally do some work in OpenSCAD on Fiverr. Instead of sending 100 screenshots each day I would like to provide my clients with a live 3D preview of the object. But I need to do this without giving the source away (in the past I have been naive enough to get scammed this way).
I want my clients to be able look at the live 3D view without being able to see the source code.
For example, the following is a possible solution I was thinking of: hardcode the contents of the .scad file into a string inside an executable. Then start OpenSCAD with this string but only show the preview window, without the client being to look at the code.
You can, in fact, use the openscad.exe to generate a preview from a .scad file:
& "C:\Program Files\OpenSCAD\openscad.exe" --preview --camera=0,0,0,45,45,0,200 test.scad -o test.png
However, there are two problems with this method. 1. It only generates a PNG, I need my clients to be able to pan and zoom. 2. It needs a local file. I could generate a tmp file, open it with above command and then quickly delete the file.
Consider sending an STL file for them to look at. OpenSCAD can export to STL. There are two versions of STL: ascii and binary. OpenSCAD outputs the binary form. Your clients could view your STL file in something like viewstl.com.
Since they could 3d print from the STL you might consider adding some watermark type textures or features that would be difficult to remove. Another option would be to change some key dimensions enough to make it unusable but not so much that it looks bad.

How to display an image in real-time using Rust?

I am trying to write a ray tracer and want to render my image in real time in a GUI window. Basically, I have a buffer: Vec<u8> that is constantly updating. The question is how do I display it on the screen after completing each row. I was thinking about using iced or egui, but couldn't figure out how to output changing image without copying it each time. Solutions that are using other toolkits are also welcome.
egui asks for TextureId:
ui.image(my_texture_id, [640.0, 480.0]);
but doesn't say where to get it
For egui there's some example here and a note here if you want to go 3D (with an example too).
For iced there's a bunch of examples, and some of them are using image/image_viewer (e.g. pokedex).
A way to go would be to copy their code, make it compile/run, and then tweak it with your logic. If something goes wrong - you'd have more input for a more concrete SO question.
Also I don't think that there's anything wrong per se in copying the data for the purpose of buffering (see this).

Processing: save color and depth images

I just started working with Processing, because I need to get a sequence of images, color and depth. When I save does images while drawing, so for each image I get I save it. I have around 2fps. Is there a way to improve this?
My thought was to store the image in an array list. I thought there is a function setup() so there would be also a function shutdown() or something. So When i hit the Esc button or close the window which is getting cold. Like a decompiler. Where I can run a loop trough that lists and save them. But I don't find such a function.
I am working on a MacBook Air (2013)
If you use OpenNI/SimpleOpenNI I recommend a nicer option: use the the .oni format (which stores both depth and rgb streams). All you have to do is:
Record to an .oni file (fast/realtime)
Read the depth/color streams from the recorded .oni streams when you need to.
To record to an .oni file you've got two options:
Use the Examples > Contributed Libraries > SimpleOpenNI > OpenNI > RecorderPlay sketch to record (some explanations at the bottom of this answer)
Use OpenNI SDK's NiViewer utility which can also save/load .oni files. (You can easily install this using homebrew: brew install homebrew/science/openni2. The path in this case will be something like /usr/local/Cellar/openni2/2.2.0.33/share/openni2/tools/NiViewer)
Once you have your .oni file, you can easily read it/play it back at different rate and access depth/rgb streams to save to disk.
Regarding your existing program
The frame rate drops because in the same thread it's encoding and writing two images to disk per frame. You can improve this by:
saving to an uncompressed format (like tiff)
threading the image save operation (see the bottom of this answer for some ideas)

Matplotlib animation: setting fps=90 creates a movie file properly, but setting fps=120 does not?

Could you help me understand why this might be the case? This is what my command looks like:
ani.save("animation.avi", codec="libx264", fps=120)
The movie file size with the above command is very small in the order of hundreds of kilobytes. Playing the movie just shows a static picture (the very first frame).
ani.save("animation.avi", codec="libx264", fps=90)
This on the other hand, creates a movie file with a reasonable size in the order of megabytes, and plays as an animation as well.
At first, I thought this was an issue with a specific writer (avconv), but this problem occurs even when I have no writer specified, so it might be a general issue with my specific case, or matplotlib.

Overidding imshow

When I use the following,
imshow(imread('image1.jpg'));
imshow(imread('image2.jpg'));
imshow(imread('image3.jpg'));
imshow(imread('image4.jpg'));
imshow(imread('image5.jpg'));
imshow(imread('image6.jpg'));
I got only image named image6.jpg in the output figure.
There is also an option figure,imshow(...); to view all the images each in new window.
But writing figure in each line where I need to view the image is a repeated and tedious process. Is there any other solution to get the same output as with figure,imshow(..);
without using figure function.
I mainly put on this question because while programming a lot somewhere we forget to use the figure function and so the image that we need to view wont be visible. It would have been overwritten by other image. So provide me some solution.
I ask this only for simplicity in writing the code. So if there is any solution, please mention.
Thanks in advance.
I'm not sure, but I don't think that there's a workaround to that. MATLAB basically changes the current figure handle to that of a new image when you use imshow. One thing you can do however is to make a copy of imshow in your local directory and edit it accordingly to make your own UDF.
What I would recommend however (so as to preserve functionality across systems) is that you open your code is an editor and replace all imshows with figure, imshow. This should be easy enough and it'll be easy to revert back as well.

Resources