December 22, 2017

TP-LINK TL-WN823N v2 on Raspberry Pi 2 Model B with Raspbian

At the beginning use http://blog.junaid.site/2017/07/11/tl-wn823n-driver-in-raspberry-pi-2-b/

In the end lsusb still can provide only line:
Bus 001 Device 004: ID 2357:0109.

Do not worry, I did not make lsusb work either, but changing /etc/network/interfaces to

auto lo
auto eth0

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0


iface wlan0 inet dhcp
        wpa-ssid "xxx"
        wpa-psk "xxx"

did the job. Results can be seen in ifconfig.
Btw to enable ssh go to Preferences -> Raspberry Pi Configuration -> Interfaces -> SSH -> Enabled
and reboot.

January 21, 2016

Linux installation of OpenCV, Qt, VTK, PCL, avahi, PointGrey, gcc, Boost, Ximea with dependencies

  • Tested on Ubuntu 14.04 64-bit
  • One of comfortable Linux IDEs is CLion.
  • CLion 1.2 IDE
https://www.jetbrains.com/clion/help/installation-and-launching.html
In addition to CLion is perfect IDE with many built-in functionality, Clion uses cmake files as solution files. 
  • essential tools
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
  • opencv
  • qt
mkdir qt5.5.1-install && cd qt5.5.1-install
wget http://download.qt-project.org/official_releases/qt/5.5/5.5.1/qt-opensource-linux-x64-5.5.1.run
chmod +x qt-opensource-linux-x64-5.5.1.run
./qt-opensource-linux-x64-5.5.1.run
  • vtk
http://www.vtk.org/Wiki/VTK/Tutorials/QtSetup

mkdir ~/VTK-Release-qt5.5.1-build && ~/VTK-Release-qt5.5.1-build
cmake -DVTK_QT_VERSION:STRING=5 -DQT_QMAKE_EXECUTABLE:PATH=~/qt5.5.1-install/5.5.1/gcc_64/bin/qmake -DVTK_Group_Qt:BOOL=ON -DCMAKE_PREFIX_PATH:PATH=~/qt.5.5.1-install/5.5.1/gcc_64/lib/cmake -DBUILD_SHARED_LIBS:BOOL=ON ~/VTK-6.3.0
make -j8
make install
x11_xt_lib could not be found when you run ccmake,
try
sudo apt-get install libxt-dev 
  • pcl
use setup, apart from OpenNI/2 and installation libflann1

cmake -DCMAKE_BUILD_TYPE=None -DBUILD_GPU=ON -DBUILD_SHARED_LIBS:BOOL=On ..
make -j 8
make install
Question: How to distinguish among boost, flann, pcl configurations on linux.
  • avahi
sudo apt-get install avahi-daemon (should be already installed)
apt-get install libavahi-client-dev
  • ximea
https://www.ximea.com/support/documents/4
to be compatible with our CMake, please copy result to ~/XIMEA_Linux_SP
  • pointgrey
sudo apt-get install libraw1394-11 libgtkmm-2.4-1c2a libglademm-2.4-1c2a libgtkglextmm-x11-1.2-dev libgtkglextmm-x11-1.2 libusb-1.0-0
cd flycapture2-2.8.3.1-amd64/
sudo sh install_flycapture.sh
  • need > gcc.4.9.0, because of variadic templates
http://stackoverflow.com/questions/22568642/parameter-packs-not-expanded-with-another-variadic-template-bug-with-gc

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5
  • some links to be followed in troubles
http://stackoverflow.com/questions/16257564/linker-error-undefined-reference-to-symbol-pthread-rwlock-trywrlockglibc-2-2
http://stackoverflow.com/questions/1620918/cmake-and-libpthread


January 19, 2016

Bonjour on Windows

Overview

  • Install Bonjour64.msi.
From now there should be Bonjour Services automatically running at your comp.
You can install Bonjour SDK to see examples in several laguages.
  • Callbacks must be static, so any information you want to provide, use void* context parameter
  • You can set several searchers. Then wait with select function until some answer is ready and call it with DNSServiceProcessResult(?), where ? is first parameter of searcher function or read (***) for other possibility.
  • DNSServiceProcessResult inside run callback(s).
Basic searching consists of several steps:
  • searcher  DNSServiceBrowse. if regtype == "_services._dns-sd._udp", it looks for all regtypes on network, otherwise it looks for instances of given regtype (in first case again call with one or more concrete regtypes)
  • searcher DNSServiceResolve for resolve concrete instance
  • searcher DNSServiceGetAddrInfo and DNSServiceQueryRecord
