Thursday 30 July 2015

Qt 4 and 5 in same machine (Ubuntu)




"qtchooser -list-versions": get available version of qt.


modify following file 
/usr/lib/x86_64-linux-gnu/qtchooser/5.conf
so that it specify directory of qmake and lib of qt. Example for qt5:
/opt/Qt5.5.0/5.5/gcc_64/bin
/opt/Qt5.5.0/5.5/gcc_64



To choose different qt version: 
"export QT_SELECT=5"

To check current using qt:
"qmake -v" 

"export PKG_CONFIG_LIBDIR=/opt/qt-4.8.7/lib:$PKG_CONFIG_LIBDIR"
"export PATH=/opt/qt-4.8.7/bin:$PATH"
"export PKG_CONFIG_PATH=/opt/qt-4.8.7/lib/pkgconfig/:$PKG_CONFIG_PATH"


Monday 27 July 2015

Configure AJA device


0. Dependency:
g++, libasound2, libsound2-dev, and libncurses5-dev
For Qt-based demo, qt4-dev-tools is required. qt4-dev-tools doesn't include QtMultimedia which is required by the demo program.

In Ubuntu:
sudo apt-get install libasound2
sudo apt-get install autoconf


1. In terminal, under directory ntv2projects in the SDK. Use make command.

2. Load the device driver: sudo SDK_Dir/bin/loadOEM2K

3. Verify XENA2 is installed using 'lsmod'

------------------------------
Load .ko (driver) from boot (DO NOT WORKED FOR AJA DEVICE):
1. copy the XENA2.ko to /lib/modules/3.16.0-41-generic/kernel/drivers/ntv2
2. edit /etc/modules and add a line "XENA2"
3. "sudo depmod -a"
4. reboot
Make sure the kernel version is the one currently used.
------------------------------

------------------------------
Base on discussion in this link. To avoid linking error of pthread, following lines need to be added to the CMakeLists.txt due to a cmake bug.
  1. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
------------------------------

Thursday 2 July 2015

OpenCV findCirclesGrid with color filter

1. Convert RGB image to HSV for better colour identification.
As a side note, in OpenCV H has values from 0 to 180, S and V from 0 to 255. The red color, in OpenCV, has the hue values approximately in the range of 0 to 10 and 160 to 180.
In HSV space:
red primary at 0°
green primary at 120° (60 - opencv)
blue primary at 240° (120 - opencv)
yellow (30 - opencv)


// Convert input image to HSV
cv::Mat hsv_image;
cv::cvtColor(bgr_image, hsv_image, cv::COLOR_BGR2HSV);

2. Use cv::inRange function to filter out colour
// Threshold the HSV image, keep only the red pixels
cv::Mat lower_red_hue_range;
cv::Mat upper_red_hue_range;
cv::inRange(hsv_image, cv::Scalar(0, 100, 100), cv::Scalar(10, 255, 255), lower_red_hue_range);
cv::inRange(hsv_image, cv::Scalar(160, 100, 100), cv::Scalar(179, 255, 255), upper_red_hue_range);

3. Use cv::addWeighted function to filter out colour
cv::Mat red_hue_image;
cv::addWeighted(lower_red_hue_range, 1.0, upper_red_hue_range, 1.0, 0.0, red_hue_image);


Reference:
[1] Detect red circles in an image using OpenCV