Jyouhou / UnrealText

Synthetic Scene Text from 3D Engines
MIT License
244 stars 39 forks source link

Can I extract background scene before add text?? #22

Closed hsl323 closed 2 years ago

hsl323 commented 3 years ago

I tried to extract image before placing text in the scene by adding self.cleint.SaveImg before 'step 3: place text' in DataGeneratorModule.py

but text already exists in the extracted scene

is it possible extract a scene that is the same as the generated image but has no text??

Jyouhou commented 3 years ago

Hi,

The text instances do not disappear after the generation of each 'image'. That's why you see the text. Though the first generated image would not have text if you take a look at it.

You can:

(1) remove/comment line 147-169 (2) when you run python3 run_generation.py --UnrealProjectName $SceneName --languages Latin, add a flag --MaxTextNum =0

hsl323 commented 3 years ago

Thanks for your answering I can extract no-text images.

but i want extract pair of text image and no-text image that have same background.

I thing if I can control random environments for two runs with and without text, it would be possible to extract the pair image.

Can I control random environments to be the same for two runs? or is there an easier way?

Jyouhou commented 3 years ago

Currently, control over camera/environment randomness is not supported. There is one workaround:

In step 3, https://github.com/Jyouhou/UnrealText/blob/dc8460a8dff37c61d5bf290b013674bb0c42d429/code/DataGenerator/DataGeneratorModule.py#L151

There is one step to generate some text regions and write their paths to a txt file. This file will be read by the game executive. You can also take a look by yourself what this file is like during generation. https://github.com/Jyouhou/UnrealText/blob/dc8460a8dff37c61d5bf290b013674bb0c42d429/code/DataGenerator/TextPlacingModule.py#L167

So the workaround is like this:

(1). First, you prepare an empty img: all 4 RGBA channels are zeros. (2) In def _GenerateOneImageInstance, after all the steps, you write a dummy word_img_paths.txt. The first line is an int, the number of text instance, which you can determine from the output of step 4. Then the followings lines are the same path to the empty img. (3) After (2), all the text instances are changed to transparent texture so no text is visible. (4) Take a shot by self.client.SaveImg(img_path) but probably you need to change the img_path.