Skip to content

Commit

Permalink
Tweak Farneback for better startup experience.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeradesign committed Oct 2, 2012
1 parent cf0ba99 commit b55e4ea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 36 deletions.
20 changes: 13 additions & 7 deletions CVFunhouse/CVFFarneback.m
Expand Up @@ -13,8 +13,6 @@
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc_c.h"

CvMat* prevgray = 0, *gray = 0, *flow = 0, *cflow = 0;

static void drawOptFlowMap(const CvMat* flow, CvMat* cflowmap, int step,
double scale, CvScalar color)
{
Expand All @@ -30,6 +28,15 @@ static void drawOptFlowMap(const CvMat* flow, CvMat* cflowmap, int step,
}
}

@interface CVFFarneback () {
CvMat *prevgray;
CvMat *gray;
CvMat *flow;
CvMat *cflow;
}

@end

@implementation CVFFarneback

/*
Expand Down Expand Up @@ -63,16 +70,15 @@ -(void)processIplImage:(IplImage*)frame
cvCvtColor(frame, gray, CV_BGR2GRAY);
cvReleaseImage(&frame);

cvCvtColor(gray, cflow, CV_GRAY2BGR);

if( !firstFrame )
{
cvCalcOpticalFlowFarneback(prevgray, gray, flow, 0.5, 3, 15, 3, 5, 1.2, 0);
cvCvtColor(prevgray, cflow, CV_GRAY2BGR);
drawOptFlowMap(flow, cflow, 16, 1.5, CV_RGB(0, 255, 0));
}
{
CvMat* temp;
CV_SWAP(prevgray, gray, temp);
}

cvCopy(gray, prevgray, nil);

// Call imageReady with your new image.
IplImage *tempImage = cvAlloc(sizeof(IplImage));
Expand Down
10 changes: 5 additions & 5 deletions CVFunhouse/en.lproj/MainStoryboard_iPad.storyboard
@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2549" systemVersion="11E53" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" initialViewController="2">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2840" systemVersion="12C54" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" initialViewController="2">
<dependencies>
<deployment defaultVersion="1296" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1498"/>
<deployment defaultVersion="1536" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1926"/>
</dependencies>
<scenes>
<!--Main View Controller-->
<scene sceneID="4">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="3" sceneMemberID="firstResponder"/>
<viewController id="2" customClass="CVFMainViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
Expand Down Expand Up @@ -82,6 +81,7 @@
</segue>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="3" sceneMemberID="firstResponder"/>
<swipeGestureRecognizer direction="up" id="haR-n2-fTo">
<connections>
<action selector="swipeUpAction:" destination="2" id="gS5-O1-qFE"/>
Expand All @@ -98,7 +98,6 @@
<!--Flipside View Controller-->
<scene sceneID="7">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="6" sceneMemberID="firstResponder"/>
<viewController id="5" customClass="CVFFlipsideViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="9">
<rect key="frame" x="0.0" y="0.0" width="320" height="852"/>
Expand Down Expand Up @@ -143,6 +142,7 @@
<outlet property="navBar" destination="17" id="mzC-dU-KrK"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="6" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="836" y="101"/>
</scene>
Expand Down
24 changes: 0 additions & 24 deletions CVFunhouse/en.lproj/MainStoryboard_iPhone.storyboard
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2840" systemVersion="12C54" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="2">
<dependencies>
<deployment defaultVersion="1536" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1926"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -154,29 +153,6 @@
<image name="SwitchCameraIcon44.png" width="44" height="25"/>
<image name="iButton30.png" width="30" height="30"/>
</resources>
<classes>
<class className="CVFFlipsideViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/CVFFlipsideViewController.h"/>
<relationships>
<relationship kind="action" name="done:"/>
<relationship kind="outlet" name="menuTable" candidateClass="UITableView"/>
<relationship kind="outlet" name="navBar" candidateClass="UINavigationBar"/>
</relationships>
</class>
<class className="CVFMainViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/CVFMainViewController.h"/>
<relationships>
<relationship kind="action" name="flipAction:"/>
<relationship kind="action" name="swipeDownAction:"/>
<relationship kind="action" name="swipeUpAction:"/>
<relationship kind="outlet" name="descriptionView" candidateClass="UIWebView"/>
<relationship kind="outlet" name="flipCameraButton" candidateClass="UIButton"/>
<relationship kind="outlet" name="fpsLabel" candidateClass="UILabel"/>
<relationship kind="outlet" name="imageView" candidateClass="UIImageView"/>
<relationship kind="outlet" name="previewView" candidateClass="UIView"/>
</relationships>
</class>
</classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<nil key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
Expand Down

0 comments on commit b55e4ea

Please sign in to comment.