HSV values of Image pixel using JavaCV


This post will explain how to get HSV color space values of Image pixel using JavaCV.
For JavaCV setup on Windows, follow link below
http://opencvlover.blogspot.in/2012/04/javacv-setup-with-eclipse-on-windows-7.html

If you want to access RGB color space values, then refer to link below
http://opencvlover.blogspot.in/2013/02/rgb-values-of-image-pixel-using-javacv.html

Pixel values in HSV color space are often required in Image processing. Following gist demonstrates how to access and print pixel values in HSVcolor space. We first convert image from RGB color space to HSV color space using 'cvCvtColor()''. We can call 'cvGet2D()' function to access image matrix and use it get pixel values at desired location.

This will print HSV values in console. This code comes really handy while using manual threshold.
You can fork me on github for complete project of this code.
https://github.com/nikhil9/getHSV

RGB values of Image pixel using JavaCV

This post will explain how to get RGB color space values of Image pixel using JavaCV.
For JavaCV setup on Windows, follow link below
http://opencvlover.blogspot.in/2012/04/javacv-setup-with-eclipse-on-windows-7.html

If you want to access HSV color space values, then refer to link below
http://opencvlover.blogspot.in/2013/02/hsv-values-of-image-pixel-using-javacv.html

Pixel values in RGB color space are often required in Image processing. Following gist demonstrates how to access and print pixel values in RGB color space. We can call 'cvGet2D()' function to access image matrix and use it get pixel values at desired location.


This will print RGB values in console. This code comes really handy while using manual threshold.
You can fork me on github for complete project of this code.
https://github.com/nikhil9/getRGB

Face Detection in JavaCV using haar classifier

OpenCV provides haar like feature detection algorithm which can be used for object detection. Wikipedia page http://en.wikipedia.org/wiki/Haar-like_features provides nice information about what are haar like feature.

OpenCV also provides haar training utility which can be used for training. It generates XML file from training samples which further can be used for fast object detection. Such XML file is provided with opencv package for face detection.

Gist below explains how to use haar classifier in JavaCV. Code loads classifier file haarcascade_frontalface_default.xml and uses cvHaarDetectObjects() to find faces in loaded image. More information about cvHaarDetectObjects() can be found at http://opencv.willowgarage.com/documentation/object_detection.html#haardetectobjects

Result of this code generates window which shows loaded picture and red rectangle around detected faces.


You can fork complete eclipse project at https://github.com/nikhil9/FaceDetection/

Hough Circle detection in Javacv

Opencv provides Hough circle Detection algorithm which can be used to detect circles. Some information about how algorithm works and its example using Opencv in cpp can be found in below link

We will see how to use cvHoughCircle using Javacv. first we will have to process image to get grayscale or binary image. Using cvSmooth() helps most of the time for good detection however it depending upon kind of object  and background more image processing may be required.

First we will load image and then convert it to grayscale. Then use cvSmooth() to smooth the edges. cvHoughCircle() is used to detect circles and are stored in CvSeq. cvGetSeqElem() is used to extract each circle. We have to use each element in CvPoint3D32f. Center of circle is obtained in CvPoint type using cvPointFrom32f(). Obtained center and radius is used to draw circle on input image using cvCircle.

Following code is a demonstration of all the above processes.


Input Image:

Output Image:

OpenCV 2.3.1 with CodeBlocks on Ubuntu 12.04

For Installing OpenCV 2.3.1 on ubuntu 12.04 please refer to previous post
http://opencvlover.blogspot.in/2012/05/install-opencv-231-on-ubuntu-1204.html

Once the installation is done, install codeblocks as mentioned in previous post http://opencvlover.blogspot.in/2011/07/installing-opencv-with-codeblocks-ide.html

Create a new console application as mentioned in above post and go to Build Options.
Make sure that GNU GCC compiler is selected in compiler drop down option.
Go to Linker Settings tab and Link libraries which are located at /usr/local/lib/ and looks like 'libopncv_*.so'
An example is shown in image below


Now go to Search directories and under Compiler tab add following location
/usr/local/include/opencv2
Here is a screenshot


Now we are ready to run OpenCV 2.3.1 on Code Blocks running on Ubuntu 12.04.
Here is a sample code to test the installtion






Install Opencv 2.3.1 on Ubuntu 12.04 Precise Pangolin

Here are instructions for installation of Opencv 2.3.1 on Ubuntu 12.04 Precise Pangolin. For opencv installation we need FFmpeg, x264, v4l and their dependencies. It is a bit longer process as compared to windows installations. Step by step process is shown below.

1. Install dependencies for FFmpeg and x264
Enter following lines in terminal to check and install dependencies.
  
sudo apt-get install build-essential checkinstall git cmake libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev
 


2. Install Gstreamer by entering following lines in terminal
sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg
 


3. Download recent version (0.8+)of FFmpeg from https://github.com/FFmpeg/FFmpeg extract it and go to the directory. Now configure and install FFmpeg by entering following commons one by one.

./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
make
sudo make install
 


4. Install recent version of x264 from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/ extract it and go to the directory. Now configure and install x264 by entering following commons one by one.

./configure --enable-static
make
sudo make install
 


5. Download video for linux v4l libs from http://www.linuxtv.org/downloads/v4l-utils/ extract it and go to the directory. Install v4l using following command.
make
sudo make install
 


6. Install gtk libs using apt-get
sudo apt-get install libgtk2.0-0 libgtk2.0-dev
 


7. Install libjpeg using following command
sudo apt-get install libjpeg62 libjpeg62-dev
 


8. Now our dependencies are complete. We can install Opencv now. Download Opencv from http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/ Extract it and go to the directory. Enter following command to configure and install Opencv
mkdir build
cd build
cmake ..
make
sudo make install
 


We are done with installing Opencv on ubuntu 12.04 Precise Pangolin. In order to set path open /etc/bash.bashrc using your favorite text editor and add following lines
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
 


Restart your system and you are ready to use awesome Opencv!