diff --git a/.gitignore b/.gitignore index 228365d9e..039d2400a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ Thumbs.db tags tegra/ bin/ -CMakeFiles/ *.sdf *.opensdf *.obj @@ -17,3 +16,9 @@ CMakeFiles/ *.depend *.rule *.tmp +*/debug +*/CMakeFiles +CMakeCache.txt +*.suo +*.log +*.tlog \ No newline at end of file diff --git a/3rdparty/libjpeg/CMakeLists.txt b/3rdparty/libjpeg/CMakeLists.txt index 65a9d1c8a..d79f00ada 100644 --- a/3rdparty/libjpeg/CMakeLists.txt +++ b/3rdparty/libjpeg/CMakeLists.txt @@ -15,6 +15,13 @@ else() ocv_list_filterout(lib_srcs jmemnobs.c) endif() +if(WINRT) + add_definitions(-DNO_GETENV) + get_directory_property( DirDefs COMPILE_DEFINITIONS ) + message(STATUS "Adding NO_GETENV to compiler definitions for WINRT:") + message(STATUS " COMPILE_DEFINITIONS = ${DirDefs}") +endif() + # ---------------------------------------------------------------------------------- # Define the library target: # ---------------------------------------------------------------------------------- diff --git a/3rdparty/libtiff/CMakeLists.txt b/3rdparty/libtiff/CMakeLists.txt index ad8a46618..b7739e0e4 100644 --- a/3rdparty/libtiff/CMakeLists.txt +++ b/3rdparty/libtiff/CMakeLists.txt @@ -17,7 +17,7 @@ check_include_file(string.h HAVE_STRING_H) check_include_file(sys/types.h HAVE_SYS_TYPES_H) check_include_file(unistd.h HAVE_UNISTD_H) -if(WIN32) +if(WIN32 AND NOT WINRT) set(USE_WIN32_FILEIO 1) endif() @@ -79,7 +79,7 @@ set(lib_srcs "${CMAKE_CURRENT_BINARY_DIR}/tif_config.h" ) -if(WIN32) +if(WIN32 AND NOT WINRT) list(APPEND lib_srcs tif_win32.c) else() list(APPEND lib_srcs tif_unix.c) diff --git a/modules/imgcodecs/CMakeLists.txt b/modules/imgcodecs/CMakeLists.txt index 50e2d5da6..6d565217a 100644 --- a/modules/imgcodecs/CMakeLists.txt +++ b/modules/imgcodecs/CMakeLists.txt @@ -1,7 +1,3 @@ -if(WINRT) - ocv_module_disable(imgcodecs) -endif() - set(the_description "Image codecs") ocv_add_module(imgcodecs opencv_imgproc WRAP java python) diff --git a/samples/winrt/OcvImageProcessing/OcvImageProcessing/MainPage.xaml.cpp b/samples/winrt/OcvImageProcessing/OcvImageProcessing/MainPage.xaml.cpp index 2e91eb156..fc7440fb2 100644 --- a/samples/winrt/OcvImageProcessing/OcvImageProcessing/MainPage.xaml.cpp +++ b/samples/winrt/OcvImageProcessing/OcvImageProcessing/MainPage.xaml.cpp @@ -10,6 +10,10 @@ #include #include #include +#include +#include + +#include using namespace OcvImageProcessing; @@ -18,6 +22,7 @@ using namespace concurrency; using namespace Platform; using namespace Windows::Foundation; using namespace Windows::Storage::Streams; +using namespace Windows::Storage; using namespace Windows::UI::Xaml::Media::Imaging; using namespace Windows::Graphics::Imaging; using namespace Windows::Foundation::Collections; @@ -37,6 +42,17 @@ MainPage::MainPage() { InitializeComponent(); +#ifdef __OPENCV_IMGCODECS_HPP__ + + // Image loading OpenCV way ... way more simple + cv::Mat image = cv::imread("Assets/Lena.png"); + Lena = cv::Mat(image.rows, image.cols, CV_8UC4); + cvtColor(image, Lena, CV_BGR2BGRA); + UpdateImage(Lena); + +#else + + // Image loading WinRT way RandomAccessStreamReference^ streamRef = RandomAccessStreamReference::CreateFromUri(InputImageUri); task (streamRef->OpenReadAsync()). @@ -68,6 +84,67 @@ MainPage::MainPage() memcpy(Lena.data, srcPixels->Data, 4*frameWidth*frameHeight); UpdateImage(Lena); }); + +#endif +} + +/// +/// Temporary file creation example. Will be created in WinRT application temporary directory +/// which usually is "C:\Users\{username}\AppData\Local\Packages\{package_id}\TempState\{random_name}.{suffix}" +/// +/// Temporary file suffix, e.g. "tmp" +std::string OcvImageProcessing::MainPage::CreateTempFile(const std::string &suffix) { + return cv::tempfile(suffix.c_str()); +} + +/// +/// Creating/writing a file in the application local directory +/// +/// Image to save +bool OcvImageProcessing::MainPage::SaveImage(cv::Mat image) { + StorageFolder^ localFolderRT = ApplicationData::Current->LocalFolder; + cv::String localFile = ConvertPath(ApplicationData::Current->LocalFolder->Path) + "\\Lena.png"; + + return cv::imwrite(localFile, image); +} + +/// +/// Getting std::string from managed string via std::wstring. +/// Provides an example of three ways to do it. +/// Can't use this one: https://msdn.microsoft.com/en-us/library/bb384865.aspx, not available on WinRT. +/// +/// Path to be converted +cv::String OcvImageProcessing::MainPage::ConvertPath(Platform::String^ path) { + std::wstring localPathW(path->Begin()); + + // Opt #1 + //std::string localPath(localPathW.begin(), localPathW.end()); + + // Opt #2 + //std::string localPath(StrToWStr(localPathW)); + + // Opt #3 + size_t outSize = localPathW.length() + 1; + char* localPathC = new char[outSize]; + size_t charsConverted = 0; + wcstombs_s(&charsConverted, localPathC, outSize, localPathW.c_str(), localPathW.length()); + cv::String localPath(localPathC); + + // Implicit conversion from std::string to cv::String + return localPath; +} + +std::string OcvImageProcessing::MainPage::StrToWStr(const std::wstring &input) { + if (input.empty()) { + return std::string(); + } + + int size = WideCharToMultiByte(CP_UTF8, 0, &input[0], (int)input.size(), NULL, 0, NULL, NULL); + std::string result(size, 0); + + WideCharToMultiByte(CP_UTF8, 0, &input[0], (int)input.size(), &result[0], size, NULL, NULL); + + return result; } /// @@ -91,15 +168,16 @@ void OcvImageProcessing::MainPage::UpdateImage(const cv::Mat& image) // Obtain IBufferByteAccess ComPtr pBufferByteAccess; - ComPtr pBuffer((IUnknown*)buffer); + ComPtr pBuffer((IInspectable*)buffer); pBuffer.As(&pBufferByteAccess); // Get pointer to pixel bytes pBufferByteAccess->Buffer(&dstPixels); - memcpy(dstPixels, image.data, 4*image.cols*image.rows); + memcpy(dstPixels, image.data, image.step.buf[1]*image.cols*image.rows); // Set the bitmap to the Image element - PreviewWidget->Source = bitmap;} + PreviewWidget->Source = bitmap; +} cv::Mat OcvImageProcessing::MainPage::ApplyGrayFilter(const cv::Mat& image) diff --git a/samples/winrt/OcvImageProcessing/OcvImageProcessing/MainPage.xaml.h b/samples/winrt/OcvImageProcessing/OcvImageProcessing/MainPage.xaml.h index 79c1ac74c..bb7c4c33d 100644 --- a/samples/winrt/OcvImageProcessing/OcvImageProcessing/MainPage.xaml.h +++ b/samples/winrt/OcvImageProcessing/OcvImageProcessing/MainPage.xaml.h @@ -39,6 +39,11 @@ namespace OcvImageProcessing cv::Mat ApplySepiaFilter(const cv::Mat& image); void UpdateImage(const cv::Mat& image); + std::string CreateTempFile(const std::string &suffix); + bool SaveImage(cv::Mat image); + + std::string StrToWStr(const std::wstring &wstr); + cv::String ConvertPath(Platform::String^ path); cv::Mat Lena; unsigned int frameWidth, frameHeight; diff --git a/samples/winrt/OcvImageProcessing/OcvImageProcessing/opencv.props b/samples/winrt/OcvImageProcessing/OcvImageProcessing/opencv.props index 40eaffd1f..64b0ac98a 100644 --- a/samples/winrt/OcvImageProcessing/OcvImageProcessing/opencv.props +++ b/samples/winrt/OcvImageProcessing/OcvImageProcessing/opencv.props @@ -17,6 +17,9 @@ true + + true + true @@ -33,7 +36,7 @@ - opencv_core300$(DebugSuffix).lib;opencv_imgproc300$(DebugSuffix).lib;opencv_features2d300$(DebugSuffix).lib;opencv_flann300$(DebugSuffix).lib;opencv_ml300$(DebugSuffix).lib;%(AdditionalDependencies) + opencv_core300$(DebugSuffix).lib;opencv_imgproc300$(DebugSuffix).lib;opencv_features2d300$(DebugSuffix).lib;opencv_flann300$(DebugSuffix).lib;opencv_ml300$(DebugSuffix).lib;opencv_imgcodecs300$(DebugSuffix).lib;%(AdditionalDependencies) $(OpenCV_Lib);%(AdditionalLibraryDirectories);