OpenCV.js
OpenCV.js is asm.js/WASM implementation of OpenCV. Currently, it is based on OpenCV version 3.3. It includes more than 100 select functions form the following OpenCV modules.
- Core
- Image processing
- Video
- Object detection
- Image codecs
Installation
npm install opencv.js
How to Use
cv = ;
Demos
Use this pointer to access the demos.
API
Please refer to the OpenCV.js documentations.
Basic Types
cv.Mat
is the main data structure that is used by the functions. The following constructors are available to create matrices.
cv.Mat()
cv.Mat(another_mat)
cv.Mat(size, type)
cv.Mat(rows, cols, type, data, step)
Simple types such as cv::Rect
, cv::Point
are represented using JavaScript value objects.
Examples
Working with Images - Canny Edge Detection
This examples demonstrates how to find edges in a given image file.
var cv = ;var jpeg = ;var fs = ; // Load an imagevar jpeg_data = fs;var raw_data = jpeg; // Create a matrix from image. input image expected to be in RGBA formatvar src = cv;cv; // Convert to grayscale dst = ;cv;cv; // Convert back to RGBA to display // Save the resultraw_data = data: dstdata width: dstsizewidth height: dstsizeheight;var jpeg_data = jpeg;fs;
Working with videos - Face detection using HARR Cascades
This example demonstrates how to use HAAR cascades to find objects in video frames. We will rely on pre-trained HAAR models that are specialized in finding certain objects. OpenCV provides several models that can be used.
let v4l2camera = ;var jpeg = ;var fs = ;let cv = ; // Loading classifier with the frontal face modelcv;let faceClassifier = ;faceClassifier; // Start the cameralet cam = "/dev/video0";if camformatName !== "YUYV" console; process; // Configure and start the cameracam;let format = cam;console;camstart; let yuvMat = null;let rgbMat = null;let grayMat = null; let stopped = false;let frameIndex = 0; cam; const ESC_KEY = '\u001b';const CTRL_C = '\u0003';let stdin = processstdin;stdin;stdin;stdin;stdin;
Contributers
- Sajjad Taheri (Architect of the initial version and GSoC mentor, University of California, Irvine)
- Congxiang Pan (GSoC student, Shanghai Jiao Tong University)
- Gang Song (GSoC student, Shanghai Jiao Tong University)
- Wenyao Gan (Student intern, Shanghai Jiao Tong University)
- Mohammad Reza Haghighat (Project initiator & sponsor, Intel Corporation)
- Ningxin Hu (Students' supervisor, Intel Corporation)
This project was supported by the Intel corporation and Google through 2017 Google Summer of Code program.
License
BSD 3 Clause