Saturday, October 4, 2014

opencv flann problems

here is a very good solution of a problem in flann opencv

http://stackoverflow.com/questions/10336568/how-to-use-opencv-flannindex

here is another example might be helpful:

int cluster_number = 4000;
int feat_size = 192;
Mat indexMat( cluster_number, feat_size, CV_32FC1);
flann::Index flann_index( indexMat, flann::SavedIndexParams( argv[1]), cvflann::FLANN_DIST_EUCLIDEAN);

you will keep getting runtime errors when you call knnSearch(). instead you might do :

#define CLUSTER_NUMBER 4000
#define FEAT_SIZE 192
Mat indexMat( CLUSTER_NUMBER, FEAT_SIZE, CV_32FC1);
flann::Index flann_index( indexMat, flann::SavedIndexParams( argv[1]), cvflann::FLANN_DIST_EUCLIDEAN);

Tuesday, September 2, 2014

merge columns of multiple files

paste <(cut -d ' ' -f1 file1) <(cut -f2-5 -d ' 'file2) -d ' '> file3

the command above merges the first column of file1 with columns 2,3, and 4 of file2 and dumps it to file3 with a white-space delimiter. columns are separated with white-spaces for file1 and file2.

qlogin to a specific compute node in a sun grid engine

qlogin -l h=<node_name>
e.g.,
qlogin -l h=compute-0-29.sge

Wednesday, June 25, 2014

sort in unix

be careful when you use "sort" in unix since it is kind of problematic with the numbers like "9.9591403640072E-4" even if you set "-n".

Friday, June 6, 2014

char * in unordered_map issue

do not use unordered_map<char*,int> map
instead use unordered_map<string, int> map since unordered_map is kind of problematic with pointers

Thursday, June 5, 2014

row and col operations in opencv

check out this link before these operations :)

http://docs.opencv.org/modules/core/doc/basic_structures.html#Mat%20Mat%3a%3arow%28int%20y%29%20const


mat.row(1) = mat.row(3) // this does not work!

mat.row(3).copyTo( mat.row(1)) // this works

Tuesday, April 8, 2014

retrieve a document from indri index

first run the command below;
./dumpindex/dumpindex <index_path> di docno <docuement_no>
this returns a document id and then run the command below;
./dumpindex/dumindex <index_path> dd <document_id>

Friday, March 28, 2014

features.isContionous() assertion - clustering - opencv

probably you forget to initialize the mat in hierarchical clustering.

region of interest (ROI) opencv

they have changed how ROI works in opencv
if you'd like to focus on a region in an image you need to copy it to another image/mat

Mat samples_hog = samples( Rect(0, 0, 96, soFar)).clone();

and do not forget the .clone() part it is important.

in Rect with four parameters (x, y, width, height) but not (x1, y1, x2, y2)

Monday, March 3, 2014

no highlighting in vim

:noh

how tu submit opencv jobs to sge (sun grid engine)

here is the script that I use to submit opencv jobs on sge

qsub -v LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<opencvPATH>/lib/ -b y -cwd -l mem_free=4g -l mem_token=4g ./FlannMatch <PARAMETERS>

Sunday, March 2, 2014

matlab figure fonts issue in ubuntu

it seems like matlab figure fonts are not changed even if you make the changes on ubuntu.

you need to install packages;
xfonts-75dpi
xfonts-100dpi

Saturday, March 1, 2014

