// Fill out your copyright notice in the Description page of Project Settings.
#include "WebcamReader.h"
// Sets default values
AWebcamReader::AWebcamReader()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Initialize OpenCV and webcam properties
CameraID = 0;
RefreshRate = 15;
isStreamOpen = false;
VideoSize = FVector2D(0, 0);
ShouldResize = false;
ResizeDeminsions = FVector2D(320, 240);
RefreshTimer = 0.0f;
stream = cv::VideoCapture();
frame = cv::Mat();
}
// Called when the game starts or when spawned
void AWebcamReader::BeginPlay()
{
Super::BeginPlay();
// Open the stream
stream.open(CameraID);
if (stream.isOpened())
{
// Initialize stream
isStreamOpen = true;
UpdateFrame();
VideoSize = FVector2D(frame.cols, frame.rows);
size = cv::Size(ResizeDeminsions.X, ResizeDeminsions.Y);
VideoTexture = UTexture2D::CreateTransient(VideoSize.X, VideoSize.Y);
VideoTexture->UpdateResource();
VideoUpdateTextureRegion = new FUpdateTextureRegion2D(0, 0, 0, 0, VideoSize.X, VideoSize.Y);
// Initialize data array
Data.Init(FColor(0, 0, 0, 255), VideoSize.X * VideoSize.Y);
// Do first frame
DoProcessing();
UpdateTexture();
OnNextVideoFrame();
}
}
// Called every frame
void AWebcamReader::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
RefreshTimer += DeltaTime;
if (isStreamOpen && RefreshTimer >= 1.0f / RefreshRate)
{
RefreshTimer -= 1.0f / RefreshRate;
UpdateFrame();
DoProcessing();
UpdateTexture();
OnNextVideoFrame();
}
}
void AWebcamReader::UpdateFrame()
{
if (stream.isOpened())
{
stream.read(frame);
if (ShouldResize)
{
cv::resize(frame, frame, size);
}
}
else {
isStreamOpen = false;
}
}
void AWebcamReader::DoProcessing()
{
}
void AWebcamReader::UpdateTexture()
{
if (isStreamOpen && frame.data)
{
// Copy Mat data to Data array
for (int y = 0; y < VideoSize.Y; y++)
{
for (int x = 0; x < VideoSize.X; x++)
{
int i = x + (y * VideoSize.X);
Data[i].B = frame.data[i * 3 + 0];
Data[i].G = frame.data[i * 3 + 1];
Data[i].R = frame.data[i * 3 + 2];
}
}
// Update texture 2D
UpdateTextureRegions(VideoTexture, (int32)0, (uint32)1, VideoUpdateTextureRegion, (uint32)(4 * VideoSize.X), (uint32)4, (uint8*)Data.GetData(), false);
}
}
void AWebcamReader::UpdateTextureRegions(UTexture2D* Texture, int32 MipIndex, uint32 NumRegions, FUpdateTextureRegion2D* Regions, uint32 SrcPitch, uint32 SrcBpp, uint8* SrcData, bool bFreeData)
{
if (Texture->Resource)
{
struct FUpdateTextureRegionsData
{
FTexture2DResource* Texture2DResource;
int32 MipIndex;
uint32 NumRegions;
FUpdateTextureRegion2D* Regions;
uint32 SrcPitch;
uint32 SrcBpp;
uint8* SrcData;
};
FUpdateTextureRegionsData* RegionData = new FUpdateTextureRegionsData;
RegionData->Texture2DResource = (FTexture2DResource*)Texture->Resource;
RegionData->MipIndex = MipIndex;
RegionData->NumRegions = NumRegions;
RegionData->Regions = Regions;
RegionData->SrcPitch = SrcPitch;
RegionData->SrcBpp = SrcBpp;
RegionData->SrcData = SrcData;
ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
UpdateTextureRegionsData,
FUpdateTextureRegionsData*, RegionData, RegionData,
bool, bFreeData, bFreeData,
{
for (uint32 RegionIndex = 0; RegionIndex < RegionData->NumRegions; ++RegionIndex)
{
int32 CurrentFirstMip = RegionData->Texture2DResource->GetCurrentFirstMip();
if (RegionData->MipIndex >= CurrentFirstMip)
{
RHIUpdateTexture2D(
RegionData->Texture2DResource->GetTexture2DRHI(),
RegionData->MipIndex - CurrentFirstMip,
RegionData->Regions[RegionIndex],
RegionData->SrcPitch,
RegionData->SrcData
+ RegionData->Regions[RegionIndex].SrcY * RegionData->SrcPitch
+ RegionData->Regions[RegionIndex].SrcX * RegionData->SrcBpp
);
}
}
if (bFreeData)
{
FMemory::Free(RegionData->Regions);
FMemory::Free(RegionData->SrcData);
}
delete RegionData;
});
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
OpenCV插件UE4
共187个文件
hpp:116个
h:59个
dll:5个
1星 需积分: 47 80 下载量 124 浏览量
2019-04-28
15:18:58
上传
评论 1
收藏 39.83MB RAR 举报
温馨提示
OpenCV插件UE4
资源推荐
资源详情
资源评论
收起资源包目录
OpenCV插件UE4 (187个子文件)
WebcamReader.cpp 4KB
OpenCV.cpp 597B
OpenCV.Build.cs 3KB
opencv_world320d.dll 62.98MB
opencv_world320.dll 39.91MB
opencv_world320.dll 39.91MB
opencv_ffmpeg320_64.dll 16.59MB
opencv_ffmpeg320_64.dll 16.59MB
core_c.h 128KB
types_c.h 59KB
imgproc_c.h 51KB
kmeans_index.h 36KB
videoio_c.h 36KB
dist.h 27KB
hierarchical_clustering_index.h 25KB
autotuned_index.h 20KB
kdtree_single_index.h 20KB
calib3d_c.h 20KB
kdtree_index.h 19KB
lsh_table.h 18KB
types_c.h 17KB
lsh_index.h 15KB
result_set.h 15KB
cvdef.h 14KB
tracking_c.h 11KB
index_testing.h 11KB
highgui_c.h 10KB
any.h 8KB
hdf5.h 7KB
allocator.h 6KB
nn_index.h 6KB
composite_index.h 6KB
objdetect_c.h 6KB
all_indices.h 6KB
saving.h 6KB
simplex_downhill.h 6KB
imgcodecs_c.h 5KB
cap_ios.h 5KB
defines.h 5KB
dynamic_bitset.h 4KB
interface.h 4KB
cvconfig.h 4KB
heap.h 4KB
logger.h 4KB
linear_index.h 4KB
random.h 4KB
ground_truth.h 3KB
matrix.h 3KB
params.h 3KB
cv.h 3KB
object_factory.h 3KB
sampling.h 3KB
WebcamReader.h 3KB
photo_c.h 3KB
timer.h 2KB
cvaux.h 2KB
ios.h 2KB
cxcore.h 2KB
highgui.h 2KB
cvwimage.h 2KB
ml.h 2KB
general.h 2KB
config.h 2KB
interface.h 481B
OpenCV.h 333B
dummy.h 251B
cxmisc.h 129B
imgproc.hpp 217KB
mat.hpp 146KB
core.hpp 144KB
calib3d.hpp 119KB
mat.inl.hpp 91KB
ml.hpp 78KB
intrin_sse.hpp 66KB
types.hpp 63KB
features2d.hpp 60KB
intrin_cpp.hpp 52KB
videoio.hpp 51KB
persistence.hpp 46KB
intrin_neon.hpp 44KB
matx.hpp 43KB
sse_utils.hpp 41KB
photo.hpp 38KB
utility.hpp 36KB
highgui.hpp 33KB
cvstd.hpp 32KB
tracking.hpp 31KB
cuda.hpp 29KB
ocl.hpp 27KB
base.hpp 26KB
opengl.hpp 23KB
flann.hpp 22KB
objdetect.hpp 22KB
warpers_inl.hpp 21KB
private.hpp 21KB
wimage.hpp 20KB
warpers.hpp 19KB
hal.hpp 19KB
operations.hpp 18KB
optim.hpp 15KB
共 187 条
- 1
- 2
资源评论
- 常小易2020-08-28为什么编译后打开工程直接崩,显示就是OpenCV里面
萌小蛋
- 粉丝: 272
- 资源: 31
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- NetOps-py通过sftp替换网络设备启动文件
- STM32单片机FPGA毕设电路原理论文报告任务驱动教学法在单片机课程教学中的应用
- STM32单片机FPGA毕设电路原理论文报告任务驱动法在单片机教学中的应用
- STM32单片机FPGA毕设电路原理论文报告人造金刚石压机智能化压力测控系统设计
- 以某列为依据匹配多项(Excel版)
- STM32单片机FPGA毕设电路原理论文报告人体短臂离心机实验台的显示控制系统
- STM32单片机FPGA毕设电路原理论文报告人工气候室监控系统的环境控制器研究
- STM32单片机FPGA毕设电路原理论文报告染整自动线张力控制系统的设计
- 数据挖掘与机器学习-实验
- 基于Linux系统Nginx的动态网站的LNMP环境源码包
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功