3

I need to extract a object of interest (a vehicle ) from a large picture, now I know the 4 coordinates of this vehicle in the picture. How could I crop the image of this vehicle in the picture and then rotate it to 90 degree as shown below

enter image description here

I need to program it in python, but I don’t know which library to use for this functionality ?

user824624
  • 7,077
  • 27
  • 106
  • 183
  • use PIL. https://pypi.python.org/pypi/PIL there is also a good tutorial for simple tasks - http://effbot.org/imagingbook/introduction.htm cropping - http://effbot.org/imagingbook/introduction.htm#cutting-pasting-and-merging-images rotating - http://effbot.org/imagingbook/introduction.htm#geometrical-transforms – marmeladze Sep 25 '15 at 10:50
  • In addition to the already proposed PIL, I would add [OpenCV](https://opencv-python-tutroals.readthedocs.org/en/latest/) or [scikits-image](http://scikit-image.org/). Although any of those libraries are a bit an overkill solution for just rotating an object, they might be useful if in the future you need to do something slightly more complicated. – Imanol Luengo Sep 25 '15 at 10:52

2 Answers2

3

You can use PIL (http://www.pythonware.com/products/pil/)

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

You also have a crop method ...

djangoliv
  • 1,698
  • 14
  • 26
1
  1. You could use PIL and do it like here : Crop the image using PIL in python

  2. You could use OpenCV and do it like here: How to crop an image in OpenCV using Python

For the rotation you could use OpenCV's cv::transpose().

Rotating using PIL: http://matthiaseisen.com/pp/patterns/p0201/

Community
  • 1
  • 1
maxx
  • 39
  • 3