Histogram of Oriented Gradient Library - Navneet Dalal (in Windows)

This is a Histogram of Oriented Gradient library ported on Windows platform. The Windows version (last updated 19 July 2008) includes minor modifications from the original version by Navneet Dalal. In the project file, I have included two sub-projects:

  1. HOG project: consists of the entire HOG source code.
  2. SVM dense: the modification of svm light (by Thorsten Joachims).

The project contains the "minimum files" required to build the codes, i.e. I have excluded all the dll's, object files, executables etc. For it to compile properly:

  1. You are require to obtain the following libraries:
  2. Once you download the libraries, build them.
  3. Copy all the dll's (boost_1.34.1*.dll, blitz_0.9.dll, opencv*.dll) into "<ROOT_PROJECT_DIR>/debug/"
  4. Change the "include" and "link" path to point to the appropriate path, under "Project->Properties->C/C++->Additional Include Directories" and "Project->Properties->Linker->Include" respectively.

The followings contain a list of the reported problems along with their suggested solutions shared by different sources:

Logical error (width and height of the image) (Updated 26 April 2009)
Jin Hui from Tsinghua University pointed out an error for mistakenly switched between width and height of IplImage and the Blitz data.
Please revise the methods in imageio.h:

  1. write(const std::string& imagename, const blitz::Array<T,2>& imageData);
  2. static inline blitz::Array<T,2> read(IplImage * img);
Corrections:
Original code Revised code
1
 
void write(const std::string& imagename, const blitz::Array<T,2>& imageData)
{
int columns = imageData.columns();
int rows = imageData.rows();
IplImage * gray = cvCreateImage( cvSize(columns, rows), 8, 1);
IplImage * color = cvCreateImage( cvSize(columns, rows), 8, 3);

// copy data to array
for( int i=0, k=imageData.lbound(0) ; i<rows ; i++, k++ ) 
for( int j=0, l=imageData.lbound(1) ; j<columns ; j++, l++ ) 
((uchar *)(gray->imagedata + i*gray->widthStep))[j] = toColor(imageData(k,l));
}
 
void write(const std::string& imagename, const blitz::Array<T,2>& imageData)
{
int columns = imageData.rows();
int rows = imageData.columns();
IplImage * gray = cvCreateImage( cvSize(columns, rows), 8, 1);
IplImage * color = cvCreateImage( cvSize(columns, rows), 8, 3);

// copy data to array
for( int i=0, k=imageData.lbound(0) ; i<rows ; i++, k++ ) 
for( int j=0, l=imageData.lbound(1) ; j<columns ; j++, l++ ) 
((uchar *)(gray->imagedata + i*gray->widthStep))[j] = toColor(imageData(k,l));
}
2
 
static inline blitz::Array<T,2> read(IplImage * img)
{
int rows = img->height;
int columns = img->width;
blitz::Array<T,2> imageData(rows,columns);

for( int i=0 ; i<rows ; i++ ) 
for( int j=0 ; j<columns ; j++ ) 
{
imageData(i,j)[0]=((uchar *)(img->imagedata+j*img->widthStep))[i*img->nChannels+2];
imageData(i,j)[1]=((uchar *)(img->imagedata+j*img->widthStep))[i*img->nChannels+1];
imageData(i,j)[2]=((uchar *)(img->imagedata+j*img->widthStep))[i*img->nChannels+0];
}
}
 
static inline blitz::Array<T,2> read(IplImage * img)
{
int rows = img->width;
int columns = img->height;
blitz::Array<T,2> imageData(rows,columns);

for( int i=0 ; i<rows ; i++ ) 
for( int j=0 ; j<columns ; j++ ) 
{
imageData(i,j)[0]=((uchar *)(img->imagedata+j*img->widthStep))[i*img->nChannels+2];
imageData(i,j)[1]=((uchar *)(img->imagedata+j*img->widthStep))[i*img->nChannels+1];
imageData(i,j)[2]=((uchar *)(img->imagedata+j*img->widthStep))[i*img->nChannels+0];
}
}

Compilation issue (Updated 10 July 2009)
Problem:
..\pedestriandetectionhog_net2005\lear\cvision\edge.h(324) : error C2668:
'blitz::ConvolveExact::dim2' : ambiguous call to overloaded function

..\edge.h(322) : error C2668:
'blitz::ConvolveExact::dim1' : ambiguous call to overloaded function

Solution:
--

Compilation problem (Updated 26 April 2009)
Problems: (1) fail to link libboost_test_exec_monitor-vc90-mt-1_38.lib under Debug mode; (2) fail to link libboost_system-vc90-mt-gd-1_38.lib under Release mode.

