In this blog post, I am going to provide a short overview of the concept of position independent code and its specification in CMake, particularly in projects using pybind11. Some time ago, when I was working on the FxIS project, which was developed in C++ with the additional Python extension realized with pybind11, I encountered a linking error, which included a line similar to this: /usr/bin/ld: libcore.a(sum.cpp.o): relocation R_X86_64_PC32 against symbol .
In the modern versions of C++ (starting from C++11) one encounters a concept of move semantics. It may confusing a bit, and in this post I am going to provide my notes on the topic (mostly based on Bjarne Stroustrup’s The C++ Programming Language (4th edition): sections 3.3, 7.7.2, 17.5.2). The first important concept is rvalue reference. For a type T, a rvalue reference is T&& (note the double ampresand). It basically represents a reference to a temporary object that is assumed to be modified and not used again.
In this post I am going to provide some examples of Git usage that may come in handy in case of unsuccessful previous actions during staging, committing, and merging. Let’s say you have staged some files to be further committed with git add and then change your mind. To unstage all or some files, invoke the git reset command (which is in a way an inverse of git add). A scenario for all changed files:
rsync is an extremely useful utility for synchronizing files between remote computers. It is the primary tool I use to deploy code to targets such as servers, Raspberry Pies, or other remote Linux machines. In this post, I am going to show the basic rsync usage examples, break down the meaning of the widely-used options of the rsync command, and demonstrate the principles of deployment of files to an AWS EC2 instance using rsync with an SSH key.
Jupyter Notebook is a great tool for data science prototyping, visualization and sharing. The first code cell of every notebook I work on contains the following commands: %matplotlib inline %load_ext autoreload %autoreload 2 These are some of the IPython Magic commands – handy enhancements added on top of the standard Python syntax to solve various tasks specific to interactive computing. The first line in the snippet above configures the notebook session to visualize and store all the Matplotlib figures inside the notebook.
Python works great together with native code. The success of the Python data science stack is largely attributed to the capability of building native extensions. It is no secret, however, that the out-of-the-box C-based facilities are rather cumbersome to use. Luckily, there are a bunch of alternatives out there. The one I liked the most is Pybind11, a fork of Boost.Python with focus on the modern C++ standards. It is distributed as a lightweight header-only library that can be bundled with your project.
When it comes to building and installing OpenCV with Python support on *nix platforms, the collection of tutorials by Adrian Rosebrock is the best. He provides detailed description of the required steps, as well as motivation for better development practices. In particular, Adrian creates a dedicated virtualenv environment, installs NumPy in it, and builds the whole thing having this environment activated. Such a solution worked pretty well for me, both on Linux and macOS.
When working with GigE Vision cameras, it is important to be able to receive Ethernet frames of larger sizes than one gets in the default configuration. In particular, the default value of Maximum Transmission Unit (MTU) is 1500 bytes. By setting this parameter to the maximum (9000 bytes), a video streaming application handles smaller number of frames per second. This results in a decreased CPU load by cutting the number of operations for reconstructing image data from multiple small Ethernet frames.
It’s been a long time since I planned to start a blog where I would publish various technical tricks which I have experienced in my work. I had greatly benefited from the others’ contributions – in blogs, Stack Overflow, and open-source software – and it’s definitely a good idea to share my own knowledge in an organized way. The goal is to make this blog a useful and interesting resource, perhaps with more than just nerdy stuff.