ODM icon indicating copy to clipboard operation
ODM copied to clipboard

Add option to export OBJs using a single material

Open pierotofy opened this issue 3 years ago • 11 comments

Add a --texturing-single-material option that post-processes the 3D model output to use a single material (something similar to https://github.com/theFroh/imagepacker/blob/master/objuvpacker.py, but with support for multispectral TIFFs inputs, thus using rasterio instead of PIL).

pierotofy avatar Aug 11 '22 22:08 pierotofy

I'd like to help in this one. Please let me know which package are you planning to use for texturing. I'll integrate that in https://github.com/OpenDroneMap/ODM/blob/master/stages/odm_postprocess.py

theoway avatar Aug 13 '22 09:08 theoway

That would be awesome. :pray:

I think you will need to modify https://github.com/theFroh/imagepacker/blob/master/objuvpacker.py to make it work with rasterio instead of PIL, write a module to bring into ODM (based on imagepacker), then call the module when required. It would be best to add it at the mvs_texturing step, replacing the multi-material model (we don't want two textured model outputs).

I doubt there's a pre-made package that does exactly what we need here.

pierotofy avatar Aug 14 '22 02:08 pierotofy

Please don't mind if it's a noob question, but why do we need rasterio instead of pillow? The module above uses .obj & .mtl file as input. It used PIL to extract images from .mtl. I'm assuming they'll be in jpg/png. Or will they be in .tif for our use case? Also if possible, please share a sample dataset so that I can fully understand the code and make necessary modifications.

theoway avatar Aug 14 '22 10:08 theoway

Because multispectral datasets use 16bit/32bit TIFFs, which are not supported by PIL.

pierotofy avatar Aug 14 '22 15:08 pierotofy

https://github.com/pierotofy/drone_dataset_micasense

(Pass --radiometric-calibration camera to generate 32bit TIFFs).

pierotofy avatar Aug 14 '22 15:08 pierotofy

I've created a public repo where I will add the code for the module. I'll get started in a day or two :)

theoway avatar Aug 21 '22 09:08 theoway

Please share a valid dataset. I'm not able to process this even with min-num-features=32000

[ERROR]   The program could not process this dataset using the current settings. 
Check that the images have enough overlap, that there are enough recognizable features 
and that the images are in focus. You could also try to increase the --min-num-features
parameter.The program will now exit.

Or it'd be awesome if someone can directly share the multispectral obj and mtl files.

theoway avatar Aug 21 '22 10:08 theoway

Mm, try this one otherwise: https://community.opendronemap.org/t/dji-phantom-4-pro-multipectral-w-o-rtk/4978 (or a subset of it, it's quite large for just testing).

pierotofy avatar Aug 22 '22 10:08 pierotofy

Created 3d models successfully. If anyone wants to use them, download here Now I can get started <3

theoway avatar Aug 29 '22 10:08 theoway

So far, everything is going well with rasterio integration. There's one thing that I noticed, the .tif texture files that I've generated from ODM don't have any crs, transforms etc. Is it normal??

theoway avatar Sep 09 '22 17:09 theoway

Yep! You can ignore rasterio's warning.

pierotofy avatar Sep 09 '22 17:09 pierotofy

Help wanted: I've been wanting to replicate this line, which use arrays extracted from images using PIL: output_array.paste(image, (block.x, block.y))

I want to do exactly this with our multispectral texture files. Insert the smaller array into the larger. For that, I've made this function:

def insert_at(big, pos, small):
        #https://stackoverflow.com/questions/66896138/python-numpy-insert-2d-array-into-bigger-2d-array-on-given-posiiton
        x1 = pos[0]
        y1 = pos[1]
        x2 = x1 + small.shape[1]
        y2 = y1 + small.shape[2]
        print(x1, '\t', x2, '\t', y1, '\t', y2)
        assert x2  <= big.shape[1], "the position will make the small matrix exceed the boundaries at x"
        assert y2  <= big.shape[2], "the position will make the small matrix exceed the boundaries at y"

        big[x1:x2,y1:y2] = small

        return big

