├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── MANIFEST ├── README.md ├── docs └── image │ └── textured.gif ├── examples ├── .gitignore ├── color000.png ├── color000.txt ├── color001.png ├── color001.txt ├── color002.png ├── color002.txt ├── color003.png ├── color003.txt ├── color004.png ├── color004.txt ├── color005.png ├── color005.txt ├── color006.png ├── color006.txt ├── color007.png ├── color007.txt ├── color008.png ├── color008.txt ├── color009.png ├── color009.txt ├── color010.png ├── color010.txt ├── color011.png ├── color011.txt ├── color012.png ├── color012.txt ├── color013.png ├── color013.txt ├── color014.png ├── color014.txt ├── color015.png ├── color015.txt ├── color016.png ├── color016.txt ├── color017.png ├── color017.txt ├── color018.png ├── color018.txt ├── color019.png ├── color019.txt ├── color020.png ├── color020.txt ├── color021.png ├── color021.txt ├── color022.png ├── color022.txt ├── color023.png ├── color023.txt ├── obj.ply └── occluded.jpg ├── setup.py ├── texture_mapping.cpp └── texture_mapping ├── __init__.py └── apps ├── __init__.py └── mapping.py /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | texture_mapping/texture_mapping 3 | _skbuild 4 | *.egg/ 5 | *.egg-info/ 6 | *.pyc 7 | \#*\# 8 | .\#* 9 | /build/ 10 | /dist/ 11 | /src/ 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | cache: 4 | - pip 5 | 6 | python: 7 | - '3.7' 8 | - '2.7' 9 | 10 | addons: 11 | apt: 12 | update: true 13 | 14 | install: 15 | - pip install --upgrade pip setuptools wheel 16 | 17 | script: 18 | - pip install hacking pytest 19 | - flake8 . 20 | 21 | sudo: false 22 | 23 | branches: 24 | only: 25 | - master 26 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8 FATAL_ERROR) 2 | project(texture_mapping) 3 | find_package(PCL REQUIRED COMPONENTS 4 | common 5 | features 6 | io 7 | kdtree 8 | search 9 | ) 10 | include_directories(${PCL_INCLUDE_DIRS}) 11 | link_directories(${PCL_LIBRARY_DIRS}) 12 | add_definitions(${PCL_DEFINITIONS}) 13 | add_executable(texture_mapping texture_mapping.cpp) 14 | target_link_libraries(texture_mapping 15 | ${OPENNI_LIBRARIES} 16 | ${PCL_LIBRARIES} 17 | boost_filesystem 18 | boost_system 19 | pcl_common 20 | pcl_features 21 | pcl_io 22 | pcl_kdtree 23 | pcl_surface 24 | pcl_visualization 25 | ) 26 | 27 | install(TARGETS texture_mapping DESTINATION texture_mapping) 28 | -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | .gitignore 2 | CMakeLists.txt 3 | README.md 4 | setup.py 5 | texture_mapping.cpp 6 | texture_mapping/__init__.py 7 | texture_mapping/apps/__init__.py 8 | texture_mapping/apps/mapping.py 9 | texture_mapping/texture_mapping 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Texture Mapping 2 | 3 | ## Install 4 | 5 | ``` 6 | pip install texture-mapping 7 | ``` 8 | 9 | ## Input txt config format 10 | 11 | `txt` file indicates camera pose and intrinsic parameters. 12 | The format is as follows. 13 | 14 | ``` 15 | translation_x translation_y translation_z 16 | rotation_00 rotation_01 rotation_02 17 | rotation_10 rotation_11 rotation_12 18 | rotation_20 rotation_21 rotation_22 19 | fx 20 | fy 21 | cx 22 | cy 23 | image_height 24 | image_width 25 | ``` 26 | 27 | ## Examples 28 | 29 | ``` 30 | git clone https://github.com/iory/texture-mapping.git 31 | cd texture-mapping 32 | texture-mapping --input examples/obj.ply --out textured.obj --config-dir examples/ 33 | ``` 34 | 35 | Output obj file `textured.obj` will be created at the same directory of input ply file. 36 | 37 | ![](docs/image/textured.gif) 38 | -------------------------------------------------------------------------------- /docs/image/textured.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/docs/image/textured.gif -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /examples/color000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color000.png -------------------------------------------------------------------------------- /examples/color000.txt: -------------------------------------------------------------------------------- 1 | 4.127158462411651407e-01 9.829605816981773492e-02 -6.098293546805623189e-01 2 | 7.768084870434921463e-02 -9.331770568985977565e-01 -3.509220229946277692e-01 3 | 9.960100531094433496e-01 5.713023100397207621e-02 6.855735416682617878e-02 4 | -4.392789375208938640e-02 -3.548474562167563962e-01 9.338916548331509526e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color001.png -------------------------------------------------------------------------------- /examples/color001.txt: -------------------------------------------------------------------------------- 1 | 4.149880059597762516e-01 -6.205541070461844111e-01 -7.777967908755506476e-02 2 | 6.331822361076477890e-02 -9.318453961549342246e-01 -3.572883432518204616e-01 3 | -5.805815492679033962e-02 -3.608397887315306640e-01 9.308189391684512648e-01 4 | -9.963031934131666434e-01 -3.819429974535237804e-02 -7.694895880834362600e-02 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color002.png -------------------------------------------------------------------------------- /examples/color002.txt: -------------------------------------------------------------------------------- 1 | 4.305361912894782317e-01 -6.497703172386842807e-02 6.240431055911834779e-01 2 | 8.040711854279010418e-02 -9.176947764716211209e-01 -3.890642524369799515e-01 3 | -9.937300424060880877e-01 -4.338170849468962059e-02 -1.030467378798337330e-01 4 | 7.768718109983838160e-02 3.949105273410449257e-01 -9.154290673165113024e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color003.png -------------------------------------------------------------------------------- /examples/color003.txt: -------------------------------------------------------------------------------- 1 | 3.961063405993485720e-01 6.438770623070300125e-01 6.064532488297424973e-02 2 | 8.022655826760136111e-02 -9.424225737426974447e-01 -3.246588853685100085e-01 3 | 1.164054790350351198e-01 3.323382420272307236e-01 -9.359492813912897446e-01 4 | 9.899562938832993098e-01 3.729591648475605314e-02 1.363655044884993783e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color004.png -------------------------------------------------------------------------------- /examples/color004.txt: -------------------------------------------------------------------------------- 1 | 4.139627648103738067e-01 -3.753728273753005329e-01 -4.930057526088921227e-01 2 | 5.520005655822574075e-02 -9.324043650175584119e-01 -3.571765023796675820e-01 3 | 6.618286325777127388e-01 -2.336808609312338303e-01 7.123033878445002021e-01 4 | -7.476201006234943769e-01 -2.757088234544577410e-01 6.041927091690821872e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color005.png -------------------------------------------------------------------------------- /examples/color005.txt: -------------------------------------------------------------------------------- 1 | 4.256443760079419714e-01 -4.812556906225301523e-01 4.050312699118168158e-01 2 | 6.093121359332713538e-02 -9.235347547328001117e-01 -3.786435579944147367e-01 3 | -7.717506483560432340e-01 -2.841641861785275114e-01 5.689039040607127840e-01 4 | -6.329994660124682593e-01 2.575544060856278517e-01 -7.300530144679959754e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color006.png -------------------------------------------------------------------------------- /examples/color006.txt: -------------------------------------------------------------------------------- 1 | 4.267279480846378759e-01 4.091321421358720123e-01 4.871566195722897286e-01 2 | 1.120455268950796834e-01 -9.226117238493265482e-01 -3.690980993158555767e-01 3 | -6.342793964925494965e-01 2.195260897332206307e-01 -7.412812847438470243e-01 4 | 7.649414664455381763e-01 3.171685718071941551e-01 -5.605966910087265553e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color007.png -------------------------------------------------------------------------------- /examples/color007.txt: -------------------------------------------------------------------------------- 1 | 4.000887636632698419e-01 5.000336844384871693e-01 -3.914442103778538184e-01 2 | 3.830499531503744892e-02 -9.398826579893593269e-01 -3.393424767764439687e-01 3 | 7.823547685788279082e-01 2.394714845243009482e-01 -5.749560193455632851e-01 4 | 6.216540383652977564e-01 -2.434625172600168030e-01 7.444946334753075323e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color008.png -------------------------------------------------------------------------------- /examples/color008.txt: -------------------------------------------------------------------------------- 1 | 4.072698495149190689e-01 -2.298032013483324310e-01 -5.767101045968323625e-01 2 | 5.597493391112473571e-02 -9.357528205718373959e-01 -3.481859640558393476e-01 3 | 8.356805104372889703e-01 -1.469219688177305638e-01 5.291994137884059590e-01 4 | -5.463560114512476806e-01 -3.205941263818956055e-01 7.737664472439417240e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color009.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color009.png -------------------------------------------------------------------------------- /examples/color009.txt: -------------------------------------------------------------------------------- 1 | 4.176892208654091609e-01 -5.741845644485608080e-01 -2.394439979768933080e-01 2 | 7.283266649034098039e-02 -9.308784013608669694e-01 -3.579955370835561923e-01 3 | 2.123868321489673638e-01 -3.362392117511475154e-01 9.175156816156841977e-01 4 | -9.744676681253379158e-01 -1.428586516834176035e-01 1.732171164104830408e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color010.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color010.png -------------------------------------------------------------------------------- /examples/color010.txt: -------------------------------------------------------------------------------- 1 | 4.140602688756394034e-01 -5.817465847733669371e-01 2.454719345952036669e-01 2 | 4.718172703302983551e-02 -9.305054680898718900e-01 -3.632264562074594139e-01 3 | -5.542884253318247634e-01 -3.268987666303152517e-01 7.654420539261904688e-01 4 | -8.309862972259813851e-01 1.652173424021443626e-01 -5.311920590447730683e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color011.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color011.png -------------------------------------------------------------------------------- /examples/color011.txt: -------------------------------------------------------------------------------- 1 | 4.393265681764568220e-01 -2.126637594354753302e-01 5.865223026944759166e-01 2 | 7.845928678930753908e-02 -9.133112560474166974e-01 -3.996331941838689450e-01 3 | -9.834372602511992634e-01 -1.366066814287402731e-01 1.191208199209539964e-01 4 | -1.633869501096303911e-01 3.836680390208642155e-01 -9.089023821994067776e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color012.png -------------------------------------------------------------------------------- /examples/color012.txt: -------------------------------------------------------------------------------- 1 | 4.356202317239339372e-01 2.607144788488016118e-01 5.747735830153475334e-01 2 | 1.020899296901289777e-01 -9.170776862342956415e-01 -3.854168699823806166e-01 3 | -8.180366102701640552e-01 1.430616563414072173e-01 -5.570901782858435070e-01 4 | 5.660333475278327420e-01 3.721584069935863770e-01 -7.355979673642606409e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color013.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color013.png -------------------------------------------------------------------------------- /examples/color013.txt: -------------------------------------------------------------------------------- 1 | 4.076188916083424707e-01 6.021211621709275930e-01 2.262105741978192031e-01 2 | 9.952384639919667486e-02 -9.350453882535019190e-01 -3.402721350680449897e-01 3 | -1.594773468429815932e-01 3.225598900767614463e-01 -9.330177346425896356e-01 4 | 9.821720724200170283e-01 1.471232110155440975e-01 -1.170161567418928350e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color014.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color014.png -------------------------------------------------------------------------------- /examples/color014.txt: -------------------------------------------------------------------------------- 1 | 4.059888624579579552e-01 5.831253079105098713e-01 -2.541237561385411570e-01 2 | 4.797143007112847357e-02 -9.373010063956327409e-01 -3.452036577249184557e-01 3 | 5.978839599816968553e-01 3.037954710718102080e-01 -7.417837165595235760e-01 4 | 8.001459318733885606e-01 -1.708073041939037195e-01 5.749707405950982286e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color015.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color015.png -------------------------------------------------------------------------------- /examples/color015.txt: -------------------------------------------------------------------------------- 1 | 4.041484338408257715e-01 2.272801442692278795e-01 -5.823173878349242605e-01 2 | 3.511322134498212622e-02 -9.370374289687158909e-01 -3.474592327143934956e-01 3 | 9.896889940210745751e-01 8.091191646314982444e-02 -1.181903417704333881e-01 4 | 1.388623663932380126e-01 -3.397265348570185362e-01 9.302167084683607978e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color016.png -------------------------------------------------------------------------------- /examples/color016.txt: -------------------------------------------------------------------------------- 1 | 4.200590870405945809e-01 -6.822839350205750497e-02 -6.088223507745689211e-01 2 | 5.761047999592444624e-02 -9.293888065858016967e-01 -3.645784946862039577e-01 3 | 9.485911725996766242e-01 -6.288163330947471596e-02 3.101945961139609409e-01 4 | -3.112166767070970730e-01 -3.637064013532783635e-01 8.779873767623531666e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color017.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color017.png -------------------------------------------------------------------------------- /examples/color017.txt: -------------------------------------------------------------------------------- 1 | 4.117321580032443640e-01 -4.917871458479640134e-01 -3.824003448300505315e-01 2 | 5.329747896078618208e-02 -9.335852177067431867e-01 -3.543698915199740007e-01 3 | 4.500595349802045120e-01 -2.943298083584859337e-01 8.430992698876329516e-01 4 | -8.914066376855331875e-01 -2.044226141871552382e-01 4.044818921769710585e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color018.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color018.png -------------------------------------------------------------------------------- /examples/color018.txt: -------------------------------------------------------------------------------- 1 | 4.155267573181017360e-01 -6.240848995836834057e-01 6.553289149562646632e-02 2 | 2.576913111582734839e-02 -9.298789975693753096e-01 -3.669618532775692499e-01 3 | -3.030015786098241293e-01 -3.570808179889751743e-01 8.835628629499308051e-01 4 | -9.526415880285140636e-01 8.842137356825757744e-02 -2.909564665973464193e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color019.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color019.png -------------------------------------------------------------------------------- /examples/color019.txt: -------------------------------------------------------------------------------- 1 | 4.234853253638151682e-01 -3.711750768829904512e-01 5.121317978987096620e-01 2 | 5.668591747429325978e-02 -9.240561555406660021e-01 -3.780303270473165944e-01 3 | -9.046123716802060288e-01 -2.077505742881344264e-01 3.721775864907264086e-01 4 | -4.224490072934358742e-01 3.208736827637221900e-01 -8.476891623386697550e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color020.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color020.png -------------------------------------------------------------------------------- /examples/color020.txt: -------------------------------------------------------------------------------- 1 | 4.342836258383846459e-01 8.288807447031987241e-02 6.233438316240953458e-01 2 | 6.640309138208412565e-02 -9.163417285294616077e-01 -3.948524610668402435e-01 3 | -9.457872727677297808e-01 6.828584564120500355e-02 -3.175271294797422095e-01 4 | 3.179261928899254075e-01 3.945312152931673144e-01 -8.621299531009312123e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color021.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color021.png -------------------------------------------------------------------------------- /examples/color021.txt: -------------------------------------------------------------------------------- 1 | 4.252485912772979715e-01 5.232134861486317234e-01 3.625944041138484675e-01 2 | 1.174537335864244969e-01 -9.241495217703667997e-01 -3.635275531210968025e-01 3 | -4.064206862796957420e-01 2.892699812118928460e-01 -8.666862775731555280e-01 4 | 9.061053174055158088e-01 2.495406567701420331e-01 -3.416176435551534496e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color022.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color022.png -------------------------------------------------------------------------------- /examples/color022.txt: -------------------------------------------------------------------------------- 1 | 4.059485549747174904e-01 6.321696861523218303e-01 -9.206584351933300159e-02 2 | 5.673986556705984396e-02 -9.373395913754948294e-01 -3.437660223108888191e-01 3 | 3.608442645032695628e-01 3.402981621177755822e-01 -8.683251566287577550e-01 4 | 9.308984930863969387e-01 -7.477734482637543589e-02 3.575420874109661584e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/color023.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/color023.png -------------------------------------------------------------------------------- /examples/color023.txt: -------------------------------------------------------------------------------- 1 | 4.000603583405251129e-01 3.749779092879066411e-01 -5.075618290002879007e-01 2 | 2.475390245009412293e-02 -9.390089359134926594e-01 -3.430006743260150537e-01 3 | 9.223649830216970047e-01 1.537693824549254407e-01 -3.543978204148763300e-01 4 | 3.855257221105685139e-01 -3.075990820760697853e-01 8.699153535241711532e-01 5 | 1.045238890839152646e+03 6 | 1.046345842268217893e+03 7 | 9.518466822597985129e+02 8 | 5.069212131671924340e+02 9 | 1.080000000000000000e+03 10 | 1.920000000000000000e+03 11 | -------------------------------------------------------------------------------- /examples/obj.ply: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/obj.ply -------------------------------------------------------------------------------- /examples/occluded.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/examples/occluded.jpg -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import distutils.spawn 4 | import shlex 5 | import subprocess 6 | import sys 7 | 8 | from setuptools import find_packages 9 | 10 | 11 | version = '0.0.8' 12 | 13 | 14 | if sys.argv[-1] == 'release': 15 | if not distutils.spawn.find_executable('twine'): 16 | print( 17 | 'Please install twine:\n\n\tpip install twine\n', 18 | file=sys.stderr, 19 | ) 20 | sys.exit(1) 21 | 22 | commands = [ 23 | 'git tag v{:s}'.format(version), 24 | 'git push origin master --tag', 25 | 'python setup.py sdist', 26 | 'twine upload dist/texture-mapping-{:s}.tar.gz'.format(version), 27 | ] 28 | for cmd in commands: 29 | print('+ {}'.format(cmd)) 30 | subprocess.check_call(shlex.split(cmd)) 31 | sys.exit(0) 32 | 33 | setup_requires = [ 34 | ] 35 | 36 | install_requires = [ 37 | 'scikit-build', 38 | 'pillow', 39 | ] 40 | 41 | setup_params = dict( 42 | name="texture-mapping", 43 | version=version, 44 | description="PCL Texture Mapping Wrapper of Python", 45 | author='iory', 46 | author_email='ab.ioryz@gmail.com', 47 | url='https://github.com/iory/texture-mapping', 48 | long_description=open('README.md').read(), 49 | long_description_content_type='text/markdown', 50 | license="MIT", 51 | classifiers=[ 52 | 'Development Status :: 5 - Production/Stable', 53 | 'Intended Audience :: Developers', 54 | 'Natural Language :: English', 55 | 'License :: OSI Approved :: MIT License', 56 | 'Programming Language :: Python', 57 | 'Programming Language :: Python :: 2.7', 58 | 'Programming Language :: Python :: 3.5', 59 | 'Programming Language :: Python :: 3.6', 60 | 'Programming Language :: Python :: 3.7', 61 | 'Programming Language :: Python :: Implementation :: CPython', 62 | ], 63 | packages=find_packages(), 64 | setup_requires=setup_requires, 65 | install_requires=install_requires, 66 | entry_points={ 67 | 'console_scripts': 68 | ['texture-mapping=texture_mapping.apps.mapping:main']} 69 | ) 70 | 71 | 72 | # https://github.com/skvark/opencv-python/blob/master/setup.py 73 | def install_packages(*requirements): 74 | # No more convenient way until PEP 518 is implemented; 75 | # setuptools only handles eggs 76 | subprocess.check_call( 77 | [sys.executable, "-m", "pip", "install"] + list(requirements) 78 | ) 79 | 80 | 81 | # https://github.com/skvark/opencv-python/blob/master/setup.py 82 | def get_or_install(name, version=None): 83 | """If a package is already installed, build against it. If not, install 84 | 85 | """ 86 | # Do not import 3rd-party modules into the current process 87 | import json 88 | js_packages = json.loads( 89 | # valid names & versions are ASCII as per PEP 440 90 | subprocess.check_output( 91 | [sys.executable, 92 | "-m", "pip", "list", "--format", "json"]).decode('ascii')) 93 | try: 94 | [package] = (package for package in js_packages 95 | if package['name'] == name) 96 | except ValueError: 97 | install_packages("%s==%s" % (name, version) if version else name) 98 | return version 99 | else: 100 | return package['version'] 101 | 102 | 103 | def main(): 104 | get_or_install('scikit-build') 105 | import skbuild # NOQA 106 | 107 | skbuild.setup(**setup_params) 108 | 109 | 110 | if __name__ == '__main__': 111 | main() 112 | -------------------------------------------------------------------------------- /texture_mapping.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Software License Agreement (BSD License) 3 | * 4 | * Point Cloud Library (PCL) - www.pointclouds.org 5 | * Copyright (c) 2010-2011, Willow Garage, Inc. 6 | * 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above 16 | * copyright notice, this list of conditions and the following 17 | * disclaimer in the documentation and/or other materials provided 18 | * with the distribution. 19 | * * Neither the name of Willow Garage, Inc. nor the names of its 20 | * contributors may be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 27 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 29 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 33 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | * Author: Raphael Favier, Technical University Eindhoven, (r.mysurname 37 | * tue.nl) 38 | */ 39 | 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | #include // for concatenateFields 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | 55 | using namespace pcl; 56 | using namespace std; 57 | 58 | std::ifstream& go_to_line(std::ifstream& file, unsigned int num) { 59 | file.seekg(std::ios::beg); 60 | for (int i = 0; i < num - 1; ++i) { 61 | file.ignore(std::numeric_limits::max(), '\n'); 62 | } 63 | return (file); 64 | } 65 | 66 | bool read_cam_pose_file(std::string filename, 67 | pcl::TextureMapping::Camera& cam) { 68 | ifstream myReadFile; 69 | myReadFile.open(filename.c_str(), ios::in); 70 | if (!myReadFile.is_open()) { 71 | PCL_ERROR("Error opening file %d\n", filename.c_str()); 72 | return false; 73 | } 74 | myReadFile.seekg(ios::beg); 75 | 76 | double val; 77 | 78 | go_to_line(myReadFile, 1); 79 | myReadFile >> val; 80 | cam.pose(0, 3) = val; // TX 81 | myReadFile >> val; 82 | cam.pose(1, 3) = val; // TY 83 | myReadFile >> val; 84 | cam.pose(2, 3) = val; // TZ 85 | 86 | go_to_line(myReadFile, 2); 87 | myReadFile >> val; 88 | cam.pose(0, 0) = val; 89 | myReadFile >> val; 90 | cam.pose(0, 1) = val; 91 | myReadFile >> val; 92 | cam.pose(0, 2) = val; 93 | 94 | myReadFile >> val; 95 | cam.pose(1, 0) = val; 96 | myReadFile >> val; 97 | cam.pose(1, 1) = val; 98 | myReadFile >> val; 99 | cam.pose(1, 2) = val; 100 | 101 | myReadFile >> val; 102 | cam.pose(2, 0) = val; 103 | myReadFile >> val; 104 | cam.pose(2, 1) = val; 105 | myReadFile >> val; 106 | cam.pose(2, 2) = val; 107 | 108 | cam.pose(3, 0) = 0.0; 109 | cam.pose(3, 1) = 0.0; 110 | cam.pose(3, 2) = 0.0; 111 | cam.pose(3, 3) = 1.0; // Scale 112 | 113 | go_to_line(myReadFile, 5); 114 | myReadFile >> val; 115 | cam.focal_length_w = val; 116 | myReadFile >> val; 117 | cam.focal_length_h = val; 118 | myReadFile >> val; 119 | cam.center_w = val; 120 | myReadFile >> val; 121 | cam.center_h = val; 122 | myReadFile >> val; 123 | cam.height = val; 124 | myReadFile >> val; 125 | cam.width = val; 126 | 127 | // close file 128 | myReadFile.close(); 129 | return true; 130 | } 131 | 132 | int main(int argc, char** argv) { 133 | pcl::PolygonMesh triangles; 134 | pcl::io::loadPolygonFilePLY(argv[1], triangles); 135 | 136 | pcl::PointCloud::Ptr cloud(new pcl::PointCloud); 137 | pcl::fromPCLPointCloud2(triangles.cloud, *cloud); 138 | 139 | // Create the texturemesh object that will contain our UV-mapped mesh 140 | TextureMesh mesh; 141 | mesh.cloud = triangles.cloud; 142 | std::vector polygon_1; 143 | 144 | // push faces into the texturemesh object 145 | polygon_1.resize(triangles.polygons.size()); 146 | for (size_t i = 0; i < triangles.polygons.size(); ++i) { 147 | polygon_1[i] = triangles.polygons[i]; 148 | } 149 | mesh.tex_polygons.push_back(polygon_1); 150 | 151 | // Load textures and cameras poses and intrinsics 152 | pcl::texture_mapping::CameraVector my_cams; 153 | 154 | const boost::filesystem::path base_dir(argv[3]); 155 | std::string extension(".txt"); 156 | std::vector filenames; 157 | try { 158 | for (boost::filesystem::directory_iterator it(base_dir); 159 | it != boost::filesystem::directory_iterator(); ++it) { 160 | if (boost::filesystem::is_regular_file(it->status()) && 161 | boost::filesystem::extension(it->path()) == extension) { 162 | filenames.push_back(it->path()); 163 | } 164 | } 165 | } catch (const boost::filesystem::filesystem_error& e) { 166 | cerr << e.what() << endl; 167 | } 168 | std::sort(filenames.begin(), filenames.end()); 169 | 170 | 171 | for(int i=0; i::Camera cam; 174 | read_cam_pose_file(filenames[i].string(), cam); 175 | cam.texture_file = filenames[i].stem().string() + ".png"; 176 | my_cams.push_back(cam); 177 | } 178 | 179 | // Create materials for each texture (and one extra for occluded faces) 180 | mesh.tex_materials.resize(my_cams.size() + 1); 181 | for (int i = 0; i <= my_cams.size(); ++i) { 182 | pcl::TexMaterial mesh_material; 183 | mesh_material.tex_Ka.r = 0.2f; 184 | mesh_material.tex_Ka.g = 0.2f; 185 | mesh_material.tex_Ka.b = 0.2f; 186 | 187 | mesh_material.tex_Kd.r = 0.8f; 188 | mesh_material.tex_Kd.g = 0.8f; 189 | mesh_material.tex_Kd.b = 0.8f; 190 | 191 | mesh_material.tex_Ks.r = 1.0f; 192 | mesh_material.tex_Ks.g = 1.0f; 193 | mesh_material.tex_Ks.b = 1.0f; 194 | 195 | mesh_material.tex_d = 1.0f; 196 | mesh_material.tex_Ns = 75.0f; 197 | mesh_material.tex_illum = 2; 198 | 199 | std::stringstream tex_name; 200 | tex_name << "material_" << i; 201 | tex_name >> mesh_material.tex_name; 202 | 203 | if (i < my_cams.size()) 204 | mesh_material.tex_file = my_cams[i].texture_file; 205 | else 206 | mesh_material.tex_file = "occluded.jpg"; 207 | 208 | mesh.tex_materials[i] = mesh_material; 209 | } 210 | 211 | // Sort faces 212 | pcl::TextureMapping 213 | tm; // TextureMapping object that will perform the sort 214 | tm.textureMeshwithMultipleCameras(mesh, my_cams); 215 | 216 | // compute normals for the mesh 217 | pcl::NormalEstimation n; 218 | pcl::PointCloud::Ptr normals(new pcl::PointCloud); 219 | pcl::search::KdTree::Ptr tree( 220 | new pcl::search::KdTree); 221 | tree->setInputCloud(cloud); 222 | n.setInputCloud(cloud); 223 | n.setSearchMethod(tree); 224 | n.setKSearch(20); 225 | n.compute(*normals); 226 | 227 | // Concatenate XYZ and normal fields 228 | pcl::PointCloud::Ptr cloud_with_normals( 229 | new pcl::PointCloud); 230 | pcl::concatenateFields(*cloud, *normals, *cloud_with_normals); 231 | 232 | pcl::toPCLPointCloud2(*cloud_with_normals, mesh.cloud); 233 | pcl::io::saveOBJFile(argv[2], mesh, 5); 234 | 235 | return 0; 236 | } 237 | -------------------------------------------------------------------------------- /texture_mapping/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | 3 | import pkg_resources 4 | import os.path as osp 5 | 6 | 7 | __version__ = pkg_resources.get_distribution('texture-mapping').version 8 | 9 | 10 | texture_mapping_executable = osp.join( 11 | osp.abspath(osp.dirname(__file__)), 'texture_mapping') 12 | -------------------------------------------------------------------------------- /texture_mapping/apps/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iory/texture-mapping/180e86d0460976fac8c1bf38cbf7245d40bfdd08/texture_mapping/apps/__init__.py -------------------------------------------------------------------------------- /texture_mapping/apps/mapping.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os.path as osp 3 | import subprocess 4 | 5 | from PIL import Image 6 | 7 | import texture_mapping 8 | 9 | 10 | def main(): 11 | parser = argparse.ArgumentParser( 12 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) 13 | parser.add_argument('--input', type=str, 14 | help='Input ply filename', required=True) 15 | parser.add_argument('--out', '-o', type=str, 16 | help='Output obj file name. This file is created at ' 17 | 'the same dir of input ply file.', 18 | required=True) 19 | parser.add_argument('--config-dir', '-c', type=str, 20 | help='Config directory', required=True) 21 | args = parser.parse_args() 22 | 23 | occluded_file = osp.join(osp.dirname(args.input), 'occluded.jpg') 24 | if not osp.exists(occluded_file): 25 | white_img = Image.new('RGB', (256, 256), (255, 255, 255)) 26 | white_img.save(occluded_file) 27 | 28 | subprocess.call( 29 | [texture_mapping.texture_mapping_executable, 30 | args.input, 31 | osp.join(osp.dirname(args.input), osp.basename(args.out)), 32 | args.config_dir]) 33 | 34 | 35 | if __name__ == '__main__': 36 | main() 37 | --------------------------------------------------------------------------------