pms
pms

Reputation: 944

opencv sliding window

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.

Upvotes: 1

Views: 6839

Answers (2)

globalex
globalex

Reputation: 569

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);
          }
         }

Upvotes: 2

gavinb
gavinb

Reputation: 20028

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:

Upvotes: 1

Related Questions