ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Video-Capture-V4l/examples/finder
Revision: 1.1
Committed: Fri May 5 20:21:53 2000 UTC (26 years, 4 months ago) by pcg
Branch: MAIN
CVS Tags: rel-0_9, rel-0_902, HEAD
Log Message:
Initial check-in

File Contents

# User Rev Content
1 pcg 1.1 #!/usr/bin/perl
2    
3     use Video::Capture::V4l;
4     use Time::HiRes 'time';
5    
6     $grab = new Video::Capture::V4l;
7    
8     my $channel = $grab->channel (0);
9     my $tuner = $grab->tuner (0);
10     $tuner->mode(MODE_PAL); $tuner->set;
11     $channel->norm(MODE_PAL); $channel->set;
12    
13     $grab->picture->brightness(32768);
14     $grab->picture->contrast(40000);
15     $grab->picture->hue(32768);
16     $grab->picture->colour(32768);
17     $grab->picture->set;
18    
19     #$RTL2 = 855250;
20     $RTL2 = 154250;
21     print $grab->freq ($RTL2),"\n";
22    
23     $|=1;
24    
25     open DB,"<sailormoon.db" or die;
26     read(DB,$w,8) == 8 or die "no header(?)";
27     ($w,$h)=unpack("N*",$w);
28     print "$w $h\n";
29     my $db = do { local $/; <DB> };
30    
31     my $frame=0;
32     my $fr=$grab->capture ($frame,$w<<4,$h<<4);
33    
34     my $fps = 25; # glorious PAL
35     my @reg;
36     my ($expect_frame,$expect_count);
37    
38     my $start = time;
39     my $next_frame = 0;
40     my $this_frame;
41     my $locked;
42     my $minb1 = 10;
43    
44     for(;;) {
45     my $nfr = $grab->capture (1-$frame,$w<<4,$h<<4);
46     $this_frame = $next_frame; $next_frame = int((time-$start)*$fps);
47     $grab->sync($frame) or die "unable to sync";
48    
49     Video::Capture::V4l::reduce2($fr,$w<<4);
50     Video::Capture::V4l::reduce2($fr,$w<<3);
51     Video::Capture::V4l::reduce2($fr,$w<<2);
52     Video::Capture::V4l::reduce2($fr,$w<<1);
53     Video::Capture::V4l::normalize($fr);
54     ($fr,$diff) = Video::Capture::V4l::findmin ($db, $fr, $expect_frame, $expect_count);
55    
56     if ($diff < 400*400) {
57     push(@reg,$this_frame,$fr);
58     if (@reg > $fps*2) {
59     shift @reg; shift @reg;
60     my ($a,$b,$r2) = Video::Capture::V4l::linreg(\@reg);
61     if ($frame_zero) {
62     $expect_frame = $this_frame + $frame_zero + 1;
63     $expect_count = 25;
64     } else {
65     $expect_frame = $expect_count = 0;
66     }
67     printf "%9.2f + %7.2f * %6d =~ %4d (@%9.2f) EXPECT %6d - %4d ($minb1)",$a,$b,$this_frame,$fr,$r2,$frame_zero,$expect_frame;
68     my $b1 = abs($b-1);
69     if ($r2<100 && $b1<0.01) {
70     $found++;
71     print " LOCKED LOCKED LOCKED ($locked, $frame_zero)";
72     }
73     if ($b1<$minb1) {
74     $frame_zero=-$a;
75     $minb1 = $b1;
76     }
77     print "\n";
78     }
79     $jitter=0;
80     } else {
81     $jitter++;
82     if ($jitter > 5) {
83     $expect_frame=$expect_count=$frame_zero=0;
84     }
85     }
86     if ($found && $this_frame>$frame_zero+2000) {
87     print "KICKOFFKICKOFFKICKOFFKICKOFFKICKOFFKICKOFFKICKOFFKICKOFFKICKOFFKICKOFFKICKOFFKICKOFFKICKOFFKICKOFF\n";
88     die;
89     }
90    
91     $count++;
92    
93     $frame = 1-$frame;
94     $fr = $nfr;
95     }
96