Archive for June, 2012

This is an example showing integration of OpenCV and PCL(Point Cloud Library) in using trackbars of OpenCV(highgui) to adjust the x,y,z limits of passthrough filter of PCL .

It is assumed that you have already installed OpenCV and PCL . Make sure that you have OpenCV version> 2.3 & PCL version > 1.1.  In my case I am using OpenCV 2.3.1 and PCL 1.6 ( Compiled from current trunk).

Before downloading the code and running, you might want to see how the output looks like.

Running the code:

This code takes a PLY file as input and applies passthrough filters to it and visualizes it. You can adjust the X,Y,Z  limits of passthrough filters using trackbars and see the output on the fly.

Step1: Download the code folder and extract it.

Step2: Create a folder named “build” inside it. Open CMake and in the field where is the source code provide the path of folder. eg: C:/Users/Sanmarino/Downloads/Integrating_Opencv_PCL_PassthroughFilters. In the field where to build the binaries provide the path to the empty build folder you created. eg:C:/Users/Sanmarino/Downloads/Integrating_Opencv_PCL_PassthroughFilters/build. Then Click configure at the bottom. Choose the compiler you want to use when prompted. In my case I chose Visual Studio 10

.

Step3: If everything is fine after configure , click generate. Else sometimes you might get an error like this –

“CMake Error at CMakeLists.txt:6 (find_package): By not providing “FindOpenCV.cmake” in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by “OpenCV”, but CMake did not find one.

Could not find a package configuration file provided by “OpenCV” with any of the following names: OpenCVConfig.cmake opencv-config.cmake

Add the installation prefix of “OpenCV” to CMAKE_PREFIX_PATH or set “OpenCV_DIR” to a directory containing one of the above files. If “OpenCV” provides a separate development package or SDK, be sure it has been installed.

If this is the case then we have to set the OpenCV_DIR to the place where it can find OpenCVConfig.cmake. So  click on OpenCV_DIR-NOTFOUND and change it to the path where OpenCVConfig.cmake exists. In my case it was  C:\OpenCV\build  where I had built the binaries of OpenCV. Now hit Configure again and hit Generate.

Changed path of OpenCV_DIR:

Step4: Now open the generated solution and build it in release/debug mode.  Place scene_mesh.ply from the unzipped code folder in the folder where simple_visualizer.exe is generated. Run simple_visualizer.exe in command prompt by giving scene_mesh.ply as argument.

eg: C:\Users\Sanmarino\Downloads\Integrating_Opencv_PCL_PassthroughFilters\build\Release>    simple_visualizer.exe  scene_mesh.ply. Change the trackbars to apply passThrough filter on the pointcloud and see the output.

simple_visualizer.cpp


#include <iostream>

// Point cloud library
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>
#include <pcl/visualization/pcl_visualizer.h>

// Opencv
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

// These are track bar initial settings adjusted to the given pointcloud to make it completely visible.
//  Need to be adjusted depending on the pointcloud and its xyz limits if used with new pointclouds.

int a = 22;
int b = 12;
int c=  10;

// PCL Visualizer to view the pointcloud
pcl::visualization::PCLVisualizer viewer ("Simple visualizing window");

