Home | History | Annotate | Download | only in video_capture_xaml.WindowsPhone
      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     void video_capture_xaml::MainPage::OnVisibilityChanged(Platform::Object ^sender,
     57         Windows::UI::Core::VisibilityChangedEventArgs ^e)
     58     {
     59         cv::winrt_onVisibilityChanged(e->Visible);
     60     }
     61 
     62     /// <summary>
     63     /// Invoked when this page is about to be displayed in a Frame.
     64     /// </summary>
     65     /// <param name="e">Event data that describes how this page was reached.  The Parameter
     66     /// property is typically used to configure the page.</param>
     67     void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
     68     {
     69         (void)e;	// Unused parameter
     70 
     71         // TODO: Prepare page for display here.
     72 
     73         // TODO: If your application contains multiple pages, ensure that you are
     74         // handling the hardware Back button by registering for the
     75         // Windows::Phone::UI::Input::HardwareButtons.BackPressed event.
     76         // If you are using the NavigationHelper provided by some templates,
     77         // this event is handled for you.
     78     }
     79 }