Subscribe:

Ads 468x60px

Friday, July 27, 2012

How to do OpenCV haar-training in Windows 7

Hi guys

      I am giving the procedure for doing opencv haar training in Windows 7



2)Building Object marker utility program. I am giving the code for object marker utility. The purpose of this utility is to mark the object to be trained. If we want to train a bottle in an image, just mark the area of bottle using this utility

Basic functions of this utility

1)Press left button and mark the object
2)After marking press double click
3)Press "SPACE" for recording the area of object
4)Press "ENTER" for next image

//Code of Object marker utility


 #include <opencv/cv.h>  
 #include <opencv/cvaux.h>  
 #include <opencv/highgui.h>  
 // for filelisting  
 #include <stdio.h>  
 // for fileoutput  
 #include <string>  
 #include <fstream>  
 #include <sstream>  
 #include "dirent.h"  
 using namespace std;  
 IplImage* image=0;  
 IplImage* image2=0;  
 //int start_roi=0;  
 int roi_x0=0;  
 int roi_y0=0;  
 int roi_x1=0;  
 int roi_y1=0;  
 int numOfRec=0;  
 int startDraw = 0;  
 char* window_name="<SPACE>add <ENTER>save and load next <ESC>exit";  
 string IntToString(int num)  
 {  
      ostringstream myStream; //creates an ostringstream object  
      myStream << num << flush;  
      /*  
      * outputs the number into the string stream and then flushes  
      * the buffer (makes sure the output is put into the stream)  
      */  
      return(myStream.str()); //returns the string form of the stringstream object  
 };  
 void on_mouse(int event,int x,int y,int flag, void *param)  
 {  
   if(event==CV_EVENT_LBUTTONDOWN)  
   {  
           if(!startDraw)  
           {  
                roi_x0=x;  
                roi_y0=y;  
                startDraw = 1;  
           } else {  
                roi_x1=x;  
                roi_y1=y;  
                startDraw = 0;  
           }  
   }  
   if(event==CV_EVENT_MOUSEMOVE && startDraw)  
      {  
           //redraw ROI selection  
           image2=cvCloneImage(image);  
           cvRectangle(image2,cvPoint(roi_x0,roi_y0),cvPoint(x,y),CV_RGB(255,0,255),1);  
           cvShowImage(window_name,image2);  
           cvReleaseImage(&image2);  
   }  
 }  
 int main(int argc, char** argv)  
 {  
      int iKey=0;  
      string strPrefix;  
      string strPostfix;  
      string input_directory;  
      string output_file;  
      if(argc != 3) {  
           fprintf(stderr, "%s output_info.txt raw/data/directory/\n", argv[0]);  
           return -1;  
      }   
      input_directory = argv[2];  
      output_file = argv[1];  
      /* Get a file listing of all files with in the input directory */  
      DIR     *dir_p = opendir (input_directory.c_str());  
      struct dirent *dir_entry_p;  
      if(dir_p == NULL) {  
           fprintf(stderr, "Failed to open directory %s\n", input_directory.c_str());  
           return -1;  
      }  
      fprintf(stderr, "Object Marker: Input Directory: %s Output File: %s\n", input_directory.c_str(), output_file.c_str());  
      //     init highgui  
      cvAddSearchPath(input_directory);  
      cvNamedWindow(window_name,1);  
      cvSetMouseCallback(window_name,on_mouse, NULL);  
      fprintf(stderr, "Opening directory...");  
      //     init output of rectangles to the info file  
      ofstream output(output_file.c_str());  
      fprintf(stderr, "done.\n");  
      while((dir_entry_p = readdir(dir_p)) != NULL)  
      {  
           numOfRec=0;  
           if(strcmp(dir_entry_p->d_name, ""))  
           fprintf(stderr, "Examining file %s\n", dir_entry_p->d_name);  
           /* TODO: Assign postfix/prefix info */  
           strPostfix="";  
           strPrefix=input_directory;  
           strPrefix+=dir_entry_p->d_name;  
           //strPrefix+=bmp_file.name;  
           fprintf(stderr, "Loading image %s\n", strPrefix.c_str());  
           if((image=cvLoadImage(strPrefix.c_str(),1)) != 0)  
           {  
                //     work on current image  
                do  
                {  
                     cvShowImage(window_name,image);  
                     // used cvWaitKey returns:  
                     //     <Enter>=13          save added rectangles and show next image  
                     //     <ESC>=27          exit program  
                     //     <Space>=32          add rectangle to current image  
                     // any other key clears rectangle drawing only  
                     iKey=cvWaitKey(0);  
                     switch(iKey)  
                     {  
                     case 27:  
                               cvReleaseImage(&image);  
                               cvDestroyWindow(window_name);  
                               return 0;  
                     case 32:  
                               numOfRec++;  
                     printf("  %d. rect x=%d\ty=%d\tx2h=%d\ty2=%d\n",numOfRec,roi_x0,roi_y0,roi_x1,roi_y1);  
                     //printf("  %d. rect x=%d\ty=%d\twidth=%d\theight=%d\n",numOfRec,roi_x1,roi_y1,roi_x0-roi_x1,roi_y0-roi_y1);  
                               // currently two draw directions possible:  
                               //          from top left to bottom right or vice versa  
                               if(roi_x0<roi_x1 && roi_y0<roi_y1)  
                               {  
                                    printf("  %d. rect x=%d\ty=%d\twidth=%d\theight=%d\n",numOfRec,roi_x0,roi_y0,roi_x1-roi_x0,roi_y1-roi_y0);  
                                    // append rectangle coord to previous line content  
                                    strPostfix+=" "+IntToString(roi_x0)+" "+IntToString(roi_y0)+" "+IntToString(roi_x1-roi_x0)+" "+IntToString(roi_y1-roi_y0);  
                               }  
                               if(roi_x0>roi_x1 && roi_y0>roi_y1)  
                               {  
                                    printf("  %d. rect x=%d\ty=%d\twidth=%d\theight=%d\n",numOfRec,roi_x1,roi_y1,roi_x0-roi_x1,roi_y0-roi_y1);  
                                    // append rectangle coord to previous line content  
                                    strPostfix+=" "+IntToString(roi_x1)+" "+IntToString(roi_y1)+" "+IntToString(roi_x0-roi_x1)+" "+IntToString(roi_y0-roi_y1);  
                               }  
                               break;  
                     }  
                }  
                while(iKey!=13);  
                // save to info file as later used for HaarTraining:  
                //     <rel_path>\bmp_file.name numOfRec x0 y0 width0 height0 x1 y1 width1 height1...  
                if(numOfRec>0 && iKey==13)  
                {  
                     //append line  
                     /* TODO: Store output information. */  
                     output << strPrefix << " "<< numOfRec << strPostfix <<"\n";  
                }  
                cvReleaseImage(&image);  
           } else {  
                fprintf(stderr, "Failed to load image, %s\n", strPrefix.c_str());  
           }  
      }  
      output.close();  
      cvDestroyWindow(window_name);  
      closedir(dir_p);  
      return 0;  
 }  