output_array = insert_at(output_array, (block.x, block.y), image)
'''
    output_array.shape -> (1, 4096, 4608)
    image.shape -> (1, 4096, 4096)
    block.x -> 0
    block.y -> 0
'''

And I'm getting this broadcast error: ValueError: could not broadcast input array from shape (1,4096,4096) into shape (1,4096,4608)

I have no experience with numpy... Let me know how to solve this.

theoway avatar Sep 23 '22 16:09 theoway

Try:

big[:,x1:x2,y1:y2] = small

https://numpy.org/devdocs/user/basics.indexing.html

pierotofy avatar Sep 23 '22 17:09 pierotofy

@pierotofy Worked like charm! Now I can proceed further.

theoway avatar Sep 23 '22 18:09 theoway

Can I inquire about the status of this issue? We also very strongly need to be able to generate single texture map from ODM. Going through blender for this task is not a feasible solution for us. We are not developers but happy to help as much as can (testing feedback etc)...

muratmaga avatar Oct 10 '22 17:10 muratmaga

@muratmaga I'm working on this. Unfortunately, my workload is very heavy. But among my other open source work, this one is high priority. I'll inform once I get this working. I intend to do it by end of month. Sure, testing & feedback will be welcomed! :)

theoway avatar Oct 12 '22 15:10 theoway

Just have to make minor changes, and it'll be ready for testing. I'll add instructions to run the code as well in the readme.

theoway avatar Oct 23 '22 15:10 theoway

We are getting ready to submit a paper that uses ODM and 3D Slicer to obtain 3D models of biological specimens. Since we can't use the multi-file texture maps in Slicer currently, we are converting the texture maps into vertex color in meshlab as a preprocessing step, which reduces their quality. Because of that step, textures look inferior to the ones generated by commercial photogrammetry software (which tpyically output a single texture file). It will be great if this is incorporated prior to our paper (which is still some time out), so that we stop doing the step that degrades, what is otherwise a great texture.

Again happy to test and report back...

muratmaga avatar Nov 10 '22 21:11 muratmaga

@muratmaga if you need this in a hurry, perhaps you could offer to sponsor the development of this feature (and I'm sure @theoway would appreciate it). https://docs.opendronemap.org/requesting-features/

pierotofy avatar Nov 10 '22 21:11 pierotofy

I would be happy to sponsor (to a certain amount), but unfortunately it is not as easy as doing a paypal or patreon or something like that as @smathermather can attest.

muratmaga avatar Nov 11 '22 23:11 muratmaga

Repo link

Please feel free to test it out. I have added instructions on how to use. Note: This still under progress. Some small changes have to be made. I'll get to them in a few days. Please feel free to add issues if you see any bugs. Keep the issues detailed so it'd be easier for me to debug.

And I'd like to thank all of you for your patience and support! Waiting for your feedback. CC @muratmaga @pierotofy

theoway avatar Nov 12 '22 16:11 theoway

@theoway thank you very much.

I tried with one of my samples, and while the command worked (i.e., produced an output), I have trouble loading the textures. I opened an issue at your repo. I also think that tiff file is not quite standard (it looks like a multichannel image, with three channels containing the identical RGB image). The GH issue contains the dataset I experimented and the commands and outputs.

muratmaga avatar Nov 13 '22 05:11 muratmaga

Thanks all for your help/contributions.

This has now been implemented in #1582. :pray: :tada:

pierotofy avatar Jan 11 '23 21:01 pierotofy

@muratmaga -- check it out... .

smathermather avatar Jan 11 '23 21:01 smathermather

Works great. Thank you all. This has been a great addition for us...

muratmaga avatar Jan 13 '23 06:01 muratmaga

I just really appreciate Murat's first example in slicermorph, including QR code "ground" control points for accurate measurements: image

smathermather avatar Jan 13 '23 16:01 smathermather

It works even nicer and accurate, when the photography is done more carefully (this was just a quick test). Thanks again everyone, much appreciate this feature and the background removal (this is raw output from ODM, no post-processing beyond what's provided).

image

muratmaga avatar Jan 13 '23 18:01 muratmaga