{"id":21018016,"url":"https://github.com/sthysel/arm-arch-opencv","last_synced_at":"2026-05-01T23:39:21.096Z","repository":{"id":138849916,"uuid":"244926970","full_name":"sthysel/arm-arch-opencv","owner":"sthysel","description":"Build optimized OpenCV on Arch for arm on a Raspberry Pi","archived":false,"fork":false,"pushed_at":"2020-03-05T06:03:32.000Z","size":73,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T04:59:45.808Z","etag":null,"topics":["arch","arm","opencv"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sthysel.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-04T14:51:27.000Z","updated_at":"2020-03-05T06:03:34.000Z","dependencies_parsed_at":"2024-02-24T14:31:47.402Z","dependency_job_id":null,"html_url":"https://github.com/sthysel/arm-arch-opencv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sthysel%2Farm-arch-opencv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sthysel%2Farm-arch-opencv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sthysel%2Farm-arch-opencv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sthysel%2Farm-arch-opencv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sthysel","download_url":"https://codeload.github.com/sthysel/arm-arch-opencv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243447641,"owners_count":20292452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arch","arm","opencv"],"created_at":"2024-11-19T10:23:09.586Z","updated_at":"2026-05-01T23:39:21.064Z","avatar_url":"https://github.com/sthysel.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+title: OpenCV 4.2.0 On Arch Arm for the Raspberry Pi 4 \n\nNotes describing how to build a Pi4 optimized OpenCV 4.2.0+ on Arch for Arm on a\nRaspberry Pi. Most all of the below can and may be scripted, there may be helper\nscripts or playbooks later on.\n\n* Installing Arch on the Pi4\n\nBy the way I use Arch Arm Linux on my Raspberry Pi's.\n\nIt is:\n- Tight\n- Arch\n- Not Raspian\n- Performant\n- In line with all my other machine in the lab and house\n- meme rich and zoomer approved\n\nBe sure to use the correct image from [[https://archlinuxarm.org][Arch Linux Arm]], specifically [[https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-4][Raspberry Pi 4]]\n\n #+caption: Raspberry Pi 4 \n [[file:pics/image.png]]\n\n** Install Arch on the Pi 4\n\n   Below are lifted from the [[https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-4][armv8/broadcom]] page on the Arch Arm wiki\n\n   The Raspberry Pi 4 has higher power requirements than the Raspberry\n   Pi 3. A power supply rated at 3A is the official recommendation. Using an\n   insufficient power supply will result in random, inexplicable errors and\n   file system corruption.\n\n   Early variants of the Raspberry Pi 4's USB Type-C power port is not compliant\n   with the USB Type-C specification, and it will not be able to be powered by\n   supplies that are compliant.\n\n*** Prep SD card and install Arch\n    Replace sdX in the following instructions with the device name for the SD\n    card as it appears on your computer.\n\n    Use ~lsblk~ to verify which labels belong to the target SD card:\n    #+BEGIN_SRC \n    ❯ lsblk\n    NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT\n    loop0    7:0    0 156.7M  1 loop /var/lib/snapd/snap/gnome-3-28-1804/110\n    loop1    7:1    0  44.9M  1 loop /var/lib/snapd/snap/gtk-common-themes/1440\n    loop2    7:2    0  54.7M  1 loop /var/lib/snapd/snap/core18/1650\n    loop3    7:3    0  97.4M  1 loop /var/lib/snapd/snap/signal-desktop/277\n    loop4    7:4    0  22.4M  1 loop /var/lib/snapd/snap/snapd/5754\n    sda      8:0    0 931.5G  0 disk \n    ├─sda1   8:1    0   512M  0 part /efi\n    ├─sda2   8:2    0    32G  0 part [SWAP]\n    └─sda3   8:3    0   899G  0 part /\n    sdb      8:16   0   2.7T  0 disk \n    └─sdb1   8:17   0   2.7T  0 part \n    sdc      8:32   1  29.7G  0 disk \n    ├─sdc1   8:33   1   100M  0 part /run/media/thys/7CE9-4243\n    └─sdc2   8:34   1  29.6G  0 part /run/media/thys/f814e33d-4b31-4bf4-8dd8-dbff7fe0f570\n    #+END_SRC\n\n    In this case the SD card is ~sdc~\n\n    1. Use fdisk to partition the SD card:\n       ~fdisk /dev/sdX~\n    2. At the fdisk prompt, delete old partitions and create a new one:\n       - Type o. This will clear out any partitions on the drive.\n       - Type p to list partitions. There should be no partitions left.\n       - Type n, then p for primary, 1 for the first partition on the drive,\n       - press ENTER to accept the default first sector, then type +100M for the last sector.\n       - Type t, then c to set the first partition to type W95 FAT32 (LBA).\n       - Type n, then p for primary, 2 for the second partition on the drive, and then press ENTER twice to accept the default first and last sector.\n       - Write the partition table and exit by typing w.\n    3. Create and mount the FAT file system:\n       #+BEGIN_SRC \n       mkfs.vfat /dev/sdX1\n       mkdir boot\n       mount /dev/sdX1 boot\n       #+END_SRC\n    4. Create and mount the ext4 file system:\n       #+BEGIN_SRC \n       mkfs.ext4 /dev/sdX2\n       mkdir root\n       mount /dev/sdX2 root\n       #+END_SRC\n    5. Download and extract the root file system (as root, not via sudo):\n       #+BEGIN_SRC \n       wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-4-latest.tar.gz\n       bsdtar -xpf ArchLinuxARM-rpi-4-latest.tar.gz -C root\n       sync\n       #+END_SRC \n    6. Move boot files to the first partition:\n       ~mv root/boot/* boot~\n    7. Unmount the two partitions:\n       ~umount boot root~\n    8. Insert the SD card into the Raspberry Pi, connect ethernet, and apply 5V power.\n    9. Use the serial console or SSH to the IP address given to the board by your router.\n       - Login as the default user alarm with the password alarm.\n       - The default root password is root.\n    10. Initialize the pacman keyring and populate the Arch Linux ARM package signing keys:\n        #+BEGIN_SRC \n        pacman-key --init\n        pacman-key --populate archlinuxarm\n        #+END_SRC\n\n* Prepare build environment\n  Install all the dependencies for the OpenCV build. I use ~yay~ to install of\n  official and the aur. This is of course not a hard requirement, use any aur\n  helper to install aur hosted dependencies or just install it manually.\n\n** Install core system dependencies  \n   ~pacman -S base-devel git nvim wget unzip~\n\n** Install yay\n   Using ~yay~ it does not matter if the dependencies come from core or aur.\n\n*** clone yay from the aur\n    ~git clone https://aur.archlinux.org/yay.git~ and build it ~makepkg -sir~\n*** use yay to install the OpenCV dependencies\n    ~yay -S pkg-config libjpeg libtiff libpng jasper ffmpeg libx264 cairo gdk-pixbuf pango gtk2 gtk-3lapack hdf5 ~\n\n* Prepare Python virtualenv\n\n  I like to keep virtualens in ~~/.virtualenvs~ :\n\n  #+BEGIN_SRC \n  python -m venv ~/.virtualenvs/cv\n  source ~/.virtualenvs/cv/bin/activate\n  pip install \"picamera[array]\"\n  #+END_SRC \n\n* Build OpenCV\n\n** Get the source\n   \n   #+BEGIN_SRC \n   wget -O opencv.zip https://github.com/opencv/opencv/archive/4.2.0.zip\n   unzip opencv.zip \n   mv opencv-4.2.0 opencv\n   wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.2.0.zip\n   unzip opencv_contrib.zip\n   mv opencv_contrib-4.2.0 opencv_contrib\n   #+END_SRC \n\n** prepare the build\n   Set some OpenCV build flags\n   #+BEGIN_SRC \n    cmake -D CMAKE_BUILD_TYPE=RELEASE \\\n        -D CMAKE_INSTALL_PREFIX=/usr/local \\\n        -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \\\n        -D ENABLE_NEON=ON \\\n        -D ENABLE_VFPV3=ON \\\n        -D BUILD_TESTS=OFF \\\n        -D INSTALL_PYTHON_EXAMPLES=OFF \\\n        -D OPENCV_ENABLE_NONFREE=ON \\\n        -D CMAKE_SHARED_LINKER_FLAGS=-latomic \\\n        -D BUILD_EXAMPLES=OFF ..\n    #+END_SRC\n\n    #+BEGIN_SRC \n    chmod +x prepare.sh \n    ./prepare.sh \n    make -j4\n    sudo make install\n    sudo ldconfig\n    #+END_SRC\n\n    #+BEGIN_SRC \n    cd /usr/local/lib/python3.8/site-packages/cv2/python-3.8/\n    sudo mv cv2.cpython-38-arm-linux-gnueabihf.so cv2.so\n    cd ~/.virtualenvs/cv/lib/python3.8/site-packages/\n    ln -s /usr/local/lib/python3.8/site-packages/cv2/python-3.8/cv2.so\n    #+END_SRC\n\n* Verify \n\n  #+BEGIN_SRC \n  (cv) [thys@pateye-1 site-packages]$ python\n  Python 3.8.1 (default, Jan 25 2020, 17:00:07) \n  [GCC 9.2.0] on linux\n  Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n  \u003e\u003e\u003e import cv2\n  \u003e\u003e\u003e cv2.__version__\n  '4.2.0'\n  #+END_SRC\n\n* Camera setup \n** Enable camera\n\n   ~/boot/config.txt~ should look like below\n   #+BEGIN_VERBATIM\n   initramfs initramfs-linux.img followkernel\n   gpu_mem=128 start_file=start_x.elf fixup_file=fixup_x.dat\n   start_x=1\n   #+END_VERBATIM\n\n  Display camera footage: ~/opt/vc/bin/raspivid --fullscreen --vflip --timeout 0~\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsthysel%2Farm-arch-opencv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsthysel%2Farm-arch-opencv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsthysel%2Farm-arch-opencv/lists"}