Photogrammetry, OpenMVG/OpenMVS integration

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
kwahoo
Posts: 683
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Photogrammetry, OpenMVG/OpenMVS integration

Post by kwahoo »

I created this topic to compile some ideas from Polish and German forums.

Let's start from a small teaser, my ~30 y.o. teddy reconstructed by openMVG and openMVS:
https://sharemy3d.com/viewer.php?m=6316 ... 8bd70cccb8 <-WebGL viewer + downloadable OBJ model

Image

I used 7 photos (10 years old cheap compact camera and pretty bad lighting), and whole reconstruction process took ~5 minutes.

Here are used commands in short:

Code: Select all

python SfM_GlobalPipeline.py teddy_in teddy_global_out
InterfaceOpenMVG2 -i teddy_global_out/sfm_data.json -o teddy.mvs
DensifyPointCloud teddy.mvs
ReconstructMesh teddy_dense.mvs
TextureMesh teddy_dense_mesh.mvs
Another idea is using Points and Reverse engineering workbenches. I opened one of *.ply files created by openMVS in Meshlab, and saved the point cloud as xyz without normals, finally renaming it to an *.asc file. Then I used Reverse engineering algorithms to create a surface:

Code: Select all

import ReverseEngineering as Reen
points = App.ActiveDocument.teddy.Points
data = [(i.x,i.y,i.z) for i in points.Points]
surf=Reen.approxSurface(Points=data,UDegree=2,VDegree=2,NbUPoles=18,NbVPoles=18,Smooth=True,Weight=0.01,Grad=0.9,Bend=0.1,Iterations=5,Correction=True,PatchFactor=1.2)
shape=App.ActiveDocument.addObject("Part::Spline")
shape.Shape=surf.toShape()
Image
Unfortunately the process was slow, and the results (as you can see) are not so great....

The aim: I want create some kind of frontend in FreeCAD, using openMVG/openMVS in similar fashion as Calculix is used in the FEM workbench. Some things to consider implementation:
a) fast 3d point cloud with colours object - for displaying point cloud
b) rendering 3d meshes with textures (not possible yet?)

Other ideas? I'm open for them, this a random project for long winter nights;)
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Photogrammetry, OpenMVG/OpenMVS integration

Post by wmayer »

If you have pcl >= 1.7.0 you can link FreeCAD against it and use it as "Reen.fitBSpline".
User avatar
kwahoo
Posts: 683
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: Photogrammetry, OpenMVG/OpenMVS integration

Post by kwahoo »

Thanks Werner.

I compiled FreeCAD with FREECAD_USE_PCL and libpcl 1.7.0, but I cannot find fitBSpline method. There is nothing visible in Python except approxSurface() and triangulate().

OS: Ubuntu 15.10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.5950 (Git)
Build type: Unknown
Branch: master
Hash: 2362239edf3dfffa5c5951d828388663e5ed7dfd
Python version: 2.7.10
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Photogrammetry, OpenMVG/OpenMVS integration

Post by wmayer »

I compiled FreeCAD with FREECAD_USE_PCL and libpcl 1.7.0, but I cannot find fitBSpline method. There is nothing visible in Python except approxSurface() and triangulate().
Strange. Anyway, I tried this method too last week and the result wasn't much better either. The problem is that you can't fit a single surface on the full point cloud because you really need a lot of control points to approximate them more or less good. But the more control points you have the longer it takes. So, the point cloud must be split into segments and each of them can then be fitted by a surface.
User avatar
kwahoo
Posts: 683
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: Photogrammetry, OpenMVG/OpenMVS integration

Post by kwahoo »

I have one more question.

I'm trying import PLY point cloud file, as listed below:

Code: Select all

ply
format ascii 1.0
element vertex 3
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
end_header
0.126044 0.178839 0.988219 186 205 177
0.100327 0.199456 0.987811 141 114  93
0.120858   0.1834  0.98431 162 164 142
I selected "Open ply as PLY points (Points)". Unfortunately FreeCAD returned an error

Code: Select all

Open in Points with /home/adi/colorized-test.plyTraceback (most recent call last):
  File "<string>", line 1, in <module>
<class 'Base.FreeCADError'>: unknown file ending
Is the file syntax wrong?

Edit: I just found that thread viewtopic.php?t=12557

It works with USE_PCL enabled.
mario52
Veteran
Posts: 4690
Joined: Wed May 16, 2012 2:13 pm

Re: Photogrammetry, OpenMVG/OpenMVS integration

Post by mario52 »

hi
same error with file PCD (ver .7) cloud FreeCAD not accept the color accept only XYZ (home)
and not X Y Z 1 1 1 or

Code: Select all

# .PCD v.7 - Point Cloud Data file format
VERSION .7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1
WIDTH 213
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 213
DATA ascii
0.93773 0.33763 0 4.2108e+06
0.90805 0.35641 0 4.2108e+06
0.81915 0.32 0 4.2108e+06
not problem with

Code: Select all

# .PCD v.5 - Point Cloud Data file format
VERSION .5
FIELDS x y z
SIZE 4 4 4
TYPE F F F
COUNT 1 1 1
WIDTH 397
HEIGHT 1
POINTS 397
DATA ascii
0.0054216 0.11349 0.040749
try only with coordinates XYZ to see

(ps: i use only coordinate without header and without color
for the color i make my procedure (not finished))
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
cogitas3d
Posts: 1
Joined: Thu Feb 18, 2016 2:23 pm

Re: Photogrammetry, OpenMVG/OpenMVS integration

Post by cogitas3d »

Hi kwahoo!

My question (O.T.) is about how do you was able to build OpenMVS on Ubuntu with support of OpenMVG?

I'm triyng to do this, following the GigHub tutorial, but ever appear OPENMVG_NOT FOUND :(

Thank you for attention!
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Photogrammetry, OpenMVG/OpenMVS integration

Post by jmaustpc »

cogitas3d wrote: My question (O.T.) is

your first post, welcome to FreeCAD.

About your actual question though, I will unfortunately have to leave others as I don't know the answer. :)
User avatar
kwahoo
Posts: 683
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: Photogrammetry, OpenMVG/OpenMVS integration

Post by kwahoo »

cogitas3d wrote:
My question (O.T.) is about how do you was able to build OpenMVS on Ubuntu with support of OpenMVG?

I'm triyng to do this, following the GigHub tutorial, but ever appear OPENMVG_NOT FOUND :(
Yes, I was. Are you cmake arguments similar to mine?

Code: Select all

cmake . ../openMVS -DCMAKE_BUILD_TYPE=RELEASE -DVCG_DIR="$main_path/vcglib" -DCERES_DIR="/usr/local/share/Ceres" -DOpenCV_CAN_BREAK_BINARY_COMPATIBILITY=OFF -DOpenMVG_DIR:STRING="/home/adi/Desktop/fotogrametria/openMVG_Build/openMVG_install/share/openMVG/cmake/"
Post Reply