patches/gnome-mousetrap-02-opencv2.diff
author jurikm
Sun, 12 Feb 2012 14:04:10 +0000
changeset 8245 383896da4129
parent 2649 c4eee335282a
permissions -rw-r--r--
SFEsauerbraten.spec: add IPS package name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2649
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
     1
diff --git a/src/mouseTrap/ocvfw.py b/src/mouseTrap/ocvfw.py
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
     2
--- a/src/mouseTrap/ocvfw.py
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
     3
+++ b/src/mouseTrap/ocvfw.py
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
     4
@@ -185,13 +185,18 @@
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
     5
         """
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
     6
         
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
     7
         # calculate the optical flow
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
     8
-        self.imgLKPoints["current"], status = cv.cvCalcOpticalFlowPyrLK (
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
     9
+        optical_flow = cv.cvCalcOpticalFlowPyrLK (
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    10
             self.prevGrey, self.grey, self.prevPyramid, self.pyramid,
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    11
             self.imgLKPoints["last"], len( self.imgLKPoints["last"] ),
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    12
             cv.cvSize (20, 20), 3, len( self.imgLKPoints["last"] ), None,
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    13
             cv.cvTermCriteria (cv.CV_TERMCRIT_ITER|cv.CV_TERMCRIT_EPS,
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    14
                                20, 0.03), 0)
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    15
 
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    16
+        if isinstance(optical_flow[0], tuple):
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    17
+            self.imgLKPoints["current"], status = optical_flow[0]
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    18
+        else:
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    19
+            self.imgLKPoints["current"], status = optical_flow
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    20
+
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    21
         # initializations
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    22
         counter = 0
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    23
         new_points = []
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    24
@@ -202,14 +207,13 @@
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    25
             if not status or not status[counter]:
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    26
                 # we will disable this point
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    27
                 continue
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    28
-            
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    29
 
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    30
             # this point is a correct point
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    31
             new_points.append( point )
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    32
             setattr(self, self.imgLKPoints["labels"][counter], cv.cvPoint(int(point.x), int(point.y)))
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    33
             
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    34
             # draw the current point
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    35
-            cv.cvCircle (self.img, [point.x, point.y], 3, cv.cvScalar (0, 255, 0, 0), -1, 8, 0)
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    36
+            cv.cvCircle (self.img, (int(point.x), int(point.y)), 3, cv.cvScalar (0, 255, 0, 0), -1, 8, 0)
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    37
                          
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    38
             # increment the counter
c4eee335282a 2010-05-16 Albert Lee <[email protected]>
trisk
parents:
diff changeset
    39
             counter += 1