diff --git a/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/_index.md b/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/_index.md index 31258105a2..96a87432bb 100644 --- a/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/_index.md +++ b/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/_index.md @@ -1,11 +1,7 @@ --- -title: Build Computer Vision Pipelines with OpenCV on Google Cloud C4A Axion VM +title: Build computer vision pipelines with OpenCV on a Google Cloud C4A Axion VM description: Deploy and run OpenCV-based computer vision pipelines on Google Cloud Axion C4A Arm-based VMs, covering image processing, video pipelines, browser-based visualization, and integration with machine learning models. - -draft: true -cascade: - draft: true - + minutes_to_complete: 45 who_is_this_for: This is an introductory topic for DevOps engineers, software developers, and AI practitioners who want to build and run computer vision pipelines on SUSE Linux Enterprise Server (SLES) Arm64 using OpenCV, process images and videos, visualize outputs in real time, and integrate ML models. diff --git a/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/background.md b/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/background.md index ed184da710..94c2ca32b9 100644 --- a/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/background.md +++ b/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/background.md @@ -1,46 +1,35 @@ --- -title: Get started with OpenCV on Google Axion C4A +title: Understand OpenCV on Google Axion C4A weight: 2 layout: "learningpathall" --- -## Explore Axion C4A Arm instances in Google Cloud +## Arm-based Axion C4A instances in Google Cloud Google Axion C4A is a family of Arm-based virtual machines built on Google’s custom Axion CPU, which is based on Arm Neoverse-V2 cores. Designed for high-performance and energy-efficient computing, these virtual machines offer strong performance for modern cloud workloads such as CI/CD pipelines, microservices, media processing, and general-purpose applications. -The C4A series provides a cost-effective alternative to x86 virtual machines while leveraging the scalability and performance benefits of the Arm architecture in Google Cloud. +The C4A series provides a cost-effective alternative to x86 virtual machines while using the scalability and performance benefits of the Arm architecture in Google Cloud. To learn more, see the Google blog [Introducing Google Axion Processors, our new Arm-based CPUs](https://cloud.google.com/blog/products/compute/introducing-googles-new-arm-based-cpu). -## Explore OpenCV on Google Axion C4A (Arm Neoverse V2) +## OpenCV on Google Axion C4A -OpenCV (Open Source Computer Vision Library) is a widely used open-source library for building real-time computer vision and image processing applications. It provides optimized implementations for image transformations, video processing, object detection, and integration with machine learning models. +Open Source Computer Vision Library (OpenCV) is an open-source library for real-time computer vision and image processing applications. It includes implementations for image transforms, video processing, object detection, and integration with machine learning models. -Key capabilities of OpenCV include: +When you run OpenCV on Google Axion C4A infrastructure, you can use multi-core CPU parallelism to scale image and video workloads on Arm. In practice, this helps you: -* **Image Processing** for transformations, filtering, and feature extraction -* **Video Processing** for frame-by-frame analysis and real-time pipelines -* **Drawing & Visualization** for overlaying text, shapes, and annotations -* **ML Integration** for combining computer vision with machine learning models - -Running OpenCV on Google Axion C4A Arm-based infrastructure enables efficient execution of image and video workloads by leveraging multi-core CPU parallelism. This allows: - -* Faster frame processing for video pipelines -* Efficient memory utilization for image transformations -* Improved performance-per-watt compared to x86 systems -* Cost-effective scaling for computer vision workloads +* Process video frames faster in CPU-based pipelines +* Use memory efficiently for common image transformations +* Improve performance-per-watt for sustained processing jobs +* Scale vision services in cloud environments with predictable costs Common use cases include real-time video analytics, image transformation pipelines, automated inspection systems, and ML-powered vision applications. -To learn more, visit the [OpenCV documentation](https://docs.opencv.org/) and explore the [OpenCV GitHub repository](https://github.com/opencv/opencv). - -## What you've accomplished and what's next +To learn more, see the [OpenCV documentation](https://docs.opencv.org/) and explore the [OpenCV GitHub repository](https://github.com/opencv/opencv). -In this section, you: +## What you've learned and what's next -* Explored Google Axion C4A Arm-based VMs and their benefits for computer vision workloads -* Understood OpenCV capabilities for image and video processing -* Learned how Arm architecture improves performance and efficiency for OpenCV pipelines +You've now reviewed what Google Axion C4A instances provide on Arm and why they are a good fit for OpenCV workloads. You also mapped OpenCV capabilities to practical cloud use cases you can run on C4A. -Next, you'll create a firewall rule to enable browser-based visualization of OpenCV pipelines running on your Arm-based virtual machine. +Next, you'll create a firewall rule so you can view OpenCV pipeline output from your browser while your application runs on an Arm-based virtual machine. diff --git a/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/firewall-setup.md b/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/firewall-setup.md index 28cab745f5..01215283af 100644 --- a/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/firewall-setup.md +++ b/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/firewall-setup.md @@ -1,6 +1,6 @@ --- -title: Create a firewall rule for OpenCV Browser Visualization +title: Create a firewall rule for OpenCV browser visualization weight: 3 @@ -9,34 +9,36 @@ weight: 3 layout: learningpathall --- - -Create a firewall rule in Google Cloud Console to expose the required port for OpenCV browser-based visualization. + +## Expose port for OpenCV browser-based visualization + +Create a firewall rule in Google Cloud Console to allow browser access to your OpenCV output on port 8000. {{% notice Note %}} -For help with GCP setup, see the Learning Path [Getting started with Google Cloud Platform](/learning-paths/servers-and-cloud-computing/csp/google/). +For help with Google Cloud Platform setup, see the Learning Path [Getting started with Google Cloud Platform](/learning-paths/servers-and-cloud-computing/csp/google/). {{% /notice %}} -## Configure the firewall rule +### Configure the firewall rule + +Configure the firewall rule using the Google Cloud Console: -Navigate to the [Google Cloud Console](https://console.cloud.google.com/), go to **VPC Network > Firewall**, and select **Create firewall rule**. +1. Open the [Google Cloud Console](https://console.cloud.google.com/), navigate to **VPC Network > Firewall**, and select **Create firewall rule**. ![Google Cloud Console VPC Network Firewall page showing the Create firewall rule button in the top menu bar#center](images/firewall-rule.png "Create a firewall rule in Google Cloud Console") -Next, create the firewall rule that exposes the required port for OpenCV visualization. +2. Set the **Name** of the new rule to **allow-opencv-port**. Select the network that you intend to bind to your VM. -Set the **Name** of the new rule to "allow-opencv-port". Select your network that you intend to bind to your VM. - -Set **Direction of traffic** to "Ingress". +3. For **Direction of traffic**, select **Ingress**. -Set **Allow on match** to "Allow". +4. For **Allow on match**, select **Allow**. -Set **Targets** to "Specified target tags". +5. For **Targets**, select **Specified target tags**. -Enter "allow-opencv" in the **Target tags** field. +6. For **Target tags**, enter **allow-opencv**. -Set **Source IPv4 ranges** to your current machine's public IP address. Run the following command in a terminal on your local machine (not on the VM) to find it: +7. Set **Source IPv4 ranges** to your current machine's public IP address. Run the following command in a terminal on your local machine to find the address: ```bash curl -4 ifconfig.me @@ -48,29 +50,17 @@ The `-4` flag forces an IPv4 response. Take the returned address and append `/32 ![Google Cloud Console Create firewall rule form configured for OpenCV with Ingress and Allow settings#center](images/network-rule.png "Configuring the OpenCV firewall rule") -## Configure port -Under **Protocols and ports**, select **Specified protocols and ports**. +8. For **Protocols and ports**, select **Specified protocols and ports**. -Select the **TCP** checkbox and enter: +9. Select the **TCP** checkbox and, for **Ports**, enter **8000**. -```text -8000 -``` +10. Select **Create**. -Then select **Create**. - -![Google Cloud Console Protocols and ports section showing TCP checkbox selected with port 8000 configured for OpenCV Browser Visualization#center](images/network-port.png "Setting Ray ports in the firewall rule") +![Google Cloud Console Protocols and ports section showing TCP checkbox selected with port 8000 configured for OpenCV browser visualization#center](images/network-port.png "Setting ports in the firewall rule") ## What you've accomplished and what's next -In this section, you: - -* Created a firewall rule for OpenCV visualization -* Enabled external browser access to your VM -* Exposed port 8000 for real-time pipeline outputs -Next, you'll: +You've now created a firewall rule for OpenCV visualization that enables external browser access to your VM and exposes port 8000 for real-time pipeline outputs. -* Run image and video pipelines -* Integrate ML models with OpenCV -* Optimize performance on Arm-based systems +Next, you'll create a Google Axion virtual machine to host your OpenCV application. diff --git a/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/instance.md b/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/instance.md index 5855126068..35c7943283 100644 --- a/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/instance.md +++ b/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/instance.md @@ -1,14 +1,14 @@ --- -title: Create a Google Axion C4A Arm virtual machine on GCP +title: Create a Google Axion C4A Arm virtual machine weight: 4 ### FIXED, DO NOT MODIFY layout: learningpathall --- -## Provision a Google Axion C4A Arm VM +## Provision a Google Axion C4A Arm-based VM -In this section, you'll create a Google Axion C4A Arm-based virtual machine on Google Cloud Platform. You'll use the `c4a-standard-4` machine type, which provides 4 vCPUs and 16 GB of memory. This VM will host your OpenCV application. +In this section, you'll create a Google Axion C4A Arm-based virtual machine (VM) on Google Cloud Platform (GCP). You'll use the `c4a-standard-4` machine type with four vCPUs and 16 GB of memory. This VM will host your OpenCV application. {{% notice Note %}} For help with GCP setup, see the Learning Path [Getting started with Google Cloud Platform](/learning-paths/servers-and-cloud-computing/csp/google/). @@ -18,22 +18,21 @@ For help with GCP setup, see the Learning Path [Getting started with Google Clou To create a virtual machine based on the C4A instance type: -- Navigate to the [Google Cloud Console](https://console.cloud.google.com/). -- Go to **Compute Engine** > **VM Instances** and select **Create Instance**. -- Under **Machine configuration**: - - Populate fields such as **Instance name**, **Region**, and **Zone**. - - Set **Series** to `C4A`. - - Select `c4a-standard-4` for machine type. +1. Navigate to the [Google Cloud Console](https://console.cloud.google.com/). +2. Go to **Compute Engine** > **VM Instances** and select **Create Instance**. +3. Under **Machine configuration**: + - Populate fields such as **Instance name**, **Region**, and **Zone**. + - Set **Series** to `C4A`. + - Select `c4a-standard-4` for **Machine type**. ![Screenshot of the Google Cloud Console showing the Machine configuration section. The Series dropdown is set to C4A and the machine type c4a-standard-4 is selected#center](images/gcp-vm.png "Configuring machine type to C4A in Google Cloud Console") -- Under **OS and storage**, select **Change**, and then choose an Arm64-based operating system image. - - For this Learning Path, select **SUSE Linux Enterprise Server**. - - For the license type, choose **Pay as you go**. - - Increase **Size (GB)** from **10** to **100** to allocate sufficient disk space. - - Select **Choose** to apply the changes. -- Expand the **Networking** section and enter `allow-opencv` in the **Network tags** field. This tag links the VM to the firewall rule you created earlier, enabling external access to the OpenCV Dashboard and Serve API ports. -- Select **Create** to launch the virtual machine. +4. Under **OS and storage**, select **Change**, and then choose an Arm64-based operating system image. For this Learning Path, select **SUSE Linux Enterprise Server**. + - For the license type, choose **Pay as you go**. + - Increase **Size (GB)** from **10** to **100** to allocate sufficient disk space. + - Select **Choose** to apply the changes. +5. Expand the **Networking** section and enter `allow-opencv` in the **Network tags** field. This tag links the VM to the firewall rule you created earlier, so your browser can access the OpenCV output. +6. Select **Create** to launch the virtual machine. After the instance starts, select **SSH** next to the VM in the instance list to open a browser-based terminal session. @@ -45,6 +44,6 @@ A new browser window opens with a terminal connected to your VM. ## What you've accomplished and what's next -In this section, you provisioned a Google Axion C4A Arm VM and connected to it using SSH. +You've now provisioned a Google Axion C4A Arm VM and connected to it using SSH. You'll use this VM to run your OpenCV application. Next, you'll install OpenCV and the required dependencies on your VM. diff --git a/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/opencv-foundation-pipelines.md b/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/opencv-foundation-pipelines.md index 7d0d7e124f..8a27951aac 100644 --- a/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/opencv-foundation-pipelines.md +++ b/content/learning-paths/servers-and-cloud-computing/opencv-on-axion/opencv-foundation-pipelines.md @@ -1,24 +1,16 @@ --- -title: Build OpenCV Pipelines on GCP Axion (Arm) +title: Build OpenCV pipelines on Google Axion weight: 5 ### FIXED, DO NOT MODIFY layout: learningpathall --- -## Build OpenCV pipelines on GCP Axion +## Set up OpenCV on an Arm-based virtual machine -This section guides you through setting up OpenCV on an Arm-based VM and building image and video processing pipelines with browser visualization. +In this section, you'll learn how to set up OpenCV on an Arm-based VM and build image and video processing pipelines with browser visualization. -## Learning objectives - -- Install OpenCV on Arm -- Build an image processing pipeline -- Build a video processing pipeline -- Visualize pipeline output in a browser - - -## Update your system +### Update your system Refresh the package metadata to ensure you install the latest available versions: @@ -26,7 +18,7 @@ Refresh the package metadata to ensure you install the latest available versions sudo zypper refresh ``` -## Install dependencies +### Install dependencies Install Python 3.11 and the build tools that OpenCV's pip package requires to compile native extensions: @@ -36,16 +28,16 @@ python311 python311-pip python311-devel \ gcc gcc-c++ make cmake ``` -## Create the project directory +### Create the project directory -Create a dedicated workspace for your OpenCV project and change into it: +Create a dedicated workspace for your OpenCV project and navigate to it: ```bash mkdir -p ~/opencv-project cd ~/opencv-project ``` -## Set up a Python virtual environment +### Set up a Python virtual environment Create an isolated Python environment to keep OpenCV and its dependencies separate from the system Python installation: @@ -54,18 +46,20 @@ python3.11 -m venv cv-env source cv-env/bin/activate ``` -## Install Python packages +### Install Python packages -`opencv-python-headless` is the server-appropriate OpenCV build — it omits GUI window support, which is not available on a remote VM. `flask` is included for optional HTTP serving use cases. +Install the following Python packages: ```bash pip install --upgrade pip pip install numpy opencv-python-headless flask ``` -## Start the browser server +`opencv-python-headless` is the server-appropriate OpenCV build. It omits GUI window support, which is not available on a remote VM. `flask` is included for optional HTTP serving use cases. -Before verifying any output in the browser, start a simple HTTP server in the background. This server serves files from `~/opencv-project` on port 8000 and must remain running throughout this Learning Path. +### Start the browser server + +Before verifying any output in the browser, start an HTTP server in the background. This server serves files from `~/opencv-project` on port 8000 and must remain running throughout this Learning Path. ```bash python -m http.server 8000 & @@ -73,9 +67,9 @@ python -m http.server 8000 & The `&` runs the server as a background process so you can continue using the same terminal. To stop it later, run `kill %1` or `pkill -f "http.server"`. -## Quick OpenCV test +### Verify OpenCV is working -Before building pipelines, verify that OpenCV is working correctly. This step creates a simple image using OpenCV and saves it for browser viewing. +Before building pipelines, verify that OpenCV is working correctly. This script creates an image using OpenCV and saves it for browser viewing. ```bash python - <` with your VM's external IP address: ```text http://:8000/test.jpg ``` -You should see an image with text: +You should see an image with the following text: ```text OpenCV OK @@ -113,11 +105,15 @@ OpenCV OK ![OpenCV test image showing "OpenCV OK" text rendered using OpenCV on Arm VM#center](images/opencv-test.png "OpenCV verification output") -## Image pipeline +## Set up an image pipeline The image pipeline reads an input image, applies transformations using OpenCV, and saves the result so the HTTP server can serve it to your browser. -Create the pipeline script: +### Create image pipeline + +First, create the image pipeline. + +Create the pipeline script by saving the following in `image_pipeline.py`: ```python import cv2 @@ -136,16 +132,11 @@ cv2.putText(img, "IMAGE PIPELINE", (20,40), cv2.imwrite("latest.jpg", img) ``` -### What this script does +The script loads an image using OpenCV and applies basic processing such as resize and text overlay. It then saves output as `latest.jpg`. The output file is used for browser visualization. -- Loads an image using OpenCV -- Applies basic processing (resize + text overlay) -- Saves output as `latest.jpg` -- This file is used for browser visualization +### Generate a sample input image -## Generate a sample input image - -Instead of downloading an external image, generate one locally. This ensures the pipeline works in all environments without an internet dependency. +Instead of downloading an external image, generate an image locally. Doing so ensures the pipeline works in all environments without an internet dependency. ```bash python - < train_ml_model.py <<'EOF' @@ -153,9 +141,9 @@ Verify that both model files were created: ```bash ls -lh iris_model.joblib iris_labels.joblib ``` -## Create the OpenCV and ML pipeline +### Create the OpenCV and ML pipeline -The pipeline loads the trained model and label names, runs a prediction on a fixed sample input, and uses OpenCV to render the input features and prediction result as text on an output image. The image is saved as `ml_output.jpg` for the HTTP server to serve. +The pipeline loads the trained model and label names, and runs a prediction on a fixed sample input. It then uses OpenCV to render the input features and prediction result as text on an output image. The image is saved as `ml_output.jpg` for the HTTP server to serve. ```bash cat > opencv_ml_pipeline.py <<'EOF' @@ -253,7 +241,7 @@ Verify the output image was created: ls -lh ml_output.jpg ``` -## View the ML output in your browser +### View the pipeline output in your browser If the HTTP server from the previous section is no longer running, restart it: @@ -263,18 +251,20 @@ source cv-env/bin/activate python -m http.server 8000 & ``` -Open the following URL in your browser, replacing `` with the external IP address of your GCP Axion VM: +Open the following URL in your browser, replacing `` with the external IP address of your Google Axion VM: ```text http://:8000/ml_output.jpg ``` You should see an image showing the pipeline title, the Arm64 platform label, the input feature values, and the predicted Iris species. -![OpenCV ML pipeline output showing prediction result on GCP Axion Arm VM#center](images/opencv-ml.png "OpenCV ML pipeline output") + +![OpenCV ML pipeline output image showing the predicted Iris class and input feature values, confirming successful inference and OpenCV rendering on Axion Arm VM.#center](images/opencv-ml.png "OpenCV ML pipeline output") + -## Troubleshooting +### Troubleshoot integration issues -**`ModuleNotFoundError: No module named 'sklearn'`** +#### ModuleNotFoundError: No module named 'sklearn' Make sure the virtual environment is activated and reinstall the dependency: @@ -284,7 +274,7 @@ source cv-env/bin/activate pip install scikit-learn joblib ``` -**`iris_model.joblib` not found** +#### iris_model.joblib not found Run the training script before running the ML pipeline: @@ -292,7 +282,7 @@ Run the training script before running the ML pipeline: python train_ml_model.py ``` -**Browser cannot access the output image** +#### Browser cannot access the output image Check that the HTTP server is running: @@ -300,9 +290,9 @@ Check that the HTTP server is running: python -m http.server 8000 & ``` -Also make sure port `8000` is allowed in the GCP firewall. +Also make sure port `8000` is allowed in the Google Cloud Platform firewall. -**Output image does not update** +#### Output image does not update Run the pipeline again after changing the sample input, then refresh the browser: @@ -310,7 +300,7 @@ Run the pipeline again after changing the sample input, then refresh the browser python opencv_ml_pipeline.py ``` -**Clean up generated files** +#### Clean up generated files Use this only if you want to remove generated ML and output files. @@ -318,6 +308,6 @@ Use this only if you want to remove generated ML and output files. rm -f iris_model.joblib iris_labels.joblib ml_output.jpg ``` -## What you've learned +## What you've accomplished -You've trained a Random Forest classifier on the Iris dataset, saved it with `joblib`, and loaded it inside an OpenCV pipeline to generate a browser-viewable prediction image on a GCP Axion Arm64 VM. This pattern — train offline, load at inference time, render output with OpenCV — applies directly to production vision pipelines where models are updated independently of the display layer. +You've trained a random forest classifier on the Iris dataset, saved it with `joblib`, and loaded it inside an OpenCV pipeline to generate a browser-viewable prediction image on a Google Axion Arm64 VM. This pattern — train offline, load at inference time, render output with OpenCV — mirrors production vision pipelines, where models are updated independently of the display layer.