undeclared variable in flann/lsh_table.h with -std=gnu++0x (Bug #2179)

if you faced with a problem like this;


/usr/local/opencv/include/opencv2/flann/lsh_index.h:49:0,

                 from /usr/local/opencv/include/opencv2/flann/all_indices.h:42,

                 from /usr/local/opencv/include/opencv2/flann/flann_base.hpp:44,

                 from /usr/local/opencv/include/opencv2/flann/flann.hpp:50,

                 from /usr/local/opencv/include/opencv/cv.h:69,

                 from FlannMatchWindows.cpp:7:

/usr/local/opencv/include/opencv2/flann/lsh_table.h: In member function ‘void cvflann::lsh::LshTable<ElementType>::add(cvflann::Matrix<T>)’:

/usr/local/opencv/include/opencv2/flann/lsh_table.h:196:14: error: ‘use_speed_’ was not declared in this scope



this then you can check this link out and even though they do not say the fix you can find it here;

remove the statement "if (!use_speed_)"  from the line 196 lsh_table.h

it is also fixed on later version of 2.4.2

Thursday, February 27, 2014

how to compile opencv on linux (ubuntu)

here is a file (compile.sh) to compile my codes
I have different versions of OpenCv in my system and using 2.4.4 in this case;


#! /bin/bash
PKG_CONFIG_PATH=/usr/local/opencv-2.4.4/lib/pkgconfig:${PKG_CONFIG_PATH}
export PKG_CONFIG_PATH
g++ -o $1 $1.cpp `pkg-config --libs opencv` `pkg-config --cflags opencv`


in order to compile the code type;
./compile.sh <FileNameWithoutExtension>

in order to execute;
./<FileNameWithoutExtension>

how to install opencv on linux

below find the steps to install opencv on linux (particularly ubuntu)

1. Remove any installed versions of ffmpeg and x264.
sudo apt-get remove ffmpeg x264 libx264-dev

2. update
sudo apt-get update

3. Get all the dependencies for x264 and ffmpeg. If you have them, it will skip it anyways.
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

4. Download and install gstreamer. ( gstreamaer and ffmpeg and x264 are important for video processing)
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

5. Download and install gtk. If you have it, it will be skipped anyways.
sudo apt-get install libgtk2.0-0 libgtk2.0-dev

6. Download and install libjpeg. If you have it, it will be skipped anyways.
sudo apt-get install libjpeg8 libjpeg8-dev

7. Download and install install x264. ( check if there is any previous version available)
cd ~
mkdir ffmpeg_sources
cd ~/ffmpeg_sources
wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20120528-2245-stable.tar.bz2
tar xvf x264-snapshot-20120528-2245-stable.tar.bz2
cd x264-snapshot-20120528-2245-stable
./configure --enable-shared --enable-pic (FOR 64-BIT MACHINE, OTHERWISE REMOVE --enable-pic)
make
sudo make install

8. Download and install install ffmpeg. ( check if there is any previous version available)
cd ~/ffmpeg_sources
wget http://ffmpeg.org/releases/ffmpeg-0.11.1.tar.bz2
tar xvf ffmpeg-0.11.1.tar.bz2
cd ffmpeg-0.11.1
./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 --enable-shared --enable-pic (FOR 64-BIT MACHINE, OTHERWISE REMOVE --enable-pic)
make sudo make install

9. Download and install install a recent version of v4l ( check if there is any previous version available)
cd ~/ffmpeg_sources
wget http://www.linuxtv.org/downloads/v4l-utils/v4l-utils-0.8.8.tar.bz2
tar xvf v4l-utils-0.8.8.tar.bz2
cd v4l-utils-0.8.8
make
sudo make install

10. Download and install OpenCv (check if there is any previous version available)
cd ~
mkdir opencv
cd opencv
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.8/OpenCV-2.4.8.tar.bz2
tar xvf OpenCV-2.4.8.tar.bz2
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. (CHECK THE FINAL CMAKE OUTPUT FOR gstreamer, ffmpeg, v4l, and gtk)
make
sudo make install
sudo ldconfig

information is gathered from this and there as well as additional tweaks
http://www.ozbotz.org/opencv-installation/
http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html
http://indranilsinharoy.com/2012/11/01/installing-opencv-on-linux/

descriptor matcher

if you are looking for matching descriptors or something else,
check out flann_based_matcher.
it also has a function for multiple results (e.g., best two-three or more matches)

to check if an element in map

map.find( string) != map.end()

to insert unordered_map

map.insert( make_pair( string, int))

or change the type within "make_pair" depending upon the map

to trim buff after reading line by line with fgets (c++)

buff[ strcspn( buff, "\n")]='\0';

solves the new line at the end of the string (kind of trim() )

to compile unordered_map with gcc under linux

try;
gcc -std=c++0x ....

opencv flann index of a data file with svm-light like --sparse-- data format (e.g., feature_index:feature_value)

 
to index:
Mat samples;
samples.create(rowSize, featSize, CV_32FC1);

putFeatures( fileName, featSize, trainSamples);
flann::Index flann_index( trainSamples, cv::flann::KMeansIndexParams( 32, 11, cvflann::CENTERS_KMEANSPP, 0.2));

flann_index.save( indexFile);

to read sparse data format:
while( fgets( buff, sizeof(buff), file) != NULL){
 first = strtok(buff, " ");
 second = strtok(NULL, " ");
 do{
  third = strtok(NULL, " ");
  if( third != NULL){
   length = strlen( third);
   indexOfCol = strcspn ( third, keys);
   if( indexOfCol < length){
    indexStr = strndup(third, indexOfCol);
    valueStr = strndup(third+indexOfCol+1, length);
    mat.at( rowIndex, atoi( indexStr)-1) = atof( valueStr);
   }
  }
 }while( third!=NULL);
 rowIndex++;
}

1st post

1st post.