mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[cscore] Add BGRA support (#6365)
This commit is contained in:
@@ -21,9 +21,6 @@
|
||||
#include <Dbt.h>
|
||||
#include <Dshow.h>
|
||||
#include <Windows.h>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <wpi/ConvertUTF.h>
|
||||
#include <wpi/MemAlloc.h>
|
||||
#include <wpi/SmallString.h>
|
||||
@@ -284,6 +281,8 @@ void UsbCameraImpl::ProcessFrame(IMFSample* videoSample,
|
||||
return;
|
||||
}
|
||||
|
||||
auto currentTime = wpi::Now();
|
||||
|
||||
ComPtr<IMFMediaBuffer> buf;
|
||||
|
||||
if (!SUCCEEDED(videoSample->ConvertToContiguousBuffer(buf.GetAddressOf()))) {
|
||||
@@ -339,56 +338,9 @@ void UsbCameraImpl::ProcessFrame(IMFSample* videoSample,
|
||||
}
|
||||
}
|
||||
|
||||
cv::Mat tmpMat;
|
||||
std::unique_ptr<Image> dest;
|
||||
bool doFinalSet = true;
|
||||
|
||||
switch (mode.pixelFormat) {
|
||||
case cs::VideoMode::PixelFormat::kMJPEG: {
|
||||
// Special case
|
||||
PutFrame(VideoMode::kMJPEG, mode.width, mode.height,
|
||||
{reinterpret_cast<char*>(ptr), length}, wpi::Now());
|
||||
doFinalSet = false;
|
||||
break;
|
||||
}
|
||||
case cs::VideoMode::PixelFormat::kGray:
|
||||
tmpMat = cv::Mat(mode.height, mode.width, CV_8UC1, ptr, pitch);
|
||||
dest = AllocImage(VideoMode::kGray, tmpMat.cols, tmpMat.rows,
|
||||
tmpMat.total());
|
||||
tmpMat.copyTo(dest->AsMat());
|
||||
break;
|
||||
case cs::VideoMode::PixelFormat::kY16:
|
||||
tmpMat = cv::Mat(mode.height, mode.width, CV_8UC2, ptr, pitch);
|
||||
dest =
|
||||
AllocImage(VideoMode::kY16, tmpMat.cols, tmpMat.rows, tmpMat.total());
|
||||
tmpMat.copyTo(dest->AsMat());
|
||||
break;
|
||||
case cs::VideoMode::PixelFormat::kBGR:
|
||||
tmpMat = cv::Mat(mode.height, mode.width, CV_8UC3, ptr, pitch);
|
||||
dest = AllocImage(VideoMode::kBGR, tmpMat.cols, tmpMat.rows,
|
||||
tmpMat.total() * 3);
|
||||
tmpMat.copyTo(dest->AsMat());
|
||||
break;
|
||||
case cs::VideoMode::PixelFormat::kYUYV:
|
||||
tmpMat = cv::Mat(mode.height, mode.width, CV_8UC2, ptr, pitch);
|
||||
dest = AllocImage(VideoMode::kYUYV, tmpMat.cols, tmpMat.rows,
|
||||
tmpMat.total() * 2);
|
||||
tmpMat.copyTo(dest->AsMat());
|
||||
break;
|
||||
case cs::VideoMode::PixelFormat::kUYVY:
|
||||
tmpMat = cv::Mat(mode.height, mode.width, CV_8UC2, ptr, pitch);
|
||||
dest = AllocImage(VideoMode::kUYVY, tmpMat.cols, tmpMat.rows,
|
||||
tmpMat.total() * 2);
|
||||
tmpMat.copyTo(dest->AsMat());
|
||||
break;
|
||||
default:
|
||||
doFinalSet = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (doFinalSet) {
|
||||
PutFrame(std::move(dest), wpi::Now());
|
||||
}
|
||||
std::string_view data_view{reinterpret_cast<char*>(ptr), length};
|
||||
SourceImpl::PutFrame(static_cast<VideoMode::PixelFormat>(mode.pixelFormat),
|
||||
mode.width, mode.height, data_view, currentTime);
|
||||
|
||||
if (buffer2d) {
|
||||
buffer2d->Unlock2D();
|
||||
@@ -480,8 +432,6 @@ static cs::VideoMode::PixelFormat GetFromGUID(const GUID& guid) {
|
||||
return cs::VideoMode::PixelFormat::kY16;
|
||||
} else if (IsEqualGUID(guid, MFVideoFormat_YUY2)) {
|
||||
return cs::VideoMode::PixelFormat::kYUYV;
|
||||
} else if (IsEqualGUID(guid, MFVideoFormat_RGB24)) {
|
||||
return cs::VideoMode::PixelFormat::kBGR;
|
||||
} else if (IsEqualGUID(guid, MFVideoFormat_MJPG)) {
|
||||
return cs::VideoMode::PixelFormat::kMJPEG;
|
||||
} else if (IsEqualGUID(guid, MFVideoFormat_RGB565)) {
|
||||
|
||||
Reference in New Issue
Block a user