Instalacija: Numpy, Matplotlib, SciPy, OpenCV
This is a short article about installing NumPy, SciPy, Matplotlib and OpenCV on the latest Ubuntu LTS, which at the time of this writing is 18.04. Ubuntu 18.04 comes with Python 3.6.5. (Source: https://solarianprogrammer.com/)
Let’s start by making sure we have an updated system:
sudo apt update
sudo apt upgrade
Now, let’s install NumPy, SciPy and Matplotlib:
sudo apt install python3-numpy python3-scipy python3-matplotlib
If you need OpenCV, you can install it with:
sudo apt install python3-opencv
Many useful Python libraries can be installed from https://pypi.org, let’s make sure we have pip on our system:
sudo apt install python3-pip
If you need to install a library from https://pypi.org, for example the Python Imaging Library Pillow, you can do it with:
pip3 install Pillow
We can test ScipPy and Matplotlib, by writing a short test program:
import scipy as sp
import matplotlib.pylab as plt
t = sp.arrange(0, 10, 1/100)
plt.plot(t, sp.sin(1.7 * 2 * sp.pi * t) + sp.sin(1.9 * 2 * sp.pi * t))
plt.show()
Save the above code as test_0.py and run it with:
python3 test_0.py
You should see something like in the next figure:
We can write a small test program that will print the OpenCV version, load an image from the disk, convert the image to gray and show the result. Start by downloading the next image:
Save it as clouds.jpg. In the same folder where you’ve saved the above image, create a new file test_1.py and write the next code:
import cv2
print("OpenCV version:")
print(cv2.__version__)
img = cv2.imread("clouds.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("Over the Clouds", img)
cv2.imshow("Over the Clouds - gray", gray)
cv2.waitKey(0) 13 cv2.destroyAllWindows()
Run the code with:
python3 test_1.py
(You can close the two windows by pressing ESC!) You should see something like in the next figure:
Let’s start by making sure we have an updated system:
sudo apt update
sudo apt upgrade
Now, let’s install NumPy, SciPy and Matplotlib:
sudo apt install python3-numpy python3-scipy python3-matplotlib
If you need OpenCV, you can install it with:
sudo apt install python3-opencv
Many useful Python libraries can be installed from https://pypi.org, let’s make sure we have pip on our system:
sudo apt install python3-pip
If you need to install a library from https://pypi.org, for example the Python Imaging Library Pillow, you can do it with:
pip3 install Pillow
We can test ScipPy and Matplotlib, by writing a short test program:
import scipy as sp
import matplotlib.pylab as plt
t = sp.arrange(0, 10, 1/100)
plt.plot(t, sp.sin(1.7 * 2 * sp.pi * t) + sp.sin(1.9 * 2 * sp.pi * t))
plt.show()
Save the above code as test_0.py and run it with:
python3 test_0.py
You should see something like in the next figure:
We can write a small test program that will print the OpenCV version, load an image from the disk, convert the image to gray and show the result. Start by downloading the next image:
Save it as clouds.jpg. In the same folder where you’ve saved the above image, create a new file test_1.py and write the next code:
import cv2
print("OpenCV version:")
print(cv2.__version__)
img = cv2.imread("clouds.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("Over the Clouds", img)
cv2.imshow("Over the Clouds - gray", gray)
cv2.waitKey(0) 13 cv2.destroyAllWindows()
Run the code with:
python3 test_1.py
(You can close the two windows by pressing ESC!) You should see something like in the next figure:
Nema komentara: