Search code examples
opencvmotion-detection

OpenCV: Detecting Movement in a tile


I would like to detect a movement in a tile of grids defined by N*N, I've tried a way which is done by https://stackoverflow.com/users/724461/andrey-kamaev and it shown in the following code, but the result isn't accurate at all, I would like to do a more accurate approach.

cv::Sobel(input, sobel, CV_32F, 1, 1); 

              int h = input.rows / NUM_BLOCK_ROWS; 
              int w = input.rows / NUM_BLOCK_COLUMNS; 
              float pos=0;
              for (int r = 0; r<NUM_BLOCK_ROWS; r++) 
                     for(int c=0; c<NUM_BLOCK_COLUMNS; c++) 
                     { 
                           cv::Scalar weight = cv::sum(sobel(cv::Range(h*r, (r+1)*h), cv::Range(c*w, (c+1)*w))); 

                           if (weight[0] + weight[1] > 60) {
                                  input(cv::Range(h*r, (r+1)*h-1), cv::Range(c*w, (c+1)*w-1)).setTo(cv::Scalar(0,0,255)); 

                           }

                     } 

Solution

  • I used Frame Differencing approach and it worked.