DNSServiceBrowse, DNSServiceQueryRecord usually runs indefinitely looking for change
do not forget DNSServiceRefDeallocate on DNSServiceRef given to DNSServiceResolve and DNSServiceGetAddrInfo.
  • You need dns_sd.h and dnssd.lib

What is not clear at first glance

  • DNSServiceProcessResult might run not only one, but several callbacks.
  • err -65563 == kDNSServiceErr_ServiceNotRunning, Start Bonjour Service. It sometimes stop working.
  • You have two possibilities (***):
    1. DNSServiceRef client = NULL;
    DNSServiceErrorType err = DNSServiceBrowse(&client,
    And then use DNSServiceRefSockFD(client) for select function

    2. DNSServiceErrorType err = DNSServiceCreateConnection(&clientDefault);
    DNSServiceRef client = clientDefault;
    DNSServiceErrorType err = DNSServiceBrowse(&client,
    And then use DNSServiceRefSockFD(clientDefault) for select function
    and so you can use client Default for many calls
  • You will use sockets on windows:
There are two version of socket library: winsock2.h and winsock.h, first one want to use.

http://stackoverflow.com/questions/9153911/is-there-a-difference-between-winsock-h-and-winsock2-h
http://stackoverflow.com/questions/14094457/winsock-h-winsock2-h-which-to-use
https://msdn.microsoft.com/en-us/library/windows/desktop/ms737629(v=vs.85).aspx

#include<winsock2.h> before #include<windows.h> and also before #include<dns_sd.h> which includes windows.h

i.e.

#include <winsock2.h>
#include <ws2tcpip.h>
#include <Iphlpapi.h>
#include <process.h>

#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "Iphlpapi.lib")
#include <dns_sd.h>

January 16, 2016

VMware - how to start

Today there are two: VMware 12 Player and Pro version, comparison here

https://www.vmware.com/products/workstation/compare.html#table2

Download i.e. here.

First of all after you have installed operating system:

Click the "VM" in menu and select "Install VMware Tools"
Then unpack vmware-tools-distrib folder and run in terminal
"cd WhereYouUnpackedIt"
"sudo perl vmware-install.pl"

After restart VM you have Clipboard and Drag&Drop active.
Then right click to YourVMtab->settings->Options->SharedFolders and set it. In Ubuntu you will find it here: /mnt/hgfs/

January 15, 2016

CPack NSIS Windows installer

When we use CMake for build it is almost straightforward to extend its usage to create installer.
It provides several advantages.

  • CPack generate new project in Visual Studio dependent from all others and building it we create installer on one click
  • installer often depends on .h files (.api) or .lib files (api) or .dll (exec) which are changed in CMake by developers during building project. In all these cases installer assembles all needed component.
  • cross-platform solution
As usual we need do standard steps but also encounter several problems.

Standard steps:

  • install targets with COMPONENT parameter target belongs to
  • if you have msvc project
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
include(InstallRequiredSystemLibraries)
install(PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
      DESTINATION bin/dll/Msvc
      COMPONENT Driver)
  • provide all needed dlls, i.e.
set(BoostDllDIR ${Boost_LIBRARY_DIR_RELEASE})
file(GLOB BoostDllList "${BoostDllDIR}/*.dll")
install(FILES ${BoostDllList}
       DESTINATION bin/dll/Boost
       COMPONENT Driver)
  • provide msi installers your app depends on, i.e.
install(PROGRAMS DependencyInstall/Bonjour64.msi
          DESTINATION DependencyInstall
 COMPONENT Driver)
  • provide exe installers your app depends on, i.e. (if your project is from msvc, do exactly this)
install(PROGRAMS DependencyInstall/vcredist_x64.exe
          DESTINATION DependencyInstall
          COMPONENT Driver)
  • copy whole directories
set(DATA_FILE_DIR D:/data)
install(DIRECTORY ${DATA_FILE_DIR}/
       DESTINATION data
       COMPONENT Driver)
  • set standard CPack variables
CPACK_PACKAGE_NAME
CPACK_PACKAGE_VENDOR 
CPACK_PACKAGE_DESCRIPTION_SUMMARY 
CPACK_PACKAGE_VERSION_MAJOR 
CPACK_PACKAGE_VERSION_MINOR 
CPACK_PACKAGE_VERSION_PATCH 
CPACK_PACKAGE_VERSION 
CPACK_PACKAGE_INSTALL_DIRECTORY
CPACK_COMPONENTS_ALL
CPACK_COMPONENT_???_DISPLAY_NAME
CPACK_COMPONENT_???_DESCRIPTION
CPACK_COMPONENT_???_DEPENDS
CPACK_COMPONENT_???_GROUP
CPACK_COMPONENT_GROUP_???_DISPLAY_NAME
CPACK_COMPONENT_GROUP_???_DESCRIPTION
CPACK_RESOURCE_FILE_LICENSE
CPACK_PACKAGE_ICON #use \\\\ where / or \ should be
CPACK_NSIS_MUI_ICON
CPACK_NSIS_MUI_UNIICON
CPACK_NSIS_MENU_LINKS

Nonstandard steps:


Not all steps you could wish are possible in CPack, but you can directly inject NSIS code. There are two lists of commands:
CPACK_NSIS_EXTRA_INSTALL_COMMANDS used in installation
CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS used in uninstallation
Main problem is how to escape strings to be parsed right. Follow the examples.
  • execute 3rdParty .exe installers
list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS " 
     ExecWait '$INSTDIR\\\\DependencyInstall\\\\vcredist_x64.exe /quiet /norestart'
     ")
  • execute 3rdParty .msi installers. There is problem (at least on my machine) to run msi installer if installation dir is protected, like Program Files. Workaround is to run it from unprotected folder like AppData/Local
list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
CopyFiles '$INSTDIR\\\\DependencyInstall\\\\Bonjour64.msi' '$LOCALAPPDATA\\\\MyProgramName\\\\Bonjour64.msi'
")
list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
         ExecWait 'msiexec /quiet /qn /norestart /i $LOCALAPPDATA\\\\MyProgramName\\\\Bonjour64.msi'
         ")
  • set entries in Windows Registry (why? check my another post  about dlls and exe) and after uninstallation remove them (we filled variable ${WindowsRegistryPath} in CMake with proper string)
set(DllInstallationPrefix "$INSTDIR/bin/dll")
set(WindowsRegistryPath "")
set(WindowsRegistryPath "${WindowsRegistryPath}${DllInstallationPrefix}/Msvc;")
set(WindowsRegistryPath "${WindowsRegistryPath}${DllInstallationPrefix}/Boost;")
list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
             WriteRegStr HKLM 'SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\App Paths\\\\MyProgram.exe' '' '$INSTDIR/bin/MyProgramExe.exe'
             WriteRegStr HKLM 'SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\App Paths\\\\MyProgram.exe' 'Path' '${WindowsRegistryPath}'")
list(APPEND CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
             DeleteRegKey HKLM 'SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\App Paths\\\\MyProgram.exe'")

CMake - useful tips

What you may need in your simple project and cannot find in tutorials (especially issues about per configuration settings -
for other usages than examples here please refer to https://cmake.org/cmake/help/v3.0/policy/CMP0043.html) 
  • get absolute path
get_filename_component(ALPHAROOT "../../../../../../../../../../../../.." ABSOLUTE CACHE)
  • black font 
message(STATUS "what I wanted to say")
  • set OutputDirectory
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY D:/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY D:/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY D:/bin)
  • some cache variables are set at the time of command "project(ProjectName)", co if you can cache these variables but set default value for them
set them before command "project(ProjectName)"
  • decide according to platform you are generating for
if( WIN32 )
if( MSVC )
if( CMAKE_COMPILER_IS_GNUCXX )
if( UNIX )
  • set custon set of configurations 
#(write before "project(ProjectName)" command)
set(CMAKE_CONFIGURATION_TYPES Debug Release ClientConfig DebugFileCamera ReleaseFileCamera  CACHE TYPE INTERNAL FORCE)
  • specify configurations which should be taken as debug (i.e. which should link with debug libs)
set_property(GLOBAL PROPERTY 
DEBUG_CONFIGURATIONS 
"Debug;DebugFileCamera")
  • compiler flags per configuration (i.e. configration with name ClientConfig)
set(CMAKE_CXX_FLAGS_CLIENTCONFIG "${CMAKE_CXX_FLAGS_RELEASE} /W1")
  • linker flags per configuration (i.e. configration with name ClientConfig) & how to avoid error with /SUBSYSTEM:WINDOWS
set(CMAKE_EXE_LINKER_FLAGS_CLIENTCONFIG "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup"
)
  • postfix per configuration
set(CMAKE_CLIENTCONFIG_POSTFIX "_ClientConfig" CACHE STRING "x")
#but it does not work for executables
#you must do it per target
set_target_properties( MySubprojct
    PROPERTIES
    DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
    RELEASE_POSTFIX ${CMAKE_RELEASE_POSTFIX}
    CLIENTCONFIG_POSTFIX ${CMAKE_CLIENTCONFIG_POSTFIX}
    DEBUGFILECAMERA_POSTFIX ${CMAKE_DEBUGFILECAMERA_POSTFIX}
    RELEASEFILECAMERA_POSTFIX ${CMAKE_ RELEASEFILECAMERA_POSTFIX}
)
  • set compile definition

set_property(DIRECTORY APPEND PROPERTY
 COMPILE_DEFINITIONS _WIN32_WINNT=0x0501
)
  • set compile definition per configuration
set_property(DIRECTORY APPEND PROPERTY
  COMPILE_DEFINITIONS $<$<CONFIG:ClientConfig>:CLIENT_CONFIG>
  )
  • embed OpenCV
#use first line if you want to use dynamically linked OpenCV
set(OpenCV_STATIC OFF)
FIND_PACKAGE(OpenCV REQUIRED)

#OpenCV does not distinguish between debug and release configurations
# as we have labeled it, we must set it separately(i.e.)
set_target_properties(${OpenCV_LIBS} PROPERTIES MAP_IMPORTED_CONFIG_DEBUGFILECAMERA "DEBUG")
  • embed Boost
FIND_PACKAGE(Boost REQUIRED COMPONENTS 
  system
  filesystem
  thread
  date_time
  iostreams
  serialization
  chrono
  atomic
  regex
  log
)
  • embed VTK
FIND_PACKAGE(VTK REQUIRED)
include(${VTK_USE_FILE})
# again VTK does not distinguish between debug and release configurations 
#as we have labeled it, we must set it separately(i.e.)
set_target_properties(${VTK_LIBRARIES} PROPERTIES MAP_IMPORTED_CONFIG_DEBUGFILECAMERA "DEBUG")
#another problem is with VTK, after use copy paste this
macro(REMOVE_VTK_DEFINITIONS)
   get_directory_property(_dir_defs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
   set(_vtk_definitions)
   foreach(_item ${_dir_defs})
       if(_item MATCHES "vtk*")
           list(APPEND _vtk_definitions -D${_item})
       endif()
   endforeach()
   remove_definitions(${_vtk_definitions})
endmacro(REMOVE_VTK_DEFINITIONS)

REMOVE_VTK_DEFINITIONS()
  • embed Qt
find_package(Qt5Gui)
find_package(Qt5Core)
find_package(Qt5Widgets)

if (${Qt5Gui_FOUND} AND ${Qt5Core_FOUND} AND ${Qt5Widgets_FOUND})
message(STATUS "Qt5 found")
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#Qt also does not distinguish between debug and release configurations 
#as we have labeled it, we must set it separately(i.e.)
set_target_properties(Qt5::Core PROPERTIES MAP_IMPORTED_CONFIG_DEBUGFILECAMERA "DEBUG")
set_target_properties(Qt5::Core PROPERTIES MAP_IMPORTED_CONFIG_RELEASEFILECAMERA "RELEASE")
set_target_properties(Qt5::Core PROPERTIES MAP_IMPORTED_CONFIG_CLIENTCONFIG "RELEASE")

set_target_properties(Qt5::Widgets PROPERTIES MAP_IMPORTED_CONFIG_DEBUGFILECAMERA "DEBUG")
set_target_properties(Qt5::Widgets PROPERTIES MAP_IMPORTED_CONFIG_RELEASEFILECAMERA "RELEASE")
set_target_properties(Qt5::Widgets PROPERTIES MAP_IMPORTED_CONFIG_CLIENTCONFIG "RELEASE")

set_target_properties(Qt5::Gui PROPERTIES MAP_IMPORTED_CONFIG_DEBUGFILECAMERA "DEBUG")
set_target_properties(Qt5::Gui PROPERTIES MAP_IMPORTED_CONFIG_RELEASEFILECAMERA "RELEASE")
set_target_properties(Qt5::Gui PROPERTIES MAP_IMPORTED_CONFIG_CLIENTCONFIG "RELEASE")

set_target_properties(Qt5::WinMain PROPERTIES MAP_IMPORTED_CONFIG_DEBUGFILECAMERA "DEBUG")
set_target_properties(Qt5::WinMain PROPERTIES MAP_IMPORTED_CONFIG_RELEASEFILECAMERA "RELEASE")
set_target_properties(Qt5::WinMain PROPERTIES MAP_IMPORTED_CONFIG_CLIENTCONFIG "RELEASE")
else()
message("Qt5 not found")
endif()


(Multiple Concurrent) Remote Desktop Windows

Windows natively provides Remote Desktop only for Pro or Ultimate editions.

For those with Pro and Ultimate version who want enable multiple concurrent remote desktop this links works

http://woshub.com/enable-multiple-concurrent-rdp-sessions-in-windows-8/

For those without Pro and Ultimate version who wants enable remote desktop at all this links works

http://www.softwareok.com/?seite=faq-Windows-10&faq=129

with small update in case of (at least mine) Windows 10 Home, that you need run also update file.