Opening an OpenCV window in a Windows Runtime component (C++) for a UWP app

asked 2018-02-16 08:26:17 -0500

GregF458XVM gravatar image

I'm stuck with some linker errors when trying to call the imshow function in my WinRT component for a UWP app. The component simply calls imshow after a type conversion on the file name string, which is supposed to show the image in a new window.

This is a proof-of-concept to show that OpenCV can be used within a UWP app without using wrappers such as EmguCV. (In the Change Log for OpenCV, it says one of the versions includes UWP build support, but it's for phones only.)

On Debug x64 mode, calling imshow raises this exception: Exception thrown at 0x00007FFAAC1E3E1F (opencv_highgui310d.dll) in OpenCVImageViewerTest.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

This exception is raised on Release x64 mode: Unhandled exception at 0x00007FFAE6D7A478 (ucrtbase.dll) in OpenCVImageViewerTest.exe: An invalid parameter was passed to a function that considers invalid parameters fatal.

A few StackOverflow questions I came across mentioned something about library mismatches between debug and release versions of OpenCV and its corresponding libraries. However, I checked the Project Properties for my WinRT component for both versions, and the Additional Libraries I specified are the right versions.


#pragma once

// OpenCV Dependent Libraries
#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>

// WinRT Dependent Headers
#include <collection.h>
#include <ppl.h>
#include <amp.h>
#include <amp_math.h>

// OpenCV Namespace
using namespace cv;

namespace OpenCVImage
    // Have this class be compiled as a WinRT Component for a UWP app
    public ref class OpenCVImageOpener sealed
        void loadImage(Platform::String^ filename); // Loads image and displays it on the screen


// Microsoft Visual Studio friendly includes
#include "pch.h"

// C++ Standard Libraries
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <memory>
#include <cmath>

// Windows Runtime Component libraries
#include <ppltasks.h>
#include <concurrent_vector.h>

// Custom Header Files
#include "OpenCVImageOpener.h"

// Namespaces
using namespace OpenCVImage;
using namespace cv;
using namespace std;

using namespace concurrency;
using namespace Platform::Collections;
using namespace Windows::Foundation::Collections;
using namespace Windows::Foundation;
using namespace Windows::UI::Core;

void OpenCVImageOpener::loadImage(Platform::String^ filename) {
    // Debugging statements omitted for brevity

    std::wstring filenameBuffer(filename->Begin());
    string rawFilenameString(filenameBuffer.begin(), filenameBuffer.end());

    Mat image = imread(rawFilenameString.c_str());

    imshow("Test image", image); // Error occurs right here

The UWP app that calls this code is simply one screen with one button and an event listener.

edit retag flag offensive close merge delete



i have not tried (and i won't ever, brrr) but it seems, that:

berak gravatar imageberak ( 2018-02-17 04:52:27 -0500 )edit

I have tried the horror and ran away in agony x_x

StevenPuttemans gravatar imageStevenPuttemans ( 2018-02-19 03:46:39 -0500 )edit

So nobody is able to build opencv for winrt? I am on windows 10 and am not sure if this is even supported by OpenCV. See

ChrisVifzack gravatar imageChrisVifzack ( 2018-11-13 02:20:25 -0500 )edit

@ChrisVifzack -- assume, it's not maintained. also: focus on number crunching, not gui ....

berak gravatar imageberak ( 2018-11-13 02:25:20 -0500 )edit