WinRT glue for video I/O
Overview
// enums enum { cv::@105::OPEN_CAMERA = 300, cv::@105::CLOSE_CAMERA, cv::@105::UPDATE_IMAGE_ELEMENT, cv::@105::SHOW_TRACKBAR, }; // global functions void cv::winrt_imshow(); void cv::winrt_onVisibilityChanged(bool visible); void cv::winrt_setFrameContainer(::Windows::UI::Xaml::Controls::Image^ image); template <typename ... Args> void cv::winrt_startMessageLoop( std::function<void(Args...)>&& callback, Args... args ); template <typename ... Args> void cv::winrt_startMessageLoop( void callback Args..., Args... args ); template void cv::winrt_startMessageLoop(void callback void);
Detailed Documentation
Global Functions
void cv::winrt_imshow()
Must be called to update attached image source. Code sample is available for winrt_startMessageLoop().
void cv::winrt_onVisibilityChanged(bool visible)
Must be called from WinRT specific callback to handle image grabber state. Here is how the class can be used:
MainPage::MainPage() { // ... Window::Current->VisibilityChanged += ref new Windows::UI::Xaml::WindowVisibilityChangedEventHandler(this, &Application::MainPage::OnVisibilityChanged); // ... } void Application::MainPage::OnVisibilityChanged(Platform::Object ^sender, Windows::UI::Core::VisibilityChangedEventArgs ^e) { cv::winrt_onVisibilityChanged(e->Visible); }
void cv::winrt_setFrameContainer(::Windows::UI::Xaml::Controls::Image^ image)
Must be called to assign WinRT control holding image you’re working with. Code sample is available for winrt_startMessageLoop().
template void cv::winrt_startMessageLoop(void callback void)
Starts (1) frame-grabbing loop and (2) message loop
Function passed as an argument must implement common OCV reading frames pattern (see cv::VideoCapture documentation) AND call cv::winrt_imgshow().
Message processing loop required to overcome WinRT container and type conversion restrictions. OCV provides default implementation Here is how the class can be used:
void cvMain() { Mat frame; VideoCapture cam; cam.open(0); while (1) { cam >> frame; // don't reprocess the same frame again if (!cam.grab()) continue; // your processing logic goes here // obligatory step to get XAML image component updated winrt_imshow(); } } MainPage::MainPage() { InitializeComponent(); cv::winrt_setFrameContainer(cvImage); cv::winrt_startMessageLoop(cvMain); }