Suggested by Xiangkui Chang:

  • find the lib drectory of Boost. copy and paste the files of "boost_system-vc90-mt-gd-1_38.lib" and "boost_system-vc90-mt-gd-1_38.lib"
  • rename the pasted files to the missing files.
  • modify the linker -> input, and add the *.libs mentioned above.
  • modified runtime librarty to: Multithreaded DLL(/MD) under both the Debug and Release mode, then we can avoid the fatal error C1189, #error: "Mixing a dll boost library with a static runtime is a really bad idea...": at auto_link.hpp (297)

Compilation problem (Updated 22 June 2009)
During the compilation, you may find the following compilation errors:

  1. *Error 62 error C2593: 'operator <<' is ambiguous. C:\boost\boost_1_34_1\boost\lexical_cast.hpp 588*
  2. *Error 63 error C2228: left of '.fail' must have class/struct/union C:\boost\boost_1_34_1\boost\lexical_cast.hpp 588*

Solution 1: Suggested by Xu Hui (Tsinghua University China) (Updated 15 July 2008)
The problem occurs because of the misused of function template (friend function of << and >> ):

  • At "tinyvecopt.h", line 49, modify the the former into
    friend std::ostream& operator << <>(std::ostream& o, const TinyVecOpt<T,N>& t);
    friend std::istream& operator >> <>(std::istream& o, TinyVecOpt<T,N>& t);
  • At line 134, modify the definition:
    template<class T,int N> std::ostream& operator << <>(std::ostream& o, const TinyVecOpt<T,N>& t){???}
    template<class T,int N>std::istream& operator >> <>(std::istream& o, TinyVecOpt<T,N>& t){???}

Solution 2
Apparently, a lot of people still find similar problem after changing the declaration suggested by Xu Hui. Another suggestion, and kind of brute way, would be to modify the boost header file "lexical_cast.hpp", to exclude lines containing '<<' and '.fail'. Note that it isn't an elegant solution, but at least it is a quick way to fix the compilation error. Unless, someone has alternative solution to this :)

Solution 3 (Updated 22 June 2009)
Another solution is to change tinyvecopt.h at line 49,51

  • From:
    template<class T, int N>
    friend std::ostream& operator << <>(std::ostream& o, const TinyVecOpt<T,N>& t);
    template<class T, int N>
    friend std::istream& operator >> <>(std::istream& o, TinyVecOpt<T,N>& t);
  • To:
    //template<class T, int N>
    friend std::ostream& operator << <T,N>(std::ostream& o, const TinyVecOpt<T,N>& t);
    //template<class T, int N>
    friend std::istream& operator >> <T,N>(std::istream& o, TinyVecOpt<T,N>& t);
For some people, this solved the problem.

Compilation issue (Updated 14 August 2008)
Problem:
1>boost_filesystem-vc80-mt-1_34_1.lib(boost_filesystem-vc80-mt- 1_34_1.dll) :
error LNK2005: "bool __cdecl boost::filesystem::native(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)"
(?native@filesystem@boost@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
already define in libboost_filesystem-vc80-mt-1_34_1.lib(portability.obj)

Solution: Suggested by Hamlet
Add "/FORCE:MULTIPLE" in Link Option to aviod these errors.

Run time problem (Updated 15 July 2008)
During the compilation, I also found run time errors while using boost library related to the command line argument. Somehow, it doesn't parse the input argument correctly. And for this reason, I haven't provide the binaries on the web.

Solution: For some people, there is an option to run the project inside Visual Studio .NET editor (by pressing Ctrl F5 or F5) and I am one of them. My temporarily solution is to replace the original codes for parsing the command line with the codes for reading an input file consisting the input parameters.

Solution: Suggested by Wongun Choi on 02 Feb 2009 (But note that it hasn't being tried extensively).
From C/C++ -> Code Generation
Change Runtime Library: Multithreaded DLL -> Multithreaded Debug DLL
By changing the above properties in Visual Studio 2008, it looks like parsing command arguments work well. The reason is because the current HoG project file tries to link to release version of boost DLLs.

If anyone has a better solution than the above, your sharing will be much appreciated, thank you.

Release mode error: svm_light_dalal (Updated 18 March 2009)
Xin Jiang pointed that the project "svm_light_dalal" does not compile properly under release mode, many errors such as:
"C2143: syntax error : missing ';' before 'type' binary.c line 44"

Solution: I didn't know exactly what solves the problem but this is what I did:

  1. I try to synchronise all entires for the Debug and Release mode under the Properties section. When I recompile, I still obtain the same errors.
  2. Next, I change the "Compile As C++ Code (/TP)" to "Compile As C Code (/TC)" in Properties -> C/C++ -> Advance -> Compile As. Try that again, the same errors still persist.
  3. When I change it back to "Compile As C++ Code(/TP)", and rebuild everything, I no longer get the erros :)

Original work
For more information about the license and the publications of the above work, please refer to the original page.

If you find any bugs/problems/solutions to share, please send an email to w.leoputra__at__postgrad.curtin.edu.au. Any usefull discussions will be posted on the web.