Commit 365323af authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #15234 from alalek:backport

parents 99f709ca ca79f75b
...@@ -850,7 +850,7 @@ macro(ocv_create_module) ...@@ -850,7 +850,7 @@ macro(ocv_create_module)
set(the_module_target ${the_module}) set(the_module_target ${the_module})
endif() endif()
if(WINRT) if(WINRT AND BUILD_TESTS)
# removing APPCONTAINER from modules to run from console # removing APPCONTAINER from modules to run from console
# in case of usual starting of WinRT test apps output is missing # 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 # so starting of console version w/o APPCONTAINER is required to get test results
......
...@@ -7,6 +7,9 @@ Installing Emscripten ...@@ -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. [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). To Install Emscripten, follow instructions of [Emscripten SDK](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html).
For example: For example:
...@@ -103,3 +106,25 @@ Building OpenCV.js from Source ...@@ -103,3 +106,25 @@ Building OpenCV.js from Source
@note @note
It requires `node` installed in your development environment. 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`
...@@ -108,7 +108,7 @@ static cv::String getModuleLocation(const void* addr) ...@@ -108,7 +108,7 @@ static cv::String getModuleLocation(const void* addr)
CV_UNUSED(addr); CV_UNUSED(addr);
#ifdef _WIN32 #ifdef _WIN32
HMODULE m = 0; 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, ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCTSTR>(addr), reinterpret_cast<LPCTSTR>(addr),
&m); &m);
......
...@@ -441,7 +441,7 @@ struct Hamming ...@@ -441,7 +441,7 @@ struct Hamming
result = vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),0); result = vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),0);
result += vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),2); 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) //for portability just use unsigned long -- and use the __builtin_popcountll (see docs for __builtin_popcountll)
typedef unsigned long long pop_t; typedef unsigned long long pop_t;
......
...@@ -106,10 +106,10 @@ class ROISelector ...@@ -106,10 +106,10 @@ class ROISelector
bool isDrawing; bool isDrawing;
Rect2d box; Rect2d box;
Mat image; Mat image;
Point2f startPos;
// parameters for drawing from the center // parameters for drawing from the center
bool drawFromCenter; bool drawFromCenter;
Point2f center;
// initializer list // initializer list
handlerT() : isDrawing(false), drawFromCenter(true){}; handlerT() : isDrawing(false), drawFromCenter(true){};
...@@ -136,19 +136,31 @@ class ROISelector ...@@ -136,19 +136,31 @@ class ROISelector
{ {
if (selectorParams.drawFromCenter) if (selectorParams.drawFromCenter)
{ {
selectorParams.box.width = 2 * (x - selectorParams.center.x); // limit half extends to imageSize
selectorParams.box.height = 2 * (y - selectorParams.center.y); float halfWidth = std::min(std::min(
selectorParams.box.x = std::min( std::abs(x - selectorParams.startPos.x),
std::max(selectorParams.center.x - selectorParams.box.width / 2.0, 0.), (double)imageSize.width); selectorParams.startPos.x),
selectorParams.box.y = std::min( imageSize.width - selectorParams.startPos.x);
std::max(selectorParams.center.y - selectorParams.box.height / 2.0, 0.), (double)imageSize.height); 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 else
{ {
selectorParams.box.width = std::max( // limit x and y to imageSize
std::min(x - selectorParams.box.x, (double)imageSize.width - selectorParams.box.x), - selectorParams.box.x); int lx = std::min(std::max(x, 0), imageSize.width);
selectorParams.box.height = std::max( int by = std::min(std::max(y, 0), imageSize.height);
std::min(y - selectorParams.box.y, (double)imageSize.height - selectorParams.box.y), - selectorParams.box.y); 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; break;
...@@ -157,7 +169,7 @@ class ROISelector ...@@ -157,7 +169,7 @@ class ROISelector
case EVENT_LBUTTONDOWN: case EVENT_LBUTTONDOWN:
selectorParams.isDrawing = true; selectorParams.isDrawing = true;
selectorParams.box = Rect2d(x, y, 0, 0); selectorParams.box = Rect2d(x, y, 0, 0);
selectorParams.center = Point2f((float)x, (float)y); selectorParams.startPos = Point2f((float)x, (float)y);
break; break;
// cleaning up the selected bounding box // cleaning up the selected bounding box
......
...@@ -80,7 +80,7 @@ static cv::Mutex _icvInitFFMPEG_mutex; ...@@ -80,7 +80,7 @@ static cv::Mutex _icvInitFFMPEG_mutex;
static const HMODULE cv_GetCurrentModule() static const HMODULE cv_GetCurrentModule()
{ {
HMODULE h = 0; 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, ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCTSTR>(cv_GetCurrentModule), reinterpret_cast<LPCTSTR>(cv_GetCurrentModule),
&h); &h);
......
...@@ -94,7 +94,7 @@ Media::CaptureFrameGrabber::~CaptureFrameGrabber() ...@@ -94,7 +94,7 @@ Media::CaptureFrameGrabber::~CaptureFrameGrabber()
void Media::CaptureFrameGrabber::ShowCameraSettings() 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) if (_state == State::Started)
{ {
CameraOptionsUI::Show(_capture.Get()); CameraOptionsUI::Show(_capture.Get());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment