Skip to content

Commit dac298e

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 3e9158a + ef27c11 commit dac298e

File tree

20 files changed

+480
-58
lines changed

20 files changed

+480
-58
lines changed

doc/js_tutorials/js_setup/js_intro/js_intro.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ OpenCV.js: OpenCV for the JavaScript programmer
1313

1414
Web is the most ubiquitous open computing platform. With HTML5 standards implemented in every browser, web applications are able to render online video with HTML5 video tags, capture webcam video via WebRTC API, and access each pixel of a video frame via canvas API. With abundance of available multimedia content, web developers are in need of a wide array of image and vision processing algorithms in JavaScript to build innovative applications. This requirement is even more essential for emerging applications on the web, such as Web Virtual Reality (WebVR) and Augmented Reality (WebAR). All of these use cases demand efficient implementations of computation-intensive vision kernels on web.
1515

16-
[Emscripten](http://kripken.github.io/emscripten-site) is an LLVM-to-JavaScript compiler. It takes LLVM bitcode - which can be generated from C/C++ using clang, and compiles that into asm.js or WebAssembly that can execute directly inside the web browsers. . Asm.js is a highly optimizable, low-level subset of JavaScript. Asm.js enables ahead-of-time compilation and optimization in JavaScript engine that provide near-to-native execution speed. WebAssembly is a new portable, size- and load-time-efficient binary format suitable for compilation to the web. WebAssembly aims to execute at native speed. WebAssembly is currently being designed as an open standard by W3C.
16+
[Emscripten](https://emscripten.org/) is an LLVM-to-JavaScript compiler. It takes LLVM bitcode - which can be generated from C/C++ using clang, and compiles that into asm.js or WebAssembly that can execute directly inside the web browsers. . Asm.js is a highly optimizable, low-level subset of JavaScript. Asm.js enables ahead-of-time compilation and optimization in JavaScript engine that provide near-to-native execution speed. WebAssembly is a new portable, size- and load-time-efficient binary format suitable for compilation to the web. WebAssembly aims to execute at native speed. WebAssembly is currently being designed as an open standard by W3C.
1717

1818
OpenCV.js is a JavaScript binding for selected subset of OpenCV functions for the web platform. It allows emerging web applications with multimedia processing to benefit from the wide variety of vision functions available in OpenCV. OpenCV.js leverages Emscripten to compile OpenCV functions into asm.js or WebAssembly targets, and provides a JavaScript APIs for web application to access them. The future versions of the library will take advantage of acceleration APIs that are available on the Web such as SIMD and multi-threaded execution.
1919

@@ -42,4 +42,4 @@ Below is the list of contributors of OpenCV.js bindings and tutorials.
4242
- Gang Song (GSoC student, Shanghai Jiao Tong University)
4343
- Wenyao Gan (Student intern, Shanghai Jiao Tong University)
4444
- Mohammad Reza Haghighat (Project initiator & sponsor, Intel Corporation)
45-
- Ningxin Hu (Students' supervisor, Intel Corporation)
45+
- Ningxin Hu (Students' supervisor, Intel Corporation)

doc/js_tutorials/js_setup/js_setup/js_setup.markdown

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ You don't have to build your own copy if you simply want to start using it. Refe
77
Installing Emscripten
88
-----------------------------
99

10-
[Emscripten](https://github.com/kripken/emscripten) is an LLVM-to-JavaScript compiler. We will use Emscripten to build OpenCV.js.
10+
[Emscripten](https://github.com/emscripten-core/emscripten) is an LLVM-to-JavaScript compiler. We will use Emscripten to build OpenCV.js.
1111

1212
@note
1313
While this describes installation of required tools from scratch, there's a section below also describing an alternative procedure to perform the same build using docker containers which is often easier.
1414

15-
To Install Emscripten, follow instructions of [Emscripten SDK](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html).
15+
To Install Emscripten, follow instructions of [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html).
1616

1717
For example:
1818
@code{.bash}
@@ -21,24 +21,29 @@ For example:
2121
./emsdk activate latest
2222
@endcode
2323

24-
@note
25-
To compile to [WebAssembly](http://webassembly.org), you need to install and activate [Binaryen](https://github.com/WebAssembly/binaryen) with the `emsdk` command. Please refer to [Developer's Guide](http://webassembly.org/getting-started/developers-guide/) for more details.
2624

27-
After install, ensure the `EMSCRIPTEN` environment is setup correctly.
25+
After install, ensure the `EMSDK` environment is setup correctly.
2826

2927
For example:
3028
@code{.bash}
3129
source ./emsdk_env.sh
32-
echo ${EMSCRIPTEN}
30+
echo ${EMSDK}
3331
@endcode
3432

35-
The version 1.39.16 of emscripten is verified for latest WebAssembly. Please check the version of emscripten to use the newest features of WebAssembly.
33+
Modern versions of Emscripten requires to use `emcmake` / `emmake` launchers:
34+
35+
@code{.bash}
36+
emcmake sh -c 'echo ${EMSCRIPTEN}'
37+
@endcode
38+
39+
40+
The version 2.0.10 of emscripten is verified for latest WebAssembly. Please check the version of Emscripten to use the newest features of WebAssembly.
3641

3742
For example:
3843
@code{.bash}
3944
./emsdk update
40-
./emsdk install 1.39.16
41-
./emsdk activate 1.39.16
45+
./emsdk install 2.0.10
46+
./emsdk activate 2.0.10
4247
@endcode
4348

4449
Obtaining OpenCV Source Code
@@ -71,8 +76,7 @@ Building OpenCV.js from Source
7176

7277
For example, to build in `build_js` directory:
7378
@code{.bash}
74-
cd opencv
75-
python ./platforms/js/build_js.py build_js
79+
emcmake python ./opencv/platforms/js/build_js.py build_js
7680
@endcode
7781

7882
@note
@@ -82,14 +86,14 @@ Building OpenCV.js from Source
8286

8387
For example, to build wasm version in `build_wasm` directory:
8488
@code{.bash}
85-
python ./platforms/js/build_js.py build_wasm --build_wasm
89+
emcmake python ./opencv/platforms/js/build_js.py build_wasm --build_wasm
8690
@endcode
8791

8892
-# [Optional] To build the OpenCV.js loader, append `--build_loader`.
8993

9094
For example:
9195
@code{.bash}
92-
python ./platforms/js/build_js.py build_js --build_loader
96+
emcmake python ./opencv/platforms/js/build_js.py build_js --build_loader
9397
@endcode
9498

9599
@note
@@ -114,7 +118,7 @@ Building OpenCV.js from Source
114118

115119
For example:
116120
@code{.bash}
117-
python ./platforms/js/build_js.py build_js --build_doc
121+
emcmake python ./opencv/platforms/js/build_js.py build_js --build_doc
118122
@endcode
119123

120124
@note
@@ -124,7 +128,14 @@ Building OpenCV.js from Source
124128

125129
For example:
126130
@code{.bash}
127-
python ./platforms/js/build_js.py build_js --build_test
131+
emcmake python ./opencv/platforms/js/build_js.py build_js --build_test
132+
@endcode
133+
134+
-# [optional] To enable OpenCV contrib modules append `--cmake_option="-DOPENCV_EXTRA_MODULES_PATH=/path/to/opencv_contrib/modules/"`
135+
136+
For example:
137+
@code{.bash}
138+
python ./platforms/js/build_js.py build_js --cmake_option="-DOPENCV_EXTRA_MODULES_PATH=opencv_contrib/modules"
128139
@endcode
129140

130141
-# [optional] To enable OpenCV contrib modules append `--cmake_option="-DOPENCV_EXTRA_MODULES_PATH=/path/to/opencv_contrib/modules/"`
@@ -193,7 +204,7 @@ node tests.js
193204

194205
For example:
195206
@code{.bash}
196-
python ./platforms/js/build_js.py build_js --build_wasm --threads
207+
emcmake python ./opencv/platforms/js/build_js.py build_js --build_wasm --threads
197208
@endcode
198209

199210
The default threads number is the logic core number of your device. You can use `cv.parallel_pthreads_set_threads_num(number)` to set threads number by yourself and use `cv.parallel_pthreads_get_threads_num()` to get the current threads number.
@@ -205,7 +216,7 @@ node tests.js
205216

206217
For example:
207218
@code{.bash}
208-
python ./platforms/js/build_js.py build_js --build_wasm --simd
219+
emcmake python ./opencv/platforms/js/build_js.py build_js --build_wasm --simd
209220
@endcode
210221

211222
The simd optimization is experimental as wasm simd is still in development.
@@ -229,7 +240,7 @@ node tests.js
229240

230241
For example:
231242
@code{.bash}
232-
python ./platforms/js/build_js.py build_js --build_wasm --simd --build_wasm_intrin_test
243+
emcmake python ./opencv/platforms/js/build_js.py build_js --build_wasm --simd --build_wasm_intrin_test
233244
@endcode
234245

235246
For wasm intrinsics tests, you can use the following function to test all the cases:
@@ -257,7 +268,7 @@ node tests.js
257268

258269
For example:
259270
@code{.bash}
260-
python ./platforms/js/build_js.py build_js --build_perf
271+
emcmake python ./opencv/platforms/js/build_js.py build_js --build_perf
261272
@endcode
262273

263274
To run performance tests, launch a local web server in \<build_dir\>/bin folder. For example, node http-server which serves on `localhost:8080`.
@@ -278,36 +289,37 @@ Building OpenCV.js with Docker
278289

279290
Alternatively, the same build can be can be accomplished using [docker](https://www.docker.com/) containers which is often easier and more reliable, particularly in non linux systems. You only need to install [docker](https://www.docker.com/) on your system and use a popular container that provides a clean well tested environment for emscripten builds like this, that already has latest versions of all the necessary tools installed.
280291

281-
So, make sure [docker](https://www.docker.com/) is installed in your system and running. The following shell script should work in linux and MacOS:
292+
So, make sure [docker](https://www.docker.com/) is installed in your system and running. The following shell script should work in Linux and MacOS:
282293

283294
@code{.bash}
284295
git clone https://github.com/opencv/opencv.git
285296
cd opencv
286-
docker run --rm --workdir /code -v "$PWD":/code "trzeci/emscripten:latest" python ./platforms/js/build_js.py build
297+
docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emcmake python3 ./dev/platforms/js/build_js.py build_js
287298
@endcode
288299

289300
In Windows use the following PowerShell command:
290301

291302
@code{.bash}
292-
docker run --rm --workdir /code -v "$(get-location):/code" "trzeci/emscripten:latest" python ./platforms/js/build_js.py build
303+
docker run --rm --workdir /src -v "$(get-location):/src" "emscripten/emsdk" emcmake python3 ./dev/platforms/js/build_js.py build_js
293304
@endcode
294305

295306
@warning
296-
The example uses latest version of emscripten. If the build fails you should try a version that is known to work fine which is `1.38.32` using the following command:
307+
The example uses latest version of emscripten. If the build fails you should try a version that is known to work fine which is `2.0.10` using the following command:
297308

298309
@code{.bash}
299-
docker run --rm --workdir /code -v "$PWD":/code "trzeci/emscripten:sdk-tag-1.38.32-64bit" python ./platforms/js/build_js.py build
310+
docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk:2.0.10 emcmake python3 ./dev/platforms/js/build_js.py build_js
300311
@endcode
301312

302313
### Building the documentation with Docker
303314

304315
To build the documentation `doxygen` needs to be installed. Create a file named `Dockerfile` with the following content:
305316

306317
```
307-
FROM trzeci/emscripten:sdk-tag-1.38.32-64bit
318+
FROM emscripten/emsdk:2.0.10
308319
309-
RUN apt-get update -y
310-
RUN apt-get install -y doxygen
320+
RUN apt-get update \
321+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends doxygen \
322+
&& rm -rf /var/lib/apt/lists/*
311323
```
312324

313325
Then we build the docker image and name it `opencv-js-doc` with the following command (that needs to be run only once):
@@ -319,5 +331,5 @@ docker build . -t opencv-js-doc
319331
Now run the build command again, this time using the new image and passing `--build_doc`:
320332

321333
@code{.bash}
322-
docker run --rm --workdir /code -v "$PWD":/code "opencv-js-doc" python ./platforms/js/build_js.py build --build_doc
334+
docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) "opencv-js-doc" emcmake python3 ./dev/platforms/js/build_js.py build_js --build_doc
323335
@endcode

doc/js_tutorials/js_setup/js_usage/js_usage.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ function onOpenCvReady() {
129129
</html>
130130
@endcode
131131

132-
@note You have to call delete method of cv.Mat to free memory allocated in Emscripten's heap. Please refer to [Memory management of Emscripten](https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/embind.html#memory-management) for details.
132+
@note You have to call delete method of cv.Mat to free memory allocated in Emscripten's heap. Please refer to [Memory management of Emscripten](https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#memory-management) for details.
133133

134134
Try it
135135
------
136136
\htmlonly
137137
<iframe src="../../js_setup_usage.html" width="100%"
138138
onload="this.style.height=this.contentDocument.body.scrollHeight +'px';">
139139
</iframe>
140-
\endhtmlonly
140+
\endhtmlonly

doc/tutorials/introduction/windows_install/windows_install.markdown

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ cd /c/lib
5555
@code{.bash}
5656
#!/bin/bash -e
5757
myRepo=$(pwd)
58-
CMAKE_CONFIG_GENERATOR="Visual Studio 14 2015 Win64"
58+
CMAKE_GENERATOR_OPTIONS=-G"Visual Studio 16 2019"
59+
#CMAKE_GENERATOR_OPTIONS=-G"Visual Studio 15 2017 Win64"
60+
#CMAKE_GENERATOR_OPTIONS=(-G"Visual Studio 16 2019" -A x64) # CMake 3.14+ is required
5961
if [ ! -d "$myRepo/opencv" ]; then
6062
echo "cloning opencv"
6163
git clone https://github.com/opencv/opencv.git
62-
mkdir -p Build/opencv
63-
mkdir -p Install/opencv
6464
else
6565
cd opencv
6666
git pull --rebase
@@ -69,16 +69,17 @@ fi
6969
if [ ! -d "$myRepo/opencv_contrib" ]; then
7070
echo "cloning opencv_contrib"
7171
git clone https://github.com/opencv/opencv_contrib.git
72-
mkdir -p Build/opencv_contrib
7372
else
7473
cd opencv_contrib
7574
git pull --rebase
7675
cd ..
7776
fi
7877
RepoSource=opencv
79-
pushd Build/$RepoSource
80-
CMAKE_OPTIONS='-DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=OFF -DWITH_CUDA:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF -DINSTALL_CREATE_DISTRIB=ON'
81-
cmake -G"$CMAKE_CONFIG_GENERATOR" $CMAKE_OPTIONS -DOPENCV_EXTRA_MODULES_PATH="$myRepo"/opencv_contrib/modules -DCMAKE_INSTALL_PREFIX="$myRepo"/install/"$RepoSource" "$myRepo/$RepoSource"
78+
mkdir -p build_opencv
79+
pushd build_opencv
80+
CMAKE_OPTIONS=(-DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=OFF -DWITH_CUDA:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF -DINSTALL_CREATE_DISTRIB=ON)
81+
set -x
82+
cmake "${CMAKE_GENERATOR_OPTIONS[@]}" "${CMAKE_OPTIONS[@]}" -DOPENCV_EXTRA_MODULES_PATH="$myRepo"/opencv_contrib/modules -DCMAKE_INSTALL_PREFIX="$myRepo/install/$RepoSource" "$myRepo/$RepoSource"
8283
echo "************************* $Source_DIR -->debug"
8384
cmake --build . --config debug
8485
echo "************************* $Source_DIR -->release"
@@ -89,15 +90,15 @@ popd
8990
@endcode
9091
In this script I suppose you use VS 2015 in 64 bits
9192
@code{.bash}
92-
CMAKE_CONFIG_GENERATOR="Visual Studio 14 2015 Win64"
93+
CMAKE_GENERATOR_OPTIONS=-G"Visual Studio 14 2015 Win64"
9394
@endcode
94-
and opencv will be installed in c:/lib/install
95+
and opencv will be installed in c:/lib/install/opencv
9596
@code{.bash}
96-
-DCMAKE_INSTALL_PREFIX="$myRepo"/install/"$RepoSource" "$myRepo/$RepoSource"
97+
-DCMAKE_INSTALL_PREFIX="$myRepo/install/$RepoSource"
9798
@endcode
9899
with no Perf tests, no tests, no doc, no CUDA and no example
99100
@code{.bash}
100-
CMAKE_OPTIONS='-DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF'
101+
CMAKE_OPTIONS=(-DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF)
101102
@endcode
102103
-# In git command line enter following command :
103104
@code{.bash}

modules/core/include/opencv2/core/bindings_utils.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ String dumpCString(const char* argument)
5858
return cv::format("String: %s", argument);
5959
}
6060

61+
CV_WRAP static inline
62+
String dumpString(const String& argument)
63+
{
64+
return cv::format("String: %s", argument.c_str());
65+
}
66+
6167
CV_WRAP static inline
6268
AsyncArray testAsyncArray(InputArray argument)
6369
{

modules/imgproc/src/color.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ inline int dstChannels(int code)
104104
return 4;
105105

106106
case COLOR_BGRA2BGR: case COLOR_RGBA2BGR: case COLOR_RGB2BGR:
107+
case COLOR_YUV2RGB: case COLOR_YUV2BGR: case COLOR_RGB2YUV: case COLOR_BGR2YUV:
107108
case COLOR_BGR5652BGR: case COLOR_BGR5552BGR: case COLOR_BGR5652RGB: case COLOR_BGR5552RGB:
108109
case COLOR_GRAY2BGR:
109110
case COLOR_YUV2BGR_NV21: case COLOR_YUV2RGB_NV21: case COLOR_YUV2BGR_NV12: case COLOR_YUV2RGB_NV12:

modules/js/generator/embindgen.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -778,15 +778,13 @@ def gen(self, dst_file, src_files, core_bindings):
778778
self.bindings+=binding
779779

780780
# generate code for the classes and their methods
781-
class_list = list(self.classes.items())
782-
783-
for name, class_info in class_list:
781+
for name, class_info in sorted(self.classes.items()):
784782
class_bindings = []
785783
if not name in white_list:
786784
continue
787785

788786
# Generate bindings for methods
789-
for method_name, method in class_info.methods.items():
787+
for method_name, method in sorted(class_info.methods.items()):
790788
if method.cname in ignore_list:
791789
continue
792790
if not method.name in white_list[method.class_name]:
@@ -824,7 +822,7 @@ def gen(self, dst_file, src_files, core_bindings):
824822

825823

826824
# Generate bindings for properties
827-
for property in class_info.props:
825+
for property in sorted(class_info.props):
828826
_class_property = class_property_enum_template if property.tp in type_dict else class_property_template
829827
class_bindings.append(_class_property.substitute(js_name=property.name, cpp_name='::'.join(
830828
[class_info.cname, property.name])))

modules/photo/test/test_hdr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ TEST(Photo_CalibrateDebevec, regression)
227227
diff = diff.mul(1.0f / response);
228228
double max;
229229
minMaxLoc(diff, NULL, &max);
230-
ASSERT_FALSE(max > 0.1);
230+
#if defined(__arm__) || defined(__aarch64__)
231+
ASSERT_LT(max, 0.131);
232+
#else
233+
ASSERT_LT(max, 0.1);
234+
#endif
231235
}
232236

233237
TEST(Photo_CalibrateRobertson, regression)

modules/python/src2/cv2.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,15 +993,31 @@ PyObject* pyopencv_from(const std::string& value)
993993
template<>
994994
bool pyopencv_to(PyObject* obj, String &value, const ArgInfo& info)
995995
{
996-
CV_UNUSED(info);
997996
if(!obj || obj == Py_None)
997+
{
998998
return true;
999+
}
9991000
std::string str;
10001001
if (getUnicodeString(obj, str))
10011002
{
10021003
value = str;
10031004
return true;
10041005
}
1006+
else
1007+
{
1008+
// If error hasn't been already set by Python conversion functions
1009+
if (!PyErr_Occurred())
1010+
{
1011+
// Direct access to underlying slots of PyObjectType is not allowed
1012+
// when limited API is enabled
1013+
#ifdef Py_LIMITED_API
1014+
failmsg("Can't convert object to 'str' for '%s'", info.name);
1015+
#else
1016+
failmsg("Can't convert object of type '%s' to 'str' for '%s'",
1017+
obj->ob_type->tp_name, info.name);
1018+
#endif
1019+
}
1020+
}
10051021
return false;
10061022
}
10071023

0 commit comments

Comments
 (0)