Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

The minimal opencv for Android, iOS, ARM Linux, Windows, Linux, MacOS, HarmonyOS, WebAssembly, watchOS, tvOS, visionOS

License

NotificationsYou must be signed in to change notification settings

nihui/opencv-mobile

Repository files navigation

Licensebuilddownload

AndroidiOSARM LinuxWindowsUbuntuMacOSHarmonyOSFirefoxChrome

✔️ This project provides the minimal build of opencv library for theAndroid,iOS andARM Linux platforms.

✔️ Packages forWindows,Linux,MacOS,HarmonyOS andWebAssembly are available now.

✔️ We provide prebuild binary packages for opencv2.4.13.7,3.4.20 and4.10.0.

✔️ We also provide prebuild package forMac-Catalyst,watchOS,tvOS,visionOS andApple xcframework.

✔️ All the binaries are compiled from source on github action,no virus,no backdoor,no secret code.

✔️NEW FEATUREcv::putText supports full-width CJK characters

✔️NEW FEATUREcv::imshow supports Linux framebuffer and Windows

✔️NEW FEATUREcv::VideoWriter supports jpg streaming over http

opencv 4.10.0 package sizeThe official opencvopencv-mobile
source zip95.2 MB8.25 MB
android292 MB17.7 MB
ios207 MB3.97 MB
Technical Exchange QQ Group
623504742(opencv-mobile夸夸群)

Download

https://github.com/nihui/opencv-mobile/releases/latest

Source

Android

HarmonyOS

iOS

iOS-Simulator

macOS

Mac-Catalyst

watchOS

watchOS-Simulator

tvOS

tvOS-Simulator

visionOS

visionOS-Simulator

Apple xcframework

Ubuntu-20.04

Ubuntu-22.04

VS2015

VS2017

VS2019

VS2022

WebAssembly

ARM-Linux

  • Android package build with ndk r26c and android api 21
  • iOS / MacOS / Mac-Catalyst / watchOS / tvOS / visionOS package build with Xcode 15.2
  • ARM Linux package build with cross-compiler on Ubuntu-22.04
  • WebAssembly package build with Emscripten 3.1.28

opencv-mobile package for development boards

milkv-duo
milkv-duo

riscv64-linux-musl
✅ HW JPG decoder
✅ MIPI CSI camera
opencv4-milkv-duo
licheerv-nano
licheerv-nano

riscv64-linux-musl
✅ HW JPG decoder
✅ MIPI CSI camera
opencv4-licheerv-nano
luckfox-pico
luckfox-pico

arm-linux-uclibcgnueabihf
✅ HW JPG encoder
✅ MIPI CSI camera
✅ DPI LCD screen
opencv4-luckfox-pico
yuzuki-lizard
yuzuki-lizard

arm-linux-uclibcgnueabihf
opencv4-yuzuki-lizard
tinyvision
tinyvision

arm-linux-uclibcgnueabihf
✅ HW JPG decoder
✅ HW JPG encoder
✅ MIPI CSI camera
✅ SPI LCD screen
opencv4-tinyvision
yuzuki-chameleon
yuzuki-chameleon

arm-openwrt-linux-gnueabi
✅ HW JPG decoder
✅ HW JPG encoder
opencv4-yuzuki-chameleon
purple-pi
purple-pi

arm-linux-uclibcgnueabihf
opencv4-purple-pi
myir-t113i
myir-t113i

arm-linux-gnueabi
✅ HW JPG decoder
✅ HW JPG encoder
opencv4-myir-t113i
2k0300-fengniao
2k0300-fengniao

loongarch64-linux-gnu
opencv4-2k0300-fengniao
lockzhiner-vision-module
lockzhiner-vision-module

arm-linux-uclibcgnueabihf
✅ HW JPG encoder
✅ MIPI CSI camera
✅ DPI LCD screen
opencv4-lockzhiner-vision-module

Usage Android

  1. Extract archive to<project dir>/app/src/main/jni/
  2. Modify<project dir>/app/src/main/jni/CMakeLists.txt to find and link opencv
