-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathEx4TrackingFeatures.scala
53 lines (41 loc) · 1.61 KB
/
Ex4TrackingFeatures.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved.
*
* Author's e-mail: jpsacha at gmail.com
*/
package opencv_cookbook.chapter11
import java.io.File
/** The example for section "Tracking feature points in video" in Chapter 10, page 266.
*
* Tracking is implemented in class `FeatureTracker`.
*
* Unlike in the C++ implementation, we do not need to pass `FeatureTracker` object as a parameter to `VideoProcessor`.
* We only need to pass to `VideoProcessor` method `process` with its "context".
* This simplifies implementation of `VideoProcessor`.
* Scala can treat `process` as a "closure", that is method `process` will have access to all local member variables
* in class `FeatureTracker`.
*/
object Ex4TrackingFeatures extends App {
// Use command line path, if provided
val inputFile = args
.headOption
.map(new File(_))
.getOrElse(new File("data/bike.avi"))
// Open video file
println("Processing video file: " + inputFile.getCanonicalPath)
// Feature tracker
val tracker = new FeatureTracker()
// Create video processor instance
val processor = new VideoProcessor()
processor.input = inputFile.getCanonicalPath
// Declare a window to display input and output the video
processor.displayInput = "Input Video"
processor.displayOutput = "Output Video"
// Play the video at the original frame rate
processor.delay = math.round(1000d / processor.frameRate)
// Set the frame processor callback function (pass FeatureTracker `process` method as a closure)
processor.frameProcessor = tracker.process
// Start the process
processor.run()
println("Done.")
}