From b9d6fc9dad33895ab3566f0eda1d33624860803d Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 19 Jul 2019 14:07:09 +0200 Subject: [PATCH 1/4] Fix cv::selectROI rectangle rendering issue backport of commit: 95c65aff75f62407ca1e99bbfa18e2d54322aab5 --- modules/highgui/src/roiSelector.cpp | 36 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/modules/highgui/src/roiSelector.cpp b/modules/highgui/src/roiSelector.cpp index d8ca58047e..4fba07eacb 100644 --- a/modules/highgui/src/roiSelector.cpp +++ b/modules/highgui/src/roiSelector.cpp @@ -106,10 +106,10 @@ class ROISelector bool isDrawing; Rect2d box; Mat image; + Point2f startPos; // parameters for drawing from the center bool drawFromCenter; - Point2f center; // initializer list handlerT() : isDrawing(false), drawFromCenter(true){}; @@ -136,19 +136,31 @@ class ROISelector { if (selectorParams.drawFromCenter) { - selectorParams.box.width = 2 * (x - selectorParams.center.x); - selectorParams.box.height = 2 * (y - selectorParams.center.y); - selectorParams.box.x = std::min( - std::max(selectorParams.center.x - selectorParams.box.width / 2.0, 0.), (double)imageSize.width); - selectorParams.box.y = std::min( - std::max(selectorParams.center.y - selectorParams.box.height / 2.0, 0.), (double)imageSize.height); + // limit half extends to imageSize + float halfWidth = std::min(std::min( + std::abs(x - selectorParams.startPos.x), + selectorParams.startPos.x), + imageSize.width - selectorParams.startPos.x); + float halfHeight = std::min(std::min( + std::abs(y - selectorParams.startPos.y), + selectorParams.startPos.y), + imageSize.height - selectorParams.startPos.y); + + selectorParams.box.width = halfWidth * 2; + selectorParams.box.height = halfHeight * 2; + selectorParams.box.x = selectorParams.startPos.x - halfWidth; + selectorParams.box.y = selectorParams.startPos.y - halfHeight; + } else { - selectorParams.box.width = std::max( - std::min(x - selectorParams.box.x, (double)imageSize.width - selectorParams.box.x), - selectorParams.box.x); - selectorParams.box.height = std::max( - std::min(y - selectorParams.box.y, (double)imageSize.height - selectorParams.box.y), - selectorParams.box.y); + // limit x and y to imageSize + int lx = std::min(std::max(x, 0), imageSize.width); + int by = std::min(std::max(y, 0), imageSize.height); + selectorParams.box.width = std::abs(lx - selectorParams.startPos.x); + selectorParams.box.height = std::abs(by - selectorParams.startPos.y); + selectorParams.box.x = std::min((float)lx, selectorParams.startPos.x); + selectorParams.box.y = std::min((float)by, selectorParams.startPos.y); } } break; @@ -157,7 +169,7 @@ class ROISelector case EVENT_LBUTTONDOWN: selectorParams.isDrawing = true; selectorParams.box = Rect2d(x, y, 0, 0); - selectorParams.center = Point2f((float)x, (float)y); + selectorParams.startPos = Point2f((float)x, (float)y); break; // cleaning up the selected bounding box From 960bb540ecdd8a2feed3cb06f305d8f315652c09 Mon Sep 17 00:00:00 2001 From: TheGoddessInari Date: Sun, 28 Jul 2019 10:21:15 -0700 Subject: [PATCH 2/4] Make sure to use defined(__GNUC__) instead of bare __GNUC__ in flann2 header. This fixes a compiler error on MSVC with Unreal Engine (at least). backport of commit: 4e998c9adeb8ec874d29a0ed5d450da3a9bdd0e8 --- modules/flann/include/opencv2/flann/dist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h index 0670122c16..4246a3dffc 100644 --- a/modules/flann/include/opencv2/flann/dist.h +++ b/modules/flann/include/opencv2/flann/dist.h @@ -441,7 +441,7 @@ struct Hamming result = vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),0); result += vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),2); } -#elif __GNUC__ +#elif defined(__GNUC__) { //for portability just use unsigned long -- and use the __builtin_popcountll (see docs for __builtin_popcountll) typedef unsigned long long pop_t; From 987bb2ca617eaab61a99da28273f513aef37665d Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Sat, 3 Aug 2019 12:53:38 -0700 Subject: [PATCH 3/4] Fix build for UWP backport of commit: f18cbd036af7b22017f5f964be6f398ccb0c1a57 --- cmake/OpenCVModule.cmake | 2 +- modules/core/src/utils/datafile.cpp | 2 +- modules/videoio/src/cap_ffmpeg.cpp | 2 +- modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index c2fda8fad6..3f7dfdc6d6 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -850,7 +850,7 @@ macro(ocv_create_module) set(the_module_target ${the_module}) endif() - if(WINRT) + if(WINRT AND BUILD_TESTS) # removing APPCONTAINER from modules to run from console # in case of usual starting of WinRT test apps output is missing # so starting of console version w/o APPCONTAINER is required to get test results diff --git a/modules/core/src/utils/datafile.cpp b/modules/core/src/utils/datafile.cpp index 257d27b738..088ad1ce79 100644 --- a/modules/core/src/utils/datafile.cpp +++ b/modules/core/src/utils/datafile.cpp @@ -108,7 +108,7 @@ static cv::String getModuleLocation(const void* addr) CV_UNUSED(addr); #ifdef _WIN32 HMODULE m = 0; -#if _WIN32_WINNT >= 0x0501 +#if _WIN32_WINNT >= 0x0501 && (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(addr), &m); diff --git a/modules/videoio/src/cap_ffmpeg.cpp b/modules/videoio/src/cap_ffmpeg.cpp index df7e44647b..67ee2e636d 100644 --- a/modules/videoio/src/cap_ffmpeg.cpp +++ b/modules/videoio/src/cap_ffmpeg.cpp @@ -80,7 +80,7 @@ static cv::Mutex _icvInitFFMPEG_mutex; static const HMODULE cv_GetCurrentModule() { HMODULE h = 0; -#if _WIN32_WINNT >= 0x0501 +#if _WIN32_WINNT >= 0x0501 && (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(cv_GetCurrentModule), &h); diff --git a/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp b/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp index 236e22766e..eccf97e979 100644 --- a/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp +++ b/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp @@ -94,7 +94,7 @@ Media::CaptureFrameGrabber::~CaptureFrameGrabber() void Media::CaptureFrameGrabber::ShowCameraSettings() { -#if WINAPI_FAMILY!=WINAPI_FAMILY_PHONE_APP +#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) && (WINAPI_FAMILY != WINAPI_FAMILY_PC_APP) if (_state == State::Started) { CameraOptionsUI::Show(_capture.Get()); From ca79f75b321c0641a17e5136e4dfa8d3022372e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Gurin?= Date: Mon, 5 Aug 2019 09:41:59 -0300 Subject: [PATCH 4/4] OpenCV.js docker container build instructions backport of commit: 59b0314a0ef49d407f78742fc44fdc19bd20bf0e --- .../js_setup/js_setup/js_setup.markdown | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/js_tutorials/js_setup/js_setup/js_setup.markdown b/doc/js_tutorials/js_setup/js_setup/js_setup.markdown index 5f6b43b167..5036fd1d97 100644 --- a/doc/js_tutorials/js_setup/js_setup/js_setup.markdown +++ b/doc/js_tutorials/js_setup/js_setup/js_setup.markdown @@ -7,6 +7,9 @@ Installing Emscripten [Emscripten](https://github.com/kripken/emscripten) is an LLVM-to-JavaScript compiler. We will use Emscripten to build OpenCV.js. +@note +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. + To Install Emscripten, follow instructions of [Emscripten SDK](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). For example: @@ -103,3 +106,25 @@ Building OpenCV.js from Source @note It requires `node` installed in your development environment. + +Building OpenCV.js with Docker +--------------------------------------- + +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. + +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: + +@code{.bash} +git clone https://github.com/opencv/opencv.git +cd opencv +docker run --rm --workdir /code -v "$PWD":/code "trzeci/emscripten:latest" python ./platforms/js/build_js.py build_js +@endcode + +In Windows use the following PowerShell command: + +@code{.bash} +docker run --rm --workdir /code -v "$(get-location):/code" "trzeci/emscripten:latest" python ./platforms/js/build_js.py build_js +@endcode + +@note +The example uses latest version of [trzeci/emscripten](https://hub.docker.com/r/trzeci/emscripten) docker container. At this time, the latest version works fine and is `trzeci/emscripten:sdk-tag-1.38.32-64bit`