Skip to content

Commit 6fdb7ae

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 22d64ae + 12a36b5 commit 6fdb7ae

File tree

51 files changed

+2878
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2878
-110
lines changed

cmake/OpenCVFindLibsGrfmt.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
if(BUILD_ZLIB)
77
ocv_clear_vars(ZLIB_FOUND)
88
else()
9+
ocv_clear_internal_cache_vars(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
910
find_package(ZLIB "${MIN_VER_ZLIB}")
1011
if(ZLIB_FOUND AND ANDROID)
1112
if(ZLIB_LIBRARIES MATCHES "/usr/(lib|lib32|lib64)/libz.so$")
@@ -31,11 +32,12 @@ if(WITH_JPEG)
3132
if(BUILD_JPEG)
3233
ocv_clear_vars(JPEG_FOUND)
3334
else()
35+
ocv_clear_internal_cache_vars(JPEG_LIBRARY JPEG_INCLUDE_DIR)
3436
include(FindJPEG)
3537
endif()
3638

3739
if(NOT JPEG_FOUND)
38-
ocv_clear_vars(JPEG_LIBRARY JPEG_LIBRARIES JPEG_INCLUDE_DIR)
40+
ocv_clear_vars(JPEG_LIBRARY JPEG_INCLUDE_DIR)
3941

4042
if(NOT BUILD_JPEG_TURBO_DISABLE)
4143
set(JPEG_LIBRARY libjpeg-turbo CACHE INTERNAL "")
@@ -76,6 +78,7 @@ if(WITH_TIFF)
7678
if(BUILD_TIFF)
7779
ocv_clear_vars(TIFF_FOUND)
7880
else()
81+
ocv_clear_internal_cache_vars(TIFF_LIBRARY TIFF_INCLUDE_DIR)
7982
include(FindTIFF)
8083
if(TIFF_FOUND)
8184
ocv_parse_header("${TIFF_INCLUDE_DIR}/tiff.h" TIFF_VERSION_LINES TIFF_VERSION_CLASSIC TIFF_VERSION_BIG TIFF_VERSION TIFF_BIGTIFF_VERSION)
@@ -119,6 +122,7 @@ if(WITH_WEBP)
119122
if(BUILD_WEBP)
120123
ocv_clear_vars(WEBP_FOUND WEBP_LIBRARY WEBP_LIBRARIES WEBP_INCLUDE_DIR)
121124
else()
125+
ocv_clear_internal_cache_vars(WEBP_LIBRARY WEBP_INCLUDE_DIR)
122126
include(cmake/OpenCVFindWebP.cmake)
123127
if(WEBP_FOUND)
124128
set(HAVE_WEBP 1)
@@ -212,6 +216,7 @@ if(WITH_PNG)
212216
if(BUILD_PNG)
213217
ocv_clear_vars(PNG_FOUND)
214218
else()
219+
ocv_clear_internal_cache_vars(PNG_LIBRARY PNG_INCLUDE_DIR)
215220
include(FindPNG)
216221
if(PNG_FOUND)
217222
include(CheckIncludeFile)
@@ -243,6 +248,7 @@ endif()
243248
if(WITH_OPENEXR)
244249
ocv_clear_vars(HAVE_OPENEXR)
245250
if(NOT BUILD_OPENEXR)
251+
ocv_clear_internal_cache_vars(OPENEXR_INCLUDE_PATHS OPENEXR_LIBRARIES OPENEXR_ILMIMF_LIBRARY OPENEXR_VERSION)
246252
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVFindOpenEXR.cmake")
247253
endif()
248254

cmake/OpenCVModule.cmake

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,6 @@ macro(ocv_add_dependencies full_modname)
9898
endforeach()
9999
unset(__depsvar)
100100

101-
# hack for python
102-
set(__python_idx)
103-
list(FIND OPENCV_MODULE_${full_modname}_WRAPPERS "python" __python_idx)
104-
if (NOT __python_idx EQUAL -1)
105-
list(REMOVE_ITEM OPENCV_MODULE_${full_modname}_WRAPPERS "python")
106-
list(APPEND OPENCV_MODULE_${full_modname}_WRAPPERS "python_bindings_generator" "python2" "python3")
107-
endif()
108-
unset(__python_idx)
109-
110101
ocv_list_unique(OPENCV_MODULE_${full_modname}_REQ_DEPS)
111102
ocv_list_unique(OPENCV_MODULE_${full_modname}_OPT_DEPS)
112103
ocv_list_unique(OPENCV_MODULE_${full_modname}_PRIVATE_REQ_DEPS)
@@ -210,9 +201,17 @@ macro(ocv_add_module _name)
210201
set(OPENCV_MODULES_DISABLED_USER ${OPENCV_MODULES_DISABLED_USER} "${the_module}" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
211202
endif()
212203

213-
# add reverse wrapper dependencies
204+
# add reverse wrapper dependencies (BINDINDS)
214205
foreach (wrapper ${OPENCV_MODULE_${the_module}_WRAPPERS})
215-
ocv_add_dependencies(opencv_${wrapper} OPTIONAL ${the_module})
206+
if(wrapper STREQUAL "python") # hack for python (BINDINDS)
207+
ocv_add_dependencies(opencv_python2 OPTIONAL ${the_module})
208+
ocv_add_dependencies(opencv_python3 OPTIONAL ${the_module})
209+
else()
210+
ocv_add_dependencies(opencv_${wrapper} OPTIONAL ${the_module})
211+
endif()
212+
if(DEFINED OPENCV_MODULE_opencv_${wrapper}_bindings_generator_CLASS)
213+
ocv_add_dependencies(opencv_${wrapper}_bindings_generator OPTIONAL ${the_module})
214+
endif()
216215
endforeach()
217216

218217
# stop processing of current file

cmake/OpenCVUtils.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,24 @@ macro(ocv_clear_vars)
400400
endforeach()
401401
endmacro()
402402

403+
404+
# Clears passed variables with INTERNAL type from CMake cache
405+
macro(ocv_clear_internal_cache_vars)
406+
foreach(_var ${ARGN})
407+
get_property(_propertySet CACHE ${_var} PROPERTY TYPE SET)
408+
if(_propertySet)
409+
get_property(_type CACHE ${_var} PROPERTY TYPE)
410+
if(_type STREQUAL "INTERNAL")
411+
message("Cleaning INTERNAL cached variable: ${_var}")
412+
unset(${_var} CACHE)
413+
endif()
414+
endif()
415+
endforeach()
416+
unset(_propertySet)
417+
unset(_type)
418+
endmacro()
419+
420+
403421
set(OCV_COMPILER_FAIL_REGEX
404422
"argument .* is not valid" # GCC 9+ (including support of unicode quotes)
405423
"command[- ]line option .* is valid for .* but not for C\\+\\+" # GNU
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set(OPENCV_SKIP_LINK_AS_NEEDED 1)
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
getBlobFromImage = function(inputSize, mean, std, swapRB, image) {
2+
let mat;
3+
if (typeof(image) === 'string') {
4+
mat = cv.imread(image);
5+
} else {
6+
mat = image;
7+
}
8+
9+
let matC3 = new cv.Mat(mat.matSize[0], mat.matSize[1], cv.CV_8UC3);
10+
cv.cvtColor(mat, matC3, cv.COLOR_RGBA2BGR);
11+
let input = cv.blobFromImage(matC3, std, new cv.Size(inputSize[0], inputSize[1]),
12+
new cv.Scalar(mean[0], mean[1], mean[2]), swapRB);
13+
14+
matC3.delete();
15+
return input;
16+
}
17+
18+
loadLables = async function(labelsUrl) {
19+
let response = await fetch(labelsUrl);
20+
let label = await response.text();
21+
label = label.split('\n');
22+
return label;
23+
}
24+
25+
loadModel = async function(e) {
26+
return new Promise((resolve) => {
27+
let file = e.target.files[0];
28+
let path = file.name;
29+
let reader = new FileReader();
30+
reader.readAsArrayBuffer(file);
31+
reader.onload = function(ev) {
32+
if (reader.readyState === 2) {
33+
let buffer = reader.result;
34+
let data = new Uint8Array(buffer);
35+
cv.FS_createDataFile('/', path, data, true, false, false);
36+
resolve(path);
37+
}
38+
}
39+
});
40+
}
41+
42+
getTopClasses = function(probs, labels, topK = 3) {
43+
probs = Array.from(probs);
44+
let indexes = probs.map((prob, index) => [prob, index]);
45+
let sorted = indexes.sort((a, b) => {
46+
if (a[0] === b[0]) {return 0;}
47+
return a[0] < b[0] ? -1 : 1;
48+
});
49+
sorted.reverse();
50+
let classes = [];
51+
for (let i = 0; i < topK; ++i) {
52+
let prob = sorted[i][0];
53+
let index = sorted[i][1];
54+
let c = {
55+
label: labels[index],
56+
prob: (prob * 100).toFixed(2)
57+
}
58+
classes.push(c);
59+
}
60+
return classes;
61+
}
62+
63+
loadImageToCanvas = function(e, canvasId) {
64+
let files = e.target.files;
65+
let imgUrl = URL.createObjectURL(files[0]);
66+
let canvas = document.getElementById(canvasId);
67+
let ctx = canvas.getContext('2d');
68+
let img = new Image();
69+
img.crossOrigin = 'anonymous';
70+
img.src = imgUrl;
71+
img.onload = function() {
72+
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
73+
};
74+
}
75+
76+
drawInfoTable = async function(jsonUrl, divId) {
77+
let response = await fetch(jsonUrl);
78+
let json = await response.json();
79+
80+
let appendix = document.getElementById(divId);
81+
for (key of Object.keys(json)) {
82+
let h3 = document.createElement('h3');
83+
h3.textContent = key + " model";
84+
appendix.appendChild(h3);
85+
86+
let table = document.createElement('table');
87+
let head_tr = document.createElement('tr');
88+
for (head of Object.keys(json[key][0])) {
89+
let th = document.createElement('th');
90+
th.textContent = head;
91+
th.style.border = "1px solid black";
92+
head_tr.appendChild(th);
93+
}
94+
table.appendChild(head_tr)
95+
96+
for (model of json[key]) {
97+
let tr = document.createElement('tr');
98+
for (params of Object.keys(model)) {
99+
let td = document.createElement('td');
100+
td.style.border = "1px solid black";
101+
if (params !== "modelUrl" && params !== "configUrl" && params !== "labelsUrl") {
102+
td.textContent = model[params];
103+
tr.appendChild(td);
104+
} else {
105+
let a = document.createElement('a');
106+
let link = document.createTextNode('link');
107+
a.append(link);
108+
a.href = model[params];
109+
td.appendChild(a);
110+
tr.appendChild(td);
111+
}
112+
}
113+
table.appendChild(tr);
114+
}
115+
table.style.width = "800px";
116+
table.style.borderCollapse = "collapse";
117+
appendix.appendChild(table);
118+
}
119+
}

0 commit comments

Comments
 (0)