I haven't found a standard way in Python to read images. Is there really none (because there are so many functions for so many custom stuff that I really wonder that there are no functions to read images)? Or what is it? (It should be available in the MacOSX standard installation and in most recent versions on Linux distributions.)
If there is none, what is the most common lib?
Many search results hint me to Python Imaging Library. If this is some well known Python-lib for reading images, why isn't it included in Python?
No, there are no modules in the standard library for reading/writing/processing images directly. But the most common library might be PIL (Python Imaging Library). Many projects are not included in the standard library because they are 1) totally optional and 2) cannot be maintained by the few Python core developers.
Coming late to the party, I would strongly suggest one of the Python interfaces to the ImageMagick library (Wand worked well in my testing, I'll know more soon...)
ImageMagick is a more powerful library and also pretty well a de-facto standard across many languages. Appealing to a wider base, they also have a wider developer base as a result.
THe suggested PIL does not support interlaced PNGs. It can be quite anoying when dealing with lots of PNGs from different origins.
It is possible to open them, but can only read headerinformation from them, all other operations fail.
Related
I want to use numpy in brython.
But I do not know how to import extra modules in brython.
If you have similar experience or question,
please tell me way to solve
You can't.
Brython is a transpiler from a Python-like syntax to Javascript code. While it holds good conformance to latest Python 3 syntax, and amazing compatibility, it does not have any features to support running binary code.
And numpy, along with a lot of third and first party Python libraries is compiled from C and other languages to native CPU code. There is no support, no way, and not even a roadmap, or prevision of prevision to allow that.
It may be possible to develop Brython front end apps that use those libraries running on the backend, though, performing all calculations on the server side, and just passing serialized data to the brython counterpart. One would habe to manually write this, though (and it might be possible to use a pure-python striped down version of numpy arrays just for deserializing, displaying, and submitting data to the backend)
I'm building a rendering engine in Python for fun. I need to load 3D scenes. Any standard modern format like DAE, 3DS, or MAX would work: I can convert my files easily between standard formats.
OpenSceneGraph seems to be the most comprehensive and well-maintained solution. It would be ideal to be able to use it in Python without much hassle. Are there working Python bindings for OSG that are easy to install, work on Mac OS X (I'm on 10.8), and are compatible with the latest versions of OSG?
I searched around and came across osgswig (http://code.google.com/p/osgswig/) and PyOSG (http://sourceforge.net/projects/pyosg/), but they don't seem to be actively maintained. I don't see any recent activity related to these packages, and it seems that people had trouble running osgswig on OSX. Ideally, I'd like to find something that "just works", without major compilation hassles. I'd like to just install a package and be able to import a module that will let me load COLLADA or 3DS files.
I also came across pycollada (https://github.com/pycollada/pycollada). It seems active, but fairly early-stage. Ideally, I'd like a reasonably comprehensive package that supports specular maps, normal maps, and other reasonably advanced features. Animation would be nice as well.
In summary, I need to load 3D scenes in Python. Bindings for OSG would probably be ideal, because OSG is so comprehensive. But I need something that works on OSX. I would also prefer something that can be installed reasonably easily. Does something like this exist?
Thanks!
Take a look at Open Asset Import Library (short name: Assimp). It is a portable Open Source library to import various well-known 3D model formats in a uniform manner. http://www.assimp.org/
You should loot at panda3D (http://www.panda3d.org/), it's a game engine with extensive python bindings. It has the features you want : http://www.panda3d.org/manual/index.php/Features
I used it for a few years and it was a solid tool.
I made my own fork of a mirror of a clone of the osgswig project for a similar purpose. I have it working with OpenSceneGraph version 3.2.1 on Windows and Mac; and it's likely I will eventually polish it for linux too. I'm already delivering one product to customers based on my version of osgswig, and I'm considering making others. Find my fork here:
https://github.com/cmbruns/osgswig
If others show enough interest, I might be coaxed into creating binary installers for my version of the osgswig module, to make installation easier.
If you just want the easiest OpenSceneGraph bindings for OSG 3.2.1, you can stop reading this answer here. Read on for more of my thoughts for the future.
Though I am maintaining a fork of osgswig (as stated above), I sort of hate SWIG, and I would prefer to use bindings based on Boost.Python, rather than on SWIG. For large, complex C++ APIs, like OpenSceneGraph, Boost.Python can be much more elegant than SWIG, both for the API consumer, and for the binding maintainer (me, and me). I found one project using Boost.Python to wrap OSG, at https://code.google.com/p/osgboostpython/, but the developer is lovingly wrapping each part of the interface by hand, and has thus only completed a tiny fraction of the large OpenSceneGraph API.
Taking that Boost.Python based project as inspiration, I created yet another OpenSceneGraph Python binding project, at https://github.com/JaneliaSciComp/osgpyplusplus. Eventually, I want to use this osgpyplusplus project for all my python osg needs. And I would appreciate help in making it ready. Right now, osgpyplusplus suffers from the following weaknesses, compared to osgswig:
osgpyplusplus is not yet used in any working product
The build environment is tricky to set up, requiring both Boost.Python and Pyplusplus
I haven't paid much attention to osgpyplusplus recently, so it might rust away if I continue to ignore it.
Though osgpyplusplus probably wraps most of the OpenSceneGraph API, there are probably some important missing pieces that won't be identified until someone tries to develop a significant project with it.
It would be a lot of work for me to create a binary module installer for osgpyplusplus at this point, so please don't ask me to.
What is the most suitable way to capture a still image from Python and convert to a PIL image?
Google gives me numerous ways with OpenCV and lesser-known libraries. I want an easy, reliable, mature, cross-platform library for this purpose. And with minimal dependencies and extra packages.
If possible, it must also support displaying live images with major windowing toolkits, although the performance (frame rate, clarity) is not important.
I use gphoto2 and with subprocess. But it should be possible to access this library from ctypes, if you prefer this.
OpenCV's Python API is pretty solid at this point, and OpenCV is easily installed on all major platforms. It's good, and it's probably your best bet. Getting a live feed from a webcam can be done in as little as 10 lines of code.
PIL or its newer fork Pillow are also good, mature, and cross platform.
PyGame also has a camera module, an intro is here: http://www.pygame.org/docs/tut/camera/CameraIntro.html but I have noticed that getting PyGame to integrate gracefully into other toolkits (wx, Qt) can be difficult.
I'd like to use OpenCV functions, like Hough Transform and Corner Detection, in Sikuli.
I tried the OpenCV installation instructions for CPython on Sikuli and it's a no go.
I understand that Sikuli is Jython and this might be the hard way to do things. What are the easier alternatives?
I'd still like to use Sikuli & Python because the code I write just works; but maybe I'm hitting the limits of Sikuli.
You could use Automa as an alternative to Sikuli. It is a pure Python library (so you can use any other Python library with it) and its image search algorithms are fully compatible with Sikuli. In fact, it uses OpenCV's Python bindings itself, and thus ships with them.
Disclaimer: I'm one of Automa's developers.
Generally spoken: Python modules containing C-based code (which is the case for Python OpenCV) cannot be used in the Sikuli Script (Jython).
The integration of some OpenCV features in Sikuli is realized using the Java-To-C interface (JNI) and the usage of OpenCV features itself is coded in C++.
If you want to use OpenCV features not supported by Sikuli, then you either have to use the above mentioned JNI approach or use the Java implementation of OpenCV (javacv) (Java stuff can be used seamlessly from Jython scripts).
Another option of course is to implement the additional things in plain Python scripts using the Python/OpenCV and call these scripts via the C-Python interpreter in a subprocess.
I am trying to use VTK from python. I tried to find and could not realy find anything on the web which can be used for documentation. I tried looking at the c++ documentation but the methods are very different.
Thanks a lot
You could see the python examples at VTK's wiki. There is another resource by going to the official nightly documentation and looking for a particular class; in the section examples for many (not all) classes you can find implementations in python (also in c++ and tcl). A third option is to go to the source folder of your last downloaded release of VTK; look for the folder "Examples", there you will also find different VTK implementations in python (besides C++ and tcl)
I recommend you use Mayavi and TVTK from Enthought, the API is much pythonic:
http://code.enthought.com/projects/mayavi/
On the VTK website you can find the VTK User's Guide. It is pretty thorough.