Friday, October 31, 2014

OpenCV Mat types

I'm currently working on reading in a depth image with OpenCV and converting it to a point cloud. After wrestling with data types for a while, I came upon a tremendously useful listing of the OpenCV Mat types and their corresponding numerical values, along with the data types corresponding to those map types. For example, a CV_16U OpenCV Mat outputs 2 with the type() member function, and stores the channel data as unsigned shorts. The mapping is posted on this blog here.

    cv::Mat depthImage;
    depthImage = cv::imread("banana_1_1_1_depth.png", CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR ); // Read the file

    if(! )                              // Check for invalid input
        std::cout <<  "Could not open or find the image" << std::endl ;
        return -1;

    std::cout << "Size of depthImage:\t" << depthImage.size() << std::endl;
    std::cout << "Type of depthImage:\t" << depthImage.type() << std::endl;
    std::cout << "Depth image at coord 0,0:\t" <<<ushort>(0,0) << std::endl;

Thursday, October 30, 2014

Installing Point Cloud Library and configuring Code::Blocks to compile (Ubuntu 14.04 LTS)

Most of the credit for this post goes to this blog post and this documentation at the Point Cloud Library website. However, those didn't quite get me to the finish line, so here's what got me there:

In anticipation of getting a Microsoft Kinect for Windows v2 to image some plants, I wanted to get the Point Cloud Library (PCL) up and running so that we could define 3D entities from the 2D RGB-D images we'll get from the Kinect. I'll be developing in C++ with Code::Blocks so my first goal was to compile some code using the PCL.

Mercifully, prebuilt binaries for the PCL are available through the apt package manager. As documented at the PCL website:
sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
sudo apt-get update
sudo apt-get install libpcl-all
As for configuring Code::Blocks, I followed a blog post at this site, but it seemed that some of the shared object libraries requirements had changed since that blog post. Ultimately, it required adding the following:
Go to Project->Build Options->Search Directories Tab->Compiler Tab and add the following locations:
Then in Project->Build Options->Linker Settings Tab add the following link libraries:
/usr/lib/libvtk* (all of the libvtk .so files)
/usr/lib/libpcl* (all of the libpcl .so files)
These files may not be in these locations on all systems, so use find to track them down, e.g.:
find /usr/lib* -name "*boost*.so"
The code I used to test if I could compile was obtained here from the Point Cloud Library, and it's also reproduced here:
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

int main (int argc, char** argv)
  pcl::PointCloud<pcl::PointXYZ> cloud;

  // Fill in the cloud data
  cloud.width    = 5;
  cloud.height   = 1;
  cloud.is_dense = false;
  cloud.points.resize (cloud.width * cloud.height);

  for (size_t i = 0; i < cloud.points.size (); ++i)
    cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);

  pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
  std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;

  for (size_t i = 0; i < cloud.points.size (); ++i)
    std::cerr << "    " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;

  return (0);
And hopefully you get the output:

Code::Blocks Son of Obsidian theme

Edit: 09/10/2015 -
I had some trouble getting back to the Code Blocks forum link to get the Son of Obsidian .conf file. Here is a link that you can get the .conf file from what I think is the original author.

Working in Code::Blocks? Might as well make it easy on the eyes.

In this post at the Code Blocks forums, a user provides a port of the Visual Studio color scheme Son of Obsidian as a .conf file. The .conf file can be imported using cb_share_config as detailed in this blog post. Importing the .conf file to the default.conf file gives the colors in the image above.

Thursday, October 16, 2014

BibTeX .bst file generation

Not all of the life science journals we submit to support $\LaTeX$ and friends, so getting the right bibliography formatting can be a challenge sometimes. I just discovered a web application that allows you to answer a series of questions about the citation formatting, after which it spits out a .dbj file that can be converted to a .bst bibliography style file for BibTeX. It's appropriately called the Bst generator, and can be found at .