//Need to include dirent.h in the Header Files
 /*****************************************************************************  
  * dirent.h - dirent API for Microsoft Visual Studio  
  *  
  * Copyright (C) 2006 Toni Ronkko  
  *  
  * Permission is hereby granted, free of charge, to any person obtaining  
  * a copy of this software and associated documentation files (the  
  * ``Software''), to deal in the Software without restriction, including  
  * without limitation the rights to use, copy, modify, merge, publish,  
  * distribute, sublicense, and/or sell copies of the Software, and to  
  * permit persons to whom the Software is furnished to do so, subject to  
  * the following conditions:  
  *  
  * The above copyright notice and this permission notice shall be included  
  * in all copies or substantial portions of the Software.  
  *  
  * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS  
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF  
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  
  * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR  
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,  
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR  
  * OTHER DEALINGS IN THE SOFTWARE.  
  *  
  * Aug 11, 2010, Toni Ronkko  
  * Added d_type and d_namlen fields to dirent structure. The former is  
  * especially useful for determining whether directory entry represents a  
  * file or a directory. For more information, see  
  * http://www.delorie.com/gnu/docs/glibc/libc_270.html  
  *  
  * Aug 11, 2010, Toni Ronkko  
  * Improved conformance to the standards. For example, errno is now set  
  * properly on failure and assert() is never used. Thanks to Peter Brockam  
  * for suggestions.  
  *  
  * Aug 11, 2010, Toni Ronkko  
  * Fixed a bug in rewinddir(): when using relative directory names, change  
  * of working directory no longer causes rewinddir() to fail.  
  *  
  * Dec 15, 2009, John Cunningham  
  * Added rewinddir member function  
  *  
  * Jan 18, 2008, Toni Ronkko  
  * Using FindFirstFileA and WIN32_FIND_DATAA to avoid converting string  
  * between multi-byte and unicode representations. This makes the  
  * code simpler and also allows the code to be compiled under MingW. Thanks  
  * to Azriel Fasten for the suggestion.  
  *  
  * Mar 4, 2007, Toni Ronkko  
  * Bug fix: due to the strncpy_s() function this file only compiled in  
  * Visual Studio 2005. Using the new string functions only when the  
  * compiler version allows.  
  *  
  * Nov 2, 2006, Toni Ronkko  
  * Major update: removed support for Watcom C, MS-DOS and Turbo C to  
  * simplify the file, updated the code to compile cleanly on Visual  
  * Studio 2005 with both unicode and multi-byte character strings,  
  * removed rewinddir() as it had a bug.  
  *  
  * Aug 20, 2006, Toni Ronkko  
  * Removed all remarks about MSVC 1.0, which is antiqued now. Simplified  
  * comments by removing SGML tags.  
  *  
  * May 14 2002, Toni Ronkko  
  * Embedded the function definitions directly to the header so that no  
  * source modules need to be included in the Visual Studio project. Removed  
  * all the dependencies to other projects so that this very header can be  
  * used independently.  
  *  
  * May 28 1998, Toni Ronkko  
  * First version.  
  *****************************************************************************/  
 #ifndef DIRENT_H  
 #define DIRENT_H  
 #define WIN32_LEAN_AND_MEAN  
 #include <windows.h>  
 #include <string.h>  
 #include <stdlib.h>  
 #include <sys/types.h>  
 #include <sys/stat.h>  
 #include <errno.h>  
 /* File type and permission flags for stat() */  
 #if defined(_MSC_VER) && !defined(S_IREAD)  
 # define S_IFMT  _S_IFMT           /* file type mask */  
 # define S_IFDIR _S_IFDIR           /* directory */  
 # define S_IFCHR _S_IFCHR           /* character device */  
 # define S_IFFIFO _S_IFFIFO          /* pipe */  
 # define S_IFREG _S_IFREG           /* regular file */  
 # define S_IREAD _S_IREAD           /* read permission */  
 # define S_IWRITE _S_IWRITE          /* write permission */  
 # define S_IEXEC _S_IEXEC           /* execute permission */  
 #endif  
 #define S_IFBLK  0              /* block device */  
 #define S_IFLNK  0              /* link */  
 #define S_IFSOCK 0              /* socket */  
 #if defined(_MSC_VER)  
 # define S_IRUSR S_IREAD           /* read, user */  
 # define S_IWUSR S_IWRITE           /* write, user */  
 # define S_IXUSR 0              /* execute, user */  
 # define S_IRGRP 0              /* read, group */  
 # define S_IWGRP 0              /* write, group */  
 # define S_IXGRP 0              /* execute, group */  
 # define S_IROTH 0              /* read, others */  
 # define S_IWOTH 0              /* write, others */  
 # define S_IXOTH 0              /* execute, others */  
 #endif  
 /* Indicates that d_type field is available in dirent structure */  
 #define _DIRENT_HAVE_D_TYPE  
 /* File type flags for d_type */  
 #define DT_UNKNOWN 0  
 #define DT_REG   S_IFREG  
 #define DT_DIR   S_IFDIR  
 #define DT_FIFO   S_IFFIFO  
 #define DT_SOCK   S_IFSOCK  
 #define DT_CHR   S_IFCHR  
 #define DT_BLK   S_IFBLK  
 /* Macros for converting between st_mode and d_type */  
 #define IFTODT(mode) ((mode) & S_IFMT)  
 #define DTTOIF(type) (type)  
 /*  
  * File type macros. Note that block devices, sockets and links cannot be  
  * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are  
  * only defined for compatibility. These macros should always return false  
  * on Windows.  
  */  
 #define     S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFFIFO)  
 #define     S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)  
 #define     S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)  
 #define     S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)  
 #define     S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)  
 #define     S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)  
 #define     S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)  
 #ifdef __cplusplus  
 extern "C" {  
 #endif  
 typedef struct dirent  
 {  
   char d_name[MAX_PATH + 1];         /* File name */  
   size_t d_namlen;              /* Length of name without \0 */  
   int d_type;                 /* File type */  
 } dirent;  
 typedef struct DIR  
 {  
   dirent      curentry;         /* Current directory entry */  
   WIN32_FIND_DATAA find_data;         /* Private file data */  
   int       cached;          /* True if data is valid */  
   HANDLE      search_handle;       /* Win32 search handle */  
   char       patt[MAX_PATH + 3];    /* Initial directory name */  
 } DIR;  
 /* Forward declarations */  
 static DIR *opendir(const char *dirname);  
 static struct dirent *readdir(DIR *dirp);  
 static int closedir(DIR *dirp);  
 static void rewinddir(DIR* dirp);  
 /* Use the new safe string functions introduced in Visual Studio 2005 */  
 #if defined(_MSC_VER) && _MSC_VER >= 1400  
 # define DIRENT_STRNCPY(dest,src,size) strncpy_s((dest),(size),(src),_TRUNCATE)  
 #else  
 # define DIRENT_STRNCPY(dest,src,size) strncpy((dest),(src),(size))  
 #endif  
 /* Set errno variable */  
 #if defined(_MSC_VER)  
 #define DIRENT_SET_ERRNO(x) _set_errno (x)  
 #else  
 #define DIRENT_SET_ERRNO(x) (errno = (x))  
 #endif  
 /*****************************************************************************  
  * Open directory stream DIRNAME for read and return a pointer to the  
  * internal working area that is used to retrieve individual directory  
  * entries.  
  */  
 static DIR *opendir(const char *dirname)  
 {  
   DIR *dirp;  
   /* ensure that the resulting search pattern will be a valid file name */  
   if (dirname == NULL) {  
    DIRENT_SET_ERRNO (ENOENT);  
    return NULL;  
   }  
   if (strlen (dirname) + 3 >= MAX_PATH) {  
    DIRENT_SET_ERRNO (ENAMETOOLONG);  
    return NULL;  
   }  
   /* construct new DIR structure */  
   dirp = (DIR*) malloc (sizeof (struct DIR));  
   if (dirp != NULL) {  
    int error;  
    /*  
     * Convert relative directory name to an absolute directory one. This  
     * allows rewinddir() to function correctly when the current working  
     * directory is changed between opendir() and rewinddir().  
     */  
    if (GetFullPathNameA (dirname, MAX_PATH, dirp->patt, NULL)) {  
      char *p;  
      /* append the search pattern "\\*\0" to the directory name */  
      p = strchr (dirp->patt, '\0');  
      if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') {  
       *p++ = '\\';  
      }  
      *p++ = '*';  
      *p = '\0';  
      /* open directory stream and retrieve the first entry */  
      dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->find_data);  
      if (dirp->search_handle != INVALID_HANDLE_VALUE) {  
       /* a directory entry is now waiting in memory */  
       dirp->cached = 1;  
       error = 0;  
      } else {  
       /* search pattern is not a directory name? */  
       DIRENT_SET_ERRNO (ENOENT);  
       error = 1;  
      }  
    } else {  
      /* buffer too small */  
      DIRENT_SET_ERRNO (ENOMEM);  
      error = 1;  
    }  
    if (error) {  
      free (dirp);  
      dirp = NULL;  
    }  
   }  
   return dirp;  
 }  
 /*****************************************************************************  
  * Read a directory entry, and return a pointer to a dirent structure  
  * containing the name of the entry in d_name field. Individual directory  
  * entries returned by this very function include regular files,  
  * sub-directories, pseudo-directories "." and "..", but also volume labels,  
  * hidden files and system files may be returned.  
  */  
 static struct dirent *readdir(DIR *dirp)  
 {  
   DWORD attr;  
   if (dirp == NULL) {  
    /* directory stream did not open */  
    DIRENT_SET_ERRNO (EBADF);  
    return NULL;  
   }  
   /* get next directory entry */  
   if (dirp->cached != 0) {  
    /* a valid directory entry already in memory */  
    dirp->cached = 0;  
   } else {  
    /* get the next directory entry from stream */  
    if (dirp->search_handle == INVALID_HANDLE_VALUE) {  
      return NULL;  
    }  
    if (FindNextFileA (dirp->search_handle, &dirp->find_data) == FALSE) {  
      /* the very last entry has been processed or an error occured */  
      FindClose (dirp->search_handle);  
      dirp->search_handle = INVALID_HANDLE_VALUE;  
      return NULL;  
    }  
   }  
   /* copy as a multibyte character string */  
   DIRENT_STRNCPY ( dirp->curentry.d_name,  
        dirp->find_data.cFileName,  
        sizeof(dirp->curentry.d_name) );  
   dirp->curentry.d_name[MAX_PATH] = '\0';  
   /* compute the length of name */  
   dirp->curentry.d_namlen = strlen (dirp->curentry.d_name);  
   /* determine file type */  
   attr = dirp->find_data.dwFileAttributes;  
   if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {  
    dirp->curentry.d_type = DT_CHR;  
   } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {  
    dirp->curentry.d_type = DT_DIR;  
   } else {  
    dirp->curentry.d_type = DT_REG;  
   }  
   return &dirp->curentry;  
 }  
 /*****************************************************************************  
  * Close directory stream opened by opendir() function. Close of the  
  * directory stream invalidates the DIR structure as well as any previously  
  * read directory entry.  
  */  
 static int closedir(DIR *dirp)  
 {  
   if (dirp == NULL) {  
    /* invalid directory stream */  
    DIRENT_SET_ERRNO (EBADF);  
    return -1;  
   }  
   /* release search handle */  
   if (dirp->search_handle != INVALID_HANDLE_VALUE) {  
    FindClose (dirp->search_handle);  
    dirp->search_handle = INVALID_HANDLE_VALUE;  
   }  
   /* release directory structure */  
   free (dirp);  
   return 0;  
 }  
 /*****************************************************************************  
  * Resets the position of the directory stream to which dirp refers to the  
  * beginning of the directory. It also causes the directory stream to refer  
  * to the current state of the corresponding directory, as a call to opendir()  
  * would have done. If dirp does not refer to a directory stream, the effect  
  * is undefined.  
  */  
 static void rewinddir(DIR* dirp)  
 {  
   if (dirp != NULL) {  
    /* release search handle */  
    if (dirp->search_handle != INVALID_HANDLE_VALUE) {  
      FindClose (dirp->search_handle);  
    }  
    /* open new search handle and retrieve the first entry */  
    dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->find_data);  
    if (dirp->search_handle != INVALID_HANDLE_VALUE) {  
      /* a directory entry is now waiting in memory */  
      dirp->cached = 1;  
    } else {  
      /* failed to re-open directory: no directory entry in memory */  
      dirp->cached = 0;  
    }  
   }  
 }  
 #ifdef __cplusplus  
 }  
 #endif  
 #endif /*DIRENT_H*/  
Download dirent.h 
 

Include dirent.h as follows






Build Object marker utility in release mode




Release folder after building .Here hello_world is the object marker utility. neg folder contain negative images. photo folder contain positive images. vec folder contain vector file.

Copy opencv training executable to the Release folder from the path opencv/build/common/x86(If you build in X86 architecture)



Object marker utility program



Object marker utility command for marking positive image samples .The positives images placed in photo folder





PRESS 'SPACE' to add ROI

PRESS 'ENTER' to save ROI

PRESS 'ESCAPE' to get the next image

After marking process, the release folder  has a text file called lent.txt contain all the coordinates of the marking







Creating vector file using existing markings

Command


lentin.vec file generated in the release folder




Next step is haar training ,for this you need some negative images which contain no object .Take equal number of positive and negative images for training.You need to write a text file describing the names of negative file and its path. If the file is in the same path,then only name is enough. Below shows the negative.txt file and a sample negative image

negative.txt

sample negative image


Haar training command



Processing stage

trained xml file generated in the name of lent_out.xml



After training you will get an xml file ,just use this xml file in face_detection code in opencv

after building face_detect command will be like this .copy-paste xml file in the release folder of face_detection  build

\face_detetct.exe --cascade=lent_out.xml 0 //for camera 
\face_detetct.exe --cascade=lent_out.xml image_name //for image 
\face_detetct.exe --cascade=lent_out.xml video_name //for video


