Texture2Matの関数はUE4の関数ですか?自作であれば見せてくれませんか?格納されずと言いましたがもらったデータが解らないなら拒否するはずです。何の値になりますか?
こんにちは
c++で構造体を作っていたのですが、よくわからない処理があったのでここでお聞きします。
USTRUCT(BlueprintType)
struct FMyStruct
{
GENERATED_BODY()
UPROPERTY(BlueprintReadWrite, Category = "Item")
UTextureRenderTarget2D* a_fake;
UPROPERTY(BlueprintReadWrite, Category = "Item")
UTextureRenderTarget2D* b_fake;
cv::Mat a;
cv::Mat b;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
bool c;
// Constructer
FMyStruct();
FMyStruct(const UTextureRenderTarget2D* InAFake, const UTextureRenderTarget2D* InBFake, const bool InC);
};
以下定義
FMyStruct::FMyStruct()
{
this->a = cv::Mat();
this->b = cv::Mat();
this->a_fake = nullptr;
this->b_fake = nullptr;
this->c = false;
}
FmyStruct::FmyStruct(const UTextureRenderTarget2D * InAFake, const UTextureRenderTarget2D * InBFake, const bool InC)
{
if (InAFake)
{
this->a = Texture2Mat(const_cast<UTextureRenderTarget2D *>(InAFake));
}
if (InBFake)
{
this->b= Texture2Mat(const_cast<UTextureRenderTarget2D *>(InBFake));
}
this->c = InC;
}
ここでTexture2Matはopencvのcv::Matを返す関数です。
このような構造体を作り、BPから構造体をMakeしたところ、a,bには値が格納されず、a_fake、b_fakeには正しいと思われる値が格納されていました。
ソースにはa_fakeに引数の値をコピーするといったことは書いていないつもりなのですが一体どういうわけでしょう?
回答が遅くなってしまい申し訳ありません。
Texture2Matは自作の関数です。
cv::Mat Texture2Mat(UTextureRenderTarget2D* RTarget)
{
// RenderTargetからTexture2Dを作成
UTexture2D* Dst;
auto temp_outer = NewObject<UObject>();
Dst = RTarget->ConstructTexture2D(temp_outer, "T_TRender512_", EObjectFlags::RF_NoFlags, CTF_DeferCompression);
RTarget->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
#if WITH_EDITORONLY_DATA
Dst->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
#endif
Dst->SRGB = 1;
Dst->UpdateResource();
auto texture = Dst;
FTexture2DMipMap* MyMipMap = &texture->PlatformData->Mips[0];
FByteBulkData* RawImageData = &MyMipMap->BulkData;
FColor* FormatedImageData = static_cast<FColor*>(RawImageData->Lock(LOCK_READ_ONLY));
auto height = MyMipMap->SizeY;
auto width = MyMipMap->SizeX;
cv::Mat mat(height, width, CV_8UC3);
for (int y = 0; y < height; ++y)
{
auto ptr = mat.ptr<cv::Vec3b>(y);
for (int x = 0; x < width; ++x)
{
auto color = FormatedImageData[y * width + x];
ptr[x][0] = color.B;
ptr[x][1] = color.G;
ptr[x][2] = color.R;
}
}
RawImageData->Unlock();
return mat;
}
長いですがこのような内容になっています。
a,bには値が格納されず、、、と判断したのはcv::Matのサイズが0で、画素値も格納されていない状態だったからです。