int
	main (int argc, char** argv)
{
	pcl::PointCloud::Ptr cloud (new pcl::PointCloud);
	pcl::PointCloud::Ptr cloud_filtered (new pcl::PointCloud);

	if (pcl::io::loadPLYFile (argv[1], *cloud) == -1) //* load the ply file from command line
	{
		PCL_ERROR ("Couldn't load the file\n");
		return (-1);
	}

	pcl::copyPointCloud( *cloud,*cloud_filtered);

	float i ;
	float j;
	float k;

	cv::namedWindow( "picture");

	// Creating trackbars uisng opencv to control the pcl filter limits
	cvCreateTrackbar("X_limit", "picture", &a, 30, NULL);
	cvCreateTrackbar("Y_limit", "picture", &b, 30, NULL);
	cvCreateTrackbar("Z_limit", "picture", &c, 30, NULL);

	// Starting the while loop where we continually filter with limits using trackbars and display pointcloud
	char last_c = 0;
	while(true && (last_c != 27))
	{

		pcl::copyPointCloud(*cloud_filtered, *cloud);

		// i,j,k Need to be adjusted depending on the pointcloud and its xyz limits if used with new pointclouds.

		i = 0.1*((float)a);
		j = 0.1*((float)b);
		k = 0.1*((float)c);

		// Printing to ensure that the passthrough filter values are changing if we move trackbars.

		cout << "i = " << i << " j = " << j << " k = " << k << endl;

		// Applying passthrough filters with XYZ limits

		pcl::PassThrough pass;
		pass.setInputCloud (cloud);
		pass.setFilterFieldName ("y");
		//  pass.setFilterLimits (-0.1, 0.1);
		pass.setFilterLimits (-k, k);
		pass.filter (*cloud);

		pass.setInputCloud (cloud);
		pass.setFilterFieldName ("x");
		// pass.setFilterLimits (-0.1, 0.1);
		pass.setFilterLimits (-j, j);
		pass.filter (*cloud);

		pass.setInputCloud (cloud);
		pass.setFilterFieldName ("z");
		//  pass.setFilterLimits (-10, 10);
		pass.setFilterLimits (-i, i);
		pass.filter (*cloud);

		// Visualizing pointcloud
		viewer.addPointCloud (cloud, "scene_cloud");
		viewer.spinOnce();
		viewer.removePointCloud("scene_cloud");
	}

	return (0);
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(visualizer_grouping)

find_package(PCL 1.4 REQUIRED)
find_package(OpenCV REQUIRED)

include_directories(${PCL_INCLUDE_DIRS} )
link_directories(${PCL_LIBRARY_DIRS} )
add_definitions(${PCL_DEFINITIONS} )

add_executable (simple_visualizer simple_visualizer.cpp)
target_link_libraries (simple_visualizer ${PCL_LIBRARIES} ${OpenCV_LIBS})

˙˙˙ɯɯH ¿ʇɹɐʇs I op ʍoɥ ‘ llǝM.                                                                                                                             Oops! Let me turn the page this way. Sorry about that! Let’s get started!

I will try to explain the thoughts in a very orderly manner. No , no. I will …. Okay I will write about my experiences in the recent past. No .no. That really sounds too cliche.  Really sorry, I see that the page is already getting dirty. Sometimes thoughts are like speeding cars that we see through our window pane. We see them all but nothing is registered in enough detail if we want them to pen down. This haziness takes a toll shallowing the little left concreteness in my ideas. Okay, I will let the randomness flow. See if you can figure out any pattern in  this randomness!

#When we are young we will completely be ourselves and do only the things that we find are cool . As we grow up we see growing dissatisfaction with our lives. We  want to be that smart chap or that cool movie star or that rich neighbor. We lose our identity in the pursuit of trying to be someone else. Sadly, most don’t realize that  being completely themselves is the coolest they can ever get. It isn’t about what you are in the eyes of other people but it is about what you are to your inner self. All that matters is whether you are happy being absolutely yourself or not. The key is to be  what you want with minimal inconvenience to the people around you. And by just believing what you do, you will be amazed to see how many people you have surpassed whom once you used to look upto.

#Engineering? Arts? Pure Sciences? Music? Dance? Don’t think about whether the career you chose will be commercially rewarding or not if you are really  passionate about it. If you are really passionate about it and willing to put in the extra hard work just go for it. Don’t let money or time dictate your ideas and hinder you from following passions.World will never fail to recognize people who are truly passionate about what they do. Even if your idea is to come up with a new chopstick model world will encourage you. May be someday you will have a google doodle  for being the designer of new chopsticks.You never know. All you gotta do is to show the world your swag. 🙂 As someone rightly said “Do not waste the vast majority of your life doing something you hate so that you can spend the small remainder sliver of your life in modest comfort. You may never reach that end anyway.” You might be the one who has taken a less trodden path but you will take pride in every footstep.

#Appreciate and take inspiration from people who are great in a paricular field but never make yourself low comparing yourself with them.

#In my opinion religion is very similar to an operating system. There is no universally superior operating system. If you started on a Mac as a kid and if that is what you have experienced your whole life then you tend to appreciate Mac better than other operating systems. So is the case with Windows or Linux. It is just about what you are more comfortable with. Same is the case with religions. The same way any operating system has  bugs and  developers, religions too appear to have their own idiosyncrasies and evolve over time.

#Atheists are of two kinds. The first kind of Atheists are those kind of developers who develop their own operating systems to suit to their specific needs. These are the real kind of Atheists as they believe that the existing operating systems don’t satisfy their needs so they build their own. The second type of Atheists are  those who know nothing about operating systems and are computer illiterates.The problem is with these kind of Atheists who advocate their senseless Atheism. The real Atheists are wise enough to understand that not every body will be able to develop a  new operating system and also most people are happy with the existing operating systems to satisfy their needs so they don’t bother about advocating their Atheism. So teach your kids the righteousness that religion has got to offer. Don’t make to grow them as Atheists. If they happen to be so they will evolve so.

#An artist should not be driven by the necessity to impress anyone else in this world. He should let his imagination flow and produce work that impresses him the most. He should take pride in being completely himself. He should believe that he is a class of his own. Then only shall the greatest pieces of art be produced.

#There is something good about being sad, gloomy and dejected sometimes. It makes you feel down to earth and makes you think as a very simple human being with no friendships and money who tries to survive every single day. These moments help you discover  more of you.


Q. I don’t know much about skateboards. What are they?
A. Well, skateboards  are basically boards with wheels that you can ride on. This is how a  typical skateboard looks like.

Q.Who uses skateboards? Where is it popular?
A. Skateboarding is mostly popular among the youth  and teenagers.  It is  majorly popular in  United states and Europe.

Q.What is the difference between longboard and skateboard?
A.Longboard has bigger wheels and a bigger board so it is stable and easy to ride long distances. Skateboards are usually used for performing tricks   and are easier to carry as they weigh less when compared to Longboards. Longboards too have their own set of tricks that can be done on them.   This is the longboard that I  currently use.

Q.What is the price range of skateboards and longboards?
A. Skateboards  are relatively cheaper when compared to longboards. The prices of skateboards are typically  between $20 – $150 whereas longboards range between $60-$320.  You would get a decent skateboard for $50 and a decent longboard for $120.

Q. What are the things required for Skateboarding as a sport?
A. Skateboard, Shoes, Helmet,Knee and elbow pads, tools to tighten or loosen the skateboard/longboard are the basic equipment needed. Optionally you may get sliding gloves and skateboarding ramp too.

Q. What do I start with? Skateboard or Longboard?
A. I would advice you to start on a mid range longboard as it is cheaper and stable for beginners. You can move on to a better longboard once you get basic riding skills or buy a good skateboard if you want to practise some tricks.The first thing is to find your balance on the board. Although it takes a while it isn’t hard with some days of practise.

Q.How do they perform tricks with Skateboards?                                                                                  A. All the tricks are done just by taking advantage of the shape of the skateboard(nose and tail). They don’t require anything else other than just a normal skateboard .Tricks can only be done once you get good mastery of skateboard riding. The following video gives a very neat introduction to beginner skateboarding and tricks.

Similar fun riding Stuff

Unicycle

Unicycle is a single tire with pedals attached to it. Unicycling is not as popular as Skateboarding but you can find Unicyclists once in a while near parks etc. A unicycle typically costs about $100-120. Watch the following cool Unicycling tricks video.

Heely

Heelys are shoes with wheels at the heel side. Heelys are generally used by kids and are fun to ride. Though the heel side has wheels you can use them and walk normally when you want to. Usually Heelys come in the price range of $40-100 Watch the following tutorial to get you started with Heelys.

Caster Board [RipStik/WaveBoard]

Caster Board is a two-wheeled vehicle that is closely related to the skateboard. The major advantage with this is  that  you need not step off the board and push it like a skateboard or longboard. You can propel this board by sideways movement just by being on the board.You would get a decent Caster Board for about 40$. Watch the following video to know how to ride Caster Board.

SkateCycle

SkateCycle is a self propelled skate that doesn’t have a hub(center part of wheel). It is driven with a similar mechanism as Caster Board and has the look of a miniature  cycle. It costs 150$ and it is an award winning design by http://www.brooklynworkshop.com/ . Watch the following video to get an idea of  skateCycle riding.

Scooter

Scooter is very popular among school age kids and teenagers. It is relatively easier to ride when compared to skateboards. You can get a good Scooter for about $60. It is easily foldable so you can carry it in hand whenever you want to.


Three Wheeled Scooter

Three wheeled scooter is a chainless, pedal less device that can be rode by leaning to right and left alternatively without ever touching foot to the ground.  A typical three wheeled scooter ranges from $150 – $400 depending on the size and make quality. Watch the following video to understand the riding mechanism better.

 

Inline Skates[Roller Blades]

Inline skates are shoes with wheels attached to each pair. They have two, three, four, or five wheels arranged in a single line. Some of them have a heel stop to slow down while skating. You can get a good pair of roller blades for about $80.

So, that ends my small description of different kinds of riding stuff .  I believe rest of them are variants of the ones described here. However excuse me if I seemed to have  missed any important ones along the way.

It took me sometime to get the installation done so just thought of making a little tutorial that would help other folks. I am assuming that you have Microsoft kinect and the adapter ready with you .

Two competing frameworks to work with Kinect are Microsoft Kinect’s sdk and Prime Sense OpenNI sdk . But since the Microsoft’s sdk is only  for non commercial use, many developers love to use  OpenNI sdk.

In this tutorial we would be installing  OpenNI, SensorKinect and NITE. In simple terms OpenNI and SensorKinect are the drivers that help to access RGB-D data [Depth & Color]  from Kinect . NITE is a skeleton tracking library that can be used by developers to create gesture interactions etc. Hence if you just want to work with depth images and pointclouds you wouldn’t necessarily need to install NITE. So, technically it is optional but most of them install it as it doesn’t take much extra effort.

I have installed 32 bit versions of openNI, sensorKinect and NITE on my 64 bit windows7 laptop. I shall walk you through the steps that I had followed  to install OpenNI drivers successfully.

Step1: Go to http://www.openni.org/Downloads/OpenNIModules.aspx . Select unstable and select windows 32 version. Download and install it.

Step 2: Go to https://github.com/avin2/SensorKinect  , download the zip file and extract it.  Navigate to the Bin folder , find SensorKinect093-Bin-Win32-v5.1.2.1.msi  and install it. Sample path where  the above sensor kinect installation file would be located is C:\Users\Sanmarino\Downloads\avin2-SensorKinect-v0.93-5.1.2.1-0-g15f1975\avin2-SensorKinect-15f1975\Bin.

Step 3:  Go to http://www.openni.org/Downloads/OpenNIModules.aspx. Select openNI compliant middleware binaries, unstable , windows 32  version then download and  install it.

Step 4: Now replace the file SamplesConfig.xml in C:\Program Files (x86)\OpenNI\Data  with the SamplesConfig.xml that is present in avin2-SensorKinect-15f1975\OpenNI\Data folder that you downloaded in step2.

Here you may get “access denied” when you try to replace in  C:\Program Files (x86)\OpenNI\Data  folder. So right click on the Data folder present in C:\Program Files (x86)\OpenNI\  , then select properties –> select security tab –>click edit. Under “Group or user names” select “users(your-computer_name\Users)” , eg: “users(Sanmarino-THINK\Users)” in my case. Now under “Permissions for users” click to allow full control , then click apply and ok.  After this you can replace without any problem. See the picture below if you have any confusion.

Step5:  Download KinectXML’s.zip from https://www.dropbox.com/s/tpl9wtx96xbe6rr/KinectXMLs.zip  and navigate to the NITE folder inside the unzipped KinectXMLs folder. Copy the three files Sample-Scene,Sample-Tracking & Sample-user from the NITE  folder in KinectXMLS and replace the files in C:\Program Files (x86)\PrimeSense\NITE\Data  with these three files. If you encounter “access denied “ problem do the same procedure explained in the step4 to the Data folder inside NITE.

Now restart your system ,  plugin Kinect and wait for the drivers to be installed. Once the drivers are installed properly open device manager[Click windows icon and search for device manager]  in your system . You should be able to see Kinect Audio,Camera & Motor when you expand PrimeSense. If you are unable to see this then refer the Errors encountered section below.

Testing the installation:

 Try out some samples   to ensure that your installation is working perfectly. Double click on NiViewer in C:\Program Files (x86)\OpenNI\Samples\Bin\Release  to see the following output. Here is the output with my kinect –

Also try Sample-SceneAnalysis in C:\Program Files (x86)\PrimeSense\NITE\Samples\Bin\Release to see if the NITE installation is working properly. Here is the output with my kinect –

If everything is working properly then you are done with the installation. If you encountered errors refer to the  section below and see if it helps. Comment if you encounter any problems. I shall offer the help I can.

Errors Encountered:

1) The procedure entry point xnloggetfilename could not be located…..

2) Device: PrimeSense/SensorKinect/5.1.2.1: The device is not connected!

3) A blank screen appears and dissapears immediately when you try to run the samples in NITE or OpenNI.

In my case all the above errors have been caused because of the conflict between Microsoft driver and OpenNI driver.  When I first connected the Kinect to my laptop Microsoft driver has been automatically installed without my knowledge and it kept causing errors like the ones mentioned above. To remove,  open Device Manager  and find Microsoft Kinect. Expand it to find Microsoft Kinect camera , right click and choose uninstall. A windows pops out and  make sure you check the box Delete the driver software for this device so that the Microsoft Driver is not installed again the next time when you unplug and plug in kinect. Then click ok to uninstall. Now uninstall the existing openNI drivers and install them newly again(i.e, Start from Step1 again). The problem should be solved. The following image clarifies the steps mentioned.