Sample output


33 comments:

anay sonawane said...

hi,
I am doing haartrainig in windows 7.To create a .vec file I used a function as follows:
cvCreateTrainingSamplesFromInfo( "C:\OpenCV2.0\bin\positives\positive_info.txt", "C:\OpenCV2.0\data\positive_vec.vec", 5, 0,24,24 );

but I am getting a error as: unresolved external symbol "int __cdecl cvCreateTrainingSamplesFromInfo(char const *,char const *,int,int,int,int)" (?cvCreateTrainingSamplesFromInfo@@YAHPBD0HHHH@Z) referenced in function _main

It is saying that "The system can not find the file Specified".
Please tell me what I did wrong here,wating for reply.

fiona richards said...

Hello,

This is exactly what I want to do, however following these instructions gives 10 LNK2012 errors when compiling.

Not sure if anyone else gets this error, or if I've made a boo boo being new to this

:)

Lentin Joseph said...

@fiona richards .Please follow this tutorial for setting opencv in windows7 .

http://www.technolabsz.com/2012/04/setting-opencv-231-on-windows-7.html

Are you using VS 2010 or VS2012?

Lentin Joseph said...

@anay
I think you need give path in windows like this

C:\\OpenCV2.0\\bin\\positives\\positive_info.txt", "C:\\OpenCV2.0\\data\\positive_vec.vec", 5, 0,24,24 );

anay sonawane said...

Sir,
still I am getting the same error....

SAGAR said...

Sir,
First of all thanx to share such a important information with us.I wrote the direcory and output file name in code:
input_directory = "C:\\OpenCV2.0\\bin\\positives\\";
output_file = "C:\\OpenCV2.0\\bin\\positives\\info.txt";
It is loading images but after selecting the ROI for them my code is creating blank info.txt.Can you please tell me how to overcome this problem??waiting eagerly,thank you.

Lentin Joseph said...

@Sagar ,after marking ROI, you have to press 'SPACE' and press "ENTER' for saving ROI. Press 'ESCAPE' for the next image. The ROI values will display in the command window.

Lentin Joseph said...

@anay .I have a doubt whether you set the linker and headers of opencv correctly .
Please follow this tutorial for setting opencv

http://www.technolabsz.com/2012/04/setting-opencv-231-on-windows-7.html

In this post there is an example code given,try to compile it. If it works fine, then i think your program will also work. And opencv_create sample.exe need not to be build,its already avlble in opencv folder
opencv\\build\\common\\x86

Yonas Teodros said...

@ Lentin Joseph thank you very much the whole program works for me

Deny Febriyanto said...
This comment has been removed by the author.
Deny Febriyanto said...
This comment has been removed by the author.
narjes said...

