Commit face0698 authored by Maxim Kostin's avatar Maxim Kostin

Added support for highgui module on WinRT 8.1+

Signed-off-by: 's avatarMaxim Kostin <v-maxkos@microsoft.com>
parent 8298644b
......@@ -29,6 +29,9 @@ file(GLOB highgui_ext_hdrs
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.h")
# Removing WinRT API headers by default
list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/highgui_winrt.hpp")
if(HAVE_QT5)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
......@@ -66,12 +69,23 @@ elseif(HAVE_QT)
if(${_have_flag})
set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS -Wno-missing-declarations)
endif()
elseif(WINRT AND NOT WINRT_8_0)
# Dependencies used by the implementation referenced
# below are not available on WinRT 8.0.
# Enabling it for WiRT 8.1+ only.
status(" ${name}: WinRT detected")
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_winrt.cpp)
elseif(WINRT)
if(NOT WINRT_8_0)
# Dependencies used by the implementation referenced
# below are not available on WinRT 8.0.
# Enabling it for WiRT 8.1+ only.
# WinRT 8.1+ detected. Adding WinRT API header.
status(" ${name}: WinRT detected. Adding WinRT API header")
list(APPEND highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/highgui_winrt.hpp")
list(APPEND highgui_srcs
${CMAKE_CURRENT_LIST_DIR}/src/window_winrt.cpp
${CMAKE_CURRENT_LIST_DIR}/src/window_winrt_bridge.cpp)
list(APPEND highgui_hdrs
${CMAKE_CURRENT_LIST_DIR}/src/window_winrt_bridge.hpp)
endif()
# libraries below are neither available nor required
# on ARM devices and/or Windows Phone
......@@ -81,6 +95,10 @@ elseif(WINRT AND NOT WINRT_8_0)
status(" ${name}: Windows Phone detected")
elseif(OpenCV_ARCH STREQUAL "ARM")
status(" ${name}: ARM detected")
if(WINRT_STORE)
list(REMOVE_ITEM HIGHGUI_LIBRARIES "ws2_32")
status(" ${name}: Removing 'ws2_32.lib'")
endif()
endif()
status(" ${name}: Removing 'comctl32.lib, gdi32.lib, ole32.lib, setupapi.lib'")
status(" ${name}: Leaving '${HIGHGUI_LIBRARIES}'")
......
......@@ -79,7 +79,7 @@ It provides easy interface to:
attached to the control panel is a trackbar, or the control panel is empty, a new buttonbar is
created. Then, a new button is attached to it.
See below the example used to generate the figure: :
See below the example used to generate the figure:
@code
int main(int argc, char *argv[])
int value = 50;
......@@ -122,6 +122,45 @@ It provides easy interface to:
}
@endcode
@defgroup highgui_winrt WinRT support
This figure explains new functionality implemented with WinRT GUI. The new GUI provides an Image control,
and a slider panel. Slider panel holds trackbars attached to it.
Sliders are attached below the image control. Every new slider is added below the previous one.
See below the example used to generate the figure:
@code
void sample_app::MainPage::ShowWindow()
{
static cv::String windowName("sample");
cv::winrt_initContainer(this->cvContainer);
cv::namedWindow(windowName); // not required
cv::Mat image = cv::imread("Assets/sample.jpg");
cv::Mat converted = cv::Mat(image.rows, image.cols, CV_8UC4);
cvtColor(image, converted, CV_BGR2BGRA);
cv::imshow(windowName, converted); // this will create window if it hasn't been created before
int state = 42;
cv::TrackbarCallback callback = [](int pos, void* userdata)
{
if (pos == 0) {
cv::destroyWindow(windowName);
}
};
cv::TrackbarCallback callbackTwin = [](int pos, void* userdata)
{
if (pos >= 70) {
cv::destroyAllWindows();
}
};
cv::createTrackbar("Sample trackbar", windowName, &state, 100, callback);
cv::createTrackbar("Twin brother", windowName, &state, 100, callbackTwin);
}
@endcode
@defgroup highgui_c C API
@}
*/
......
// highgui (UX) support for Windows Runtime
// Copyright (c) Microsoft Open Technologies, Inc.
// All rights reserved.
//
// (3 - clause BSD License)
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
// the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
// following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
// promote products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
using namespace Windows::UI::Xaml::Controls;
namespace cv
{
//! @addtogroup highgui_winrt
//! @{
/********************************** WinRT Specific API *************************************************/
/** @brief Initializes container component that will be used to hold generated window content.
@param container Container (Panel^) reference that will be used to hold generated window content: controls and image.
@note
Must be called to assign WinRT container that will hold created windows content.
*/
CV_EXPORTS void winrt_initContainer(::Windows::UI::Xaml::Controls::Panel^ container);
//! @} videoio_winrt
} // cv
\ No newline at end of file
......@@ -95,16 +95,18 @@
#define CV_WINDOW_MAGIC_VAL 0x00420042
#define CV_TRACKBAR_MAGIC_VAL 0x00420043
//Yannick Verdie 2010
//Yannick Verdie 2010, Max Kostin 2015
void cvSetModeWindow_W32(const char* name, double prop_value);
void cvSetModeWindow_GTK(const char* name, double prop_value);
void cvSetModeWindow_CARBON(const char* name, double prop_value);
void cvSetModeWindow_COCOA(const char* name, double prop_value);
void cvSetModeWindow_WinRT(const char* name, double prop_value);
double cvGetModeWindow_W32(const char* name);
double cvGetModeWindow_GTK(const char* name);
double cvGetModeWindow_CARBON(const char* name);
double cvGetModeWindow_COCOA(const char* name);
double cvGetModeWindow_WinRT(const char* name);
double cvGetPropWindowAutoSize_W32(const char* name);
double cvGetPropWindowAutoSize_GTK(const char* name);
......
......@@ -65,7 +65,10 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu
cvSetModeWindow_CARBON(name,prop_value);
#elif defined (HAVE_COCOA)
cvSetModeWindow_COCOA(name,prop_value);
#elif defined (WINRT)
cvSetModeWindow_WinRT(name, prop_value);
#endif
break;
case CV_WND_PROP_AUTOSIZE:
......@@ -104,6 +107,8 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
return cvGetModeWindow_CARBON(name);
#elif defined (HAVE_COCOA)
return cvGetModeWindow_COCOA(name);
#elif defined (WINRT)
return cvGetModeWindow_WinRT(name);
#else
return -1;
#endif
......
This diff is collapsed.
This diff is collapsed.
// highgui to XAML bridge for OpenCV
// Copyright (c) Microsoft Open Technologies, Inc.
// All rights reserved.
//
// (3 - clause BSD License)
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
// the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
// following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
// promote products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <map>
#include <opencv2\core.hpp>
using namespace Windows::UI::Xaml::Controls;
class CvWindow;
class CvTrackbar;
class HighguiBridge
{
public:
/** @brief Instantiates a Highgui singleton (Meyers type).
The function Instantiates a Highgui singleton (Meyers type) and returns reference to that instance.
*/
static HighguiBridge& getInstance();
/** @brief Finds window by name and returns the reference to it.
@param name Name of the window.
The function finds window by name and returns the reference to it. Returns nullptr
if window with specified name is not found or name argument is null.
*/
CvWindow* findWindowByName(cv::String name);
/** @brief Returns reference to the trackbar(slider) registered within window with a provided name.
@param name Name of the window.
The function returns reference to the trackbar(slider) registered within window with a provided name.
Returns nullptr if trackbar with specified name is not found or window reference is nullptr.
*/
CvTrackbar* findTrackbarByName(cv::String trackbarName, cv::String windowName);
/** @brief Converts cv::String to Platform::String.
@param name String to convert.
The function converts cv::String to Platform::String.
Returns nullptr if conversion fails.
*/
Platform::String^ convertString(cv::String name);
/** @brief Creates window if there is no window with this name, otherwise returns existing window.
@param name Window name.
The function creates window if there is no window with this name, otherwise returns existing window.
*/
CvWindow* namedWindow(cv::String name);
/** @brief Shows provided window.
The function shows provided window: makes provided window current, removes current container
contents and shows current window by putting it as a container content.
*/
void showWindow(CvWindow* window);
/** @brief Destroys window if there exists window with this name, otherwise does nothing.
@param name Window name.
The function destroys window if there exists window with this name, otherwise does nothing.
If window being destroyed is the current one, it will be hidden by clearing the window container.
*/
void destroyWindow(cv::String name);
/** @brief Destroys all windows.
The function destroys all windows.
*/
void destroyAllWindows();
/** @brief Assigns container used to display windows.
@param _container Container reference.
The function assigns container used to display windows.
*/
void setContainer(Windows::UI::Xaml::Controls::Panel^ _container);
private:
// Meyers singleton
HighguiBridge(const HighguiBridge &);
void operator=(HighguiBridge &);
HighguiBridge() {
windowsMap = new std::map<cv::String, CvWindow*>();
};
/** @brief Creates window if there is no window with this name.
@param name Window name.
The function creates window if there is no window with this name.
*/
CvWindow* createWindow(cv::String name);
/** @brief Cleans current container contents.
The function cleans current container contents.
*/
void cleanContainer();
// see https://msdn.microsoft.com/en-US/library/windows/apps/xaml/hh700103.aspx
// see https://msdn.microsoft.com/ru-ru/library/windows.foundation.collections.aspx
std::map<cv::String, CvWindow*>* windowsMap;
CvWindow* currentWindow;
// Holds current container/content to manipulate with
Windows::UI::Xaml::Controls::Panel^ container;
};
class CvTrackbar
{
public:
CvTrackbar(cv::String name, Slider^ slider, CvWindow* parent);
~CvTrackbar();
double getPosition();
void setPosition(double pos);
double getMaxPosition();
void setMaxPosition(double pos);
Slider^ getSlider();
void setSlider(Slider^ pos);
CvTrackbarCallback2 callback;
private:
cv::String name;
Slider^ slider;
CvWindow* parent;
};
class CvWindow
{
public:
CvWindow(cv::String name, int flag = CV_WINDOW_NORMAL);
~CvWindow();
/** @brief NOTE: prototype.
Should create button if there is no button with this name already.
*/
void createButton(cv::String name);
/** @brief Creates slider if there is no slider with this name already.
The function creates slider if there is no slider with this name already OR resets
provided values for the existing one.
*/
void createSlider(cv::String name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata);
/** @brief Updates window image.
@param src Image data object reference.
The function updates window image. If argument is null or image control is not found - does nothing.
*/
void updateImage(CvMat* arr);
/** @brief Returns reference to the trackbar(slider) registered within provided window.
@param name Name of the window.
The function returns reference to the trackbar(slider) registered within provided window.
Returns nullptr if trackbar with specified name is not found or window reference is nullptr.
*/
CvTrackbar* findTrackbarByName(cv::String name);
Page^ getPage();
private:
cv::String name;
// Holds image data in CV format
CvMat* imageData;
// Map of all sliders assigned to this window
std::map<cv::String, CvTrackbar*>* sliderMap;
// Window contents holder
Page^ page;
// Image control displayed by this window
Image^ imageControl;
// Container for sliders
Panel^ sliderPanel;
// Container for buttons
// TODO: prototype, not available via API
Panel^ buttonPanel;
// Holds image width to arrange other UI elements.
// Required since imageData->width value gets recalculated when processing
int imageWidth;
// Default markup for the container content allowing for proper components placement
static const Platform::String^ markupContent;
// Default Slider size, fallback solution for unexpected edge cases
static const double sliderDefaultWidth;
};
\ No newline at end of file
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