работа с изображениями для python 3 (получить размер изображения и матрицу значений пикселей)

Модератор: Модераторы разделов

Аватара пользователя
Mifodix
Сообщения: 373
ОС: Fedora 17 x86_64

работа с изображениями для python 3

Сообщение Mifodix »

Здравствуйте!
Надо получить размеры изображения и матрицу значений пикселей из файла. Как бы это провернуть в 3 питоне? PIL'а нет, а разбирать форматы файлов изображений не хочется.
Спасибо сказали:
aumit
Сообщения: 28

Re: работа с изображениями для python 3

Сообщение aumit »

ImageMagick, GD.
Спасибо сказали:
Аватара пользователя
Mifodix
Сообщения: 373
ОС: Fedora 17 x86_64

Re: работа с изображениями для python 3

Сообщение Mifodix »

aumit писал(а):
09.11.2011 23:13
ImageMagick, GD.

Спасибо. Только вот понять не могу откуда взять ImageMagick для 3 питона? Качнул сорцы для компилирования, но вроде они как для 2 питона...
ЗЫ прошу сильно не пинать, только начинаю знакомство с питоном.
Спасибо сказали:
Аватара пользователя
Mifodix
Сообщения: 373
ОС: Fedora 17 x86_64

Re: работа с изображениями для python 3

Сообщение Mifodix »

Так, по крайней мере я разобрался что исходники PythonMagick собираются и под 2 питон, и под 3. Вот только собрать никак не получается! ./configure упорно не хочет видеть boost::python, пока явно не пропишешь инклуды до 3 питона:

Код: Выделить всё

mifodix@linux-yusg:~/Загрузки/PythonMagick-0.9.7> ./configure CPPFLAGS="-I/usr/include -I/usr/include/python3.1"
checking whether build environment is sane... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking whether ln -s works... yes
checking whether make sets $(MAKE)... (cached) yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/x86_64-suse-linux/bin/ld
checking if the linker (/usr/x86_64-suse-linux/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/x86_64-suse-linux/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /usr/x86_64-suse-linux/bin/ld -m elf_x86_64
checking if the linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking for a Python interpreter with version >= 3.1... python3
checking for python3... /usr/bin/python3
checking for python3 version... 3.1
checking for python3 platform... linux2
checking for python3 script directory... ${prefix}/lib/python3.1/site-packages
checking for python3 extension module directory... ${exec_prefix}/lib64/python3.1/site-packages
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for boostlib >= 1.20.0... yes
checking for python build information...
checking for python2.6... no
checking for python2.5... no
checking for python2.4... no
checking for python2.3... no
checking for python2.2... no
checking for python2.1... no
checking for python... python
checking for main in -lpython... no
checking python/Python.h usability... yes
checking python/Python.h presence... yes
checking for python/Python.h... yes
  results of the Python check:
    Binary:      python
    Library:     no
    Include Dir: no
checking whether the Boost::Python library is available... yes
checking for exit in -lboost_python... no
checking for exit in -lboost_python... (cached) no
checking for MAGICKCORE... yes
checking for MAGICKPP... yes
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for an ANSI C-conforming const... yes
checking for size_t... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating helpers_src/Makefile
config.status: creating pythonmagick_src/Makefile
config.status: creating config/config.h
config.status: executing depfiles commands
config.status: executing libtool commands

Но на мэйке всё падает.

Код: Выделить всё

..вырезано...
libtool: link: g++  -fPIC -DPIC -shared -nostdlib /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.5/crtbeginS.o  -Wl,--whole-archive pythonmagick_src/.libs/libpymagick.a helpers_src/.libs/libhelper.a -Wl,--no-whole-archive  -L/usr/lib -lboost_python -lMagick++ -lMagickCore -l -L/usr/lib64/gcc/x86_64-suse-linux/4.5 -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib64/gcc/x86_64-suse-linux/4.5/crtendS.o /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crtn.o  -O2   -Wl,-soname -Wl,_PythonMagick.so -o .libs/_PythonMagick.so
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld: cannot find -l-L/usr/lib64/gcc/x86_64-suse-linux/4.5
collect2: ld returned 1 exit status
make[1]: *** [_PythonMagick.la] Ошибка 1
make[1]: Выход из каталога `/home/mifodix/Загрузки/PythonMagick-0.9.7'
make: *** [all-recursive] Ошибка 1

Кто-нибудь сталкивался?
Спасибо сказали:
NickLion
Сообщения: 3408
Статус: аватар-невидимка
ОС: openSUSE Tumbleweed x86_64

Re: работа с изображениями для python 3

Сообщение NickLion »

По-хорошему, надо найти откуда прибыл "-l " в приведённой команде он и мешает сборке. Решение на скорую руку - поправьте Makefile вручную.
Спасибо сказали:
Аватара пользователя
Mifodix
Сообщения: 373
ОС: Fedora 17 x86_64

Re: работа с изображениями для python 3

Сообщение Mifodix »

Код: Выделить всё

# And the libraries to include
_PythonMagick_la_LIBADD = pythonmagick_src/libpymagick.la helpers_src/libhelper.la $(BOOST_LDFLAGS) -lboost_python $(MAGICKPP_LIBS) $(MAGICK_LIBS) -l$(PYTHON_LIB)

Вот где лишний -l затисался. Скомпилировал и установил, теперь буду разбираться с документацией.
Спасибо сказали:
Аватара пользователя
Mifodix
Сообщения: 373
ОС: Fedora 17 x86_64

Re: работа с изображениями для python 3

Сообщение Mifodix »

Код: Выделить всё

>>> from PythonMagick import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PythonMagick/__init__.py", line 1, in <module>
    import _PythonMagick
ImportError: No module named _PythonMagick

Понять не могу что не так теперь?

Код: Выделить всё

mifodix@linux-yusg:~> ls -la /usr/lib64/python3.1/site-packages/PythonMagick/
итого 168864
drwxr-xr-x 2 root root      4096 Ноя 11 22:33 .
drwxr-xr-x 3 root root      4096 Ноя 11 22:33 ..
-rw-r--r-- 1 root root      5720 Ноя 11 22:33 __init__.py
-rw-r--r-- 1 root root     23171 Ноя 11 22:33 __init__.pyc
-rw-r--r-- 1 root root     23171 Ноя 11 22:33 __init__.pyo
-rw-r--r-- 1 root root 125965134 Ноя 11 22:33 _PythonMagick.a
-rwxr-xr-x 1 root root      1031 Ноя 11 22:33 _PythonMagick.la
-rwxr-xr-x 1 root root  46874158 Ноя 11 22:33 _PythonMagick.so
Спасибо сказали:
Аватара пользователя
VoidExp
Сообщения: 208
Статус: Lead guitar adept
ОС: Ubuntu

Re: работа с изображениями для python 3

Сообщение VoidExp »

Попробуй использовать python3-config (или python-config, если третий пайтон по дефолту используется) в качестве аргумента для ./configure

Ну, что-то типа ./configure CFLAGS=`python3-config --cflags` LIBS=`python3-config --libs` :)
Спасибо сказали:
Аватара пользователя
Mifodix
Сообщения: 373
ОС: Fedora 17 x86_64

Re: работа с изображениями для python 3

Сообщение Mifodix »

VoidExp писал(а):
22.11.2011 17:32
Попробуй использовать python3-config (или python-config, если третий пайтон по дефолту используется) в качестве аргумента для ./configure

Ну, что-то типа ./configure CFLAGS=`python3-config --cflags` LIBS=`python3-config --libs` :)

Так даже конфиг не делается:)

Код: Выделить всё

mifodix@linux-yusg:~/Загрузки/PythonMagick-0.9.7> ./configure CFLAGS='python3-config --cflags' LIBS='python3-config --libs' --prefix=/usr
checking whether build environment is sane... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for g++... g++
checking whether the C++ compiler works... no
configure: error: in `/home/mifodix/Загрузки/PythonMagick-0.9.7':
configure: error: C++ compiler cannot create executables
See `config.log' for more details


ЗЫ хоть на 2 питоне пиши:(
Спасибо сказали:
watashiwa_daredeska
Бывший модератор
Сообщения: 4038
Статус: Искусственный интеллект (pre-alpha)
ОС: Debian GNU/Linux

Re: работа с изображениями для python 3

Сообщение watashiwa_daredeska »

Mifodix писал(а):
22.11.2011 19:52
Так даже конфиг не делается
Там не апострофы, а backtick'и. Ср. «'» и «`». Используйте copy-paste, если не видите разницы :)
backtick'и слегка устарели, хотя и работают. В современном исполнении это выглядит так: ./configure CFLAGS="$(python3-config --cflags)" LIBS="$(python3-config --libs)"
Спасибо сказали:
Аватара пользователя
/dev/random
Администратор
Сообщения: 5427
ОС: Gentoo

Re: работа с изображениями для python 3

Сообщение /dev/random »

Mifodix писал(а):
22.11.2011 19:52
Так даже конфиг не делается:)

Код: Выделить всё

mifodix@linux-yusg:~/Загрузки/PythonMagick-0.9.7> ./configure CFLAGS='python3-config --cflags' LIBS='python3-config --libs' --prefix=/usr
...

«`», а не «'».
Спасибо сказали:
Аватара пользователя
Mifodix
Сообщения: 373
ОС: Fedora 17 x86_64

Re: работа с изображениями для python 3

Сообщение Mifodix »

Всё равно толку нет! В упор не хочет видеть boost python

Код: Выделить всё

checking whether the Boost::Python library is available... no

И на мэйке вылетает:

Код: Выделить всё

/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directoryIn file included from /usr/include/boost/python/detail/prefix.hpp:13:0,
                 from /usr/include/boost/python/args.hpp:8,
                 from /usr/include/boost/python.hpp:11,
                 from _Blob.cpp:3:
/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory

Спасибо сказали: