OpenMesh is a very powerful library for processing 3D meshes. It provides a wide range of operations for meshes (like creating vertices and faces, manipulation with texture mapping of vertices) and moreover includes handful functions for iterating over adjacent vertices and faces in mesh. OpenMesh has Python version which can be used for fast implementation.
Here I will show how to work with 3D meshes using Python bindings of OpenMesh library.
Install it using pip:
pip install openmesh
Let’s write a simple test app using openmesh module
import openmesh as om
import numpy as np
Create mesh object
mesh =…
There are two awesome Linux commands providing a great flexibility in manipulating with text files: awk and sed. These commands sadly are not so popular and widely highlighted as another Linux commands. Let’s see what we can do with these commands.
Print all line containing string
awk '/mtllib/' test.txt
Print line number for lines containing substring
awk '/mtllib/ {print NR, $1, $2}' test.txt
Print fifth line
awk 'NR==5 {print}' test.txt
Print number of lines in file
awk 'END {print NR}'
Interesting trick: compare output of two commands awk using command diff
awk '{print $3}' f1.txt | sort -u > out1…
There is a great library OpenMesh for working with 3D meshes which has Python version.
I had a problem with saving texture coordinates in obj file. I use Python version of OpenMesh for manipulating with texture coordinates in 3D mesh stored in obj file and save the result mesh using method write_mesh. When I open the resultant obj file there is no texture coordinates information, only list of vertices and faces.
Let’s say we have following code
mesh = om.TriMesh()
# create vertices
vh0 = mesh.add_vertex([0, 1, 0])
vh1 = mesh.add_vertex([1, 0, 0])
...
mesh.set_texcoord2D(vh1, [0.24, 0.4])
And we write…
When apply Hole closing filter in Meshlab duplicate vertices can occur.
I have told about this filter in this post. Here we will see what problems can occur due to the presence of duplicate vertices in obj file and how we can fix it using MeshLab.
Let’s test on simple example. Create obj file with following content
v 0 0 0 v 1 0 0 v 0 1 0 v 1 1 0 f 0 1 2 f 1 2 3…
Common problem with 3D meshes is incomplete surface with holes. That could be caused by imperfect reconstruction algorithm or low quality in depth sensor.
We can easily repair surfaces of mesh in Meshlab program. Meshlab includes special filter for filling holes in 3D meshes.
First open Meshlab. Then import mesh: File > Import Mesh.
Here is an example of mesh with holes
Now apply filter. Open Filters > Remeshing, Simplification … > Close Holes
We can easily profile functions in Python using line_profiler package. This package profiling functions simply using decorator around these functions.
First Install package:
pip install line_profiler
And add decorator @profile around function
@profile
def fact(n):
if n == 0: return 1
elif n == 1: return 1
Then use profiler. First create dump file for out test.py
kernprof --line-by-line test.py
This command will create file test.py.lprof
Now run profiler
python -m line_profiler test.py.lprof
Output
Timer unit: 1e-06 sTotal time: 1e-05 s
File: test.py
Function: fact at line 1Line # Hits Time Per Hit % Time Line Contents ==============================================================…
Sometimes when run PyTorch model with GPU on Kaggle we get error “RuntimeError: CUDA out of memory. Tried to allocate …”
Clear memory with command:
torch.cuda.empty_cache()
Check CUDA memory
!pip install GPUtil
from GPUtil import showUtilization as gpu_usagegpu_usage()
Output
| ID | GPU | MEM |
------------------
| 0 | 0% | 0% |
We had a task to find best matching image to the given query image.
First we tried classic image matching with SIFT descriptors and Flann based matcher in OpenCV. Results were completely wrong. Then Bag-of-Words …
Finally we have learnt about combination of AffNet and HardNet from these slides.
AffNet is a novel method for learning local affine-covariant regions with
the hard negative-constant loss which outperform s the state-of-the-art in Bag-of-Words image retrieval and wide baseline stereo.
HardNet is a novel compact learned feature descriptor showing state-of-art superior performance relating to both hand-crafted and learned descriptors on standard matching and…
Lets imagine we need to compile some C++ library and get error telling that newer version of cmake is required. For instance, I had cmake v2.8 but version larger than 3.1 was required.
Compile cmake from source
$ sudo su
And compile it
# apt-get update
# apt-get dist-upgrade
# cd /Downloads
/Downloads# wget https://cmake.org/files/v3.5/cmake-3.5.0-rc1.tar.gz
/Downloads# tar xzf cmake-3.5.0-rc1.tar.gz
/Downloads# cd cmake-3.5.0-rc1
/Downloads/cmake-3.5.0-rc1#
Rename the existing installation directory to the new version where, “x.x” is the existing installation directory and “3.5” will be the new name. …
We had a task to detect anomalies (oil spill, excavation, materials storage etc) from UAV photos. There is no dataset of UAV photos containing such anomalies. In this post I will tell how to training YOLOv5 object detection model from scratch on own dataset.
Oil company using drones for monitoring oil production areas. There some anomalies could take place like oil spill, excavation, storage of material,
work of special equipment. This process is done manually which is time consuming. Artificial intelligence can be used here to automatically detect such anomalies from UAV photos. …