Skip to content

Commit 5714d40

Browse files
Shiven Miansigmavirus24
authored andcommitted
Added OpenCV to Image Processing
1 parent 6387f5d commit 5714d40

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

docs/scenarios/imaging.rst

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ Image Manipulation
55
.. todo::
66
Add introduction about image manipulation and its Python libraries.
77

8+
Most image processing and manipulation techniques can be carried out effectively using
9+
two libraries: Python Imaging Library (PIL) and OpenSource Computer Vision (OpenCV).
10+
11+
A brief description of both is given below.
12+
813
Python Imaging Library
914
----------------------
1015

1116
The `Python Imaging Library <http://www.pythonware.com/products/pil/>`_, or PIL
12-
for short, is *the* library for image manipulation in Python. Unfortunately,
17+
for short, is one of the core libraries for image manipulation in Python. Unfortunately,
1318
its development has stagnated, with its last release in 2009.
1419

1520
Luckily for you, there's an actively-developed fork of PIL called
@@ -55,3 +60,47 @@ Example
5560
5661
There are more examples of the Pillow library in the
5762
`Pillow tutorial <http://pillow.readthedocs.org/en/3.0.x/handbook/tutorial.html>`_.
63+
64+
65+
OpenSource Computer Vision
66+
---------------------------
67+
68+
OpenSource Computer Vision, or OpenCV in short, is a slightly more advanced and useful
69+
image manipulation and processing software than PIL. It has been implemented in several
70+
languages and is very widely used.
71+
72+
Installation
73+
~~~~~~~~~~~~~
74+
75+
In Python, image processing using OpenCV is implemented using the **cv2** and **NumPy** modules.
76+
Check the installation instructions for OpenCV `here <https://help.ubuntu.com/community/OpenCV>`_.
77+
78+
NumPy can be easily downloaded from the Python Package Index(PyPI):
79+
80+
.. code-block:: console
81+
82+
$ pip install numpy
83+
84+
Example
85+
~~~~~~~~
86+
87+
.. code-block:: python
88+
89+
from cv2 import *
90+
import numpy as np
91+
#Read Image
92+
img = cv2.imread('testimg.jpg')
93+
#Display Image
94+
cv2.imshow('image',img)
95+
cv2.waitKey(0)
96+
cv2.destroyAllWindows()
97+
98+
#Applying Grayscale filter to image
99+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
100+
101+
#Saving filtered image to new file
102+
cv2.imwrite('graytest.jpg',gray)
103+
104+
There are more examples of OpenCV in the documentation
105+
`here <http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_tutorials.html>`_.
106+

0 commit comments

Comments
 (0)