🧩 OpenCV
An extension for MIT App Inventor 2.Full OpenCV Image Processing Extension for App Inventor
Specifications
Package: cn.kevinkun.opencv
Size: 3.43 MB
Minimum API Level: 14
Updated On: 2026-05-17T16:00:00Z
Built & documented using: FAST v6.0.0-beta
Events:
OpenCV has total 2 events.
1. OnReady
Event triggered when OpenCV is fully initialized and ready.
2. OnError
Event triggered when an error occurs. Returns error message and function name.
| Parameter | Type |
|---|---|
| error | text |
| funcName | text |
Methods :
OpenCV has total 48 methods.
1. GetSize
Get image width, height, channels, type. Callback returns JSON.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
2. GetPixelColor
Get pixel color at (x,y). Callback returns {r,g,b,a,hex,aicolor}.
| Parameter | Type |
|---|---|
| base64 | text |
| x | number |
| y | number |
| callback | Procedure |
3. ToGray
Convert image to grayscale. Callback returns processed base64.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
4. ToBinary
Convert image to binary black-white. Callback returns processed base64.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
5. ToInvert
Invert all colors of the image. Callback returns processed base64.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
6. ToCanny
Canny edge detection. Callback returns edge image base64.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
7. DetectFace
Detect human faces and return face rectangles. Callback returns JSON list.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
8. TesseractOCR
OCR text recognition using Tesseract. Supports Chinese & English. Callback returns text.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
9. Crop
Crop image at rect [x,y,width,height]. Callback returns cropped base64.
| Parameter | Type |
|---|---|
| base64 | text |
| rect | text |
| callback | Procedure |
10. Resize
Resize image proportionally to maxWidth, maxHeight. Callback returns resized base64.
| Parameter | Type |
|---|---|
| base64 | text |
| maxWidth | number |
| maxHeight | number |
| callback | Procedure |
11. Stretch
Stretch image to any width & height without keep ratio. Callback returns stretched base64.
| Parameter | Type |
|---|---|
| base64 | text |
| targetWidth | number |
| targetHeight | number |
| callback | Procedure |
12. Flip
Flip image: 1=horizontal, 0=vertical, -1=both. Callback returns flipped base64.
| Parameter | Type |
|---|---|
| base64 | text |
| flipCode | number |
| callback | Procedure |
13. Rotate
Rotate image by any angle (0~360). Auto center & custom background color. Use aiColor for background. Callback returns rotated base64.
| Parameter | Type |
|---|---|
| base64 | text |
| angle | number |
| bgAiColor | number |
| callback | Procedure |
14. RoundCorner
Add rounded corners with given radius. Callback returns rounded base64.
| Parameter | Type |
|---|---|
| base64 | text |
| radius | number |
| callback | Procedure |
15. CompressImage
Compress image: quality 0~100, format jpg/png. Callback returns compressed base64.
| Parameter | Type |
|---|---|
| base64 | text |
| quality | number |
| format | text |
| callback | Procedure |
16. WarpPerspective
Perspective correction(document scan). Pass 4 points [[x,y],...]. Callback returns corrected image.
| Parameter | Type |
|---|---|
| base64 | text |
| pointJson | text |
| callback | Procedure |
17. AdjustBrightness
Adjust brightness: range -100~100. Callback returns adjusted base64.
| Parameter | Type |
|---|---|
| base64 | text |
| brightness | number |
| callback | Procedure |
18. AdjustContrast
Adjust contrast: range 0.1~5.0. Callback returns adjusted base64.
| Parameter | Type |
|---|---|
| base64 | text |
| contrast | number |
| callback | Procedure |
19. AdjustWhiteBalance
Adjust white balance (color temp): 2000K~10000K. Callback returns adjusted base64.
| Parameter | Type |
|---|---|
| base64 | text |
| temp | number |
| callback | Procedure |
20. AdjustSaturation
Adjust saturation: range 0.0~2.0. Callback returns adjusted base64.
| Parameter | Type |
|---|---|
| base64 | text |
| sat | number |
| callback | Procedure |
21. Threshold
Global binary threshold: thresh 0~255. Callback returns binary base64.
| Parameter | Type |
|---|---|
| base64 | text |
| thresh | number |
| callback | Procedure |
22. AdaptiveThreshold
Adaptive threshold for uneven lighting. Callback returns processed base64.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
23. Blur
Mean blur (simple blur). Callback returns blurred base64.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
24. GaussBlur
Gaussian blur: ksize 3~31 (odd number). Callback returns blurred base64.
| Parameter | Type |
|---|---|
| base64 | text |
| ksize | number |
| callback | Procedure |
25. MedianBlur
Median blur (noise reduction): ksize 3~31 (odd). Callback returns blurred base64.
| Parameter | Type |
|---|---|
| base64 | text |
| ksize | number |
| callback | Procedure |
26. BilateralBlur
Bilateral filter (skin smooth, keep edges). Callback returns processed base64.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
27. Erode
Erode image: kernel size 1~15. Callback returns processed base64.
| Parameter | Type |
|---|---|
| base64 | text |
| size | number |
| callback | Procedure |
28. Dilate
Dilate image: kernel size 1~15. Callback returns processed base64.
| Parameter | Type |
|---|---|
| base64 | text |
| size | number |
| callback | Procedure |
29. MorphOpen
Morphology open (erode then dilate): size 1~15. Callback returns base64.
| Parameter | Type |
|---|---|
| base64 | text |
| size | number |
| callback | Procedure |
30. MorphClose
Morphology close (dilate then erode): size 1~15. Callback returns base64.
| Parameter | Type |
|---|---|
| base64 | text |
| size | number |
| callback | Procedure |
31. DrawRects
Draw rotated rectangles. rectJson: [[x,y,w,h]...] thickness=-1 for fill. Callback returns image base64.
| Parameter | Type |
|---|---|
| base64 | text |
| rectJson | text |
| aiColor | number |
| thickness | number |
| angle | number |
| callback | Procedure |
32. DrawCircles
Draw circles. circleJson: [[cx,cy,r]...], thickness=-1 for fill. Callback returns image base64.
| Parameter | Type |
|---|---|
| base64 | text |
| circleJson | text |
| aiColor | number |
| thickness | number |
| callback | Procedure |
33. DrawLines
Draw lines or closed polygons. pointsJson: [[x,y],[x,y]...], thickness=-1 for fill. Callback returns base64.
| Parameter | Type |
|---|---|
| base64 | text |
| pointsJson | text |
| aiColor | number |
| thickness | number |
| callback | Procedure |
34. DrawText
Draw rotated text at (x,y). Callback returns image base64.
| Parameter | Type |
|---|---|
| base64 | text |
| text | text |
| x | number |
| y | number |
| aiColor | number |
| fontSize | number |
| thickness | number |
| angle | number |
| callback | Procedure |
35. ConcatH
Concatenate two images horizontally. Callback returns combined base64.
| Parameter | Type |
|---|---|
| leftBase64 | text |
| rightBase64 | text |
| callback | Procedure |
36. ConcatV
Concatenate two images vertically. Callback returns combined base64.
| Parameter | Type |
|---|---|
| topBase64 | text |
| bottomBase64 | text |
| callback | Procedure |
37. Watermark
Add sticker/watermark. angle 0~360, scale 0.1~3.0, alpha 0.0~1.0. Callback returns result.
| Parameter | Type |
|---|---|
| bgBase64 | text |
| fgBase64 | text |
| x | number |
| y | number |
| angle | number |
| scale | number |
| alpha | number |
| callback | Procedure |
38. Sketch
Apply sketch effect. Callback returns sketch base64.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
39. Cartoon
Apply cartoon effect. Callback returns cartoon base64.
| Parameter | Type |
|---|---|
| base64 | text |
| callback | Procedure |
40. MosaicArea
Apply mosaic on multiple areas. Input rect JSON array [[x,y,w,h],...]. blockSize 2~20. Callback returns processed base64.
| Parameter | Type |
|---|---|
| base64 | text |
| rectJson | text |
| blockSize | number |
| callback | Procedure |
41. FilterColor
HSV color filter. lowHsv and highHsv: [h,s,v]. Callback returns filtered base64.
| Parameter | Type |
|---|---|
| base64 | text |
| lowHsv | text |
| highHsv | text |
| callback | Procedure |
42. GetAllContours
Get all contours with area >= minArea. Callback returns JSON list.
| Parameter | Type |
|---|---|
| base64 | text |
| minArea | number |
| callback | Procedure |
43. ContourApproxPolygon
Approximate contour to polygon. epsilonRatio: 0.02~0.1 recommended. Callback returns points.
| Parameter | Type |
|---|---|
| pointJson | text |
| epsilonRatio | number |
| callback | Procedure |
44. ContourFitMinRotateRect
Fit minimum rotated rectangle to contour. Callback returns rect info.
| Parameter | Type |
|---|---|
| pointJson | text |
| callback | Procedure |
45. ContourGetConvexHull
Get convex hull of contour. Callback returns hull points.
| Parameter | Type |
|---|---|
| pointJson | text |
| callback | Procedure |
46. ContourFitMinCircle
Fit minimum enclosing circle to contour. Callback returns circle info.
| Parameter | Type |
|---|---|
| pointJson | text |
| callback | Procedure |
47. ContourFitEllipse
Fit ellipse to contour. Callback returns ellipse info.
| Parameter | Type |
|---|---|
| pointJson | text |
| callback | Procedure |
48. ContourFitStraightLine
Fit straight line to contour points. Callback returns line info.
| Parameter | Type |
|---|---|
| pointJson | text |
| callback | Procedure |
Gette r:
OpenCV has total 1 getter property.
1. IsReady
Whether OpenCV is loaded and ready to use.
- Return type:
boolean
Something to know for this extension:
- You need to get base64 of the image before call the functions. you can use this extension to get and set base64 from/to files/Image/Canvas components
- x,y,width,height used in this extension is with pixel, not same as in App Inventor.
- All functions can work offline, except DetectFace and TesseractOCR (these two need to connect internet for download model for once, then no need internet any more)
- This extension is done with help of Doubao AI, If any issue when using, please post here below.
- This extension is build with FAST. Thanks to @JEWEL quick response. I think this is the first extension on web which using anonymous procedure.
DOWNLOAD LINK
cn.kevinkun.opencv.aix (3.4 MB)
BASIC USAGE
- get image size
-
face detect and mosaic


