diff --git a/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ground-Pts3D.xml b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ground-Pts3D.xml new file mode 100644 index 0000000000..8aabd20ae7 --- /dev/null +++ b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ground-Pts3D.xml @@ -0,0 +1,48 @@ + + + + 0.182895665614618341 -3.78002060469805157 2.56022810571964277 + Stone-1 + 1 1 1 + + + 0.234792215591026754 -5.36333800580974884 2.42659720440635063 + Stone-2 + 1 1 1 + + + 0.194213046998492761 -4.82293063921051068 1.75377255914109642 + Stone-3 + 1 1 1 + + + 0.754045221758523621 0.496427193197002514 0.431416432371162006 + I-of-I + 1 1 1 + + + 0.898750585424819226 1.10409507249266081 0.444680581722013746 + Acute + 1 1 1 + + + 1.31771333753878528 0.989188464947304724 0.370627429238321537 + Finger-1 + 1 1 1 + + + 0.150697933447584281 1.10818337179321613 0.773464897817899177 + Stone-6 + 1 1 1 + + + 0.256396378205514475 2.35318759021626445 2.23887785258234207 + Stone-7 + 1 1 1 + + + 1.40207519252831658 2.1945458898399548 0.40382985984277503 + Grille + 1 1 1 + + diff --git a/MMVII/MMVII-TestDir/Input/Saisies-MMV1/GroundMeasure.xml b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/GroundMeasure.xml new file mode 100644 index 0000000000..554b2fb1dd --- /dev/null +++ b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/GroundMeasure.xml @@ -0,0 +1,91 @@ + + + + IMGP4170.JPG + + I-of-I + 452.278142467572422 808.192805895297056 + + + u-of-You + 521.272784862528056 1015.52756464228401 + + + Acute + 458.441997415626133 1100.83130652515365 + + + Finger-1 + 344.785721369910448 1112.92280566175327 + + + + IMGP4168.JPG + + I-of-I + 430.52658272147653 227.090326619720145 + + + u-of-You + 495.717626755149013 454.825546116027397 + + + Acute + 431.735281413390453 510.222991095907105 + + + Finger-1 + 316.373353330086218 471.678176822389275 + + + Stone-6 + 667.402028214032839 479.731591690534685 + + + Stone-7 + 1284.05120739189965 981.021140912616147 + + + Grille + 362.602015084684353 1078.96450589692108 + + + + IMGP4169.JPG + + I-of-I + 475.161154787777321 516.404520623212079 + + + u-of-You + 538.999416573275425 732.995393503311675 + + + Acute + 475.850364860953221 802.548038024082189 + + + Finger-1 + 362.721106696891582 789.307120972098687 + + + Stone-6 + 706.139274179003905 741.525951210447488 + + + + IMGP4167.JPG + + Stone-6 + 644.286307996218966 232.6833164507199 + + + Stone-7 + 1265.36807144116688 735.26882940476105 + + + Grille + 322.076097286495724 766.811866179541425 + + + diff --git a/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4167.JPG b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4167.JPG new file mode 100644 index 0000000000..387ab4d443 Binary files /dev/null and b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4167.JPG differ diff --git a/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4168.JPG b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4168.JPG new file mode 100644 index 0000000000..4cdf086a08 Binary files /dev/null and b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4168.JPG differ diff --git a/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4169.JPG b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4169.JPG new file mode 100644 index 0000000000..ff620e8101 Binary files /dev/null and b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4169.JPG differ diff --git a/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4170.JPG b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4170.JPG new file mode 100644 index 0000000000..54c23c6f6f Binary files /dev/null and b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/IMGP4170.JPG differ diff --git a/MMVII/apib11/Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5.xml b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5.xml similarity index 57% rename from MMVII/apib11/Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5.xml rename to MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5.xml index 9a528a7641..8e88701b71 100644 --- a/MMVII/apib11/Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5.xml +++ b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5.xml @@ -11,22 +11,22 @@ 3 1 1 - 2113.26900143641 - 857.203461218707 577.076198246255 + 2113.29189076302 + 857.206754888925 577.075355949847 - -0.0992818343588939 - 0.105926341210555 - 0.0365920357111148 + -0.0992778414574082 + 0.105924077620665 + 0.0366404677720908 - 6.32129028493475e-05 - -7.41880900367172e-05 + 6.3479994323078e-05 + -7.41705215866132e-05 - -1.24734259119908e-08 - 4.79395702261653e-07 + -1.62457752333968e-08 + 4.80179377691907e-07 diff --git a/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4167.JPG.xml b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4167.JPG.xml new file mode 100644 index 0000000000..d9700b4d29 --- /dev/null +++ b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4167.JPG.xml @@ -0,0 +1,14 @@ + + + "IMGP4167.JPG" + "Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5" +
5.20644436052294 1.49611001038881 2.11724479232937
+ + -0.162074830392862 0.0384131738848583 0.986030515463501 + 0.0965180346057596 0.995067755113336 -0.0229004744393625 + -0.982046851402196 0.0914581369031654 -0.164983001685735 + + 0.645757292454901 -0.0442730622939557 -0.761926109801983 -0.022494852710068 + -150.998255793775 -79.1267383625106 -149.225556118573 + 166.666421173337 -80.4118527918605 -172.097549838315 +
diff --git a/MMVII/apib11/Ori-PerspCentral-IMGP4168.JPG.xml b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4168.JPG.xml similarity index 100% rename from MMVII/apib11/Ori-PerspCentral-IMGP4168.JPG.xml rename to MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4168.JPG.xml diff --git a/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4169.JPG.xml b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4169.JPG.xml new file mode 100644 index 0000000000..d9a803313c --- /dev/null +++ b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4169.JPG.xml @@ -0,0 +1,14 @@ + + + "IMGP4169.JPG" + "Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5" +
5.15627029486289 0.215205620108451 2.08689313795566
+ + -0.176953806326696 0.0409905785444553 0.983365203216529 + 0.102280177137307 0.994488561576619 -0.0230492138266792 + -0.978890247061056 0.0965001210561815 -0.180171059953831 + + 0.63979756472186 -0.0467137347321854 -0.766748561762124 -0.0239488245862174 + -151.826374151718 -78.2064061610764 -149.971874858426 + 166.957716505788 -79.5347343248668 -172.709771641196 +
diff --git a/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4170.JPG.xml b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4170.JPG.xml new file mode 100644 index 0000000000..d628fb4d9b --- /dev/null +++ b/MMVII/MMVII-TestDir/Input/Saisies-MMV1/Ori-Ground-MMVII/Ori-PerspCentral-IMGP4170.JPG.xml @@ -0,0 +1,14 @@ + + + "IMGP4170.JPG" + "Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5" +
5.05921122405539 -0.271167237239889 2.10496651279359
+ + -0.166220702212525 0.066458650739172 0.983846495088489 + 0.0817737345468281 0.995218720586036 -0.0534111835981814 + -0.982692085291339 0.0715747576805015 -0.170860526654747 + + 0.643843438212809 -0.0485311854795092 -0.763593469958542 -0.00594674221196073 + -157.270824042625 -79.3244958204942 -153.804715242581 + 158.207395729614 -79.6876565611983 -162.640699790022 +
diff --git a/MMVII/apib11/.gitignore b/MMVII/apib11/.gitignore index 6533a85e56..6311f06221 100644 --- a/MMVII/apib11/.gitignore +++ b/MMVII/apib11/.gitignore @@ -7,3 +7,8 @@ Tmp-MM-Dir *.jpg *.TIF *.tif +/dist/ +/build/ +MMVII.egg-info/ +Tmmmp-MM-Dir/ +__pycache__ diff --git a/MMVII/apib11/MMVII.py b/MMVII/apib11/MMVII.py new file mode 100644 index 0000000000..0f2f9bb1e0 --- /dev/null +++ b/MMVII/apib11/MMVII.py @@ -0,0 +1,39 @@ +import os +import sys +from pathlib import Path + +mmv2_src_relative_path = '../' +mmv2_install_relative_path = '../../../MMVII/MMVII' + +mm_data_path = None + +# test if run from MMVII sources +test_path = os.path.normpath(os.path.dirname(__file__) + '/' + mmv2_src_relative_path) +if os.path.isfile(test_path + '/bin/MMVII'): + print("Using local MMVII") + mm_data_path = os.path.normpath(os.path.dirname(__file__) + '/' + mmv2_src_relative_path) + #search for .so file + so_path = None + for path in Path('build').rglob('_MMVII.*.so'): + if so_path is None: + so_path = path.parent + else : + print('Warning: multiple _MMVII.*.so files found in build directory') + if so_path is not None: + print("Using _MMVII.*.so file from directory ",so_path) + sys.path = [ str(so_path) ] + sys.path +else: + # test if installed + for p in sys.path: + test_path = os.path.normpath(os.path.dirname(__file__) + '/' + mmv2_install_relative_path) + if os.path.isfile(test_path + '/bin/MMVII'): + mm_data_path = os.path.normpath(os.path.dirname(__file__) + '/' + mmv2_install_relative_path) + break + +if mm_data_path is not None: + print('MMVII path:', mm_data_path) + from _MMVII import * + themodule = MM_Module(mm_data_path) +else: + print('Error: impossible to find MMVII binary. Error at installation?') + diff --git a/MMVII/apib11/Makefile b/MMVII/apib11/Makefile index dabb723b12..513f9577c7 100755 --- a/MMVII/apib11/Makefile +++ b/MMVII/apib11/Makefile @@ -4,12 +4,11 @@ MMV1_LIBDIR=${MMV1_DIR}/lib MMV2_DIR=${MMV1_DIR}/MMVII MMV2_BINDIR=${MMV2_DIR}/bin MMV2_INCDIR=${MMV2_DIR}/include -MODULE=MMVII$(shell python3-config --extension-suffix) +MODULE_NAME = MMVII DOC_INCLUDES=../include/MMVII_PCSens.h ../include/MMVII_memory.h ../include/MMVII_AimeTieP.h ../include/MMVII_Geom3D.h ../include/MMVII_Mappings.h - # =========== Includes & Libraries MMV1_INCLUDES=-I ${MMV1_DIR}/include -I${MMV1_DIR} MMV2_INCLUDES=-I ${MMV2_DIR} -I ${MMV2_INCDIR} -I ${MMV2_DIR}/ExternalInclude @@ -25,9 +24,10 @@ EXT_LIBS=-lpthread -lX11 -lstdc++fs # =========== Compiler & Flags CXX=g++ LD=g++ -CXXFLAGS=-fopenmp -std=c++17 -Wall -Werror -O3 -fPIC ${MMV2_INCLUDES} ${MMV1_INCLUDES} ${PYBIND_INCLUDES} '-DPYBIND_MMVII_DIR="$(abspath ${MMV2_DIR})"' -LDFLAGS=-fopenmp -shared +CXXFLAGS=-fopenmp -std=c++17 -Wall -Werror -O3 -fPIC ${MMV2_INCLUDES} ${MMV1_INCLUDES} ${PYBIND_INCLUDES} +PYTHON = python3 +PIP = pip3 # =========== Use ccache if found CCACHE:=${shell which ccache} @@ -35,39 +35,27 @@ ifneq (,${CCACHE}) override CXX:=${CCACHE} ${CXX} endif +SRCS:=${wildcard *.cpp} # ============ Targets -.phony: all clean -all: ${MODULE} +.phony: all module clean install uninstall +all: module -clean: - rm -f ${OBJS} ${DEPS} ${MODULE} docstrings.h +clean: uninstall + rm -f docstrings.h + rm -Rf build/ dist/ $(MODULE_NAME).egg-info/ __pycache__/ + $(PYTHON) setup.py clean docstrings.h: ${DOC_INCLUDES} Makefile pybind11-mkdoc -o $@ ${DOC_INCLUDES} ${CXXFLAGS} >/dev/null -# =========== Build Objs - -SRCS:=${wildcard *.cpp} -OBJS:=${SRCS:.cpp=.o} - +module: docstrings.h ${SRCS} + CC="${CXX}" $(PYTHON) setup.py build + CC="${CXX}" $(PYTHON) setup.py bdist_wheel -%.o: %.cpp Makefile docstrings.h - ${CXX} -c ${CXXFLAGS} $(python3 -m pybind11 --includes) $< -o $@ +install: module + $(PIP) install --user dist/*.whl +uninstall: + $(PIP) uninstall -y $(MODULE_NAME) -# ========== Build Module -${MODULE}: ${OBJS} ${MMV2_LIB} ${MMV1_LIBS} - ${CXX} ${LDFLAGS} $^ ${EXT_LIBS} -o ${MODULE} - - -# =========== Auto dependancies -DEPS=${join ${addsuffix ., ${dir ${OBJS}}}, ${notdir ${OBJS:.o=.d}}} - -.%.d: %.cpp - @set -e; rm -f $@; \ - ${CXX} -MM -MP -MT '${patsubst %.cpp,%.o,$<} $@' -MF $@ ${CXXFLAGS} $< 2>/dev/null - -ifneq (${MAKECMDGOALS},clean) --include ${DEPS} -endif diff --git a/MMVII/apib11/README.md b/MMVII/apib11/README.md index 3ac12db861..3b93b8c176 100644 --- a/MMVII/apib11/README.md +++ b/MMVII/apib11/README.md @@ -1,2 +1,40 @@ -pip3 install pybind11_mkdoc +MicMac v2 Python3 API +===================== +Compilation +----------- + +First, compile MMv1 and MMv2. + +Then, in 'apib11' directory: + + make + +The module can be used from this directory without installation (this local version has priority to installed modules). + +Installation +------------ + + make install + +Distribution +------------ + +The file dist/MMVII-*.whl, created at compilation, can be distributed to machines with same OS, arch and python version. + +It can be installed with: + + pip3 install MMVII-*.whl + +Upgrade pip if needed: + + python3 -m pip install --upgrade pip + +Usage +----- + +```python + import MMVII +``` + +See 'examples' directory for use cases. diff --git a/MMVII/apib11/ex_cam.py b/MMVII/apib11/ex_cam.py deleted file mode 100644 index 2e1a854e70..0000000000 --- a/MMVII/apib11/ex_cam.py +++ /dev/null @@ -1,55 +0,0 @@ -from MMVII import * - -""" - TP photogra - Data from MurSaintMartin -""" - - -pts3d = { - 'I-of-I': (0.754045221758523621, 0.496427193197002514, 0.431416432371162006), - 'Acute': (0.898750585424819226, 1.10409507249266081, 0.444680581722013746), - 'Finger-1': (1.31771333753878528, 0.989188464947304724, 0.370627429238321537), - 'Stone-6': (0.150697933447584281, 1.10818337179321613, 0.773464897817899177), - 'Stone-7': (0.256396378205514475, 2.35318759021626445, 2.23887785258234207), - 'Grille': (1.40207519252831658, 2.1945458898399548, 0.40382985984277503) -} - -pts2d = { - 'I-of-I': (430.52658272147653, 227.090326619720145), - #'u-of-You': (495.717626755149013, 454.825546116027397), - #'Acute': (431.735281413390453, 510.222991095907105), - #'Finger-1': (316.373353330086218, 471.678176822389275), - #'Stone-6': (667.402028214032839, 479.731591690534685), - 'Stone-7': (1284.05120739189965, 981.021140912616147), - 'Grille': (362.602015084684353, 1078.96450589692108) -} - -imName = 'IMGP4168.JPG' -calib = PerspCamIntrCalib.fromFile('Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5.xml') -cam = SensorCamPC(imName, Isometry3D.identity(), calib) - -# recompute orientation with 4 points -# TODO - - -# compare with oritentation in reference file -cam = SensorCamPC.fromFile('Ori-PerspCentral-IMGP4168.JPG.xml') - - -predicts = {} -for name, pt in pts3d.items(): - predicts[name] = cam.ground2ImageAndDepth(pt) - -# Show predictions -allX = [p.x for p in predicts.values()] -allY = [p.y for p in predicts.values()] - -import matplotlib.pyplot as plt -import matplotlib.image as mpimg -img = mpimg.imread(imName) -plt.imshow(img) -plt.scatter(allX, allY, 3) - - - diff --git a/MMVII/apib11/ex_camera_ori.py b/MMVII/apib11/examples/ex_camera_ori.py similarity index 90% rename from MMVII/apib11/ex_camera_ori.py rename to MMVII/apib11/examples/ex_camera_ori.py index af3398caec..9b698807bf 100644 --- a/MMVII/apib11/ex_camera_ori.py +++ b/MMVII/apib11/examples/ex_camera_ori.py @@ -1,6 +1,7 @@ from MMVII import * -cam = SensorCamPC.fromFile('Ori-PerspCentral-IMGP4168.JPG.xml') +dirData = '../../MMVII-TestDir/Input/Saisies-MMV1/' +cam = SensorCamPC.fromFile(dirData + 'Ori-Ground-MMVII/Ori-PerspCentral-IMGP4168.JPG.xml') pose = cam.pose icalib = cam.internalCalib diff --git a/MMVII/apib11/ex_test.py b/MMVII/apib11/examples/ex_test.py similarity index 66% rename from MMVII/apib11/ex_test.py rename to MMVII/apib11/examples/ex_test.py index 65f8078ced..2c7bc4e7b0 100644 --- a/MMVII/apib11/ex_test.py +++ b/MMVII/apib11/examples/ex_test.py @@ -2,7 +2,7 @@ import numpy as np -calib=PerspCamIntrCalib.fromFile("../MMVII-TestDir/Input/Ply/MMVII-PhgrProj/Ori/TestProjMesh/Calib-PerspCentral-Foc-14000_Cam-DCGX9.xml") +calib=PerspCamIntrCalib.fromFile("../../MMVII-TestDir/Input/Ply/MMVII-PhgrProj/Ori/TestProjMesh/Calib-PerspCentral-Foc-14000_Cam-DCGX9.xml") pp0=Pt3di(1,2,3) p0=Pt2di(0,0) p1=Pt2di(5,6) @@ -19,10 +19,10 @@ a=np.array(m,copy=False) -im=Im2Di.fromFile("../MMVII-TestDir/Input/EPIP/Tiny/ImL.tif") +im=Im2Di.fromFile("../../MMVII-TestDir/Input/EPIP/Tiny/ImL.tif") im_np=np.array(im,copy=False) -scpc=SensorCamPC.fromFile("../MMVII-TestDir/Input/Ply/MMVII-PhgrProj/Ori/TestProjMesh/Ori-PerspCentral-P1056160.JPG.xml") +scpc=SensorCamPC.fromFile("../../MMVII-TestDir/Input/Ply/MMVII-PhgrProj/Ori/TestProjMesh/Ori-PerspCentral-P1056160.JPG.xml") p=(10,20,100) diff=scpc.ground2ImageAndDepth(scpc.imageAndDepth2Ground(p))-p print("diff = ",diff) diff --git a/MMVII/apib11/examples/ex_tp_cam.py b/MMVII/apib11/examples/ex_tp_cam.py new file mode 100644 index 0000000000..2ec62736f0 --- /dev/null +++ b/MMVII/apib11/examples/ex_tp_cam.py @@ -0,0 +1,161 @@ +from MMVII import * +import matplotlib.pyplot as plt +import matplotlib.image as mpimg + +""" + TP photogra + Data from MurSaintMartin +""" + +dirData = '../../MMVII-TestDir/Input/Saisies-MMV1/' + +# from Ground-Pts3D.xml +pts3d = { + 'I-of-I': (0.754045221758523621, 0.496427193197002514, 0.431416432371162006), + 'Acute': (0.898750585424819226, 1.10409507249266081, 0.444680581722013746), + 'Finger-1': (1.31771333753878528, 0.989188464947304724, 0.370627429238321537), + 'Stone-6': (0.150697933447584281, 1.10818337179321613, 0.773464897817899177), + 'Stone-7': (0.256396378205514475, 2.35318759021626445, 2.23887785258234207), + 'Grille': (1.40207519252831658, 2.1945458898399548, 0.40382985984277503) +} + +# from GroundMeasure.xml +pts2d = { + 'IMGP4168.JPG' : { + 'I-of-I': (430.52658272147653, 227.090326619720145), + 'u-of-You': (495.717626755149013, 454.825546116027397), + 'Acute': (431.735281413390453, 510.222991095907105), + 'Finger-1': (316.373353330086218, 471.678176822389275), + 'Stone-6': (667.402028214032839, 479.731591690534685), + 'Stone-7': (1284.05120739189965, 981.021140912616147), + 'Grille': (362.602015084684353, 1078.96450589692108) + }, + 'IMGP4169.JPG' : { + 'I-of-I': (475.161154787777321, 516.404520623212079), + 'u-of-You': (538.999416573275425, 732.995393503311675), + 'Acute': (475.850364860953221, 802.548038024082189), + 'Finger-1': (362.721106696891582, 789.307120972098687), + 'Stone-6': (706.139274179003905, 741.525951210447488) + } +} + +######################################################## +# 1 - Read Calib, apply it +######################################################## + + +imName1 = 'IMGP4168.JPG' + +# Show 2d points +plt.title('Read 2d points') +allX, allY = zip(*pts2d[imName1].values()) +img = mpimg.imread(dirData + imName1) +plt.imshow(img) +plt.scatter(allX, allY, 30) +plt.show() + +# apply calibration +calib = PerspCamIntrCalib.fromFile(dirData + 'Ori-Ground-MMVII/Calib-PerspCentral-Foc-28000_Cam-PENTAX_K5.xml') + +dist = calib.dir_Dist() +sten = calib.calibStenPerfect() +inv_sten = sten.mapInverse() +inv_dist = DataInvertOfMapping2D(calib.dir_DistInvertible()) + +for name, pt in pts2d[imName1].items(): + print('Pt im: ', pt) + print(' -> central with disto: ', inv_sten.value(pt)) + print(' -> central no disto: ', inv_dist.value(inv_sten.value(pt))) + print(' -> lig/col no disto: ', sten.value(inv_dist.value(inv_sten.value(pt)))) + + +def mySten(calib: PerspCamIntrCalib, pt_central: tuple) -> tuple: + # TODO, see doc 3.2 + pass + +def myDist(calib: PerspCamIntrCalib, pt_central: tuple) -> tuple: + # TODO, see doc ... + pass + +print('Test mySten:') +for name, pt in pts2d[imName1].items(): + print('Pt im: ', pt) + pt_central = inv_sten.value(pt) + print(' -> central with disto: ', pt_central) + print(' -> my lig/col with disto: ', mySten(dist, pt_central)) + + +print('Test myDist:') +for name, pt in pts2d[imName1].items(): + print('Pt im: ', pt) + pt_central_nodist = inv_dist.value(inv_sten.value(pt)) + print(' -> central no disto: ', pt_central_nodist) + print(' -> my central with disto: ', myDist(dist, pt_central_nodist)) + + + +######################################################## +# 2 - Read Ori, projection +######################################################## + +cam1= SensorCamPC.fromFile(dirData + 'Ori-Ground-MMVII/Ori-PerspCentral-'+imName1+'.xml') + +# project ground points on image +allX, allY,_ = zip(*map(cam1.ground2ImageAndDepth,pts3d.values())) + +plt.title('Projected 3d points') +img = mpimg.imread(dirData + imName1) +plt.imshow(img) +plt.scatter(allX, allY, 30) +plt.show() + +def myGround2ImageAndDepth(camPose: Isometry3D, calib: PerspCamIntrCalib, pt3d: tuple) -> tuple: + # TODO, see doc 3.2 + pass + +for name, pt in pts3d.items(): + print('Proj MM: ', cam1.ground2ImageAndDepth(pt)) + print('My proj: ', myGround2ImageAndDepth(cam1.pose, cam1.internalCalib, pt)) + +######################################################## +# 3 - Pseudo-intersection +######################################################## + +# Second image +imName2 = 'IMGP4169.JPG' +cam2= SensorCamPC.fromFile(dirData + 'Ori-Ground-MMVII/Ori-PerspCentral-'+imName2+'.xml') + +# Compute 2d points without disortion +pts2d_nodist = {} +for imName in pts2d.keys(): + pts2d_nodist[imName] = {} + for name, pt in pts2d[imName].items(): + pts2d_nodist[imName][name] = list(inv_dist.value(inv_sten.value(pt))) + + +# TODO: compute 3d coordinates of common points +def myPseudoIntersect(cam1: SensorCamPC, pt2d1: tuple, cam2: SensorCamPC, pt2d2: tuple) -> tuple: + # TODO, see doc 3.2 + pass + +print('Pseudo-intersection:') +# apply to common points between im1 and im2 +for ptName, pt1 in pts2d[imName1].items(): + if not ptName in pts3d : + continue + if not ptName in pts2d[imName2] : + continue + pt2 = pts2d[imName2][ptName] + print(ptName, ': GND =', pts3d[ptName]) + print('Pseudo-intersection: ', myPseudoIntersect(cam1, pt1, cam2, pt2)) + + +######################################################## +# 4 - Orientation from known points +######################################################## + +# recompute orientation from 4 2d/3d points +# TODO + + + diff --git a/MMVII/apib11/py_MMVII.cpp b/MMVII/apib11/py_MMVII.cpp index 706eed9f5d..372c38d45c 100644 --- a/MMVII/apib11/py_MMVII.cpp +++ b/MMVII/apib11/py_MMVII.cpp @@ -9,8 +9,6 @@ namespace MMVII { void CloseRandom(); } -const char* pybindMMVIIDir = PYBIND_MMVII_DIR; - static void ErrHanlderPy(const std::string & aType,const std::string & aMes,const char * aFile,int aLine) { MMVII::ErrOut() << "\n\n######################################"; @@ -31,28 +29,33 @@ void ElExit(int aLine,const char * aFile,int aCode,const std::string & aMessage) } -class TheModule +class MM_Module { public: - TheModule() + MM_Module(const std::string &pybindMMVIIDir) { + if (init) //TODO: improve + { + ErrHanlderPy("python","MM_Module already initialized!",__FILE__,__LINE__); + } MMVII::cMMVII_Appli::InitMMVIIDirs(pybindMMVIIDir); MMVII::MMVII_SetErrorHandler(ErrHanlderPy); MMVII::InitStandAloneAppli("apipy"); MMVII::OpenRandom(); std::cout<<"MMVII initialized."<(m, "MM_Module") + .def(py::init()) + ; pyb_init_Ptxd(m); pyb_init_DataMappings(m); diff --git a/MMVII/apib11/pyproject.toml b/MMVII/apib11/pyproject.toml new file mode 100644 index 0000000000..89a314ed2e --- /dev/null +++ b/MMVII/apib11/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "wheel", "pybind11", "pybind11_mkdoc"] +build-backend = "setuptools.build_meta" diff --git a/MMVII/apib11/setup.py b/MMVII/apib11/setup.py new file mode 100644 index 0000000000..73a292696b --- /dev/null +++ b/MMVII/apib11/setup.py @@ -0,0 +1,57 @@ +import sys +import glob +import os + +# Available at setup time due to pyproject.toml +from pybind11 import get_cmake_dir +from pybind11.setup_helpers import Pybind11Extension +from setuptools import setup + +from pybind11.setup_helpers import ParallelCompile +ParallelCompile("NPY_NUM_BUILD_JOBS").install() + +__version__ = "0.0.2" + +module_name = 'MMVII' + +all_cpp_api_files = glob.glob('./*.cpp') + +cxxflags = ['-fopenmp', '-std=c++17', '-Wall', '-Werror', '-O3', '-fPIC'] + + +ext_modules = [ + Pybind11Extension("_MMVII", + all_cpp_api_files, + libraries = ['X11', 'Xext', 'm', 'dl', 'pthread', 'stdc++fs', 'gomp'], + library_dirs = [], + include_dirs = ['/usr/local/include', '.', '..', '../include/', '../ExternalInclude/'], + language = 'c++', + extra_objects = ['../bin/libP2007.a', '../../lib/libelise.a', '../../lib/libANN.a'], + extra_compile_args = cxxflags, + define_macros = [('VERSION_INFO', __version__)], + ), +] + +xml_micmac_files = glob.glob('../../include/XML_MicMac/*.xml') +xml_gen_files = glob.glob('../../include/XML_GEN/*.xml') + +setup( + name=module_name, + version=__version__, + author="IGN", + #author_email="", + url="https://github.com/micmacIGN", + description="MicMac v2 Python API", + long_description="", + ext_modules=ext_modules, + py_modules=['MMVII'], + data_files = [ + (module_name+"/MMVII/bin", ['../bin/MMVII']), + (module_name+"/include/XML_MicMac", xml_micmac_files), + (module_name+"/include/XML_GEN", xml_gen_files) + ], + platforms = ['x86_64'], + install_requires=['numpy'], + zip_safe=False, + python_requires=">=3.7", +)