How to use vtkPNGWriter with interactor? - python

I am new to VTK and using python bindings. I am trying to render some objects as images. I am using vtkPNGWriter to save the rendered image. I want to attach the vtkPNGWriter to the interactor so that it saves the rendered images after every time I change the object pose using the interactor. Could someone please help me with this task?

Related

How can I use svgwrite.image.Image to set an image in the background of a canvas I have other elements on?

I have an svgwrite.Drawing into which I wish to insert a JPG image as the background image. Here's the code to what I have so far. It is using computer vision for a machine learning task. The essential part to help me begin understanding how I can insert an image, is on line 147 where I create a drawing using svgwrite. The problem I'm running into is that in the documentation, if you scroll down to where the factory methods are, it says that you can use Drawing.image and set an href for an image that you want to use. I did further down notice that in the factory methods it also has Drawing.saveas in the form svg_canvas.saveas, which does end up working for me so I know that I am using this Drawing method to create an svgwrite.image.Image object correctly, but it doesn't seem to be working. For reference, I insert the following code right after this line:
svg_canvas.image(href="/home/mendel/project/bg/bg.jpg", size = src_size)
I triple checked that my href was correctly written out and that my bg image was in fact in the folder. src_size is already defined before as well so I'm pretty sure it's all working. But I'm not sure why the above line isn't working for me at all to give me a background image for the canvas. Please let me know if I'm using it incorrectly I really appreciate it!
I already tried the above solutions using the Python API but it isn't working. I also tried looking into other stack posts, none have worked for me so far.

How do you resize a image in google colab when using IPython

I was using this code:
display(HTML(''.join(img_data[i]))) #just ignore the things inside the HTML function
I want to know how do you make it a specific size
Thanks for helping!

Set active image in UV Editor for certain object in Blender 2.78

Currently I am writing a script for blender which imports model saved in custom format. My problem is that I want to set active texture in UV Editor using Python. When I hover the button which allows me to select image I want to show in UV Editor, there's no python function name on the tooltip. Is there any way to set another image to each object? When i tried to use this method the image was present in image editor, but after i select certain object and then i select all his faces, there was no image in the editor.
P.S. Sorry for my bad english. If you don't understand something, just ask me.
I had a similar problem, this post on the Blender stack exchange board solved it for me.

Building series of images in python

I am trying to build an application that builds tool-strings by selecting and inserting pre-made png that are saved in a folder. The pngs need to be placed onto a canvas and built up one by one by selecting an image from a folder and placing onto the canvas in a grid like format.
I have including an example of the toolstring I am trying to make. Currently this is being built manually in a photo manipulation software but I would like to automate the process in a stand alone python application.
Any pointers in the right direction would be grateful, I'm not sure what to google. (Relevant plugins, tutorials, examples). I have a small amount of experience in python programming.
You will want to look at this Python library, PIL

Is it possible to save in a file an animation created with Tkinter?

I wanted to use Python to create animations (video) containing text and simple moving geometric objects (lines, rectangles, circles and so on).
In the book titled "Python 2.6 Graphics Cookbook" I found examples using Tkinter library. First, it looked like what I need. I was able to create simple animation but then I realized that in the end I want to have a file containing my animation (in gif or mp4 format). However, what I have, is an application with GUI running on my computer and showing me my animation.
Is there a simple way to save the animation that I see in my GUI in a file?
There is no simple way.
The question Programmatically generate video or animated GIF in Python? has answers related strictly to creating these files with python (ie: it doesn't mention tkinter).
The question How can I convert canvas content to an image? has answers related to saving the canvas as an image
You might be able to take the best answers from those two questions and combine them into a single program.
I've accomplished this before, but not in a particularly pretty way.
Tl;dr save your canvas as an image at each step of the iteration, use external tools to convert from image to gif
This won't require any external dependencies or new packages except having imagemagick already installed on your machine
Save the image
I assume that you're using a Tkinter canvas object. If you're posting actual images to the tk widgets, it will probably be much easier to save them; the tk canvas doesn't have a built-in save function except as postcript. Postscript might actually be fine for making the animation, but otherwise you can
Concurrently draw in PIL and save the PIL image https://www.daniweb.com/software-development/python/code/216929/saving-a-tkinter-canvas-drawing-python
Take a screenshot at every step, maybe using imagegrab http://effbot.org/imagingbook/imagegrab.htm
Converting the images to to an animation
Once the images are saved, I used imagemagick to dump them into either a gif, or into a mpg. You can run the command right from python using How to run imagemagick in the background from python or something similar. It also means that the process is implictely run on a separate thread, so it won't halt your program while it happens. You can query the file to find out when the process is done.
The command
convert ../location/*.ps -quality 100 ../location/animation.gif
should do the trick.
Quirks:
There are some small details, and the process isn't perfect. Imagemagick reads files in order, so you'll need to save the files so that alphabetical and chronological line up. Beware that the name
name9.ps
Is alphabetically greater than
name10.ps
From imagemagick's point of view.
If you don't have imagemagick, you can download it easily (its a super useful command-line tool to have) on linux and mac, and cygwin comes with it on windows. If you're worried about portability... well... PIL isn't standard either
There is a way of doing that, with the "recording screen method", this was explained in other question: "how can you record your screen in a gif?".
Click the link -->LICEcap : https://github.com/lepht/licecap
They say that it's free software for Mac (OS X) and Windows
You could look at Panda3D, but it could be a little over killed for what you need.
I would say you can use Blender3d too but i'm not really sure of how it works. Someone more experimented then me could tell you more about this.

Categories