set(OpenCV_DIR${CMAKE_SOURCE_DIR}/opencv-mobile-4.10.0-android/sdk/native/jni)find_package(OpenCV REQUIRED)target_link_libraries(your_jni_target${OpenCV_LIBS})

Usage iOS, macOS, watchOS, tvOS, visionOS

  1. Extract archive, and dragopencv2.framework oropencv2.xcframework into your project

Usage ARM Linux, Windows, Linux, WebAssembly

  1. Extract archive to<project dir>/
  2. Modify<project dir>/CMakeLists.txt to find and link opencv
  3. Pass-DOpenCV_STATIC=ON to cmake option for windows build
set(OpenCV_DIR${CMAKE_SOURCE_DIR}/opencv-mobile-4.10.0-armlinux/arm-linux-gnueabihf/lib/cmake/opencv4)find_package(OpenCV REQUIRED)target_link_libraries(your_target${OpenCV_LIBS})

How-to-build your custom package

We reduce the binary size of opencv-mobile in 3 ways

  1. Reimplement some modules (such as highgui) and functions (such as putText)
  2. Apply patches to disable rtti/exceptions and do not install non-essential files
  3. Carefully select cmake options to retain only the modules and functions you want

Steps 1 and 2 are relatively cumbersome and difficult, and require intrusive changes to the opencv source code. If you want to know the details, please refer to the steps in.github/workflows/release.yml

The opencv-mobile source code package is the result of steps 1 and 2. Based on it, we can adjust the cmake option to compile our own package and further delete and add modules and other functions.

step 1. download opencv-mobile source

wget -q https://github.com/nihui/opencv-mobile/releases/latest/download/opencv-mobile-4.10.0.zipunzip -q opencv-mobile-4.10.0.zipcd opencv-mobile-4.10.0

step 2. apply your opencv option changes to options.txt

vim options.txt

step 3. build your opencv package with cmake

mkdir -p buildcd buildcmake -DCMAKE_INSTALL_PREFIX=install \  -DCMAKE_BUILD_TYPE=Release \`cat ../options.txt` \  -DBUILD_opencv_world=OFF ..make -j4make install

step 4. make a package

zip -r -9 opencv-mobile-4.10.0-mypackage.zip install

Some notes

  • The minimal opencv build contains most basic opencv operators and common image processing functions, with some handy additions like keypoint feature extraction and matching, image inpainting and opticalflow estimation.

  • Many computer vision algorithms that reside in dedicated modules are discarded, such as face detection etc.You could try deep-learning based algorithms with neural network inference library optimized for mobile.

  • Image IO functions in highgui module, likecv::imread andcv::imwrite, are re-implemented usingstb for smaller code size. GUI functions, likecv::imshow, are discarded.

  • cuda and opencl are disabled because there is no cuda on mobile, no opencl on ios, and opencl on android is slow. opencv on gpu is not suitable for real productions. Write metal on ios and opengles/vulkan on android if you need good gpu acceleration.

  • C++ RTTI and exceptions are disabled for minimal build on mobile platforms and webassembly build. Be careful when you writecv::Mat roi = image(roirect); :P

cv::putText supports full-width CJK characters

  1. Openhttps://nihui.github.io/opencv-mobile/patches/fontface.html oropencv-mobile-X.Y.Z/fontface.html in your browser.
  2. In the opened page, enter all the text to be drawn, select the TTF font file (optional), click theConvert to Font Header button to download the fontface header. This step is completely local operation, without connecting to a remote server, your data is private and safe.
  3. Include the generated fontface header, initialize a fontface instance, and pass it as the argument tocv::putText. The source file must be encoded in UTF-8.

Since all characters have been converted to embedded bitmap, the drawing routine does not depend on freetype library or any font files at runtime.

#include<opencv2/core/core.hpp>#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgproc/imgproc.hpp>#include"myfontface.h"intmain(){    cv::Mat bgr =cv::imread("atari.jpg",1);// use this font    MyFontFace myfont;// draw full-width text with myfontconstchar* zhtext ="称呼机器人为破铜烂铁,\n违反了禁止歧视机器人法!";cv::putText(bgr, zhtext,cv::Point(30,250),cv::Scalar(127,0,127), myfont,20);// get bounding rect    cv::Rect rr =cv::getTextSize(bgr.size(), zhtext,cv::Point(30,250), myfont,20);cv::imwrite("out.jpg", bgr);return0;}

