You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/smartphones-and-mobile/android_opencv_kleidicv/background.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ OpenCV integrates well with Android development, leveraging Kotlin’s concise s
19
19
OpenCV is optimized for high performance, utilizing native C++ code for efficient processing. This ensures real-time performance, particularly on mobile devices where computational resources may be limited. A critical component enabling these optimizations is the Hardware Acceleration Layer (HAL). HAL serves as an abstraction layer that enables hardware-specific acceleration by utilizing device-specific optimizations. This significantly boosts the performance of OpenCV functions on supported hardware, reducing processing time and power consumption. HAL makes OpenCV highly adaptable to modern multi-core processors and GPU architectures, vital for computationally intensive tasks like object detection and image recognition.
20
20
21
21
### ARM and KleidiCV
22
-
To further enhance OpenCV’s capabilities on ARM-based devices, ARM developed KleidiCV, a specialized library that leverages OpenCV’s HAL for hardware acceleration. KleidiCV focuses on optimizing various OpenCV functions specifically for ARM processors, ensuring faster execution and lower power consumption. This integration is particularly beneficial for mobile and embedded systems where performance efficiency is critical. By utilizing HAL, KleidiCV allows developers to harness the full potential of ARM hardware, making it an ideal solution for applications requiring high-performance computer vision on ARM-based devices.
22
+
To further enhance OpenCV’s capabilities on ARM-based devices, ARM developed KleidiCV, a specialized library that leverages OpenCV’s HAL for hardware acceleration. KleidiCV is an Arm Kleidi Library, a suite of highly performant open-source Arm routines. KleidiCV focuses on optimizing various OpenCV functions specifically for ARM processors, ensuring faster execution and lower power consumption. This integration is particularly beneficial for mobile and embedded systems where performance efficiency is critical. By utilizing HAL, KleidiCV allows developers to harness the full potential of ARM hardware, making it an ideal solution for applications requiring high-performance computer vision on ARM-based devices.
23
23
24
24
### OpenCV for Android Developers
25
25
For Android developers, OpenCV offers an SDK designed for seamless integration with Android Studio, the primary development environment. The SDK simplifies the process of adding OpenCV libraries, managing dependencies, and configuring projects, enabling developers to incorporate sophisticated vision capabilities into their applications effortlessly.
Copy file name to clipboardExpand all lines: content/learning-paths/smartphones-and-mobile/android_opencv_kleidicv/process-images.md
+8-16Lines changed: 8 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,12 @@ layout: "learningpathall"
10
10
## Process images
11
11
In this final step, you will implement the application logic to process the images.
12
12
13
-
Start by adding a `assets` folder under `src/main`. Then, under `assets` folder add a `img.png` image. We will use this image for processing. Here, we use the cameraman image.
13
+
Start by adding a `assets` folder under `src/main`. Then, under `assets` folder add a `img.png` image. This image can be any kind of image as it converted to the right type by the app. We will use this image for processing. Here, we use the [cameraman image](https://github.com/antimatter15/cameraman).
14
+
15
+
To make navigation betwee files easier in Android Studio, select "Project" from the project browser pane.
14
16
15
17
## ImageOperation
16
-
You will now create an enumeration (enum class) for a set of image processing operations in an application that uses the OpenCV library. Under the `src/main/java` add the `ImageOperation.kt` file and modify it as follows:
18
+
You will now create an enumeration (enum class) for a set of image processing operations in an application that uses the OpenCV library. Under the `src/main/java/com/arm/arm64kleidicvdemo` add the `ImageOperation.kt` file and modify it as follows:
17
19
18
20
```Kotlin
19
21
packagecom.arm.arm64kleidicvdemo
@@ -72,15 +74,7 @@ Each enum constant must override the abstract method apply to define its specifi
72
74
73
75
We configured processing operations to align with current KleidiCV restrictions. Specifically, in-place changes are not supported, so the source and destination must be different images. In general, only single-channel images are supported (Gaussian blur is an exception). Sobel’s output type must be 16SC1; dx and dy must be either (1,0) or (0,1); and the border mode must be replicate. Gaussian blur supports a non-zero sigma, but its performance is best with sigma 0.0. Its uplift is most noticeable with a kernel size of 7×7.
74
76
75
-
There is also the companion object provides a utility method:
76
-
```Kotlin
77
-
companionobject {
78
-
funfromDisplayName(name:String): ImageOperation?=
79
-
values().find { it.displayName == name }
80
-
}
81
-
```
82
-
83
-
This function maps a string (displayName) to its corresponding enum constant by iterating through the list of all enum values and returns null if no match is found.
77
+
There is also the companion object provides a utility method fromDisplayName. This function maps a string (displayName) to its corresponding enum constant by iterating through the list of all enum values and returns null if no match is found.
84
78
85
79
## ImageProcessor
86
80
Similarly, add the ImageProcessor.kt:
@@ -232,9 +226,7 @@ class MainActivity : AppCompatActivity() {
232
226
returnMat(bitmap.height, bitmap.width, CvType.CV_8UC1).also { mat ->
@@ -315,7 +307,7 @@ When the activity starts, it sets up the user interface, initializes OpenCV and
315
307
The activity also implements several helper methods:
316
308
1. setupSpinner - populates the spinner with the names of available ImageOperation enums.
317
309
2. showToast - displays a short toast message for user feedback.
318
-
3. loadImage - loads the test image (img.png) from the app’s assets. Then, the method converts the image into a Bitmap and stores it for display. The bitmap is also converted to an OpenCV Mat object and changed its color format to BGR (used in OpenCV).
310
+
3. loadImage - loads the test image (img.png) from the app’s assets. Then, the method converts the image into a Bitmap and stores it for display. The bitmap is also converted to an OpenCV Mat object and changed its color format to grayscale (used in OpenCV).
319
311
4. displayAndStoreBitmap - updates the app’s ImageView to display the loaded image.
320
312
5. convertBitmapToMat - converts the Bitmap to a Mat using OpenCV utilities.
321
313
6. processImage - this method performs the following:
@@ -421,4 +413,4 @@ We achieved the following performance uplift:
421
413
| Resize | 0,02 | 0,04 | 2x |
422
414
| Rotate | 0,02 | 0,06 | 3x |
423
415
424
-
As shown above, we achieved 4× faster computations for Gaussian blur and the Sobel filter, 3× faster for rotation, and 2× faster for resizing.
416
+
As shown above, we achieved 4× faster computations for Gaussian blur and the Sobel filter, 3× faster for rotation, and 2× faster for resizing. Note that his numbers are noise (large standard deviation), and measurements for another device can vary.
Copy file name to clipboardExpand all lines: content/learning-paths/smartphones-and-mobile/android_opencv_kleidicv/ui.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ layout: "learningpathall"
9
9
You will now define the application UI.
10
10
11
11
## Modify the application view
12
-
To modify the application view, open `activity_main.xml` and replace the file contents with the following code:
12
+
To modify the application view, open `app/src/main/res/layout/activity_main.xmlactivity_main.xml` and replace the file contents with the following code:
0 commit comments