To start working with OpenCV for image processing, we first need to install OpenCV in Python and configure a development environment. The most common setup is using Jupyter Notebook, which makes it easy to test and visualize images step by step.
Follow these steps to install OpenCV using pip:
pip install opencv-python pip install opencv-python-headless # For servers without GUI pip install matplotlib numpy jupyter
✅ opencv-python – Main OpenCV library ✅ opencv-python-headless – OpenCV without GUI features (useful for servers) ✅ matplotlib, numpy – Support libraries for image processing and visualization ✅ jupyter – Interactive notebook environment
Once installation is complete, launch Jupyter Notebook:
jupyter notebook
This will open a web interface in your browser where you can create a new Python 3 Notebook and start coding with OpenCV.
Try this simple code to check if OpenCV is installed correctly:
import cv2
print("OpenCV version:", cv2.__version__)
If everything is installed properly, you should see the version number of OpenCV.
🎉 Congratulations! You have successfully installed OpenCV and set up your environment. In the next chapter, we will explore how images are represented in pixels and different color spaces like RGB, Grayscale, and HSV.
