Git Product home page Git Product logo

opencvjs's Introduction

OpenCV.js

This is a JavaScript binding that exposes OpenCV library to the web. This project is made possible by support of Intel corporation. Currently, this is based on OpenCV 3.1.0.

How to Build

  1. Get the source code
git clone https://github.com/ucisysarch/opencvjs.git
cd opencvjs
git clone https://github.com/opencv/opencv
cd opencv
git checkout 3.1.0
  1. Install emscripten. You can obtain emscripten by using Emscripten SDK.
./emsdk update
./emsdk install sdk-master-64bit --shallow
./emsdk activate sdk-master-64bit
source ./emsdk_env.sh
  1. Patch Emscripten & Rebuild.
patch -p1 < PATH/TO/patch_emscripten_master.diff
  1. Rebuild emscripten
./emsdk install sdk-master-64bit --shallow
  1. Compile OpenCV and generate bindings by executing make.py script.
  python make.py

Tests

Test suite contains several tests and examples demonstrating how the API can be used. Run the tests by launching test/tests.html file usig a browser.

Exported OpenCV Subset

Classes and functions that are intended for binding generators (i.e. come with wrapping macros such as CV_EXPORTS_W and CV_WRAP) are exposed. Hence, supported OpenCV subset is comparable to OpenCV for Python. Also, enums with exception of anonymous enums are also exported.

Currently, the following modules are supported. You can modify the make script to exclude certain modules.

  1. Core
  2. Image processing
  3. Photo
  4. Shape
  5. Video
  6. Object detection
  7. Features framework
  8. Image codecs

At a glance

The following example demonstrates how to apply a gaussian blur filter on an image. Note that everything is wrapped in a JavaScript module ('cv').

  // Gaussian Blur
  var mat1 = cv.Mat.ones(7, 7, cv.CV_8UC1),
      mat2 = new cv.Mat();

  cv.GaussianBlur(mat1, mat2, [3, 3], 0, 0, cv.BORDER_DEFAULT);

  mat1.delete();
  mat2.delete();

Next example shows how to calculate image keypoints and their descriptors using ORB (Oriented Brief) method.

  var numFeatures = 900,
	    scaleFactor = 1.2,
	    numLevels = 8,
	    edgeThreshold = 31,
		  firstLevel =0,
		  WTA_K= 2,
		  scoreType = 0, //ORB::HARRIS_SCORE
		  patchSize = 31,
		  fastThreshold=20,
		  keyPoints = new cv.KeyPointVector(),
		  descriptors = new cv.Mat();

	var orb = new cv.ORB(numFeatures, scaleFactor, numLevels, edgeThreshold, firstLevel,
									     WTA_K, scoreType, patchSize, fastThreshold);

  // image and mask are of type cv.Mat
	orb.detect(image, keyPoints, mask);
	orb.compute(image, keyPoints, descriptors);

	keyPoints.delete();
	descriptors.delete();
	orb.delete();

Functions work on cv::Mat and various vectors. The following vectors are registered and can be used.

  register_vector<int>("IntVector");
  register_vector<unsigned char>("UCharVector"););
  register_vector<float>("FloatVector");
  register_vector<std::vector<Point>>("PointVectorVector");
  register_vector<cv::Point>("PointVector");
  register_vector<cv::Mat>("MatVector");
  register_vector<cv::KeyPoint>("KeyPointVector");
  register_vector<cv::Rect>("RectVector");
  register_vector<cv::Point2f>("Point2fVector");

Memory management

All the allocated objects should be freed manually by calling delete() method. To avoid manual memory management for basic types, the following data types are exported as JavaScript value arrays.

cv.Size
cv.Point

File System Access

If your OpenCV application needs to access a file, for instance a dataset or a previoulsy trained classifier, you can modify the make script and attach the files by using emscripten "--preload-file" flag.

Limitations

  1. MatExpr is not exported.
  2. No support for default parameters yet.
  3. Constructor overloading are implemented by number of paramteres and not their types. Hence, only following Mat constructors are exported.
  cv::Mat()
  cv::Mat(const std::vector<unsigned char>& data)
  cv::Mat(Size size, int type)
  cv::Mat(int rows, int cols, int type)
  cv::Mat(Size size, int type, void* data, size_t step)

opencvjs's People

Contributors

dbkaplun avatar dgulie avatar sajjadt avatar vilie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opencvjs's Issues

TypeError: module is not a function

When I run the the tests I will get the above error on the first line of code, where it presumable imports the required lib. Where is module() defined?

Tests Failed

I have a failed test for "Core" with following output:

