1 // 2 // MainPage.xaml.cpp 3 // Implementation of the MainPage class. 4 // 5 6 #include "pch.h" 7 #include "MainPage.xaml.h" 8 9 #include <opencv2/core.hpp> 10 #include <opencv2/imgproc.hpp> 11 #include <opencv2/features2d.hpp> 12 #include <opencv2/videoio.hpp> 13 #include <opencv2/videoio/cap_winrt.hpp> 14 15 using namespace video_capture_xaml; 16 17 using namespace Platform; 18 using namespace Windows::Foundation; 19 using namespace Windows::Foundation::Collections; 20 using namespace Windows::UI::Xaml; 21 using namespace Windows::UI::Xaml::Controls; 22 using namespace Windows::UI::Xaml::Controls::Primitives; 23 using namespace Windows::UI::Xaml::Data; 24 using namespace Windows::UI::Xaml::Input; 25 using namespace Windows::UI::Xaml::Media; 26 using namespace Windows::UI::Xaml::Navigation; 27 28 // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 29 30 using namespace ::Windows::Foundation; 31 using namespace Windows::UI::Xaml::Media::Imaging; 32 33 namespace video_capture_xaml 34 { 35 // nb. implemented in main.cpp 36 void cvMain(); 37 38 MainPage::MainPage() 39 { 40 InitializeComponent(); 41 42 Window::Current->VisibilityChanged += ref new Windows::UI::Xaml::WindowVisibilityChangedEventHandler(this, &video_capture_xaml::MainPage::OnVisibilityChanged); 43 44 // attach XAML elements 45 cv::winrt_setFrameContainer(cvImage); 46 47 // start (1) frame-grabbing loop and (2) message loop 48 // 49 // 1. Function passed as an argument must implement common OCV reading frames 50 // pattern (see cv::VideoCapture documentation) AND call cv::winrt_imgshow(). 51 // 2. Message processing loop required to overcome WinRT container and type 52 // conversion restrictions. OCV provides default implementation 53 cv::winrt_startMessageLoop(cvMain); 54 } 55 } 56 57 void video_capture_xaml::MainPage::OnVisibilityChanged(Platform::Object ^sender, 58 Windows::UI::Core::VisibilityChangedEventArgs ^e) 59 { 60 cv::winrt_onVisibilityChanged(e->Visible); 61 } 62