我的目標是做一個對象跟蹤。WinRT C++(Win10),opencv HSV色彩空間,圖像顯示,工件
我有一個UWP c#應用程序和鏈接的c + + windows運行時組件。在那裏我可以獲得訪問opencv。
- 在c#中,MediaCapture返回SoftwareBitmap。
- 然後我將SoftwareBitmap傳遞給C++並將其轉換爲opencv的Mat。
- 然後
cvtColor(cvFrame, cvFrame, COLOR_BGR2HSV);
- ,然後再轉換回SoftwareBitmap,與BitmapPixelFormat :: Bgra8和BitmapAlphaMode(僅Bgra8由軟件位圖接受)::忽略
而且有我有什麼screen
如果我跳過cvtColor
一部分,只是轉換爲CV ::墊和回SoftwareBitmap,我已經有了一個不錯的圖像結果...
我知道圖片頻道存在問題,但我失去了在哪裏挖。 我認爲cvtColor
之後的cv :: Mat是正確的......但是我想看看圖片創建的中間步驟。 (HSV,門檻,然後結果)
任何意見,將不勝感激。
PS 我試過imwrite
但沒有創建文件。自/至
Mat Convert(SoftwareBitmap^ from)
{
BitmapBuffer^ bmpBuffer = from->LockBuffer(BitmapBufferAccessMode::ReadWrite);
unsigned char* pPixels = GetPointerToPixelData(bmpBuffer->CreateReference());
Mat mat(from->PixelHeight, from->PixelWidth, CV_8UC4);
memcpy(mat.data, pPixels, 4 * from->PixelHeight * from->PixelWidth);
return mat;
}
SoftwareBitmap^ Convert(Mat from)
{
SoftwareBitmap^ sBitmap = ref new SoftwareBitmap(BitmapPixelFormat::Bgra8, from.cols, from.rows, BitmapAlphaMode::Ignore);
BitmapBuffer^ bmpBuffer = sBitmap->LockBuffer(BitmapBufferAccessMode::ReadWrite);
auto reference = bmpBuffer->CreateReference();
unsigned char* dstPixels = GetPointerToPixelData(reference);
memcpy(dstPixels, from.data, from.step.buf[1] * from.cols*from.rows);
return sBitmap;
}
unsigned char* GetPointerToPixelData(IBuffer^ buffer)
{
ComPtr<IBufferByteAccess> bufferByteAccess;
ComPtr<IInspectable> insp((IInspectable*)buffer);
ThrowIfFailed(insp.As(&bufferByteAccess));
unsigned char* pixels = nullptr;
ThrowIfFailed(bufferByteAccess->Buffer(&pixels));
return pixels;
}
unsigned char* GetPointerToPixelData(IMemoryBufferReference^ reference)
{
ComPtr<IMemoryBufferByteAccess> bufferByteAccess;
ThrowIfFailed(reinterpret_cast<IInspectable*>(reference)->QueryInterface(IID_PPV_ARGS(&bufferByteAccess)));
unsigned char* pixels = nullptr;
unsigned int capacity = 0;
ThrowIfFailed(bufferByteAccess->GetBuffer(&pixels, &capacity));
return pixels;
}
我想指出 - 儘管它沒有作爲答案發布 - 我的猜測是對的。 – boaz001