cv::imshow supports Linux framebuffer and Windows

In Linux,cv::imshow can display images on the screen (/dev/fb0) via theLinux Framebuffer API.cv::imshow can work without desktop environment (gnome, KDE Plasma, xfce, etc.) or window manager (X or wayland), making it suitable for embedded scenarios. The first argument tocv::imshow must befb.

In Windows,cv::imshow will use the Windows API to create a simple window for displaying.

display image

#include<opencv2/core/core.hpp>#include<opencv2/highgui/highgui.hpp>intmain(){    cv::Mat bgr =cv::imread("im.jpg",1);cv::imshow("fb", bgr);return0;}

realtime camera preview

#include<opencv2/core/core.hpp>#include<opencv2/highgui/highgui.hpp>intmain(){    cv::VideoCapture cap;    cap.set(cv::CAP_PROP_FRAME_WIDTH,320);    cap.set(cv::CAP_PROP_FRAME_HEIGHT,240);    cap.open(0);    cv::Mat bgr;while (1)    {        cap >> bgr;cv::imshow("fb", bgr);    }return0;}

cv::VideoWriter supports jpg streaming over http

In Linux,cv::VideoWriter could be used for streaming images as jpg over http, while it is noop on other platforms. Initialize acv::VideoWriter instance,open the writer with namehttpjpg and a port number, then it will setup a simple http server. You can open the streaming url with a web browser, and image will be shown in the browser as soon as it is sent to the writer. The image size and content can be dynamic, which is useful for streaming frames from a live camera.

#include<opencv2/core/core.hpp>#include<opencv2/highgui/highgui.hpp>intmain(){    cv::VideoCapture cap;    cap.open(0);    cv::VideoWriter http;    http.open("httpjpg",7766);// open streaming url http://<server ip>:7766 in web browser    cv::Mat bgr;while (1)    {        cap >> bgr;        http << bgr;    }return0;}

opencv modules included

modulecomment
opencv_coreMat, matrix operations, etc
opencv_imgprocresize, cvtColor, warpAffine, etc
opencv_highguiimread, imwrite
opencv_features2dkeypoint feature and matcher, etc (not included in opencv 2.x package)
opencv_photoinpaint, etc
opencv_videoopticalflow, etc

opencv modules discarded

modulecomment
opencv_androidcamerause android Camera api instead
opencv_calib3dcamera calibration, rare uses on mobile
opencv_contribexperimental functions, build part of the source externally if you need
opencv_dnnvery slow on mobile, try ncnn for neural network inference on mobile
opencv_dynamicudano cuda on mobile
opencv_flannfeature matching, rare uses on mobile, build the source externally if you need
opencv_gapigraph based image processing, little gain on mobile
opencv_gpuno cuda/opencl on mobile
opencv_imgcodecslink with opencv_highgui instead
opencv_javawrap your c++ code with jni
opencv_jswrite native code on mobile
opencv_legacyvarious good-old cv routines, build part of the source externally if you need
opencv_mltrain your ML algorithm on powerful pc or server
opencv_nonfreethe SIFT and SURF, use ORB which is faster and better
opencv_objdetectHOG, cascade detector, use deep learning detector which is faster and better
opencv_oclno opencl on mobile
opencv_pythonno python on mobile
opencv_shapeshape matching, rare uses on mobile, build the source externally if you need
opencv_stitchingimage stitching, rare uses on mobile, build the source externally if you need
opencv_superresdo video super-resolution on powerful pc or server
opencv_tstest modules, useless in production anyway
opencv_videoiouse android MediaCodec or ios AVFoundation api instead
opencv_videostabdo video stablization on powerful pc or server
opencv_vizvtk is not available on mobile, write your own data visualization routines

About

The minimal opencv for Android, iOS, ARM Linux, Windows, Linux, MacOS, HarmonyOS, WebAssembly, watchOS, tvOS, visionOS

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    [8]ページ先頭

    ©2009-2025 Movatter.jp