Shotdetect logic

Shotdetect logic:
Shotdetect is a nice useful tool, for video processing area of work. In essence, it tells you at which shots there was/is a scene/shot change. It takes a threshold value and compares two consecutive frames.(I’d like an option to compare more ,but the compare algo gets complicated).

Even for the two images, he’s doing summary statistics of the frames/images. But, there are problems with that approach, (i.e: high intensity object in a small corner of an image, like a car headlight, ) can be counted as shot, it can be valid in cases where 25% of the image/frame is a car light, but on a long shot of the road, it’s probably a bad idea.

So he splits the image into segments and summarizes the segments and compare segment by segment.
Here’s the logic/code:
(in cscope/grep for CompareFrame function )

for (y = 0; y < height; y++) {
for (x = 0; x data[0] + y * pFrame->linesize[0] + x * 3);
c2 = *(pFrame->data[0] + y * pFrame->linesize[0] + x * 3 + 1);
c3 = *(pFrame->data[0] + y * pFrame->linesize[0] + x * 3 + 2);

c1prev = *(pFramePrev->data[0] + y * pFramePrev->linesize[0] + x * 3);
c2prev = *(pFramePrev->data[0] + y * pFramePrev->linesize[0] + x * 3 + 1);
c3prev = *(pFramePrev->data[0] + y * pFramePrev->linesize[0] + x * 3 + 2);

c1tot += int ((char) c1 + 127);
c2tot += int ((char) c2 + 127);
c3tot += int ((char) c3 + 127);

score += abs (c1 - c1prev);
score += abs (c2 - c2prev);
score += abs (c3 - c3prev);

He splits the image into 3 parts and then multiplies the x and y values and calculates differences.

One immediate improvement I can think of is to split the image into 9 parts(3×3 square matrix) and weight each of the subsections differently. For example: I would weight the centermost(2,2) section higher (atleast in some type of movies/videos).
However, on second thoughts ,it’s better to make it a user choice. I think, I’ll tary to work on it and send a pull request, when I find free time to revive my long-dead C skills. Here’s an initial untested attempt.

UPDATE: Jun. 27-2015 Initial test run says it takes longer to run and prints fewer shots. but the code is still buggy giving I/O error while saving the data.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s