x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to reade and write pixel value of UTexture2D?

Hi everybody, I capture a scene with OpenCV and I want to write pixel value of captured image to UTexture2D but I can't I already setup a material which has a texture parameter and I also created an instance Material of that then I create a C++ class but when I trying to change pixel value it does not work properly it's change just top part of mesh, and I already read Ginku's wiki but I don't understant that it's to messy, here is my function code.

 void ADynamicTexture::capture()
 {
     cv::Mat img = cv::imread("D:\\img.jpg");
 
     UTexture2D *ut2 = UTexture2D::CreateTransient(img.size().width, img.size().height);
     ut2->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
     ut2->SRGB = 0;
     ut2->AddToRoot();
     ut2->UpdateResource();
     FTexture2DMipMap &mip = ut2->PlatformData->Mips[0];
     void *data = mip.BulkData.Lock(LOCK_READ_WRITE);
     FMemory::Memcpy(data, img.data, img.size().width * img.size().height);
     mip.BulkData.Unlock();
     ut2->UpdateResource();
     matInst->SetTextureParameterValue(FName("DTexture"), ut2);
     mesh->SetMaterial(0, matInst);
 }

Product Version: UE 4.11
Tags:
more ▼

asked Apr 22 '16 at 05:28 PM in C++ Programming

avatar image

Bahman Mokri
1 2 5 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Your not copying enough information you need to provide a stride to your mem copy.

 auto stride = (int32)( sizeof(uint8) * 4 ); // for r, g, b, a
 FMemory::Memcpy(data, img.data, img.size().width * img.size().height * stride);


more ▼

answered May 06 '16 at 10:40 PM

avatar image

DigitalKarnage
75 2 4 11

avatar image Hnomer Mar 11 '18 at 09:19 AM

Thanks! Solved my problem!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question