Hi,
Thank you for this code.for the objectMarker i do the same work and the image is displayed,but when i click the mouse at the top left corner of the object area and hold it pressed then i drag the mouse to bottom right corner of the object, the rectangle is not drawn and the image disappears and the process is terminated.I don't know what is the problem !!!
Thank you fo your help

MVB109 said...

the following are the errors i have when i copy the code.. im using VS2010, i also followed how you set up the opencv.my opencv version is 2.4.6, the latest one. please help, i am doing my project related to this one.
'Test.exe': Loaded 'C:\Users\Michael Vance\Documents\Visual Studio 2010\Projects\Test\x64\Debug\Test.exe', Symbols loaded.
'Test.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Program Files\Bitdefender\Bitdefender 2013\active virus control\Avc3_00197_003\avcuf64.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'D:\opencv\build\x64\vc10\bin\opencv_core246d.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.
'Test.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'Test.exe': Loaded 'D:\opencv\build\x64\vc10\bin\opencv_highgui246d.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\winsxs\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_a4d6a923711520a9\comctl32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\avifil32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\winmm.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\msacm32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\msvfw32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\avicap32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'Test.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
The program '[1748] Test.exe: Native' has exited with code -1 (0xffffffff).

Lentin Joseph said...

Hi MVB109

I have done this tutorial in opencv 2.4.3. Opencv_test project, is using opencv 2.4.3. I think you have to change the dll names according to the version, othervice it shows error, and also try to build in release mode.

Michael Vance Bajilar said...

my dll's are place on this directory D:\opencv\build\x64\vc10\bin all the dll are in like this ex.(opencv_core246.dll) how can i set the path for it? is this to be configured within VS2010?how?

Michael Vance Bajilar said...

this are the errors i had..
msvcr100.dll!00000000757e346e()
[Frames below may be incorrect and/or missing, no symbols loaded for msvcr100.dll]
msvcr100.dll!00000000757be7e9()
>Test.exe!main(int argc, char * argv) Line 66 + 0x1d bytes C++
Test.exe!__tmainCRTStartup() Line 555 + 0x19 bytes C
kernel32.dll!0000000077b5652d()
ntdll.dll!0000000077c8c521()

Lentin Joseph said...

Hi Michael

Add the dll path into path of system environmental variable.

Michael Vance Bajilar said...

i have setted the path where my dll are.

then everytime i run the program it always BREAk then this is what appears.

Unhandled exception at 0x74d3346e in Test.exe: 0xC0000005: Access violation reading location 0x00000000ffffffea.

Anonymous said...

Hi Lentin,
I used opencv 2.1.0 version on vs 2008 and i copied the code above and set up everything but then there's an error,i don't know what is the problem really need help. These are the errors:
'Test.exe': Loaded 'C:\Users\Lolita\Documents\Visual Studio 2008\Projects\Test\Debug\Test.exe', Symbols loaded.
'Test.exe': Loaded 'C:\Windows\System32\ntdll.dll'
'Test.exe': Loaded 'C:\Windows\System32\kernel32.dll'
'Test.exe': Loaded 'C:\Windows\System32\KernelBase.dll'
'Test.exe': Loaded 'C:\OpenCV2.1\bin\cxcore210d.dll'
'Test.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcp90d.dll', Symbols loaded.
'Test.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcr90d.dll', Symbols loaded.
'Test.exe': Loaded 'C:\OpenCV2.1\bin\highgui210d.dll'
'Test.exe': Loaded 'C:\Windows\System32\user32.dll'
'Test.exe': Loaded 'C:\Windows\System32\gdi32.dll'
'Test.exe': Loaded 'C:\Windows\System32\lpk.dll'
'Test.exe': Loaded 'C:\Windows\System32\usp10.dll'
'Test.exe': Loaded 'C:\Windows\System32\msvcrt.dll'
'Test.exe': Loaded 'C:\Windows\System32\ole32.dll'
'Test.exe': Loaded 'C:\Windows\System32\rpcrt4.dll'
'Test.exe': Loaded 'C:\Windows\System32\advapi32.dll'
'Test.exe': Loaded 'C:\Windows\System32\sechost.dll'
'Test.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll'
'Test.exe': Loaded 'C:\Windows\System32\avifil32.dll'
'Test.exe': Loaded 'C:\Windows\System32\winmm.dll'
'Test.exe': Loaded 'C:\Windows\System32\msacm32.dll'
'Test.exe': Loaded 'C:\Windows\System32\msvfw32.dll'
'Test.exe': Loaded 'C:\Windows\System32\shell32.dll'
'Test.exe': Loaded 'C:\Windows\System32\shlwapi.dll'
'Test.exe': Loaded 'C:\Windows\System32\avicap32.dll'
'Test.exe': Loaded 'C:\Windows\System32\version.dll'
'Test.exe': Loaded 'C:\Windows\System32\olepro32.dll'
'Test.exe': Loaded 'C:\Windows\System32\oleaut32.dll'
'Test.exe': Loaded 'C:\Windows\System32\imm32.dll'
'Test.exe': Loaded 'C:\Windows\System32\msctf.dll'
'Test.exe': Loaded 'C:\Windows\System32\cryptbase.dll'
'Test.exe': Loaded 'C:\Windows\System32\uxtheme.dll'
The program '[3528] Test.exe: Native' has exited with code -1 (0xffffffff).

Lentin Joseph said...

Hi all

Make an empty project and do this, dont use test project, that is only for learning purpose.

After seeing this error,i builded this code using VS2008 and Opencv 2.4. It is working. Please note to build in release mode also include "dirent.h".

Anonymous said...

Hi sir,
i also used opencv 2.4.0 version in vs2008 and when i tried to run the program the error look like this
1>------ Build started: Project: edshufa, Configuration: Release Win32 ------
1>Compiling...
1>maluoy.cpp
1>C:\Users\lot\Downloads\Programs\opencv\include\opencv\cv.h(63) : fatal error C1083: Cannot open include file: 'opencv2/core/core_c.h': No such file or directory
1>Build log was saved at "file://c:\Users\lot\Documents\Visual Studio 2008\Projects\edshufa\edshufa\Release\BuildLog.htm"
1>edshufa - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

can you please tell me what's this error?thanks.

Lentin Joseph said...

Hi

Did you include opencv headers in your project. Please check Project settings->C/C++>include directories.

Sravanthi Simhadri said...

Hi,
I am not able to view the folder opencv\\build\\common\\x86 and hence the opencv_createsamples and other executables are not present.
What do you think is the problem?

Thanks,
Sravanthi

Ginson Mathew said...

Hello Lentin,

Thanks for the code!!

I use Visual studio 2010 on Windows7 (x64 bit) pc. I tried the above code, but couldn't compile the program.

Can you sent the .exe file to my mail ginson.mathew@yahoo.com.

Thanks a billion Lentin!!!

Lentin Joseph said...

Hi Ginson
What error you getting. Can you paste here

Ginson Mathew said...

Hi Lentin,

Actually i loaded the dirent.h file... but still i get these errors.

Error 1 error C1083: Cannot open include file: 'dirent.h': No such file or directory f:\itl\visual studio projects\object marker\object marker\main.cpp 10 1 Object Marker
2 IntelliSense: cannot open source file "dirent.h" f:\itl\visual studio projects\object marker\object marker\main.cpp 10 2 Object Marker
3 IntelliSense: identifier "DIR" is undefined f:\itl\visual studio projects\object marker\object marker\main.cpp 72 7 Object Marker
4 IntelliSense: identifier "dir_p" is undefined f:\itl\visual studio projects\object marker\object marker\main.cpp 72 16 Object Marker
5 IntelliSense: identifier "opendir" is undefined f:\itl\visual studio projects\object marker\object marker\main.cpp 72 24 Object Marker
6 IntelliSense: identifier "readdir" is undefined f:\itl\visual studio projects\object marker\object marker\main.cpp 87 28 Object Marker
7 IntelliSense: pointer to incomplete class type is not allowed f:\itl\visual studio projects\object marker\object marker\main.cpp 90 22 Object Marker
8 IntelliSense: pointer to incomplete class type is not allowed f:\itl\visual studio projects\object marker\object marker\main.cpp 91 51 Object Marker
9 IntelliSense: pointer to incomplete class type is not allowed f:\itl\visual studio projects\object marker\object marker\main.cpp 95 23 Object Marker
10 IntelliSense: identifier "closedir" is undefined f:\itl\visual studio projects\object marker\object marker\main.cpp 153 7 Object Marker

Lentin Joseph said...

Hi
Make a header file from visual studio and name it as dirent.h and paste the dirent.h to the newly created file.

Ginson Mathew said...

Hello Lentin,

I'm also getting few linker errors. Please provide your valuable inputs for these errors
Error 1 error LNK2019: unresolved external symbol _cvReleaseImage referenced in function "void __cdecl on_mouse(int,int,int,int,void *)" (?on_mouse@@YAXHHHHPAX@Z) F:\ITL\Visual Studio projects\Object Marker\Object Marker\main.obj Object Marker
Error 2 error LNK2019: unresolved external symbol _cvShowImage referenced in function "void __cdecl on_mouse(int,int,int,int,void *)" (?on_mouse@@YAXHHHHPAX@Z) F:\ITL\Visual Studio projects\Object Marker\Object Marker\main.obj Object Marker
Error 3 error LNK2019: unresolved external symbol _cvRectangle referenced in function "void __cdecl on_mouse(int,int,int,int,void *)" (?on_mouse@@YAXHHHHPAX@Z) F:\ITL\Visual Studio projects\Object Marker\Object Marker\main.obj Object Marker
Error 4 error LNK2019: unresolved external symbol _cvCloneImage referenced in function "void __cdecl on_mouse(int,int,int,int,void *)" (?on_mouse@@YAXHHHHPAX@Z) F:\ITL\Visual Studio projects\Object Marker\Object Marker\main.obj Object Marker
Error 5 error LNK2019: unresolved external symbol _cvDestroyWindow referenced in function _main F:\ITL\Visual Studio projects\Object Marker\Object Marker\main.obj Object Marker
Error 6 error LNK2019: unresolved external symbol _cvWaitKey referenced in function _main F:\ITL\Visual Studio projects\Object Marker\Object Marker\main.obj Object Marker
Error 7 error LNK2019: unresolved external symbol _cvLoadImage referenced in function _main F:\ITL\Visual Studio projects\Object Marker\Object Marker\main.obj Object Marker
Error 8 error LNK2019: unresolved external symbol _cvSetMouseCallback referenced in function _main F:\ITL\Visual Studio projects\Object Marker\Object Marker\main.obj Object Marker
Error 9 error LNK2019: unresolved external symbol _cvNamedWindow referenced in function _main F:\ITL\Visual Studio projects\Object Marker\Object Marker\main.obj Object Marker
Error 10 error LNK1120: 9 unresolved externals F:\ITL\Visual Studio projects\Object Marker\Debug\Object Marker.exe Object Marker

Lentin Joseph said...

Hi
I think you are not properly linked the library, thats why you getting this error and also build in release mode

Anonymous said...

Hi lentin
can the same code be run in Raspberry pi?

Anonymous said...

Hi lentin, I am using python and opencv, I am desperate to get answer from my objectmarker.py
Here the link is where I found the converted to python, https://gist.github.com/sqshemet/3195874
I am debug no error, when running it, it get error actually in here if in your
program:
if(argc != 3) {
fprintf(stderr, "%s output_info.txt raw/data/directory/\n", argv[0]);
return -1;
}
and the result is just the directory "D:\Folder\positive\ObjectMarker output_info.txt raw/data/directory"..
Could you help me??
Thanks for your time..
Devina

Anonymous said...

Hi lentin, I am using python and opencv, I am desperate to get answer from my objectmarker.py
Here the link is where I found the converted to python, https://gist.github.com/sqshemet/3195874
I am debug no error, when running it, it get error actually in here if in your
program:
if(argc != 3) {
fprintf(stderr, "%s output_info.txt raw/data/directory/\n", argv[0]);
return -1;
}
and the result is just the directory "D:\Folder\positive\ObjectMarker output_info.txt raw/data/directory"..
Could you help me??
Thanks for your time..
Devina

Anonymous said...

how much time it will take i mean training ??

Post a Comment