Tuesday, 24 January 2017

VTK volume dimension

These settings specifies the dimension and position of your vtkImageData object.
SetExtent sets the dimensions in each axis. e.g. a dataset of 50 images and width/height of 512/512
myVtkImageData->SetExtent(0,511,0,511,0,49);
SetSpacing sets the size of a voxel (size in each direction x,y,z) in your dataset.
(default)
myVtkImageData->SetSpacing(1,1,1);
SetOrigin sets the position in 3D space of point 0 0 0 (first pixel)
(default)
myVtkImageData->SetOrigin(0,0,0)

The absolute size of a volume is determined by the 'Extent' x 'Spacing' (i.e. number of voxel multiply by size of the voxel). To downsample the volume (increase spacing), we should:

double scale = 2.0;
// Specify the size of the image data
imageData->SetExtent(-100/scale, 100/scale, -100/scale, 100/scale, -50/scale, 50/scale);

imageData->SetSpacing(scale, scale, scale);


//----------------------------------------------------------------------------
void vtkImageData::GetDimensions(int *dOut)
{
  const int* extent = this->Extent;
  dOut[0] = extent[1] - extent[0] + 1;
  dOut[1] = extent[3] - extent[2] + 1;
  dOut[2] = extent[5] - extent[4] + 1;

}

Friday, 7 October 2016

Compile & Install OpenCVBlobsLib on Windows

Win7 64bit, Visual Studio 2012, OpenCV 3.0

1. Install pthread-win32 which is required by OpenCVBlobsLib
Instruction: InstallingpthreadsforVisualStudio.pdf

2. Download OpenCVBlobsLib: http://opencvblobslib.github.io/opencvblobslib/

3. Configure with CMake. Make sure BUILD_SHARED_LIBS is off. CMAKE_CXX_FLAGS_(DEBUG/RELEASE)/CMAKE_C_FLAGS_(DEBUG/RELEASE) has value /MTd (Debug) and /MT (Release) for static link.

4. Configure/Generate/Build

Wednesday, 24 February 2016

Add additional slice to model in Solidworks

  1. Open part of model if it's in assembly
  2. Sketch tap -> Sketch button (3D Sketch) -> Select Line (ShortcutL)
  3. Draw three lines (points) and define a plane using the points (NOT two lines)
  4. To define a plane, Feature tab -> Reference Geometry -> Plane
  5. Right click the created plane underFeatureManager Design Tree, select sketch
  6. Select the new sketch, press Convert Entities, then select the plane we want to extrude from original model.
  7. With the sketch selected, press Extruded Boss/Base button.
    • After all slices extruded, we can hide the 3D sketches for better visualization.
  8. Hide other part, only leave extruded part shown. Save the extruded part as separate file with proper name (Note: usecopy and continue in save dialog).
  9. Leave the part edit mode without saving or changing anything in assembly.
  10. Import the saved extruded part in assembly.
  11. Mate three planes (front/top/right) between extruded part and original part.

Export to mesh for colouring

  1. Save as IGS (choose specified coordinate)
  2. Open the IGS file, save as VRML (*.wrl) with VRML97 version which is supported by meshlab
  3. Close IGS file without saving it.

Tuesday, 2 February 2016

Setup ROS for multiple machines

1. Pre-request

  • Setup ssh for all computers, usually ssh-client is installed but not ssh-server.
      sudo apt-get install openssh-server
      sudo service ssh status
      sudo ufw allow ssh
    
  • Set host IP for each computer:
    • Get the IP:
        hostname -I
      
    • set IP for ROS_IP
        export ROS_IP=$IP_ADDR$
      

2. Master

There will be a computer run as master machine where roscore will be run.
  • Set ROS_MASTER_URI
      export ROS_MASTER_URI=http://localhost:11311
    
  • Start roscore
  • Start test program
      rosrun rospy_tutorials listener.py
    

3. Slaves (other machines)

  • ssh to remote PC
  • Set ROS_MASTER_URI
      export ROS_MASTER_URI=http://$MASTER_IP_HERE$:11311
    
  • Start test program
      rosrun rospy_tutorials talker.py
    
We should see in the master the message sent by slave is received.
http://nootrix.com/software/ros-networking/

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