English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Method to implement image capture function based on PyGraphics package in Python

This article describes the method of implementing the image capture function based on the PyGraphics package in Python. Share it with everyone for reference, as follows:

Firstly install the PyGraphics package (python import media module)

There is a piece of code to import media, open the Python built-in IDLE, and input:

>>>import media

It will prompt that there is no media module!

The media module is not a standard system module, and it needs to be installed with third-party software before it can be used. This library is in PyGraphics, but PyGraphics depends on some other libraries. You can install it in this way (refer to here:http://packages.python.org/PyGraphics/install.html):

Download: Python Imaging Library 117 for Python 27-->Install
Download: pygame-191.win32-py27.msi-->Install
Download: numpy-161-win32-superpack-Python27.exe-->Install
Download: ampy-123.win32.exe-->Install
http://pragprog.com/titles/gwpy/source_code Download gwpy-code.zip After unzipping, extract code-->install-->PyGraphics-2.0.win32.exe-->Install

If you want to use the tests in the PyGraphics package, you must download and install the Nose package as follows:

Firstly, download: setuptool-->Install

Secondly, open cmd-->Enter the command prompt, at this time, keep the computer connected to the Internet, and input C:\Python in the command prompt.27\Scripts\easy_install nose Enter, at this time, it will automatically download things from the Internet, don't worry about it, Nose will automatically complete the installation.

Note: Here C:\Python27It refers to the folder where Python is located, and you can change it if necessary!

Now you can use all the contents of the PyGraphics package~~ For example: the media module, picture module, pixel module, color module, sound module, and so on.

Alright, now try import media in IDLE, and the error will no longer occur!

Reference:

http://packages.python.org/PyGraphics/
http://packages.python.org/PyGraphics/install.html

Open the image

>>>import media
>>>f=media.choose_file()
>>>pic=media.load_picture(f)
>>>media.show(pic)

Get the length and width of the image

>>>pic.get_width()
...
>>>pic.get_height()
...
>>>pic.title
...

Image Cropping

>>>media.crop_picture(pic,150,50,450,300) # top left (150,50) bottom right (450,300)
>>>media.show(pic)
>>>media.save_as(pic,'new_.jpg')

Readers who are interested in more about Python-related content can check the special topics on this site: 'Summary of Python Image Operation Skills', 'Python Data Structures and Algorithms Tutorial', 'Summary of Python Socket Programming Skills', 'Summary of Python Function Usage Skills', 'Summary of Python String Operation Skills', 'Classic Tutorial of Python入门与进阶', and 'Summary of Python File and Directory Operation Skills'.

I hope the content described in this article will be helpful to everyone's Python program design.

Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)

You may also like