{"id":78620,"date":"2023-06-26T21:20:06","date_gmt":"2023-06-27T01:20:06","guid":{"rendered":"https:\/\/www.engineersgarage.com\/?p=78620"},"modified":"2023-07-08T07:41:10","modified_gmt":"2023-07-08T11:41:10","slug":"opencv4-5-installation-raspberry-pi-raspbian-bullseye","status":"publish","type":"post","link":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/","title":{"rendered":"How to install OpenCV 4.5 &#038; QT5 on Raspberry Pi &#038; NVIDIA Jetson Nano for computer vision"},"content":{"rendered":"<p>OpenCV is one of the <a href=\"https:\/\/www.engineersgarage.com\/computer-vision-tools-opencv-matlab-simplecv-tensorflow-cuda\/\">best computer vision tools<\/a> available out there. It is the most popular machine vision library among developers and makers. Due to being open-source, the library has enjoyed vast community support and evolved as one of the most mature software packages. OpenCV itself stands for &#8220;Open-source Computer Vision.&#8221; The latest version of the library is OpenCV 4.7 available for free commercial use under Apache license. The library is especially useful for real-time computer vision applications. It also supports most of the common machine learning algorithms like K-Nearest Neighbor, Naive Bayes, Random Forest, Decision Tree, Support Vector Machine, Artificial <a href=\"https:\/\/www.engineersgarage.com\/what-is-neural-network\/\" target=\"_blank\" rel=\"noopener\">Neural Networks<\/a> (ANN), and deep neural networks.<\/p>\n<p>Whether one wants to build a machine vision project using C++ or <a href=\"https:\/\/www.engineersgarage.com\/rpi-python-programming-06-python-basics\/\" target=\"_blank\" rel=\"noopener\">Python<\/a>, OpenCV is the best tool to start with. A computer vision project can be easily built on any PC or Mac using OpenCV. It is also possible to invest in OpenCV in embedded machine vision projects. The new generation microcomputers like Raspberry Pi, NVIDIA Jetson Nano, RockPi, etc., are quite capable to support the OpenCV environment.<\/p>\n<p>There are great benefits to running embedded computer vision applications on these low-cost embedded computers. The microcomputers can run 24&#215;7 hours to host a dedicated computer vision project that may even involve machine learning algorithms or deep learning, that too without any special arrangements other than a good heat sink. The application can be implemented at incredibly low costs without compromising efficiency. Plus, the microcomputers are capable of doing a lot of computation locally which makes them best suitable for edge computing or as a <a href=\"https:\/\/www.engineersgarage.com\/iot-technology-trends-2023\/\">fog<\/a>.<\/p>\n<p>In this tutorial, we will look into how to install OpenCV 4.5 on Raspberry Pi. The Raspberry Pi model used in this tutorial is Raspberry Pi 4B with 8GB RAM. Other Raspberry Pi 4 models can also be used. Even though the setup can be done on Raspberry Pi 3 or 2, OpenCV may have a compromised performance on those boards. The Raspberry Pi 4B used in this tutorial is installed with Raspbian Bullseye. The same instructions that are dictated here are applicable to OpenCV installation on NVIDIA Jetson Nano booted from a Debian OS.<\/p>\n<p>The OpenCV setup on Raspberry Pi or any other Linux microcomputer is the first thing one needs to do before embarking on the development of a machine vision application. The setup is time-consuming and could be frustrating to newbies, particularly to those who are new to Linux and Shell scripting. Even if one step is missed, the entire setup can jeopardize. This tutorial will take you step-by-step to complete the installation of OpenCV 4.5 plus QT5 on Raspberry Pi 4B installed with Raspbian Bullseye.<\/p>\n<p>There are two ways to install OpenCV on any system. One is a simple PIP install method. The second is compiling OpenCV from the source. The PIP install method is simple and short but does not expose all tidbits of the software. The compiling from source though takes hours to complete, resulting in a full and optimized installation, where all features of OpenCV can be reaped at once. This tutorial details the compile from source method and takes step-by-step through complete installation on a Raspberry Pi. Unlike a PC or Mac, installation on a microcomputer like Raspberry Pi involve several steps required to optimize the installation specifically for the target board. All these steps are provided in this tutorial in the right sequence.<\/p>\n<p>Without wasting any time let us quickly get to the setup. The complete process will take few hours to complete. Depending upon the target board like some other Raspberry Pi variant or a different microcomputer, it may take even longer. So, be patient and have occasional breaks right out from your cubicle to grab some coffee while the installation completes. Let&#8217;s get started.<\/p>\n<p><strong>Confirm OS specifications<br \/>\n<\/strong>The first thing that you need to check is OS specifications. The setup for a 32-bit operating system would be different than a setup for the 64-bit operating system. Open Bash Terminal and execute the following command.<br \/>\n<strong><span style=\"color: #993300;\">$ uname -a<\/span><\/strong><\/p>\n<p>If the Linux version reported contains the string &#8216;armv7l&#8217;, the OS installed on Raspberry Pi is 32-bit. If it contains the string &#8216;aarch64&#8217;, it is 64-bit. The installation guide presented in this tutorial is for 32-bit operating systems only.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-01-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78719\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-01-1.png\" alt=\"\" width=\"656\" height=\"428\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-01-1.png 656w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-01-1-300x196.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-01-1-365x238.png 365w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Next, you need to confirm the operating system version. This can be done by executing the following command in the Terminal.<br \/>\n<strong><span style=\"color: #993300;\">$ cat \/etc\/os-release<\/span><\/strong><\/p>\n<p>The above command results in meta-information about the Raspbian version installed on Raspberry Pi. Our Raspberry Pi 4B (8GB) is installed with the latest Raspbian Bullseye OS. There is one other command that provides even more information about the board as well as the operating system. That is as follows.<br \/>\n<span style=\"color: #993300;\"><strong>$ hostnamectl<\/strong><\/span><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-02-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78718\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-02-1.png\" alt=\"\" width=\"656\" height=\"430\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-02-1.png 656w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-02-1-300x197.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-02-1-363x238.png 363w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/a>If you have not prepared your Raspberry Pi, better install the 32-bit Raspbian OS for this tutorial and the computer vision tutorials that follow this. If you already have Raspberry Pi installed with an operating system, confirm if it is the 32-bit version. We suggest installing 32-bit Raspberry Pi OS with desktop and recommended software.<\/p>\n<p><strong>Expand filesystem<br \/>\n<\/strong>Next, you must expand the Raspberry Pi filesystem and make use of all space on the MicroSD card. By default, when an OS image is applied to a MicroSD card, a lot of space on it is left unusable. Since the OpenCV setup itself consumes a few gigabytes, we must reclaim all space on a 32GB MicroSD card by expanding Raspberry Pi filesystem. Otherwise, the setup could fail or even if completed, OpenCV may not have sufficient space for user files and updates. A depleted space could result in the serious underperformance of a computer vision application. To expand the filesystem on Raspberry Pi, open Bash Terminal and execute the following command to open Raspberry Pi configurations.<br \/>\n<span style=\"color: #993300;\"><strong>$ sudo raspi-config<\/strong><\/span><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-03-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78679\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-03-1.png\" alt=\"\" width=\"657\" height=\"444\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-03-1.png 657w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-03-1-300x203.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-03-1-352x238.png 352w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/a>In the pop-up window, select &#8220;advanced options.&#8221;<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-04-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78716\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-04-1.png\" alt=\"\" width=\"648\" height=\"442\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-04-1.png 648w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-04-1-300x205.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-04-1-349x238.png 349w\" sizes=\"auto, (max-width: 648px) 100vw, 648px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Next, select &#8220;A1 Expand Filesystem&#8221;&#8216; and click &#8220;OK&#8221; to reboot.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-05-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78717\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-05-1.png\" alt=\"\" width=\"654\" height=\"448\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-05-1.png 654w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-05-1-300x206.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-05-1-347x238.png 347w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-06-1-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78720\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-06-1-1.png\" alt=\"\" width=\"655\" height=\"446\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-06-1-1.png 655w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-06-1-1-300x204.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-06-1-1-350x238.png 350w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/a><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-07-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78715\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-07-1.png\" alt=\"\" width=\"295\" height=\"153\" \/><\/a>After reboot, the entire space on the MicroSD card will be reclaimed by the Raspberry Pi OS. The newly available space on the card can be checked by executing the following command in the Bash Terminal.<br \/>\n<strong><span style=\"color: #993300;\">df -h<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #993300;\"><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-08-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78712\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-08-1.png\" alt=\"\" width=\"652\" height=\"443\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-08-1.png 652w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-08-1-300x204.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-08-1-350x238.png 350w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/a><\/span><\/strong>You can see we have 18GB space available on the MicroSD card after expanding the filesystem while 8.9GB is used by the OS.<\/p>\n<p><strong>Increase GPU memory<br \/>\n<\/strong>The RAM is used by both CPU and GPU. In Raspberry Pi 2B\/3B, only 64MB of RAM is allocated to GPU while in Raspberry Pi 4B, it is just 76MB. This can be inadequate for machine vision projects. The RAM allocation to GPU must be at least 128 MB, so a computer vision application does not choke. To increase RAM allocation to GPU, open &#8220;Raspberry Pi Configuration&#8221; window by navigating to Raspberry Pi Menu-&gt;Preferences-&gt;Raspberry Pi Configuration.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-09-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78683\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-09-1.png\" alt=\"\" width=\"538\" height=\"714\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-09-1.png 538w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-09-1-226x300.png 226w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-09-1-179x238.png 179w\" sizes=\"auto, (max-width: 538px) 100vw, 538px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>In the &#8220;Raspberry Pi Configuration&#8221; window, select &#8220;Performance&#8221; tab and increase the GPU memory to 128. When you click &#8220;OK&#8221; after increasing RAM allocation to GPU, Raspberry Pi prompts you to reboot. Select &#8220;Yes&#8221; to reboot, and GPU allocation takes effect.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-10-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78714\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-10-1.png\" alt=\"\" width=\"529\" height=\"411\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-10-1.png 529w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-10-1-300x233.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-10-1-306x238.png 306w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-10-1-216x168.png 216w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-11-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78708\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-11-1.png\" alt=\"\" width=\"614\" height=\"410\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-11-1.png 614w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-11-1-300x200.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-11-1-356x238.png 356w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-11-1-600x400.png 600w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Upgrade EEPROM<br \/>\n<\/strong>Another optimization that we must do before proceeding to OpenCV installation is upgrading Raspberry Pi EEPROM. While the Raspberry Pi boots its operating system from the MicroSD card, it is also booted partially from two EEPROMs. Though EEPROMs have nothing to do with OpenCV, the latest release of EEPROM has been noted to reduce the CPU temperature from 65\u02daC to 48\u02daC. The computer vision applications are quite CPU-extensive, if a simple upgrade on EEPROM can drop CPU temperatures, that can boast the application&#8217;s performance. To check out the EEPROM version, execute the following command in the Bash Terminal.<br \/>\n<span style=\"color: #993300;\"><strong>$ sudo rpi-eeprom-update<br \/>\n<\/strong><\/span>If the EEPROM is reported to be updated, it&#8217;s fine. Otherwise, execute the following command in the Terminal to update EEPROM.<br \/>\n<strong><span style=\"color: #993300;\">$ sudo rpi-eeprom-update -a<\/span><\/strong><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-12-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78710\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-12-1.png\" alt=\"\" width=\"651\" height=\"443\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-12-1.png 651w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-12-1-300x204.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-12-1-350x238.png 350w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/a><\/p>\n<p><strong>Increase SWAP space<br \/>\n<\/strong>OpenCV requires a lot of memory to compile. The latest stable version OpenCV4.5 requires at least 6.5GB of space before building. That is why, you must increase the swap space, which is by default limited to 2048 MB. To increase the swap space, open \/sbin\/dphys-swapfile by executing the following command in the Bash Terminal.<br \/>\n<strong><span style=\"color: #993300;\">$ sudo nano \/sbin\/dphys-swapfile<\/span><\/strong><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-13-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78707\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-13-1.png\" alt=\"\" width=\"655\" height=\"161\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-13-1.png 655w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-13-1-300x74.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-13-1-368x90.png 368w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/a><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-14-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78709\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-14-1.png\" alt=\"\" width=\"655\" height=\"448\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-14-1.png 655w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-14-1-300x205.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-14-1-348x238.png 348w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/a>Once the file is open in the nano editor, jump over to the CONF_MAXSWAP flag and change it to 4096 MB from 2048 MB. Save file by pressing Ctrl+S and close the file by pressing Ctrl+X. Next open \/etc\/dphys-swapfile by executing the following command.<br \/>\n<strong><span style=\"color: #993300;\">$ sudo nano \/etc\/dphys-swapfile<br \/>\n<\/span><\/strong>Now, change CONF_SWAPSIZE to 4096 from 2048. Finally reboot Raspberry Pi for changes to take effect by executing following command in the Terminal.<br \/>\n<span style=\"color: #993300;\"><strong>$ sudo reboot<\/strong><\/span><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-15-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78711\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-15-1.png\" alt=\"\" width=\"651\" height=\"152\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-15-1.png 651w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-15-1-300x70.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-15-1-368x86.png 368w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/a><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-16-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78706\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-16-1.png\" alt=\"\" width=\"652\" height=\"153\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-16-1.png 652w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-16-1-300x70.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-16-1-368x86.png 368w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Successfully updating and upgrading Raspbian<br \/>\n<\/strong>On a fresh installation of Raspbian, when commands for updating and upgrading the OS are run, it is observed that while the update is done successfully, the upgrade results in the following error.<br \/>\n<strong><span style=\"color: #993300;\">E: Unable to fetch some archives, may be run apt-get update or try with &#8211;fix-missing?<br \/>\n<\/span><\/strong>The above error is only encountered in 32-bit Raspberry Pi OS. In 64-bit Raspberry Pi OS, no such error is encountered. While many makers turn to 64-bit OS just to get around the above error. The error is a result of missing files and libraries from the source repository. It can be easily corrected by redirecting the source repository to a suitable mirror link. It is important to get around this error, otherwise, broken or missing files in Raspbian can result in unpredictable behavior by our OpenCV application.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-17-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78702\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-17-1.png\" alt=\"\" width=\"657\" height=\"444\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-17-1.png 657w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-17-1-300x203.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-17-1-352x238.png 352w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/a><\/p>\n<p>To redirect the source repository, open \/etc\/apt\/sources.list in the nano editor by executing the following command in the Bash Terminal.<br \/>\n<span style=\"color: #993300;\"><strong>$ sudo nano \/etc\/apt\/sources.list<\/strong><\/span><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-18-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78705\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-18-1.png\" alt=\"\" width=\"654\" height=\"122\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-18-1.png 654w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-18-1-300x56.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-18-1-368x69.png 368w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a><\/p>\n<p>When the file opens in the nano editor, comment the first line indicating original source repository and add the following line at the end.<br \/>\n<strong><span style=\"color: #993300;\">deb http:\/\/mirror.ox.ac.uk\/sites\/archive.raspbian.org\/archive\/raspbian bullseye main contrib non-free rpi<\/span><\/strong><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-19-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-78703\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-19-1.png\" alt=\"\" width=\"754\" height=\"380\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-19-1.png 877w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-19-1-300x151.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-19-1-768x387.png 768w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-19-1-368x185.png 368w\" sizes=\"auto, (max-width: 754px) 100vw, 754px\" \/><\/a><\/p>\n<p>Save the file by pressing Ctrl+S and close the file by pressing Ctrl+X. Reboot Raspberry Pi for changes to take effect. Now when you update and upgrade 32-bit Raspbian, no errors are encountered. The other mirror links that are workable near specific geographical locations can be found in <a href=\"http:\/\/www.raspbian.org\/RaspbianMirrors\">this link<\/a>.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-20-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78704\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-20-1.png\" alt=\"\" width=\"653\" height=\"442\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-20-1.png 653w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-20-1-300x203.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-20-1-352x238.png 352w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><\/a><\/p>\n<p><strong>Install dependencies<br \/>\n<\/strong>Before installing OpenCV, you need to install several third-party packages required by OpenCV. Some of these packages might have come already installed with Raspbian. Still, it is better to install all required packages than to encounter some errors later. If the latest version of some package is already installed with Raspbian, it will be automatically skipped by the command execution. Run the following commands in the Bash Terminal one by one to install the required sets of software packages by OpenCV.<\/p>\n<p><span style=\"color: #993300;\"><strong>$ sudo apt-get update<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get upgrade<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install cmake gfortran<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install python3-dev python3-numpy<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install libjpeg-dev libtiff-dev libgif-dev<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install libgstreamer1.0-dev gstreamer1.0-gtk3<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install libgstreamer-plugins-base1.0-dev gstreamer1.0-gl<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install libgtk2.0-dev libcanberra-gtk*<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install libxvidcore-dev libx264-dev libgtk-3-dev<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install libtbb2 libtbb-dev libdc1394-22-dev libv4l-dev<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install libopenblas-dev libatlas-base-dev libblas-dev<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install libjasper-dev liblapack-dev libhdf5-dev<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get install protobuf-compiler<\/strong> <\/span><\/p>\n<p><strong><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-21-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78701\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-21-1.png\" alt=\"\" width=\"650\" height=\"565\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-21-1.png 650w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-21-1-300x261.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-21-1-274x238.png 274w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/a>Install QT5<br \/>\n<\/strong>QT5 is an open-source framework for developing cross-platform graphical user interfaces. It can be used in Raspberry Pi too for building beautiful user interfaces for embedded applications. Some computer vision applications may require interaction through a user interface. Though adding a user interface can slow down the machine vision application a little bit, it may be required or could be useful to add an interface in some applications. For installing QT5 in Raspbian Buster, execute the following commands one by one in Bash Terminal.<\/p>\n<p><strong><span style=\"color: #993300;\">$ sudo apt-get install qt5-default<br \/>\n<\/span><\/strong><strong><span style=\"color: #993300;\">$ sudo apt-get install qtcreator<br \/>\n<\/span><\/strong><strong><span style=\"color: #993300;\">$ sudo apt-get install qtdeclarative5-dev<\/span><\/strong><\/p>\n<p>For installing QT5 in Raspbian Bullseye, execute the following commands one by one in Bash Terminal.<\/p>\n<p><strong><span style=\"color: #993300;\">$ sudo apt-get install qtbase5-dev qtchooser<\/span><\/strong><br \/>\n<strong><span style=\"color: #993300;\">$ sudo apt-get install qt5-qmake qtbase5-dev-tools<\/span><\/strong><br \/>\n<strong><span style=\"color: #993300;\">$ sudo apt-get install qtcreator<\/span><\/strong><br \/>\n<strong><span style=\"color: #993300;\">$ sudo apt-get install qtdeclarative5-dev<\/span><\/strong><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-22-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78697\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-22-1.png\" alt=\"\" width=\"654\" height=\"571\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-22-1.png 654w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-22-1-300x262.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-22-1-273x238.png 273w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a>We already have some tutorials on building graphical user interfaces on Raspberry Pi for embedded applications using Tkinter framework. You must have a look at them.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/rpi-python-programming-11-python-gui-with-tkinter\/\">Python GUI with Tkinter<\/a><br \/>\n<a href=\"https:\/\/www.engineersgarage.com\/rpi-python-programming-12-tkinter-and-ttk-widgets\/\">Tkinter and TTK widgets<\/a><br \/>\n<a href=\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-python-gui-tkinter-ttk-menus-layout-management-events-multi-threading-2\/\">TTK menus, layout management, events &amp; multi-threading<\/a><br \/>\n<a href=\"https:\/\/www.engineersgarage.com\/rpi-python-programming-14-gui-controlled-led-driver-on-raspberry-pi\/\">GUI-controlled LED driver<\/a><br \/>\n<a href=\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-python-push-button-interface-digital-input\/\">Interfacing a push button &amp; digital input<\/a><\/p>\n<p><strong>Download OpenCV<br \/>\n<\/strong>After installing all third-party packages, it&#8217;s time to install OpenCV. There are two packages for OpenCV \u2014 a basic version and additional contributions. You can find the latest releases of OpenCV from <a href=\"https:\/\/opencv.org\/releases\/\">this link<\/a>. We will be installing OpenCV4.5.5 here. You can also install the latest one and change the version number accordingly in the following commands. The installation will consume enough RAM, so first check if enough RAM is available for installation by executing the following command in the Bash Terminal.<br \/>\n<span style=\"color: #993300;\"><strong>$ free -m<\/strong><\/span><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-23-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78700\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-23-1.png\" alt=\"\" width=\"654\" height=\"446\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-23-1.png 654w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-23-1-300x205.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-23-1-349x238.png 349w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a>As we are using 8GB variant of Raspberry Pi 4B, you can notice we have more than sufficient RAM at our disposal. Next open the root directory by executing the following command in the Bash Terminal.<br \/>\n<strong><span style=\"color: #993300;\">$ cd ~<\/span><\/strong><\/p>\n<p>Download the OpenCV4.5 packages in the root directory by executing the following commands in Bash Terminal.<br \/>\n<span style=\"color: #993300;\"><strong>$ wget -O opencv.zip https:\/\/github.com\/opencv\/opencv\/archive\/4.5.5.zip<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ wget -O opencv_contrib.zip https:\/\/github.com\/opencv\/opencv_contrib\/archive\/4.5.5.zip<\/strong><\/span><\/p>\n<p>Unzip the packages by running the following commands in the Terminal.<br \/>\n<span style=\"color: #993300;\"><strong>$ unzip opencv.zip<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ unzip opencv_contrib.zip<\/strong><\/span><\/p>\n<p>Rename directories to simpler names by executing the following commands in the Terminal.<br \/>\n<span style=\"color: #993300;\"><strong>$ mv opencv-4.5.5 opencv<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ mv opencv_contrib-4.5.5 opencv_contrib<\/strong><\/span><\/p>\n<p>Finally, get rid of the downloaded ZIP files by executing the following commands in the Terminal.<br \/>\n<strong><span style=\"color: #993300;\">$ rm opencv.zip<\/span><\/strong><br \/>\n<strong><span style=\"color: #993300;\">$ rm opencv_contrib.zip<\/span><\/strong><\/p>\n<p><strong><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-24-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78699\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-24-1.png\" alt=\"\" width=\"655\" height=\"444\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-24-1.png 655w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-24-1-300x203.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-24-1-351x238.png 351w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/a>Installing virtual environments<br \/>\n<\/strong>OpenCV can be installed on a system with or without a virtual environment. If you are willing to work with only one version of OpenCV, there is no need for a virtual environment. However, it is possible that you may need to exploit some features from a newly released OpenCV version or try some old OpenCV version, you cannot run both versions together without virtual environments. Suppose you have two OpenCV versions installed on your Raspberry Pi, and you import OpenCV in a Python script, how will Python come to know which OpenCV version to import? OpenCV installation typically occupies a little more than 1GB of space on a MicroSD card. There is no harm in installing and keeping more than one OpenCV version on the same SD card. But, multiple OpenCV versions can be called within a script only through different virtual environments. So, if you have both OpenCV 4.5 and OpenCV 3.4 installed on the same MicroSD card, you need two different virtual environments to call different CV versions in Python scripts.<\/p>\n<p>If you do not wish to access OpenCV through virtual environments and still want to work with different versions of OpenCV, the only way left is to install different versions of OpenCV on different MicroSD cards carrying Raspbian OS. For installing virtual environments on Raspberry Pi, it will be best to do it through pip, virtualenv, and virtualenvwrapper. You must have pip installed on Raspberry Pi. With a 32-bit Raspberry Pi OS including desktop and recommended software, pip3 must be already installed on Raspberry Pi. To install virtualenv and virtualenvwrapper, execute the following commands in the Bash Terminal.<br \/>\n<strong><span style=\"color: #993300;\">$ sudo pip3 install virtualenv<\/span><\/strong><br \/>\n<strong><span style=\"color: #993300;\">$ sudo pip3 install virtualenvwrapper<\/span><\/strong><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-25-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78698\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-25-1.png\" alt=\"\" width=\"657\" height=\"445\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-25-1.png 657w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-25-1-300x203.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-25-1-351x238.png 351w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/a>After both virtualenv and virtualenvwrapper are installed, open the ~\/.bashrc file by executing the following command in the Terminal.<br \/>\n<strong><span style=\"color: #993300;\">$ nano ~\/.bashrc<\/span><\/strong><\/p>\n<p>In the ~\/.bashrc file, append the following lines in the bottom.<br \/>\n<span style=\"color: #993300;\"><strong>export WORKON_HOME=$HOME\/.virtualenvs<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>export VIRTUALENVWRAPPER_PYTHON=\/usr\/bin\/python3<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>source \/usr\/local\/bin\/virtualenvwrapper.sh<\/strong><\/span><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-26-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78696\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-26-1.png\" alt=\"\" width=\"654\" height=\"449\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-26-1.png 654w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-26-1-300x206.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-26-1-347x238.png 347w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-27-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78695\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-27-1.png\" alt=\"\" width=\"652\" height=\"444\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-27-1.png 652w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-27-1-300x204.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-27-1-349x238.png 349w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/a>Save the file by pressing Ctrl+S and close the file by pressing Ctrl+X. Now reload the ~\/.bashrc file to apply changes to the current bash session by executing the following command.<br \/>\n<span style=\"color: #993300;\"><strong>$ source ~\/.bashrc<\/strong><\/span><\/p>\n<p>Next create a virtual environment with the name &#8220;cv&#8221; with Python3.x by executing the following command in the Terminal.<br \/>\n<span style=\"color: #993300;\"><strong>$ mkvirtualenv cv -p python3<\/strong><\/span><\/p>\n<p>As soon you will create a virtual environment, it will be activated in the current Bash session.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-28-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78694\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-28-1.png\" alt=\"\" width=\"652\" height=\"440\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-28-1.png 652w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-28-1-300x202.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-28-1-353x238.png 353w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/a><\/p>\n<p>While the virtual environment is activated, install picamera and numpy within the environment by executing the following commands in the Bash Terminal.<br \/>\n<strong><span style=\"color: #993300;\">$ pip install &#8220;picamera[array]&#8221;<\/span><\/strong><br \/>\n<strong><span style=\"color: #993300;\">$ pip3 install numpy<\/span><\/strong><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-29-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78693\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-29-1.png\" alt=\"\" width=\"654\" height=\"446\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-29-1.png 654w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-29-1-300x205.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-29-1-349x238.png 349w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a>You can deactivate the virtual environment in a current Bash session anytime by executing the following command.<br \/>\n<strong><span style=\"color: #993300;\">$ deactivate<\/span><\/strong><\/p>\n<p>Also, the virtual environment can be activated in a current Bash session anytime by executing the following command<br \/>\n<span style=\"color: #993300;\"><strong>$ workon cv<\/strong><\/span><\/p>\n<p>Note that &#8220;cv&#8221; is the name of the virtual environment we created.<\/p>\n<p><strong>Build OpenCV<br \/>\n<\/strong>Now, it&#8217;s time to build the OpenCV package. Activate the &#8216;cv&#8217; virtual environment by executing following command in the Bash Terminal (if it is not activated).<br \/>\n<strong><span style=\"color: #993300;\">$ workon cv<\/span><\/strong><\/p>\n<p>Open OpenCV folder, create a directory named build, and open the directory by executing the following commands.<br \/>\n<strong><span style=\"color: #993300;\">$ cd ~\/opencv\/<br \/>\n$ mkdir build<\/span><\/strong><br \/>\n<span style=\"color: #993300;\"><strong>$ cd build<\/strong><\/span><\/p>\n<p>Finally, tell cmake to build OpenCV by executing the following command that includes a number of important flags.<\/p>\n<p><span style=\"color: #993300;\"><strong>$ cmake -D CMAKE_BUILD_TYPE=RELEASE \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D CMAKE_INSTALL_PREFIX=\/usr\/local \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D OPENCV_EXTRA_MODULES_PATH=~\/opencv_contrib\/modules \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D ENABLE_NEON=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D ENABLE_VFPV3=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D WITH_OPENMP=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D WITH_OPENCL=OFF \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D BUILD_ZLIB=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D BUILD_TIFF=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D WITH_FFMPEG=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D WITH_TBB=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D BUILD_TBB=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D BUILD_TESTS=OFF \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D WITH_EIGEN=OFF \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D WITH_GSTREAMER=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D WITH_V4L=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D WITH_LIBV4L=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D WITH_VTK=OFF \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D WITH_QT=OFF \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D OPENCV_ENABLE_NONFREE=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D INSTALL_C_EXAMPLES=OFF \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D INSTALL_PYTHON_EXAMPLES=OFF \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D PYTHON3_PACKAGES_PATH=\/usr\/lib\/python3\/dist-packages \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D OPENCV_GENERATE_PKGCONFIG=ON \\<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>-D BUILD_EXAMPLES=OFF ..<\/strong><\/span><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-30-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78692\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-30-1.png\" alt=\"\" width=\"653\" height=\"445\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-30-1.png 653w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-30-1-300x204.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-30-1-349x238.png 349w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><\/a>The build process will take a lot of time. Once OpenCv is built, you could see the output message as shown in the image below.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-31-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78690\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-31-1.png\" alt=\"\" width=\"654\" height=\"446\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-31-1.png 654w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-31-1-300x205.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-31-1-349x238.png 349w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a><\/p>\n<p><strong>Make &amp; install OpenCV<br \/>\n<\/strong>After building OpenCV is done, launch the compilation process using all four cores of Raspberry Pi by executing the following command within the activated virtual environment of the current Bash session.<br \/>\n<strong><span style=\"color: #ff0000;\">$ make -j4<\/span><\/strong><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-32-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78691\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-32-1.png\" alt=\"\" width=\"656\" height=\"442\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-32-1.png 656w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-32-1-300x202.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-32-1-353x238.png 353w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/a>On Raspberry Pi 4, it may take around 2 hours. On other variants of Raspberry Pi, it could take 5~8 hours. You need to wait until the 100% build target is complete.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-33-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78681\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-33-1.png\" alt=\"\" width=\"654\" height=\"451\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-33-1.png 654w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-33-1-300x207.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-33-1-345x238.png 345w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a><\/p>\n<p>Once OpenCV is successfully compiled, install the OpenCV in the &#8220;cv&#8221; virtual environment by executing the following command.<br \/>\n<span style=\"color: #993300;\"><strong>$ sudo make install<\/strong><\/span><\/p>\n<p>Next, create the necessary links &amp; cache to the recently installed OpenCV package by executing the following command.<br \/>\n<span style=\"color: #993300;\"><strong>$ sudo ldconfig<\/strong><\/span><\/p>\n<p>Clean resources and update the database of the system by executing the following commands.<br \/>\n<span style=\"color: #993300;\"><strong>$ make clean<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ sudo apt-get update<\/strong><\/span><\/p>\n<p>Finally, open \/etc\/dphys-swapfile file &amp; reset CONF_SWAPSIZE to 100.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-34-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-78688 size-full\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-34-1.png\" alt=\"\" width=\"654\" height=\"523\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-34-1.png 654w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-34-1-300x240.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-34-1-298x238.png 298w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-35-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78689\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-35-1.png\" alt=\"\" width=\"656\" height=\"526\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-35-1.png 656w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-35-1-300x241.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-35-1-297x238.png 297w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/a><\/p>\n<p><strong>Sym-link to OpenCV<br \/>\n<\/strong>We have OpenCV installed in a virtual environment &#8216;cv&#8217;. Finally, we need to create a symbolic link to the library. Otherwise, Python could not find and import OpenCV. For creating a symbolic link open ~\/.virtualenvs\/cv\/lib\/python3.9\/site-packages folder. The folder path can be different depending on the name assigned to the virtual environment and Python version. Recall the name you assigned to the virtual environment and confirm the Python version by executing the following command.<br \/>\n<span style=\"color: #993300;\"><strong>$ python &#8211;version<\/strong><\/span><\/p>\n<p>Execute the following commands to open ~\/.virtualenvs\/cv\/lib\/python3.9\/site-packages folder, create a symbolic link named &#8216;cv2.so&#8217; and return to root folder.<br \/>\n<span style=\"color: #993300;\"><strong>$ cd ~\/.virtualenvs\/cv\/lib\/python3.9\/site-packages<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ ln -s \/usr\/local\/lib\/python3.9\/site-packages\/cv2\/python-3.9\/cv2.cpython-37m-arm-linux-gnueabihf.so<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>$ cd ~<\/strong><\/span><\/p>\n<p><strong><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-36-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78687\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-36-1.png\" alt=\"\" width=\"655\" height=\"246\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-36-1.png 655w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-36-1-300x113.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-36-1-368x138.png 368w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/a>\u00a0<\/strong><strong>Check OpenCV installation<br \/>\n<\/strong>Last, you must now check your OpenCV installation. Activate the &#8216;cv&#8217; virtual environment and import the OpenCV library by the symbolic link &#8220;cv2&#8221; in a Python script. If OpenCV is successfully imported into the script without producing any errors, OpenCV is installed for the virtual environment.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-37-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78684\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-37-1.png\" alt=\"\" width=\"829\" height=\"363\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-37-1.png 829w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-37-1-300x131.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-37-1-768x336.png 768w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-37-1-368x161.png 368w\" sizes=\"auto, (max-width: 829px) 100vw, 829px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>You can confirm build information about the installed OpenCV version by running the following Python script.<br \/>\n<span style=\"color: #993300;\"><strong>$ python<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>&gt;&gt;&gt; import cv2<\/strong><\/span><br \/>\n<span style=\"color: #993300;\"><strong>&gt;&gt;&gt; print( cv2.getBuildInformation() )<\/strong><\/span><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-38-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78685\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-38-1.png\" alt=\"\" width=\"835\" height=\"274\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-38-1.png 835w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-38-1-300x98.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-38-1-768x252.png 768w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-38-1-368x121.png 368w\" sizes=\"auto, (max-width: 835px) 100vw, 835px\" \/><\/a><\/p>\n<p>On running the script, the build information for the installed OpenCV version will be printed to the Terminal.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-39-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78686\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-39-1.png\" alt=\"\" width=\"816\" height=\"444\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-39-1.png 816w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-39-1-300x163.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-39-1-768x418.png 768w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/CV01-39-1-368x200.png 368w\" sizes=\"auto, (max-width: 816px) 100vw, 816px\" \/><\/a><\/p>\n<p>This completes the installation of OpenCV4.5 on Raspbian Bullseye. A similar installation will follow for other microcomputers running a Linux Debian derivative.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OpenCV is one of the best computer vision tools available out there. It is the most popular machine vision library among developers and makers. Due to being open-source, the library has enjoyed vast community support and evolved as one of the most mature software packages. OpenCV itself stands for &#8220;Open-source Computer Vision.&#8221; The latest version&hellip;<\/p>\n","protected":false},"author":387,"featured_media":78678,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[13,3993],"tags":[3996,3998,4000,3995,3997,3999],"class_list":{"2":"type-post","15":"entry","16":"has-post-thumbnail"},"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.2 (Yoast SEO v25.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Install OpenCV 4.5 in Raspberry Pi for Computer Vision<\/title>\n<meta name=\"description\" content=\"How to install OpenCV 4 on Raspberry Pi 32-bit Raspbian Bullseye for computer vision projects.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to install OpenCV 4.5 &amp; QT5 on Raspberry Pi &amp; NVIDIA Jetson Nano for computer vision\" \/>\n<meta property=\"og:description\" content=\"How to install OpenCV 4 on Raspberry Pi 32-bit Raspbian Bullseye for computer vision projects.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/\" \/>\n<meta property=\"og:site_name\" content=\"Engineers Garage\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/engineersgarage\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"955\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nikhil Agnihotri\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EngineersGarage\" \/>\n<meta name=\"twitter:site\" content=\"@EngineersGarage\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nikhil Agnihotri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"22 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/\"},\"author\":{\"name\":\"Nikhil Agnihotri\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6\"},\"headline\":\"How to install OpenCV 4.5 &#038; QT5 on Raspberry Pi &#038; NVIDIA Jetson Nano for computer vision\",\"datePublished\":\"2023-06-27T01:20:06+00:00\",\"dateModified\":\"2023-07-08T11:41:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/\"},\"wordCount\":3367,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured.jpg\",\"keywords\":[\"OpenCV 4 installation\",\"OpenCV 4 installation Raspberry Pi\",\"OpenCV 4 installation Raspbian Bullseye\",\"OpenCV installation\",\"OpenCV installation Raspberry Pi\",\"OpenCV installation Raspbian Bullseye\"],\"articleSection\":[\"Electronic Projects\",\"Raspberry pi\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/\",\"url\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/\",\"name\":\"Install OpenCV 4.5 in Raspberry Pi for Computer Vision\",\"isPartOf\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured.jpg\",\"datePublished\":\"2023-06-27T01:20:06+00:00\",\"dateModified\":\"2023-07-08T11:41:10+00:00\",\"description\":\"How to install OpenCV 4 on Raspberry Pi 32-bit Raspbian Bullseye for computer vision projects.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#primaryimage\",\"url\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured.jpg\",\"contentUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured.jpg\",\"width\":955,\"height\":500},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.engineersgarage.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to install OpenCV 4.5 &#038; QT5 on Raspberry Pi &#038; NVIDIA Jetson Nano for computer vision\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.engineersgarage.com\/#website\",\"url\":\"https:\/\/www.engineersgarage.com\/\",\"name\":\"Engineers Garage\",\"description\":\"Electronic Projects, Electrical Engineering Resources, Makers Articles and Product News\",\"publisher\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.engineersgarage.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\",\"name\":\"Engineer's Garage - WTWH Media\",\"url\":\"https:\/\/www.engineersgarage.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png\",\"contentUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png\",\"width\":372,\"height\":52,\"caption\":\"Engineer's Garage - WTWH Media\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/engineersgarage\",\"https:\/\/x.com\/EngineersGarage\",\"https:\/\/www.youtube.com\/channel\/UC0VITh11JSYk-UW7toLebUw\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6\",\"name\":\"Nikhil Agnihotri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g\",\"caption\":\"Nikhil Agnihotri\"},\"url\":\"https:\/\/www.engineersgarage.com\/author\/nikhil-agnihotri\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Install OpenCV 4.5 in Raspberry Pi for Computer Vision","description":"How to install OpenCV 4 on Raspberry Pi 32-bit Raspbian Bullseye for computer vision projects.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/","og_locale":"en_US","og_type":"article","og_title":"How to install OpenCV 4.5 & QT5 on Raspberry Pi & NVIDIA Jetson Nano for computer vision","og_description":"How to install OpenCV 4 on Raspberry Pi 32-bit Raspbian Bullseye for computer vision projects.","og_url":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/","og_site_name":"Engineers Garage","article_publisher":"https:\/\/www.facebook.com\/engineersgarage","og_image":[{"width":955,"height":500,"url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured.jpg","type":"image\/jpeg"}],"author":"Nikhil Agnihotri","twitter_card":"summary_large_image","twitter_creator":"@EngineersGarage","twitter_site":"@EngineersGarage","twitter_misc":{"Written by":"Nikhil Agnihotri","Est. reading time":"22 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#article","isPartOf":{"@id":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/"},"author":{"name":"Nikhil Agnihotri","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6"},"headline":"How to install OpenCV 4.5 &#038; QT5 on Raspberry Pi &#038; NVIDIA Jetson Nano for computer vision","datePublished":"2023-06-27T01:20:06+00:00","dateModified":"2023-07-08T11:41:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/"},"wordCount":3367,"commentCount":0,"publisher":{"@id":"https:\/\/www.engineersgarage.com\/#organization"},"image":{"@id":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#primaryimage"},"thumbnailUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured.jpg","keywords":["OpenCV 4 installation","OpenCV 4 installation Raspberry Pi","OpenCV 4 installation Raspbian Bullseye","OpenCV installation","OpenCV installation Raspberry Pi","OpenCV installation Raspbian Bullseye"],"articleSection":["Electronic Projects","Raspberry pi"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/","url":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/","name":"Install OpenCV 4.5 in Raspberry Pi for Computer Vision","isPartOf":{"@id":"https:\/\/www.engineersgarage.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#primaryimage"},"image":{"@id":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#primaryimage"},"thumbnailUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured.jpg","datePublished":"2023-06-27T01:20:06+00:00","dateModified":"2023-07-08T11:41:10+00:00","description":"How to install OpenCV 4 on Raspberry Pi 32-bit Raspbian Bullseye for computer vision projects.","breadcrumb":{"@id":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#primaryimage","url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured.jpg","contentUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured.jpg","width":955,"height":500},{"@type":"BreadcrumbList","@id":"https:\/\/www.engineersgarage.com\/opencv4-5-installation-raspberry-pi-raspbian-bullseye\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.engineersgarage.com\/"},{"@type":"ListItem","position":2,"name":"How to install OpenCV 4.5 &#038; QT5 on Raspberry Pi &#038; NVIDIA Jetson Nano for computer vision"}]},{"@type":"WebSite","@id":"https:\/\/www.engineersgarage.com\/#website","url":"https:\/\/www.engineersgarage.com\/","name":"Engineers Garage","description":"Electronic Projects, Electrical Engineering Resources, Makers Articles and Product News","publisher":{"@id":"https:\/\/www.engineersgarage.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.engineersgarage.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.engineersgarage.com\/#organization","name":"Engineer's Garage - WTWH Media","url":"https:\/\/www.engineersgarage.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png","contentUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png","width":372,"height":52,"caption":"Engineer's Garage - WTWH Media"},"image":{"@id":"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/engineersgarage","https:\/\/x.com\/EngineersGarage","https:\/\/www.youtube.com\/channel\/UC0VITh11JSYk-UW7toLebUw"]},{"@type":"Person","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6","name":"Nikhil Agnihotri","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g","caption":"Nikhil Agnihotri"},"url":"https:\/\/www.engineersgarage.com\/author\/nikhil-agnihotri\/"}]}},"featured_image_src":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured-600x400.jpg","featured_image_src_square":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2023\/05\/Install-OpenCV-featured-600x500.jpg","author_info":{"display_name":"Nikhil Agnihotri","author_link":"https:\/\/www.engineersgarage.com\/author\/nikhil-agnihotri\/"},"_links":{"self":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts\/78620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/users\/387"}],"replies":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/comments?post=78620"}],"version-history":[{"count":0,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts\/78620\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/media\/78678"}],"wp:attachment":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/media?parent=78620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/categories?post=78620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/tags?post=78620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}