1

Is there any built in library for sliding a window (custom size) over an image in opencv version 2.x? I tried to write the algorithm by myself but I found it very painful and probably error-prone. I need to slide over an image and create histogram for the input of svm. there is one for HOG Descriptor, which calculates HOG features but I have my own feature set so I just need an algorithm to let me slide over an image.

pms
  • 944
  • 12
  • 28
  • There is no such built-in library over OpenCV as far as I am aware. OpenCV does not containing any advanced GUI features. You will have to write your own code to do that. – bubble Aug 11 '12 at 06:33
  • I implemented such algorithm to do that, but that sounds awkward for openCV to not to have such an important feature, because sliding window is very useful and applicable to many purposes. – pms Aug 13 '12 at 18:50
  • dlib.net has nice solutions. specially this one:http://dlib.net/dlib/image_processing/scan_fhog_pyramid_abstract.h.html#scan_fhog_pyramid – Babak.Abad Oct 19 '20 at 16:55

2 Answers2

1

You can define a Region of Interest (ROI) on a cv::Mat object, which gives you a new Mat object referring to the sub-window. This does not copy the underlying data, merely a new header with the appropriate metadata.

See also this other question:

Community
  • 1
  • 1
gavinb
  • 19,278
  • 3
  • 45
  • 60
  • I know about ROI but question is how can I use this technique as sliding window and more importantly how to use this in SVM – pms Aug 13 '12 at 18:09
  • Is this what you're trying to do? http://docs.opencv.org/modules/objdetect/doc/latent_svm.html Doesn't the implementation already do the windowing for you? – gavinb Aug 14 '12 at 13:29
  • I am not doing Latent SVM. It is regular SVM. however I found an CvSVM which already implements SVM in opencv. but finally I had to write the window slider by myself. – pms Aug 23 '12 at 07:32
1

Basic code can looks like. The code is described good enought. I hope.

This is single scale slideing window 60x60 witch Step 30.

enter image description here

Result of this simple example is ROI.

enter image description here

You can visit this basic tutorial Tutorial Here.

     // Parameters of your slideing window

      int windows_n_rows = 60;
      int windows_n_cols = 60;

      // Step of each window
       int StepSlide = 30;

 for (int row = 0; row <= LoadedImage.rows - windows_n_rows; row += StepSlide)
        {

  for (int col = 0; col <= LoadedImage.cols - windows_n_cols; col += StepSlide)
          {

           Rect windows(col, row, windows_n_rows, windows_n_cols);
           Mat Roi = LoadedImage(windows);
          }
         }
globalex
  • 549
  • 3
  • 11