29#define HOUGH_MAX_OFFSET 90
30#define MAX_FRAMERATE 60
38#define STATUS_END_REACHED 1
39#define STATUS_BEGIN_REACHED 2
53 int i, j, tmp_i, tmp_j,count;
56 for (
i = 0, count = 0;
i < 242;
i++) {
57 for (j =
i + 1; j < 243; j++, count++) {
62 dist +=
FFABS((tmp_j % 3) - (tmp_i % 3));
65 }
while (tmp_i > 0 || tmp_j > 0);
74 for (
i = 0;
i < 28;
i += 4) {
76 (first[
i+1] & second[
i+1]) << 16 |
77 (first[
i+2] & second[
i+2]) << 8 |
78 (first[
i+3] & second[
i+3]) );
81 (first[29] & second[29]) << 8 |
82 (first[30] & second[30]) );
86static unsigned int union_word(
const uint8_t *first,
const uint8_t *second)
89 for (
i = 0;
i < 28;
i += 4) {
91 (first[
i+1] | second[
i+1]) << 16 |
92 (first[
i+2] | second[
i+2]) << 8 |
93 (first[
i+3] | second[
i+3]) );
96 (first[29] | second[29]) << 8 |
97 (first[30] | second[30]) );
104 unsigned int dist = 0;
108 if (first[
i] != second[
i]) {
113 dist += sc->
l1distlut[243*242/2 - (243-
s)*(242-
s)/2 +
f -
s - 1];
115 dist += sc->
l1distlut[243*242/2 - (243-
f)*(242-
f)/2 +
s -
f - 1];
128 int jaccarddist,
i, composdist = 0, cwthcount = 0;
129 for (
i = 0;
i < 5;
i++) {
133 jaccarddist = (1 << 16) - jaccarddist;
135 if (++cwthcount > 2) {
140 composdist += jaccarddist;
156 if ((*second)->next) {
157 *second = (*second)->
next;
158 }
else if ((*first)->next) {
159 *second = secondstart;
160 *first = (*first)->
next;
171 if ((*second)->next) {
172 *second = (*second)->
next;
173 }
else if ((*first)->next) {
174 *second = secondstart;
175 *first = (*first)->
next;
189 size_t i, j, k, l, hmax = 0, score;
202 typedef struct hspace_elem {
211 hspace_elem *hspaces;
222 hspace[
i][j].score = 0;
223 hspace[
i][j].dist = 99999;
230 pairs[
i].dist = 99999;
232 for (j = 0,
s = second; j <
COARSE_SIZE &&
s->next; j++,
s =
s->next) {
235 if (l1dist < sc->thl1) {
236 if (l1dist < pairs[
i].dist) {
238 pairs[
i].dist = l1dist;
239 pairs[
i].b_pos[0] = j;
241 }
else if (l1dist == pairs[
i].dist) {
242 pairs[
i].b[pairs[
i].size] =
s;
243 pairs[
i].b_pos[pairs[
i].size] = j;
250 if (
f->next ==
NULL) {
253 pairs[
i].dist = 99999;
259 for (j = 0; j < pairs[
i].size; j++) {
261 for (l = 0; l < pairs[k].size; l++) {
262 if (pairs[
i].
b[j] != pairs[k].
b[l]) {
264 m = (pairs[k].b_pos[l]-pairs[
i].b_pos[j]) / (k-
i);
267 offset = pairs[
i].b_pos[j] - ((int) (m*
i + 0.5));
269 if (pairs[
i].dist < pairs[k].dist) {
296 hmax = (int) (0.7*hmax);
299 if (hmax < hspace[
i][j].score) {
306 c->framerateratio = (
i+1.0) / 30;
307 c->score = hspace[
i][j].score;
309 c->first = hspace[
i][j].a;
310 c->second = hspace[
i][j].b;
332 step = ((int) 0.5 + fcount * frr)
333 -((
int) 0.5 + (fcount-1) * frr);
351 if ((*b)->next && (*b)->next->next) {
352 *
b = (*b)->next->next;
373 if ((*a)->next && (*a)->next->next) {
374 *
a = (*a)->next->next;
397 if ((*b)->prev && (*b)->prev->prev) {
398 *
b = (*b)->prev->prev;
419 if ((*a)->prev && (*a)->prev->prev) {
420 *
a = (*a)->prev->prev;
432 int dist, distsum = 0, bcount = 1, dir =
DIR_NEXT;
433 int fcount = 0, goodfcount = 0, gooda = 0, goodb = 0;
434 double meandist, minmeandist = bestmatch.
meandist;
435 int tolerancecount = 0;
439 for (; infos !=
NULL; infos = infos->
next) {
445 if (dist > sc->
thl1) {
446 if (
a->confidence >= 1 ||
b->confidence >= 1) {
451 if (tolerancecount > 2) {
472 if (
a->confidence < 1) gooda++;
473 if (
b->confidence < 1) goodb++;
491 if (sc->
thdi != 0 && bcount >= sc->
thdi) {
496 if (bcount < sc->thdi)
498 if ((
double) goodfcount / (
double) fcount < sc->thit)
500 if ((
double) goodfcount*0.5 <=
FFMAX(gooda, goodb))
503 meandist = (
double) distsum / (
double) goodfcount;
505 if (meandist < minmeandist ||
508 minmeandist = meandist;
557 "indices of first frame: %"PRIu32
" and %"PRIu32
"\n",
563 for (
i = infos;
i !=
NULL;
i =
i->next) {
565 "ratio %f, offset %d\n",
i->first->index,
i->second->index,
566 i->framerateratio,
i->offset);
574 "ratio %f, offset %d, score %d, %d frames matching\n",
static double val(void *priv, double ch)
static AVFormatContext * ctx
#define i(width, name, range_min, range_max)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int av_log_get_level(void)
Get the current log level.
Memory handling functions.
MPEG-7 video signature calculation and lookup filter.
static int iterate_frame(double frr, FineSignature **a, FineSignature **b, int fcount, int *bcount, int dir)
static int find_next_coarsecandidate(SignatureContext *sc, CoarseSignature *secondstart, CoarseSignature **first, CoarseSignature **second, int start)
step through the coarsesignatures as long as a good candidate is found
static void sll_free(MatchingInfo **sll)
static unsigned int union_word(const uint8_t *first, const uint8_t *second)
static MatchingInfo evaluate_parameters(AVFilterContext *ctx, SignatureContext *sc, MatchingInfo *infos, MatchingInfo bestmatch, int mode)
static unsigned int intersection_word(const uint8_t *first, const uint8_t *second)
#define STATUS_BEGIN_REACHED
#define STATUS_END_REACHED
static MatchingInfo lookup_signatures(AVFilterContext *ctx, SignatureContext *sc, StreamContext *first, StreamContext *second, int mode)
static void fill_l1distlut(uint8_t lut[])
static MatchingInfo * get_matching_parameters(AVFilterContext *ctx, SignatureContext *sc, FineSignature *first, FineSignature *second)
compares framesignatures and sorts out signatures with a l1 distance above a given threshold.
static unsigned int get_l1dist(AVFilterContext *ctx, SignatureContext *sc, const uint8_t *first, const uint8_t *second)
static int get_jaccarddist(SignatureContext *sc, CoarseSignature *first, CoarseSignature *second)
calculates the jaccard distance and evaluates a pair of coarse signatures as good
struct FineSignature * first
struct CoarseSignature * next
struct MatchingInfo * next
struct FineSignature * second
struct FineSignature * first
uint8_t l1distlut[243 *242/2]
CoarseSignature * coarsesiglist
static void error(const char *err)