OpenCV Viz seems to be able to load 3D wavefront (.obj) image as well as to display them. I was searching for some tutorial explaining the basic steps, but without success.
I have both obj and jpg files which contains all the information to display a 3D colored image, as I obtained by using the simple 3D viewer f3d.
Someone could be kindly explain me the basic commands for loading my 3D wavefront images and displaying them?
OpenCV is a computer vision library, not a 3D object viewer. If you’d like to display an obj file, probably there are better solutions.
But In static Mesh is possible Loads a mesh from a ply or a obj file.
Maybe I misunderstood , but it seem quite close to my purpose. For me even only the loading and storing of such data would be great.
Thanks for the explanation!
tutorial for the viz module:
https://docs.opencv.org/3.4/d7/df9/tutorial_table_of_content_viz.html
mesh class that can load such files:
https://docs.opencv.org/3.4/dc/d4f/classcv_1_1viz_1_1Mesh.html
I read those links. For that I believed that opencv could manage 3D images, that is (x,y,z, color). So now I am again confused.
Many thanks Laurent, but that does not solve my problem:
I obtained a wavefront file (.obj) and the related jpg images of an object of my interest by a 3D scanner.
Now I am wondering if I can load it in my C++ code by means of the OpenCV library (as an example by viz::mesh).
More precisely, of the whole obj file I am just interested to the vertex coordinates together with the colour associated at each one vertex.
Have you try load in viz module? there is an obj format
Yes of course. I tried by the following command, but it return error
viz::Mesh Mesh=load (nameFD, LOAD_OBJ);
What’s error message ? It works for me
with this code :
viz::Viz3d window("Coordinate Frame");
window.setWindowSize(Size(500, 500));
window.setWindowPosition(Point(150, 150));
window.setBackgroundColor(); // black by default
cv::viz::Mesh x;
x = cv::viz::Mesh::load("airboat.obj",cv::viz::Mesh::LOAD_OBJ);
cv::viz::WMesh a(x);
/// Create and show widgets
window.showWidget("point_cloud", a);
/// Wait for key 'q' to close the window
cout << endl << "Press 'q' to close each windows ... " << endl;
window.spin();
obj file is here
GREAT!!!
I even successfully loaded my file!!!
Now I have the last question: how to use the jpg file produced by the scanner to set the color to the image?
Add colors :
viz::Viz3d window("Coordinate Frame");
window.setWindowSize(Size(500, 500));
window.setWindowPosition(Point(150, 150));
window.setBackgroundColor(); // black by default
cv::viz::Mesh x;
x = cv::viz::Mesh::load("C:\\Users\\Laurent\\Desktop\\airboat.obj", cv::viz::Mesh::LOAD_OBJ);
Mat couleur(1,x.cloud.cols,CV_8UC3);
randu(couleur, 0, 255);
x.colors = couleur;
cv::viz::WMesh a(x);
/// Create and show widgets
window.showWidget("point_cloud", a);
/// Wait for key 'q' to close the window
cout << endl << "Press 'q' to close each windows ... " << endl;
window.spin();
Sorry Laurent, the colors I need are the real ones of the object as taken by the 3 D scanner : as matter of fact its output is composed by 3 files, Model.obj Model.jpg. and Model.mtl.
The jpg is quite strange because appear as composed by a main photos of the object plus other smaller part of it.
If I load the obj file with F3D I see the object right colored.
If I suppress the jpg, I obtain a image with gray level, as the one you shown.
Unfortunately the upload functionality of this forum does not allow obj. I send you the jpg.
To find a color for each 3d point you need camera pose and calibration matrices relative to jpeg image
By googling I found this site where is explained what I need: UV mapping - Wikipedia
Maybe what are you saying is the content of the mtl file, which is following:
newmtl material0
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.000000 0.000000 0.000000
Tr 1.000000
illum 1
Ns 0.000000
map_Kd Model.jpg
How do you get your data (harware)?
Good morning Laurent.
We use the low cost device STRUCTURE by Occipital to be intsalled on an iPad. When the 3D scanning is done, an email is sent with a zip file containing the 3 files obj, mtl and jpg.
Finally I understood: I attached an image where the plot of the values of the “vt” rows of the obj file (X=vt_1 ; Y=vt_2) is compared with the strange jpg image. As you can see the jpg image can be use to assign the proper color to each geometrical vertex. Thais the so called UV mapping above cited.
I suppose should be some viz function to manage the UV mapping