BindingError: Function 'Mat.create' called with an invalid number of arguments (3) - expects one of (,,function Mat$create(arg0, arg1) {
if (arguments.length !== 2) {
throwBindingError('function Mat.create called with ' + arguments.length + ' arguments, expected 2 args!');
}
Module.emscripten_trace_enter_context('embind::Mat.create');
var thisWired = classParam.toWireType(null, this);
var arg0Wired = argType0.toWireType(null, arg0); // Size
var arg1Wired = argType1.toWireType(null, arg1); // int
invoker(fn, thisWired, arg0Wired, arg1Wired);
arg0Wired_dtor(arg0Wired); // Size
Module.emscripten_trace_exit_context();
})!
extendError/errorClass<@file:///C:/Users/Workspace/test2/opencvjs/test/cv.js:4:1651615
BindingError@file:///C:/Users/Workspace/test2/opencvjs/test/cv.js line 4 > Function:2:29
throwBindingError@file:///C:/Users/Workspace/test2/opencvjs/test/cv.js:4:1652060
ensureOverloadTable/proto[methodName]@file:///C:/Users/Workspace/test2/opencvjs/test/cv.js:4:1752582
@file:///C:/Users/Workspace/test2/opencvjs/test/test_mat.js:99:9

It's seems that the emcc didn't transpile Mat.create() function with 3 arguments, is there any solution for this issue.

convexityDefects

Can anyone offer tips on how to interpret the results of the convexityDefects method? I am seeing a 1 col n row Mat with 16 values like this:

defects.row(0).data(): Uint8Array[16]
0:183
1:4
2:0
3:0
4:228
5:5
6:0
7:0
8:94
9:3
10:0
11:0
12:25
13:129
14:1
15:0

... and having problems mentally mapping that to the struct I would get from C.

struct CvConvexityDefect
{
   CvPoint* start; // point of the contour where the defect begins
   CvPoint* end; // point of the contour where the defect ends
   CvPoint* depth_point; // the farthest from the convex hull point within the defect
   float depth; // distance between the farthest point and the convex hull
};

Thanks.

License

Any chance you can change the license to the new BSD License instead of the old one as the Free Software Foundation recommended retiring the advertising clause many years ago.

"fs" dependency causing compiling error

System information (version)
  • OpenCV.js => 1.2.1
  • Operating System / Platform => Arch Linux
Steps to reproduce

Just added one line of code
cv = require('opencv.js')
in script section of my Nuxt.js project and got that error

Screenshot_20190610_173317


in new plain simple Vue project I've got

App.vue?234e:10 Uncaught ReferenceError: cv is not defined
    at eval (App.vue?234e:10)
    at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/App.vue?vue&type=script&lang=js& (app.js:1336)
    at __webpack_require__ (app.js:724)
    at fn (app.js:101)
    at eval (App.vue?8b47:1)
    at Module../src/App.vue?vue&type=script&lang=js& (app.js:3110)
    at __webpack_require__ (app.js:724)
    at fn (app.js:101)
    at eval (App.vue?a938:1)
    at Module../src/App.vue (app.js:3098)

Compiling using n_make.py build errors - emscripten.Building.make(['make', '-j4'])

Hello,

This project looks amazing.

However, when building the example.cpp application there was an error on line 157 of n_make.py

emscripten.Building.make(['make', '-j4'])

This occurs at around 33% of the OpenCV build.

[ 33%] Built target libprotobuf
Scanning dependencies of target ittnotify
[ 33%] Building C object 3rdparty/ittnotify/CMakeFiles/ittnotify.dir/src/ittnotify/ittnotify_static.c.o
In file included from /Users/daniel/Documents/opencv_js_compiler/opencv/3rdparty/ittnotify/src/ittnotify/ittnotify_static.c:59:
/Users/daniel/Documents/opencv_js_compiler/opencv/3rdparty/ittnotify/src/ittnotify/ittnotify_config.h:370:12: error: implicit declaration of function '__TBB_machine_fetchadd4' is
invalid in C99 [-Werror,-Wimplicit-function-declaration]
return __TBB_machine_fetchadd4(ptr, 1) + 1L;
^
/Users/daniel/Documents/opencv_js_compiler/opencv/3rdparty/ittnotify/src/ittnotify/ittnotify_config.h:370:12: warning: this function declaration is not a prototype [-Wstrict-prototypes]
1 warning and 1 error generated.
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting
make[2]: *** [3rdparty/ittnotify/CMakeFiles/ittnotify.dir/src/ittnotify/ittnotify_static.c.o] Error 1
make[1]: *** [3rdparty/ittnotify/CMakeFiles/ittnotify.dir/all] Error 2
make: *** [all] Error 2
Traceback (most recent call last):
File "n_make.py", line 159, in
emscripten.Building.make(['make'])
File "/Users/daniel/Documents/emsdk-portable/emscripten/1.37.33/tools/shared.py", line 1558, in make
raise subprocess.CalledProcessError(cmd=args, returncode=process.returncode)
subprocess.CalledProcessError: Command '['make']' returned non-zero exit status 2
Hal:opencv_js_compiler daniel$ python n_make.py example/example.cpp

