From 52100328d82d0502534323e9524a701baa3a1e2a Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 25 Oct 2024 22:32:44 +0300 Subject: [PATCH] WinRT/UWP build: fix some specific warnings --- cmake/OpenCVModule.cmake | 10 ------ modules/core/src/utils/datafile.cpp | 2 +- modules/highgui/src/window_winrt.cpp | 17 +++++++--- modules/highgui/src/window_winrt_bridge.cpp | 36 +++++++++++---------- modules/highgui/src/window_winrt_bridge.hpp | 3 +- modules/objdetect/src/face_detect.cpp | 2 +- modules/objdetect/src/face_recognize.cpp | 2 +- 7 files changed, 35 insertions(+), 37 deletions(-) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 5411a28c61..84e8216fe0 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -916,16 +916,6 @@ macro(ocv_create_module) POST_BUILD COMMAND link.exe /edit /APPCONTAINER:NO $(TargetPath)) endif() - - if("${the_module}" STREQUAL "opencv_ts") - # copy required dll files; WinRT apps need these dlls that are usually substituted by Visual Studio - # however they are not on path and need to be placed with executables to run from console w/o APPCONTAINER - add_custom_command(TARGET ${the_module} - POST_BUILD - COMMAND copy /y "\"$(VCInstallDir)redist\\$(PlatformTarget)\\Microsoft.VC$(PlatformToolsetVersion).CRT\\msvcp$(PlatformToolsetVersion).dll\"" "\"${CMAKE_BINARY_DIR}\\bin\\$(Configuration)\\msvcp$(PlatformToolsetVersion)_app.dll\"" - COMMAND copy /y "\"$(VCInstallDir)redist\\$(PlatformTarget)\\Microsoft.VC$(PlatformToolsetVersion).CRT\\msvcr$(PlatformToolsetVersion).dll\"" "\"${CMAKE_BINARY_DIR}\\bin\\$(Configuration)\\msvcr$(PlatformToolsetVersion)_app.dll\"" - COMMAND copy /y "\"$(VCInstallDir)redist\\$(PlatformTarget)\\Microsoft.VC$(PlatformToolsetVersion).CRT\\vccorlib$(PlatformToolsetVersion).dll\"" "\"${CMAKE_BINARY_DIR}\\bin\\$(Configuration)\\vccorlib$(PlatformToolsetVersion)_app.dll\"") - endif() endif() endmacro() diff --git a/modules/core/src/utils/datafile.cpp b/modules/core/src/utils/datafile.cpp index 3af83a5d8f..67cc2571ac 100644 --- a/modules/core/src/utils/datafile.cpp +++ b/modules/core/src/utils/datafile.cpp @@ -164,9 +164,9 @@ bool getBinLocation(std::string& dst) #ifdef _WIN32 bool getBinLocation(std::wstring& dst) { - void* addr = (void*)getModuleLocation; // using code address, doesn't work with static linkage! HMODULE m = 0; #if _WIN32_WINNT >= 0x0501 && (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) + void* addr = (void*)getModuleLocation; // using code address, doesn't work with static linkage! ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(addr), &m); diff --git a/modules/highgui/src/window_winrt.cpp b/modules/highgui/src/window_winrt.cpp index 93d14e3aef..9c80a52941 100644 --- a/modules/highgui/src/window_winrt.cpp +++ b/modules/highgui/src/window_winrt.cpp @@ -41,10 +41,13 @@ __FILE__, __LINE__ ); \ } +#ifdef CV_ERROR +#undef CV_ERROR #define CV_ERROR( Code, Msg ) \ { \ cvError( (Code), cvFuncName, Msg, __FILE__, __LINE__ ); \ }; +#endif /********************************** WinRT Specific API Implementation ******************************************/ @@ -86,6 +89,7 @@ CV_IMPL void cvShowImage(const char* name, const CvArr* arr) CV_IMPL int cvNamedWindow(const char* name, int flags) { + CV_UNUSED(flags); CV_FUNCNAME("cvNamedWindow"); if (!name) @@ -116,8 +120,6 @@ CV_IMPL int cvCreateTrackbar2(const char* trackbar_name, const char* window_name { CV_FUNCNAME("cvCreateTrackbar2"); - int pos = 0; - if (!window_name || !trackbar_name) CV_ERROR(cv::Error::StsNullPtr, "NULL window or trackbar name"); @@ -197,7 +199,7 @@ CV_IMPL int cvGetTrackbarPos(const char* trackbar_name, const char* window_name) CvTrackbar* trackbar = HighguiBridge::getInstance().findTrackbarByName(trackbar_name, window_name); if (trackbar) - pos = trackbar->getPosition(); + pos = (int)trackbar->getPosition(); return pos; } @@ -209,11 +211,11 @@ CV_IMPL int cvWaitKey(int delay) CV_WINRT_NO_GUI_ERROR("cvWaitKey"); // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms724411(v=vs.85).aspx - int time0 = GetTickCount64(); + //int time0 = GetTickCount64(); for (;;) { - CvWindow* window; + // CvWindow* window; if (delay <= 0) { @@ -224,6 +226,7 @@ CV_IMPL int cvWaitKey(int delay) CV_IMPL void cvSetMouseCallback(const char* window_name, CvMouseCallback on_mouse, void* param) { + CV_UNUSED(on_mouse); CV_UNUSED(param); CV_WINRT_NO_GUI_ERROR("cvSetMouseCallback"); CV_FUNCNAME("cvSetMouseCallback"); @@ -242,11 +245,13 @@ CV_IMPL void cvSetMouseCallback(const char* window_name, CvMouseCallback on_mous CV_IMPL void cvMoveWindow(const char* name, int x, int y) { + CV_UNUSED(name); CV_UNUSED(x); CV_UNUSED(y); CV_WINRT_NO_GUI_ERROR("cvMoveWindow"); } CV_IMPL void cvResizeWindow(const char* name, int width, int height) { + CV_UNUSED(name); CV_UNUSED(width); CV_UNUSED(height); CV_WINRT_NO_GUI_ERROR("cvResizeWindow"); } @@ -269,10 +274,12 @@ CV_IMPL const char* cvGetWindowName(void*) } void cvSetModeWindow_WinRT(const char* name, double prop_value) { + CV_UNUSED(name); CV_UNUSED(prop_value); CV_WINRT_NO_GUI_ERROR("cvSetModeWindow"); } double cvGetModeWindow_WinRT(const char* name) { + CV_UNUSED(name); CV_WINRT_NO_GUI_ERROR("cvGetModeWindow"); return cv::Error::StsNotImplemented; } diff --git a/modules/highgui/src/window_winrt_bridge.cpp b/modules/highgui/src/window_winrt_bridge.cpp index 6057f2d5b4..221ed8dc9a 100644 --- a/modules/highgui/src/window_winrt_bridge.cpp +++ b/modules/highgui/src/window_winrt_bridge.cpp @@ -64,9 +64,9 @@ HighguiBridge& HighguiBridge::getInstance() return instance; } -void HighguiBridge::setContainer(Windows::UI::Xaml::Controls::Panel^ container) +void HighguiBridge::setContainer(Windows::UI::Xaml::Controls::Panel^ container_) { - this->container = container; + this->container = container_; } CvWindow* HighguiBridge::findWindowByName(cv::String name) @@ -190,9 +190,9 @@ void CvTrackbar::setMinPosition(double pos) slider->Minimum = pos; } -void CvTrackbar::setSlider(Slider^ slider) { - if (slider) - this->slider = slider; +void CvTrackbar::setSlider(Slider^ slider_) { + if (slider_) + this->slider = slider_; } double CvTrackbar::getPosition() @@ -219,6 +219,7 @@ Slider^ CvTrackbar::getSlider() CvWindow::CvWindow(cv::String name, int flags) : name(name) { + CV_UNUSED(flags); this->page = (Page^)Windows::UI::Xaml::Markup::XamlReader::Load(const_cast(markupContent)); this->sliderMap = new std::map(); @@ -246,14 +247,15 @@ CvWindow::CvWindow(cv::String name, int flags) : name(name) CvWindow::~CvWindow() {} -void CvWindow::createSlider(cv::String name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata) +void CvWindow::createSlider(cv::String name_, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata) { - CvTrackbar* trackbar = findTrackbarByName(name); + CV_UNUSED(userdata); + CvTrackbar* trackbar = findTrackbarByName(name_); // Creating slider if name is new or reusing the existing one Slider^ slider = !trackbar ? ref new Slider() : trackbar->getSlider(); - slider->Header = HighguiBridge::getInstance().convertString(name); + slider->Header = HighguiBridge::getInstance().convertString(name_); // Making slider the same size as the image control or setting minimal size. // This is added to cover potential edge cases because: @@ -282,26 +284,26 @@ void CvWindow::createSlider(cv::String name, int* val, int count, CvTrackbarCall if (!sliderPanel) return; // Adding slider to the list for current window - CvTrackbar* trackbar = new CvTrackbar(name, slider, this); - trackbar->callback = on_notify; + CvTrackbar* trackbar_ = new CvTrackbar(name_, slider, this); + trackbar_->callback = on_notify; slider->ValueChanged += ref new Controls::Primitives::RangeBaseValueChangedEventHandler( [=](Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e) { Slider^ slider = (Slider^)sender; - trackbar->callback(slider->Value, nullptr); + trackbar_->callback((int)slider->Value, nullptr); }); - this->sliderMap->insert(std::pair(name, trackbar)); + this->sliderMap->insert(std::pair(name_, trackbar_)); // Adding slider to the window sliderPanel->Children->Append(slider); } } -CvTrackbar* CvWindow::findTrackbarByName(cv::String name) +CvTrackbar* CvWindow::findTrackbarByName(cv::String name_) { - auto search = sliderMap->find(name); + auto search = sliderMap->find(name_); if (search != sliderMap->end()) { return search->second; } @@ -342,12 +344,12 @@ Page^ CvWindow::getPage() } //TODO: prototype, not in use yet -void CvWindow::createButton(cv::String name) +void CvWindow::createButton(cv::String name_) { if (!buttonPanel) return; Button^ b = ref new Button(); - b->Content = HighguiBridge::getInstance().convertString(name); + b->Content = HighguiBridge::getInstance().convertString(name_); b->Width = 260; b->Height = 80; b->Click += ref new Windows::UI::Xaml::RoutedEventHandler( @@ -361,4 +363,4 @@ void CvWindow::createButton(cv::String name) buttonPanel->Children->Append(b); } -// end \ No newline at end of file +// end diff --git a/modules/highgui/src/window_winrt_bridge.hpp b/modules/highgui/src/window_winrt_bridge.hpp index 25f4aef8ed..03f0bd6e06 100644 --- a/modules/highgui/src/window_winrt_bridge.hpp +++ b/modules/highgui/src/window_winrt_bridge.hpp @@ -113,7 +113,6 @@ private: // Meyers singleton HighguiBridge(const HighguiBridge &); - void operator=(HighguiBridge &); HighguiBridge() { windowsMap = new std::map(); }; @@ -232,4 +231,4 @@ private: // Default Slider size, fallback solution for unexpected edge cases static const double sliderDefaultWidth; -}; \ No newline at end of file +}; diff --git a/modules/objdetect/src/face_detect.cpp b/modules/objdetect/src/face_detect.cpp index 441c55e788..5aa5357f97 100644 --- a/modules/objdetect/src/face_detect.cpp +++ b/modules/objdetect/src/face_detect.cpp @@ -309,7 +309,7 @@ Ptr FaceDetectorYN::create(const String& framework, #ifdef HAVE_OPENCV_DNN return makePtr(framework, bufferModel, bufferConfig, input_size, score_threshold, nms_threshold, top_k, backend_id, target_id); #else - CV_UNUSED(bufferModel); CV_UNUSED(bufferConfig); CV_UNUSED(input_size); CV_UNUSED(score_threshold); CV_UNUSED(nms_threshold); CV_UNUSED(top_k); CV_UNUSED(backend_id); CV_UNUSED(target_id); + CV_UNUSED(framework); CV_UNUSED(bufferModel); CV_UNUSED(bufferConfig); CV_UNUSED(input_size); CV_UNUSED(score_threshold); CV_UNUSED(nms_threshold); CV_UNUSED(top_k); CV_UNUSED(backend_id); CV_UNUSED(target_id); CV_Error(cv::Error::StsNotImplemented, "cv::FaceDetectorYN requires enabled 'dnn' module."); #endif } diff --git a/modules/objdetect/src/face_recognize.cpp b/modules/objdetect/src/face_recognize.cpp index a5f4641da3..b024c787eb 100644 --- a/modules/objdetect/src/face_recognize.cpp +++ b/modules/objdetect/src/face_recognize.cpp @@ -210,7 +210,7 @@ Ptr FaceRecognizerSF::create(const String& framework, #ifdef HAVE_OPENCV_DNN return makePtr(framework, bufferModel, bufferConfig, backend_id, target_id); #else - CV_UNUSED(bufferModel); CV_UNUSED(bufferConfig); CV_UNUSED(backend_id); CV_UNUSED(target_id); + CV_UNUSED(framework); CV_UNUSED(bufferModel); CV_UNUSED(bufferConfig); CV_UNUSED(backend_id); CV_UNUSED(target_id); CV_Error(cv::Error::StsNotImplemented, "cv::FaceRecognizerSF requires enabled 'dnn' module"); #endif }