0

I am working on Edge change Ratio Algorithm for Video shot Detection. I have the basic idea of the algorithm and have implemented a part of it using OpenCV which includes identifying edges using Canny's Algorithm.

But I am confused about how to find the edge pixels and number of entering and exiting pixels between two video frames. I am working on OpenCV Please help me with some code or logic or OpenCV functions to do it

Thanks

pratpor
  • 1,954
  • 1
  • 27
  • 46

1 Answers1

0

As far as I have understood your problem...If your gray image is frameg then the following API produces the image with edges..

Canny(frameg,frameEdge,50,150,3,false);

where frameEdge is the image containing the edges. frameEdge is a binary image with edge pixels being white (255) and the other pixels are black(0).

for(int r = 0;r<frameEdge.rows;r++)
  {
    for(int c=0;c<frameEdge.cols;c++)
     {
      if( *(frameEdge.data + frameEdge.cols*r + c) == (uchar)255 )
            {
               Point edgepixel;
               edgepixel.x = c; edgepixel.y = r;
               myedges.push_back(edgepixel);
            }
     }
  } 

So you can easily scan the image and find the white pixels ans store their locations. That way you find the edge pixels. Make a an array vector<Point> myedges to store the edge pixel locations. Do this for each frame in your video and do the necessary comparisons. Note : I have taken the images as cv::Mat. You can use IplImage also.

rotating_image
  • 3,046
  • 4
  • 28
  • 46
  • Thanks for the reply. I think this assumes a pixel to be either completely black or white. Won't there be cases of partially colored pixels? Also I have problems with counting number of entering and exiting pixels per frames. Any help! – pratpor May 03 '13 at 13:58
  • There wont be any partially colored pixels...after performing the Canny function on the image its just a binary image...and what exactly you mean by entering and existing pixel? can u please elaborate a little.. – rotating_image May 03 '13 at 14:19
  • Suppose we have two frames E and E' to compare. So here is the definition of entering and exiting pixels I got from a research paper. "The entering edge pixel is the edge pixels that is present in current frame E and is farther away than r in next frame E’. The exiting edge pixel is the edge pixel that is present in the next frame E’ and is farther away than r in current frame E." Here r can be some number of pixels say 6. Neither i got its proper meaning nor a way to do this. – pratpor May 03 '13 at 14:45
  • got you...but to ensure that the SAME edge pixel has moved some displacement (r) you need to first ensure that a edge pixel in E is the same edge pixel in E' i.e belonging to the same edge and same position w.r.t that edge...you need to make the computer understand that two edges in two consecutive frames belong to the same feature...its like edge registration... – rotating_image May 03 '13 at 15:20
  • it would be better if you can mention what problem you want to solve by using this technique of entering-exiting edge... – rotating_image May 03 '13 at 15:21
  • Ya exactly. How to identify now that the pixel which we are considering is the same as one in previous frame at a distance of r. Actually m trying to implement Edge Change Ratio Algorithm for shot detection. – pratpor May 03 '13 at 15:32
  • what you can do is ..detect edges in frame E and in E'..store the location of the pixels in both frames...run a neighborhood search for each edge pixel in frame E...in the neighborhood search check whether you are getting any pixels of E'or not...if positive then you assert that the same edge has moved...try to keep the neighborhood <= r pixels...dnt make it large or else you might get false detections... – rotating_image May 03 '13 at 15:54
  • Ya but how to judge that a neighborhood pixel is of the frame E'? I mean all pixels will either be black or white. So they are identical. So how will I identify that the pixel m considering is of the previous frame and and has moved a distance r. If m getting something wrong, can you please help me with some code implementation. – pratpor May 03 '13 at 18:58