如何裁剪和旋转python中的图像的一部分?

问题描述:

我需要从一张大图片中提取一个感兴趣的对象(一辆车),现在我知道图片中这辆车的4个坐标。我怎么能裁剪此车在画面的图像,然后将其旋转到90度如下图所示如何裁剪和旋转python中的图像的一部分?

enter image description here

我需要它在Python程序,但我不知道要使用哪个库这个功能?

+0

使用PIL。 https://pypi.python.org/pypi/PIL 也有一个简单的任务很好的教程 - http://effbot.org/imagingbook/introduction.htm 裁剪 - http://effbot.org/imagingbook /introduction.htm#cutting-pasting-and-merging-images rotate - http://effbot.org/imagingbook/introduction.htm#geometrical-transforms – marmeladze

+0

除了已经提出的PIL之外,我还会添加[OpenCV] (https://opencv-python-tutroals.readthedocs.org/en/latest/)或[scikits-image](http://scikit-image.org/)。尽管任何这些库对于旋转对象都有点过大,但如果将来您需要稍微复杂些,它们可能会很有用。 –

  1. 你可以使用PIL,做它喜欢这里: Crop the image using PIL in python

  2. 你可以使用OpenCV的和做喜欢这里: How to crop an image in OpenCV using Python

对于你可以使用的OpenCV的旋转CV ::转()。

旋转使用PIL:http://matthiaseisen.com/pp/patterns/p0201/

您可以使用PIL(http://www.pythonware.com/products/pil/

from PIL import Image 
im = Image.open("img.jpg") 
im.rotate(45) 

你也有一个作物的方法...