Here is the content of my MainPage.cpp
//
// MainPage.xaml.cpp
// Implementation of the MainPage class.
//
#include “pch.h”
#include “MainPage.xaml.h”
#include <opencv2\core.hpp>
#include <opencv2\imgcodecs.hpp>
#include <opencv2\imgproc.hpp>
#include <robuffer.h>
using namespace CVProj;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::Storage::Streams;
using namespace Microsoft::WRL;
MainPage::MainPage()
{
InitializeComponent();
cv::Mat input;
input = cv::imread(“Image file from the ‘Assets’ folder of your project.“);
cv::Mat img = cv::Mat(input.rows, input.cols, CV_8UC4);
cv::cvtColor(input, img, CV_BGR2BGRA);
cv::resize(img, img, cv::Size(640, 480));
BitmapImage ^bitImg = ref new BitmapImage();
WriteableBitmap;
WriteableBitmap^ wbmp = ref new WriteableBitmap(img.cols, img.rows);
IBuffer^ buffer = wbmp->PixelBuffer;
unsigned char* dstPixels;
ComPtr<IBufferByteAccess> pBufferByteAccess;
ComPtr<IInspectable> pBuffer((IInspectable*)buffer);
pBuffer.As(&pBufferByteAccess);
pBufferByteAccess->Buffer(&dstPixels);
memcpy(dstPixels, img.data, img.step.buf[1] * img.cols * img.rows);
cvImg->Source = wbmp;
}