0% found this document useful (0 votes)
0 views

Project Compilation Guide

This document outlines the prerequisites and steps to install necessary build tools, including Python, CMake, Ninja, and the Emscripten SDK, for compiling an OpenCV C++ program to WebAssembly. It details the commands to activate the Emscripten environment, compile the program, and test it locally using a Python HTTP server. Additionally, it provides instructions for web deployment, including setting the correct MIME type for .wasm files in the .htaccess file.

Uploaded by

contactdivyajeet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Project Compilation Guide

This document outlines the prerequisites and steps to install necessary build tools, including Python, CMake, Ninja, and the Emscripten SDK, for compiling an OpenCV C++ program to WebAssembly. It details the commands to activate the Emscripten environment, compile the program, and test it locally using a Python HTTP server. Additionally, it provides instructions for web deployment, including setting the correct MIME type for .wasm files in the .htaccess file.

Uploaded by

contactdivyajeet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Prerequisites: Install Build Tools

1. Python Installation

● Download Python: Python Downloads


○ Ensure Python 3.12.3 is installed.
○ Add Python to PATH: During installation, select the option to add Python to
your system PATH.

2. CMake Installation

● Download CMake: CMake Downloads


○ Install CMake and ensure it's added to your system PATH.

3. Ninja Installation

● Download Ninja: Ninja Releases


○ Extract Ninja and add the executable to your system PATH.

4. Emscripten SDK Installation

Open PowerShell and execute the following commands:

git clone https://github.com/emscripten-core/emsdk.git


cd .\emsdk
.\emsdk install latest
.\emsdk activate latest
.\emsdk_env.ps1

Note: Replace .\emsdk with the path where you cloned the Emscripten SDK if different.

Compilation of the OpenCV C++ Program to


WebAssembly
IMPORTANT: For this step, you need the OpenCV library compiled earlier.

Steps:

1. Activate the Emscripten Environment


Open PowerShell and execute the following commands:

cd C:\emsdk
.\emsdk activate latest
.\emsdk_env.ps1

2. Navigate to The Project Directory

cd C:\Projects\TheProjectDirectory\

3. Compile The C++ Program


em++ demo.cpp -o demo.js ^
-I "C:\Projects\3rdParty\opencv-4.9.0-wasm\include" ^
-L "C:\Projects\3rdParty\opencv-4.9.0-wasm\lib" ^
-lopencv_world -llibpng -lzlib ^
-s NO_EXIT_RUNTIME=1 ^
-s "EXPORTED_RUNTIME_METHODS=['ccall']" ^
-s ASSERTIONS=1 --bind

● Note: The include and lib directories specified are the OpenCV include and
lib directories.
● The lib directory should contain the following files:

liblibjpeg-turbo.a
liblibopenjp2.a
liblibpng.a
libopencv_world.a
libzlib.a

4. Generated Files

Running the above command should generate the following JavaScript and WebAssembly
files:

demo.js
demo.wasm

5. Testing Locally

If you place the provided video_utils.js and index.html files in the same directory as
the generated files, you can test your code immediately by starting a local HTTP server.

Start the server:

python -m http.server

Open in your browser:


http://localhost:8000/index.html

Web Deployment
To deploy your application on the web, ensure that the server correctly serves .wasm files
with the appropriate MIME type.

● Add the following line to your .htaccess file:

AddType application/wasm .wasm

Note: If the .htaccess file does not exist, you need to create it on your server.

You might also like