Installing Pythong, OpenCV, numpy, and Matplotlib Seprately
You can also install them independently. As in the world of data science and machine learning, having a solid foundation of essential software is crucial
for success. These tools enable you to manipulate data, perform complex calculations, create visualizations, and
even delve into computer vision tasks. In this guide, we will walk you through the step-by-step installation
process of four fundamental software packages: Python, NumPy, Matplotlib, and OpenCV.
1. Python Installation
Python is the backbone of the data science world, offering a versatile and powerful programming language.
Follow these steps to install Python on your system:
Download
Visit the official Python website at
python.org. Choose the latest version of Python suitable for
your operating system (Windows, macOS, or Linux).
Installer
Run the downloaded installer. Make sure to check the box that says "Add Python to PATH" during installation.
This will allow you to use Python from the command line.
Verification
Open a command prompt (Windows) or terminal (macOS/Linux) and type the following command to ensure that
Python is installed correctly. You should see the version number displayed.
2. NumPy Installation
NumPy is a fundamental package for scientific computing with Python. It provides support for large,
multi-dimensional arrays and matrices. To install NumPy:
Package Manager
Open a command prompt or terminal and run the following command: pip install numpy
Verification
You can verify the installation by opening a Python interpreter and entering import numpy
.
3. Matplotlib Installation
Matplotlib is a popular data visualization library that allows you to create a wide range of charts, graphs,
and plots. To install Matplotlib:
Package Manager
In the same command prompt or terminal, run: pip install matplotlib
Verification
Open a Python interpreter again and execute import matplotlib.pyplot as plt
4. OpenCV Installation
OpenCV (Open Source Computer Vision Library) is vital for tasks involving image and video processing. Installing
OpenCV might require a few additional steps due to its complexity:
Package Manager
Install OpenCV's Python package using pip by running the following command in windows powershell:
pip install opencv-python
Verifying OpenCV Installation
To verify the installation of OpenCV, you can follow these steps:
- Open the Windows PowerShell.
- Copy and paste the following command into the PowerShell window:
- Press Enter to execute the command.
python -c "import cv2; print('OpenCV version:', cv2.__version__)"
1
2
3
4
5
6
7
8
|
import cv2
import numpy as np
path = r'F:\img\lena.jpg'
img = cv2.imread(path,cv2.IMREAD_COLOR)
ROI = img[80:170, 60:160,:]
cv2.imshow('ROI',ROI)
cv2.waitKey(0)
cv2.destroyAllWindows()
|
The script will output the version of OpenCV installed on your system. Make sure you have Python and OpenCV properly installed and added to your system's PATH.
Additional Dependencies
Depending on your use case, you might need additional OpenCV modules like OpenCV-contrib. You can install it by running the following command on windows powershell:
pip install opencv-python
Conclusion
By following this guide, you've successfully installed Python and three essential libraries for data science and
machine learning: NumPy, Matplotlib, and OpenCV. These software packages provide you with the tools necessary to
manipulate data, create visualizations, and explore computer vision tasks. With a solid foundation in these
tools, you're well-equipped to embark on your data science journey. Happy coding!