Note: I have built OpenCV on it's own using cmake and it worked ok.

  • I can build OpenCV on it's own.
  • I can build OpenCVjs from their platform folder.

This would indicate an emscripten problem. Any thoughts or experience with this issue?

Similar issue here - emscripten-core/emscripten#5298

Which version of Emscripten did you use when compiling your example.cpp?

cv.getROI_Rect gives wrong results

Hi,
I try to copy a small image into a ROI of a larger image.
On this coarse, I found two issues.

First, I cannot manage to use Mat.copyTo, as it throws the following error:
Unbound TypeError, message: "Cannot call Mat.copyTo due to unbound types: N2cv12_OutputArrayE"

Then, I decided to select a ROI and edit the data directly through the typed array output of Mat.data16u().
However, I found that Mat.getRectROI().data() does also not deliver the data of the subview.
Example:
a = new cv.Mat(3,3,cv.CV_16U)
a.data16u().set([1,2,3,4,5,6,7,8,9])
b = a.getROI_Rect(new cv.Rect(1,1,2,2));
b.data16u();

the output is [5,6,7,8], yet, it should be [5,6,8,9].

Bottom line: I cannot overwrite a ROI in a image.
Any Suggestions are highly welcome!!

CascadeClassifier load always returns false

Whenever i try to load a classifier cascade file it returns false.

The cascade is in the root directory of the site and other opencv examples work ok.

xml mime type is definitely registered.

Any tips or things to look for?

this.classifier = new cv.CascadeClassifier();

this.classifierName = "haarcascade_frontalface_default.xml"

if(!this.classifier.load(this.classifierName))
{
return false;
}

Using HoughLinesP issue

Hi !

Great job done with that JS port. It's very impressive.

However, I have an issue with using HoughLinesP. When I use OpenCV in C++, the second argument is of type Vector4i, and in the JS version it asks for a cv::Mat. I tried to get the data out of this Mat by looping over the array provided by the data() method, but do not seems correct.

Could you guide me trough the right way of doing thid ?

Here is my code:

` var canny_output = new cv.Mat();
var blurred = new cv.Mat();
var cthresh = Control.canny_threshold;
var lines = new cv.Mat();
cv.blur(src, blurred, [5, 5], [-1, -1], 4);
cv.Canny(blurred, canny_output, cthresh, cthresh*2, 3, 0);

	cv.HoughLinesP(canny_output, lines, 1, Math.PI/180, 80, 100, 10); 
	console.log("data", lines.data());
	lines = lines.data();
	
	for(var i = 0; i < lines.length; i += 4)
	{
		console.log("draing line");
	    var l = [lines[i], lines[i+1], lines[i+2], lines[i+3]];
		cv.line(canny_output,
					[l[0], l[1]],
					[l[2], l[3]],
					new cv.Scalar(255, 0, 0),
					3,
					cv.LineTypes.LINE_8.value,
					0
				);
	}
	
	show_image(canny_output, "canvas2")`

Cannot access Scalar value

When I try to calculate the mean value of an image like this:

data = new cv.Mat.zeros(10,10,cv.CV_8S)
mask = new cv.Mat.ones(10,10,cv.CV_8U)
mean = cv.mean(data,mask)

the returned mean value is of type cv Scalar and I either cannot access its value or its value is wrong.

mean.$$.count.value returns 1, whereas the mean of a zero-image is obviously 0.

Any help?

Error while allocating new cv.Mat

Hello everyone! I'm working on a project using opencv.js.

My system is a Mac running Mojave 10.14.3.

For my opencv, I'm using these files instead of building locally:

  1. https://docs.opencv.org/3.4/opencv.js
  2. https://docs.opencv.org/3.4/utils.js

I can create new objects (mostly cv.Mat) just fine, but after some number of new objects (depending on the size of the object, about 700 for a 128x128 matrix), the allocation fails with an uncatchable error (see the image below).

The cloning/instantiation call that fails happens within the scope of a function, and so it should be garbage collected when the function returns. Deleting the object after it's used in the function, using the delete() method, doesn't cure the error or change anything.

Screen Shot 2019-03-28 at 2 21 49 PM

opencvjs with getUserMedia API

Hi,

I am using the getUserMedia API to capture a lifestream using my device's webcam; I am then showing it in a browser.

I have taken a look at the opencvjs examples, but all of them do manipulation on images, not live videos. Is there a way to for example apply a Gaussian blur on a captured live video and then display the blurred lifestream in the browser? Would I need to convert the livestream into frames/individual images first?

compiler frontend failed to generate LLVM bitcode, halting

I've issues in the point 5: Compile OpenCV and generate bindings by executing make.py script. python make.py

RESULT:

Stage 3: Generating Bindings

In file included from ../../bindings.cpp:33: In file included from ../modules/core/include/opencv2/core.hpp:54: ../modules/core/include/opencv2/core/base.hpp:52:10: fatal error: 'opencv2/opencv_modules.hpp' file not found #include "opencv2/opencv_modules.hpp" ^ 1 error generated. ERROR:root:compiler frontend failed to generate LLVM bitcode, halting Traceback (most recent call last):
File "make.py", line 181, in emscripten.Building.emcc('../../bindings.cpp', emcc_binding_args, 'bindings.bc') File "/home/davide/Documents/emsdk_portable/emscripten/master/tools/shared.py", line 1565, in emcc assert os.path.exists(output_filename), 'emcc could not create output file: ' + output_filename AssertionError: emcc could not create output file: bindings.bc
What could i do?

Issue with running the samples

Hi!

After I build the project and try to run the samples, I am getting the following error:
Uncaught Error: Parent path must exist.
at Object.createObject (zee.js:1047)
at Object.createFile (zee.js:1096)
at Object.createDataFile [as FS_createDataFile] (zee.js:1107)
at DataRequest.finish (cv.js:21)
at DataRequest.onload (cv.js:21)
at processPackageData (cv.js:21)
at cv.js:21
at XMLHttpRequest.xhr.onload (cv.js:21)

I had tried this project about a year ago and I didn't see this issue. Please let me know how I can resolve it.

Thanks.

Could not work on Google Chrome

I downloaded the whole file and found it could not work on Google Chrome but work on Firefox.
Did I make something wrong?

opencvjs is working in dev mode with react but it is not built!

I installed opencv.js by following this link: https://www.ics.uci.edu/~sysarch/projects/OpenCV.html

I want to use CLAHE method in my project. 1.2.1 version is working with CLAHE and I can compile it in development mode. When I build it, I get this error:

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x224123da5879 <JSObject>
    1: push(this=0xe1c1bcbc51 <JSArray[114467]>)
    2: visit [0x68eab6022d1 <undefined>:~5587] [pc=0x275c3848a5f9](this=0x5b136002201 <TreeWalker map = 0x2751e0dfa5a1>,node=0x108cb5047831 <AST_SymbolRef map = 0xb614eea3a99>,descend=0x11580d1bc3b1 <JSFunction noop (sfi = 0x7cc5ad3f959)>)
    3: _walk [0x68eab6022d1 <undefined>:~479] [pc=0x275c381e4a4b](this=0x108cb5047831 <AST_SymbolRef map = 0x...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x8c21ec [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewUninitializedFixedArray(int) [node]
 6: 0xd4b26f [node]
 7: 0xd5f3a5 [node]
 8: v8::internal::JSObject::AddDataElement(v8::internal::Handle<v8::internal::JSObject>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow) [node]
 9: v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow, v8::internal::Object::StoreFromKeyed) [node]
10: v8::internal::Object::SetProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::LanguageMode, v8::internal::Object::StoreFromKeyed) [node]
11: v8::internal::Runtime_SetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [node]
12: 0x275c37c842fd
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Older version does not allow to work with CLAHE. How can I solve this problem?

Performance question for NodeJs

Dear,

I started yesterday developing a Node-Red contribution, to allow OpenCv.js to be used in our dataflows. Must admit that I'm new to OpenCv, but I'm already very enthousiastic about this project!

I tried the Canny Edge Detection example from npm, but the performance was not really what I expected. I executed the tests on my Raspberry Pi 3 running NodeJs version 7.9.0.

Issue 1 - descending execution duration

I repeated the same test (on the same image) a couple of times, and the execution durations were descending (and becoming rather stable after about 3 tests):

  • 8631 millisecs
  • 1333 millisecs
  • 1103 millisecs
  • 591 millisecs
  • 568 millisecs

And even the CPU consumption was descending:

image

Does this make any sense?

Issue 2 - high execution duration

Don't know about native OpenCv performance, but for example on this forum I found following measurement:

A pure OpenCV VideoCapture vc(0) grabbing loop (no display, no waitKey) gets about 30 fps at 640x480 with nearly no CPU load. Adding a Canny edge filter, I still get 30 fps at 640x480 but CPU load increases to 250% (out of the 400% for all cores).

I realize that (w)asm is slower than native C++, but are my execution times normal? If not normal, is there any kind of troubleshooting I can do to find the root cause?

I would also have expected that more CPU would be used in this case, but it seems only a single core is being used. Hopefully somebody can help me out ...

Thanks a lot !!!
Bart Butenaers

Include Modules in building cv.js

Hello,

I'm completely new to emscripten so my question may be stupid, but I needed to rebuild the cv.js file to include new haar files.

But when compiling the new file it seems that it didn't include some of the modules since I receive a
cv.VideoCapture is not a constructor
when calling new cv.VideoCapture(this.myVideo);

Did I made something wrong, or is the make.py file provided missing something?

Thank you.

ERROR:root:compiler frontend failed to generate LLVM bitcode, halting

Hello.
At a stage "Stage 3: Generating Bindings" there is an error: "ERROR:root:compiler frontend failed to generate LLVM bitcode, halting".
Here a broad gull of errors:
`Stage 3: Generating Bindings

../../bindings.cpp:3271:39: error: too many template arguments for class
template 'base'
emscripten::class_<cv::Feature2D ,base<Algorithm ,true>>("Feature2D")
^ ~~~~~~
D:\Work\TEMP_PROJECT\openCVjs\emsdk-portable-64bit\emscripte
n\1.37.22\system\include\emscripten/bind.h:1034:12: note:
template is declared here
struct base {
^
../../bindings.cpp:3271:62: error: expected unqualified-id
emscripten::class_<cv::Feature2D ,base<Algorithm ,true>>("Feature2D")
^
../../bindings.cpp:3271:62: error: expected ')'
../../bindings.cpp:3271:61: note: to match this '('
emscripten::class_<cv::Feature2D ,base<Algorithm ,true>>("Feature2D")
^
3 errors generated.
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting
Traceback (most recent call last):
File "make.py", line 183, in
emscripten.Building.emcc('../../bindings.cpp', emcc_binding_args, 'bindings.
bc')
File "D:/Work/TEMP_PROJECT/openCVjs/emsdk-portable-64bit/e
mscripten/1.37.22\tools\shared.py", line 1996, in emcc
assert os.path.exists(output_filename), 'emcc could not create output file:
' + output_filename
AssertionError: emcc could not create output file: bindings.bc`

Here a broad gull from "emsdk list":
`The following precompiled tool packages are available for download:
clang-nightly-e1.37.9-2017_04_19_23_39-64bit
clang-nightly-e1.37.9-2017_04_20_04_06-64bit
clang-e1.30.0-64bit
clang-e1.34.1-64bit
clang-e1.35.0-64bit
clang-e1.37.1-64bit
clang-e1.37.21-64bit
* clang-e1.37.22-64bit INSTALLED
node-4.1.1-32bit
* node-4.1.1-64bit INSTALLED
python-2.7.5.3-32bit
* python-2.7.5.3-64bit INSTALLED
java-7.45-32bit
* java-7.45-64bit INSTALLED
spidermonkey-37.0.1-64bit
spidermonkey-nightly-2015-04-12-64bit
git-1.9.4
emscripten-1.30.0
emscripten-1.34.1
emscripten-1.35.0
emscripten-1.37.1
emscripten-1.37.21
* emscripten-1.37.22 INSTALLED
emscripten-nightly-1.37.9-2017_04_19_23_39
emscripten-nightly-1.37.9-2017_04_20_04_06
* vs-tool-0.9.4 INSTALLED
crunch-1.03
gnu-2.5.4
mingw-7.1.0-64bit

The following tools can be compiled from source:
clang-tag-e1.37.21-32bit
clang-tag-e1.37.22-32bit
clang-tag-e1.37.21-64bit
clang-tag-e1.37.22-64bit
clang-incoming-32bit
clang-incoming-64bit
clang-master-32bit
clang-master-64bit
emscripten-tag-1.37.21-32bit
emscripten-tag-1.37.22-32bit
emscripten-tag-1.37.21-64bit
emscripten-tag-1.37.22-64bit
binaryen-tag-1.37.21-32bit
binaryen-tag-1.37.22-32bit
binaryen-tag-1.37.21-64bit
binaryen-tag-1.37.22-64bit
emscripten-incoming-32bit
emscripten-master-32bit
emscripten-incoming-64bit
emscripten-master-64bit
binaryen-master-32bit
binaryen-master-64bit

The following precompiled SDKs are available for download: (Run "./emsdk update"
to pull in the latest list)
sdk-nightly-1.37.9-2017_04_19_23_39-64bit
sdk-nightly-1.37.9-2017_04_20_04_06-64bit
sdk-1.30.0-64bit
sdk-1.34.1-64bit
sdk-1.35.0-64bit
sdk-1.37.1-64bit
sdk-1.37.21-64bit
* sdk-1.37.22-64bit INSTALLED

The following SDKs can be compiled from source:
sdk-incoming-32bit
sdk-incoming-64bit
sdk-master-32bit
sdk-master-64bit
sdk-tag-1.37.21-32bit
sdk-tag-1.37.22-32bit
sdk-tag-1.37.21-64bit
sdk-tag-1.37.22-64bit

Items marked with * are activated for the current user.

To access the historical archived versions, type 'emsdk list --old'
`
I the beginner in it. I want to expand the experience, having studied this library. But it is impossible to compile.
I will be grateful for any help.

Add support for calib3d module

Hi, is there any future plan to add the calib3d module. I'm specifically interested in the five-point algorithm. algorithm . It would be great to use this on the web.

All functions except cv.imread() and cv.imshow() throw exception like " Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch. "

When I load the page correctly, it will show

  1. wasm streaming compile failed: TypeError: Response has unsupported MIME type
    opencv.js:24:19910 falling back to ArrayBuffer instantiation
  2. IndexSizeError: Index or size is negative or greater than the allowed amount
    and when it run at cv.addWeighted(src1,alpha,src2,beta,0.0,-1),
  3. uncaught exception: 6411184 - Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch.

patch_emscripten_master.diff needs additional configuration on Windows

The diff file fails on Windows because of the naming convention of Emscripten installation.
--- ./emscripten/master/src/embind/embind.js 2016-12-20 13:05:20.498980029 -0800

should be
--- ./emscripten/1.37.21/src/embind/embind.js 2016-12-20 13:05:20.498980029 -0800

As this version keeps increasing, you may want to include additional instructions for users to change the dir name.

Could not install OpenCVjs

Hello !

I tried to install OpenCVjs today to test it, so I installed EMSDK

.\emsdk update
.\emsdk install latest
.\emsdk activate latest

After doing this I tried to install OpenCVjs

.\python\2.7.5.3_64bit\python.exe make.py

I had some problems with environment variables, but I fixed them.
And it is still not working, I have a non-zero exit status .

The entire Log is here https://pastebin.com/qEPfHPcd
I really do not understand because I have MinGW, python and CMake in my environment variable.

Thanks for helping me

Build OpenCV as library

This is an amazing project, but I think it misses one very important opportunity: Allow people would to build they're OpenCV based project for the browser.

How can I build OpenCV as a library (no bindings), that I can then link to from my own libs?
The bindings/JS-expoting will be done from my own code.

I don't what to program my algorithms in JS, but instead export my C++ code with OpenCV linked internally. How can I do that?

HogDescriptor

I am trying to use the HogDescriptor, but I have the next error:

uncaught exception: abort() at jsStackTrace@file:///cv.js:20:18035 stackTrace@file:///cv.js:20:18206 abort@file:///cv.js:55:49083 _abort@file:///cv.js:20:653624 zNb@file:///cv.js:48:132031 zhb@file:///cv.js:27:76826 sub@file:///cv.js:35:258360 $y@file:///cv.js:31:62393 bz@file:///cv.js:31:62667 wTb@file:///cv.js:48:175690 dynCall_viiiiiii_62@file:///cv.js line 20 > Function:4:12 HOGDescriptor$compute@file:///cv.js line 20 > Function:13:1 Icar.processVideoFrameForFaceLiveness_CheckBlink_Phase1_NEW@file:///js/icarFaceCapture_opencvjs.js:1566:14 Icar.processVideoFrameForFaceLiveness@file:///js/icarFaceCapture_opencvjs.js:2662:5 IcarVid.processVideoFrame@file:///js/icarVideo.js:421:4

Here, you can see how I have implemented the code:

I_winSize1 = 128;
I_winSize2 = 64;
I_blockSize = 16;
I_blockStride = 8;
I_cellSize = 8;
I_nbins = 9;
I_derivAperture = 1;
I_winSigma = -1;
I_histogramNormType = 0;
I_L2HysThreshold = 0.2;
I_gammaCorrection = true;
I_nlevels = 64;
I_HogDescriptor = new cv.HOGDescriptor([I_winSize1, I_winSize2], [I_blockSize, I_blockSize], [I_blockStride, I_blockStride], [I_cellSize, I_cellSize], I_nbins, I_derivAperture , I_winSigma, I_histogramNormType , I_L2HysThreshold, I_gammaCorrection, I_nlevels, false);
// image_eyes is a imageData
var image_eyes_mat = cv.matFromArray(image_eyes, 24); // 24 for rgba
var image_eyes_mat_gray = new cv.Mat();
cv.cvtColor(image_eyes_mat, image_eyes_mat_gray, cv.ColorConversionCodes.COLOR_RGBA2GRAY.value, 0);

var descriptors = new cv.FloatVector();
var locations = new cv.PointVector();
I_HogDescriptor.compute(image_eyes_mat_gray, descriptors, [0,0], [0,0], locations);

Does someone have any idea because I get this error?

Is ML is supported?

The notes in Readme do not mention support for ML, but the build seems to include the ML module from OpenCV. So is it supported?

Thanks!

Error while following the readme instruction

I am trying to follow the Readme, when I issued ./emsdk install sdk-master-64bit --shallow- I see below error.

Machine Spec:

  1. Ubuntu 16.04
ubuntu@ip-172-31-20-37:~/emsdk-portable$ ./emsdk install sdk-master-64bit --shallow
Installing SDK 'sdk-master-64bit'..
Installing tool 'clang-master-64bit'..
Repository 'https://github.com/kripken/emscripten-fastcomp.git' already cloned to directory '/home/ubuntu/emsdk-portable/clang/fastcomp/src', skipping.
Fetching latest changes to the branch 'master' for '/home/ubuntu/emsdk-portable/clang/fastcomp/src'...
error: pathspec 'master' did not match any file(s) known to git.
['/usr/bin/git', 'checkout', '--quiet', 'master'] failed with error code 1!
Installation failed!

Problems using get() method

Hello!
I'm having troubles with the use of get() method. It is returning strange float values, like 1.4109027513288258e-86 etc.
Here is the part of the code where I'm calling the method:

img_gray = im.copy();
img_gray.convertGrayscale();`
for(var i=0; i<im.height();i=i+1){
        for(var j=0; j<im.width();j=j+1){
                var data = img_gray.get(i,j);  
                console.log(data);
          }
} 

I saw this on wiki :

Accessing Data For color images, be careful with get, row, and col.
They return a number that represents the pixel by bit-shifting all
the channels together.

But I'm using grayscale...
Any tip how to fix this? I'd like to get integer values from .get()

cv.invert returns incorrect result

Invert function does not return the same value as the C++ function in Visual Studio for the same matrix.

Also, i validated the inversion with an online matrix calculator. C++ is correct.

Wrapper seems fine, so perhaps it's the opencv build, however searching opencv bugs, there are no entries since 2012 for the invert function, waaaay before 3.10 release.

Alternative is to use math.js if your matrix is relatively small.

(http://mathjs.org/docs/reference/functions/inv.html)

Example
SR and rotation are cv.Mat of type cv.CV_32FC1


    var invMat = math.inv(this.listToMatrix(SR.data32f(), 2));
        var invVector = invMat[0].concat(invMat[1]);
    rotation.data32f().set(invVector);

Where list to matrix......


.prototype.listToMatrix = function(list, elementsPerSubArray) {
    var matrix = [], i, k;

    for (i = 0, k = -1; i < list.length; i++) {
        if (i % elementsPerSubArray === 0) {
            k++;
            matrix[k] = [];
        }

        matrix[k].push(list[i]);
    }

    return matrix;
}

Caching of module? asm.js or webassembly

Hello,
has anyone looked into caching the browser-compiled / optimized result of the loaded module in either the asm.js version or njors webassembly version of opencvjs?
In both versions, my PC takes 10 seconds of work untilt the module is ready, even AFTER the data is fully downloaded (both, firefox and chrome tested). On my android tablet its even about 30 seconds in Chrome.

I think caching the module would immensly increase its usability.

I've looked into caching of webassembly modules:
https://developer.mozilla.org/en-US/docs/WebAssembly/Caching_modules

However, if I understand correctly, the loading and instanciating of the opencvjs modules are implemented by emscripten into the corresponding cv.js and cv-wasm.js files, which are minified and hard to understand for me.

Any recommendation where to start?

Question: Support for video frame as input

Hi,

I only see canvas or img element as supported input to cv.imread().

I'm planning to read frames from webcam using getUserMedia and display it in video element.
Is there a better way to use the MediaStream object as input to cv.imread()?

Make error

Got this error during Make

../../bindings.cpp:3252:39: error: too many template arguments for class
template 'base'
emscripten::class_<cv::Feature2D ,base<Algorithm ,true>>("Feature2D")
^ ~~~~~~
/home/osboxes/Desktop/emsdk_portable/emscripten/master/system/include/emscripten/bind.h:1003:12: note:
template is declared here
struct base {
^
../../bindings.cpp:3252:62: error: expected unqualified-id
emscripten::class_<cv::Feature2D ,base<Algorithm ,true>>("Feature2D")
^
../../bindings.cpp:3252:62: error: expected ')'
../../bindings.cpp:3252:61: note: to match this '('
emscripten::class_<cv::Feature2D ,base<Algorithm ,true>>("Feature2D")
^
3 errors generated.
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting
Traceback (most recent call last):
File "make.py", line 181, in
emscripten.Building.emcc('../../bindings.cpp', emcc_binding_args, 'bindings.bc')
File "/home/osboxes/Desktop/emsdk_portable/emscripten/master/tools/shared.py", line 1565, in emcc
assert os.path.exists(output_filename), 'emcc could not create output file: ' + output_filename
AssertionError: emcc could not create output file: bindings.bc

Module is not defined

cv.js:50 Uncaught ReferenceError: Module is not defined
at cv.js:50
at cv.js:14
at cv.js:16

Compilation issues in stage 3 (Generate bindings)

Hello,

I could not successfully compile this project. It gets a lot of errors in Stage 3 (Generate bindings).

==========================
Stage 3: Generate Bindings
==========================

['-I../modules/core/include', '-I../modules/flann/include', '-I../modules/ml/include', '-I../modules/imgproc/include', '-I../modules/calib3d/include', '-I../modules/features2d/include', '-I../modules/video/include', '-I../modules/objdetect/include', '-I../modules/imgcodecs/include', '-I../modules/videoio/include', '-I../modules/highgui/include', '-I../modules/hal/include']
clang: warning: argument unused during compilation: '-nostdinc++'
In file included from ../../bindings.cpp:1:
In file included from ../modules/core/include/opencv2/core.hpp:52:
In file included from ../modules/core/include/opencv2/core/cvdef.h:197:
In file included from /usr/share/emscripten/system/include/libcxx/cmath:302:
/usr/share/emscripten/system/include/libcxx/type_traits:638:50: error: pointer to function type 'typename
      remove_reference<unsigned int () const>::type' (aka 'unsigned int () const') cannot have 'const' qualifier
    {typedef typename remove_reference<_Tp>::type* type;};
                                                 ^
/usr/share/emscripten/system/include/emscripten/bind.h:265:5: note: in instantiation of template class
      'std::__1::add_pointer<unsigned int () const>' requested here
    typename std::add_pointer<Signature>::type select_overload(typename std::add_pointer<Signature>::type fn) {
    ^
../../bindings.cpp:3587:32: note: while substituting explicitly-specified template arguments into function template
      'select_overload'
        .function("elemSize1", select_overload<size_t()const>(&cv::Mat::elemSize1))
                               ^
In file included from ../../bindings.cpp:1:
In file included from ../modules/core/include/opencv2/core.hpp:52:
In file included from ../modules/core/include/opencv2/core/cvdef.h:197:
In file included from /usr/share/emscripten/system/include/libcxx/cmath:302:
/usr/share/emscripten/system/include/libcxx/type_traits:638:50: error: pointer to function type 'typename
      remove_reference<void (Mat &, int) const>::type' (aka 'void (cv::Mat &, int) const') cannot have 'const'
      qualifier
[..]
20 errors generated.
ERROR    root: compiler frontend failed to generate LLVM bitcode, halting

Is there anything special that needs to be made to the emscripten installation (or config file)? What js engine needs to be used?

Emscripten link issue in make.py

Hello,

I followed the tutorial to build OpenCVJS with emscripten (Windows 10 x64) but the script 'make.py' crashes before the end.
It goes in an infinite forking loop when linking the different opencv libraries to create 'libOpenCV.bc'.
log_2018_04_04.txt

Concerning emscripten, I have installed the 'sdk-incoming-64bit' version, and here is my .emscripten configuration :
emscripten_conf.txt

OpenCV is built correctly (all the modules' .a files are generated) and the binding file 'bindings.bc' has been generated.

I'm not very used to emscripten so I really don't know what can cause this issue. Do you have any Idea ?

Johann

RotatedRect UnboundTypeError with minAreaRect

I get an "UnboundTypeError" when calling cv.minAreaRect(). The error says: Cannot call minAreaRect due to unbound types: N2cv11RotatedRectE.

I see the same errors for cv.fitEllipse() and cv.ellipse1() which also use the RotatedRect class.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.