Permalink
Browse files

Added Face Recognition example. Added TODO file. Cleaned up project.

  • Loading branch information...
1 parent 82db48e commit 3f5686a6b9cbdcad0227a32db92e573c9af1ca28 @jeradesign committed Jul 25, 2012
@@ -15,6 +15,8 @@
425370911508384900BFE3C0 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4253708F1508384900BFE3C0 /* CoreVideo.framework */; };
42537094150839FF00BFE3C0 /* CVFImageProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 42537093150839FF00BFE3C0 /* CVFImageProcessor.m */; };
4275AFCC15095A2C00D74063 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4275AFCB15095A2C00D74063 /* libz.dylib */; };
+ 4285252815BF698800622EE8 /* CVFFaceDetect.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4285252715BF698800622EE8 /* CVFFaceDetect.mm */; };
+ 4285252F15BF750000622EE8 /* haarcascade_frontalface_alt.xml in Resources */ = {isa = PBXBuildFile; fileRef = 4285252E15BF750000622EE8 /* haarcascade_frontalface_alt.xml */; };
42AA08581508314600B379F4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42AA08571508314600B379F4 /* UIKit.framework */; };
42AA085A1508314600B379F4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42AA08591508314600B379F4 /* Foundation.framework */; };
42AA085C1508314600B379F4 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42AA085B1508314600B379F4 /* CoreGraphics.framework */; };
@@ -45,6 +47,10 @@
42537093150839FF00BFE3C0 /* CVFImageProcessor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CVFImageProcessor.m; sourceTree = "<group>"; };
4253709515083BA800BFE3C0 /* CVFImageProcessorDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CVFImageProcessorDelegate.h; sourceTree = "<group>"; };
4275AFCB15095A2C00D74063 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
+ 4285252515BF5A9300622EE8 /* TODO.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = TODO.rtf; sourceTree = "<group>"; };
+ 4285252615BF696700622EE8 /* CVFFaceDetect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CVFFaceDetect.h; sourceTree = "<group>"; };
+ 4285252715BF698800622EE8 /* CVFFaceDetect.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CVFFaceDetect.mm; sourceTree = "<group>"; };
+ 4285252E15BF750000622EE8 /* haarcascade_frontalface_alt.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = haarcascade_frontalface_alt.xml; sourceTree = "<group>"; };
42AA08531508314600B379F4 /* CVFunhouse.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CVFunhouse.app; sourceTree = BUILT_PRODUCTS_DIR; };
42AA08571508314600B379F4 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
42AA08591508314600B379F4 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -91,17 +97,24 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
- 42AA08481508314500B379F4 = {
+ 4285252915BF6CDF00622EE8 /* Resources */ = {
isa = PBXGroup;
children = (
+ 4285252E15BF750000622EE8 /* haarcascade_frontalface_alt.xml */,
42B3377815BA94A000CBD888 /* CVFunhouse57.png */,
42B3377515BA949400CBD888 /* CVFunhouse114.png */,
42B3376F15BA945A00CBD888 /* CVFunhouse72.png */,
42B3376C15BA944400CBD888 /* CVFunhouse144.png */,
- 42171D1315BA6C37008BEA68 /* libstdc++.dylib */,
- 42171D1115BA6C19008BEA68 /* opencv2.framework */,
- 4275AFCB15095A2C00D74063 /* libz.dylib */,
+ );
+ name = Resources;
+ sourceTree = "<group>";
+ };
+ 42AA08481508314500B379F4 = {
+ isa = PBXGroup;
+ children = (
+ 4285252515BF5A9300622EE8 /* TODO.rtf */,
42AA085D1508314600B379F4 /* CVFunhouse */,
+ 4285252915BF6CDF00622EE8 /* Resources */,
42AA08561508314600B379F4 /* Frameworks */,
42AA08541508314600B379F4 /* Products */,
);
@@ -124,6 +137,9 @@
4253708B1508383800BFE3C0 /* AVFoundation.framework */,
4253708E1508384900BFE3C0 /* CoreMedia.framework */,
4253708F1508384900BFE3C0 /* CoreVideo.framework */,
+ 42171D1115BA6C19008BEA68 /* opencv2.framework */,
+ 4275AFCB15095A2C00D74063 /* libz.dylib */,
+ 42171D1315BA6C37008BEA68 /* libstdc++.dylib */,
);
name = Frameworks;
sourceTree = "<group>";
@@ -147,6 +163,8 @@
CD7E937615BB5354004D709A /* CVFSephiaDemo.m */,
420A3F8315BC6724004804EF /* CVFPassThru.h */,
420A3F8415BC6724004804EF /* CVFPassThru.m */,
+ 4285252615BF696700622EE8 /* CVFFaceDetect.h */,
+ 4285252715BF698800622EE8 /* CVFFaceDetect.mm */,
4253709515083BA800BFE3C0 /* CVFImageProcessorDelegate.h */,
42AA085E1508314600B379F4 /* Supporting Files */,
);
@@ -223,6 +241,7 @@
42B3377015BA945A00CBD888 /* CVFunhouse72.png in Resources */,
42B3377615BA949400CBD888 /* CVFunhouse114.png in Resources */,
42B3377915BA94A000CBD888 /* CVFunhouse57.png in Resources */,
+ 4285252F15BF750000622EE8 /* haarcascade_frontalface_alt.xml in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -241,6 +260,7 @@
42B3377C15BB2F5200CBD888 /* CVFCannyDemo.m in Sources */,
CD7E937715BB5354004D709A /* CVFSephiaDemo.m in Sources */,
420A3F8515BC6724004804EF /* CVFPassThru.m in Sources */,
+ 4285252815BF698800622EE8 /* CVFFaceDetect.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -0,0 +1,13 @@
+//
+// CVFFaceDetect.h
+// CVFunhouse
+//
+// Created by John Brewer on 7/24/12.
+// Copyright (c) 2012 Jera Design LLC. All rights reserved.
+//
+
+#import "CVFImageProcessor.h"
+
+@interface CVFFaceDetect : CVFImageProcessor
+
+@end
View
@@ -0,0 +1,113 @@
+//
+// CVFFaceDetect.m
+// CVFunhouse
+//
+// Created by John Brewer on 7/22/12.
+// Copyright (c) 2012 Jera Design LLC. All rights reserved.
+//
+
+// Based on the OpenCV example: <opencv>/samples/c/facedetect.cpp
+
+#import "CVFFaceDetect.h"
+
+#include "opencv2/objdetect/objdetect.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+
+using namespace std;
+using namespace cv;
+
+CascadeClassifier cascade;
+double scale = 1;
+
+@interface CVFFaceDetect() {
+ bool _inited;
+}
+
+@end
+
+@implementation CVFFaceDetect
+
+/*
+ * processIplImage
+ *
+ * Inputs:
+ * iplImage: an IplImage in BGRA format, 8 bits per pixel.
+ * YOU ARE RESPONSIBLE FOR CALLING cvReleaseImage on this image.
+ *
+ * Outputs:
+ * When you are done, call imageReady: with an RGB, RGBA, or grayscale
+ * IplImage with 8-bits per pixel.
+ *
+ * You can call imageReady: from any thread and it will do the right thing.
+ * You can fork as many threads to process the image as you like; just call
+ * imageReady when you are done.
+ *
+ * imageReady: will dispose of the IplImage you pass it once the system is
+ * done with it.
+ */
+-(void)processIplImage:(IplImage*)iplImage
+{
+ if (!_inited) {
+ NSString* haarDataPath =
+ [[NSBundle mainBundle] pathForResource:@"haarcascade_frontalface_alt.xml" ofType:nil];
+
+ cascade.load([haarDataPath UTF8String]);
+ _inited = true;
+ }
+
+ // To do the conversion, first create an IplImage the same size...
+ IplImage *rgbImage = cvCreateImage(cvGetSize(iplImage), IPL_DEPTH_8U, 3);
+
+ // Call cvCvtColor to do the conversion
+ cvCvtColor(iplImage, rgbImage, CV_BGR2RGB);
+
+ // Release the original image or you will run out of memory very fast!
+ cvReleaseImage(&iplImage);
+
+ Mat img = Mat::Mat(rgbImage, false);
+
+ int i = 0;
+ double t = 0;
+ vector<cv::Rect> faces;
+ const static Scalar colors[] = { CV_RGB(0,0,255),
+ CV_RGB(0,128,255),
+ CV_RGB(0,255,255),
+ CV_RGB(0,255,0),
+ CV_RGB(255,128,0),
+ CV_RGB(255,255,0),
+ CV_RGB(255,0,0),
+ CV_RGB(255,0,255)} ;
+ Mat gray, smallImg( cvRound (img.rows/scale), cvRound(img.cols/scale), CV_8UC1 );
+
+ cvtColor( img, gray, CV_BGR2GRAY );
+ resize( gray, smallImg, smallImg.size(), 0, 0, INTER_LINEAR );
+ equalizeHist( smallImg, smallImg );
+
+ t = (double)cvGetTickCount();
+ cascade.detectMultiScale( smallImg, faces,
+ 1.1, 2, 0
+ //|CV_HAAR_FIND_BIGGEST_OBJECT
+ //|CV_HAAR_DO_ROUGH_SEARCH
+ |CV_HAAR_SCALE_IMAGE
+ ,
+ cv::Size(30, 30) );
+ t = (double)cvGetTickCount() - t;
+ printf( "detection time = %g ms\n", t/((double)cvGetTickFrequency()*1000.) );
+ for( vector<cv::Rect>::const_iterator r = faces.begin(); r != faces.end(); r++, i++ )
+ {
+ Mat smallImgROI;
+ vector<cv::Rect> nestedObjects;
+ cv::Point center;
+ Scalar color = colors[i%8];
+ int radius;
+ center.x = cvRound((r->x + r->width*0.5)*scale);
+ center.y = cvRound((r->y + r->height*0.5)*scale);
+ radius = cvRound((r->width + r->height)*0.25*scale);
+ circle( img, center, radius, color, 3, 8, 0 );
+ }
+
+ // img is just an alias to the data in iplImage, so just return it.
+ [self imageReady:rgbImage];
+}
+
+@end
@@ -30,6 +30,7 @@ - (void)viewDidLoad
_flipsidePopoverArray = [[NSMutableArray alloc] initWithObjects:
@"Canny Edge Detector",
@"Sepia Filter",
+ @"Face Detector",
@"Pass Thru",
NULL];
_menuTable = [[UITableView alloc] init];
@@ -9,6 +9,7 @@
#import "CVFMainViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "CVFCannyDemo.h"
+#import "CVFFaceDetect.h"
#import "CVFSephiaDemo.h"
#import "CVFPassThru.h"
#import "CVFFlipsideViewController.h"
@@ -58,10 +59,14 @@ - (void)resetImageProcessor {
break;
case 1:
- self.imageProcessor = [[CVFSephiaDemo alloc] init];
+ self.imageProcessor = [[CVFFaceDetect alloc] init];
break;
case 2:
+ self.imageProcessor = [[CVFSephiaDemo alloc] init];
+ break;
+
+ case 3:
self.imageProcessor = [[CVFPassThru alloc] init];
break;
View
104 TODO.rtf
@@ -0,0 +1,104 @@
+{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf470
+{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fswiss\fcharset0 ArialMT;\f2\fnil\fcharset0 LucidaGrande;
+}
+{\colortbl;\red255\green255\blue255;\red26\green26\blue26;}
+{\*\listtable{\list\listtemplateid1\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'01\uc0\u8226 ;}{\levelnumbers;}\fi-360\li720\lin720 }{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid2\'01\uc0\u8259 ;}{\levelnumbers;}\fi-360\li1440\lin1440 }{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid3\'01\uc0\u8259 ;}{\levelnumbers;}\fi-360\li2160\lin2160 }{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid4\'01\uc0\u8259 ;}{\levelnumbers;}\fi-360\li2880\lin2880 }{\listname ;}\listid1}}
+{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}}
+\margl1440\margr1440\vieww9000\viewh8400\viewkind0
+\pard\tx220\tx720\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li720\fi-720\pardirnatural
+\ls1\ilvl0
+\f0\fs24 \cf0 {\listtext \'95 }TODO\
+\pard\tx940\tx1440\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li1440\fi-1440\pardirnatural
+\ls1\ilvl1\cf0 {\listtext \uc0\u8259 }Integrate video demos from samples bundled with OpenCV.\
+\pard\tx1660\tx2160\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li2160\fi-2160\pardirnatural
+\ls1\ilvl2\cf0 {\listtext \uc0\u8259 }
+\f1\fs26 \cf2 c:\
+\pard\tx2380\tx2880\pardeftab720\li2880\fi-2880
+\ls1\ilvl3\cf2 {\listtext
+\f2 \uc0\u8259
+\f1 }facedetect.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }fback_c.c\
+{\listtext
+\f2 \uc0\u8259
+\f1 }motempl.c\
+{\listtext
+\f2 \uc0\u8259
+\f1 }polar_transforms.c\
+\pard\tx1660\tx2160\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li2160\fi-2160\pardirnatural
+\ls1\ilvl2
+\f0\fs24 \cf0 {\listtext \uc0\u8259 }
+\f1\fs26 \cf2 cpp:\
+\pard\tx2380\tx2880\pardeftab720\li2880\fi-2880
+\ls1\ilvl3\cf2 {\listtext
+\f2 \uc0\u8259
+\f1 }bgfg_segm.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }calibration.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }camshiftdemo.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }fback.cpp\
+\pard\tx2380\tx2880\pardeftab720\li2880\fi-2880
+\ls1\ilvl3\cf2 {\listtext
+\f2 \uc0\u8259
+\f1 }hybridtrackingsample.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }laplace.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }linemod.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }lkdemo.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }multicascadeclassifier.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }openni_capture.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }phase_corr.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }retinaDemo.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }segment_objects.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }select3dobj.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }starter_video.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }video_dmtx.cpp\
+{\listtext
+\f2 \uc0\u8259
+\f1 }video_homography.cpp\
+\pard\tx2380\tx2880\pardeftab720\li2880\fi-2880
+\ls1\ilvl3
+\f0\fs24 \cf0 {\listtext \uc0\u8259 }Build opencv2.framework with optimizations turned on.\
+\pard\tx940\tx1440\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li1440\fi-1440\pardirnatural
+\ls1\ilvl1\cf0 {\listtext \uc0\u8259 }Build opencv2.framework with optimizations turned on.\
+{\listtext \uc0\u8259 }Disable "switch camera" button for devices with only one camera.\
+{\listtext \uc0\u8259 }Set default demo to passthru if no demo found in switch statement.\
+{\listtext \uc0\u8259 }Figure out how to add demos without touching CVFMainViewController and CVFFlipsideViewController every time.\
+{\listtext \uc0\u8259 }"App mode"\
+\pard\tx1660\tx2160\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li2160\fi-2160\pardirnatural
+\ls1\ilvl2\cf0 {\listtext \uc0\u8259 }Used for writing custom apps based on CVFunhouse\
+\pard\tx1660\tx2160\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li2160\fi-2160\pardirnatural
+\ls1\ilvl2\cf0 {\listtext \uc0\u8259 }Separate target\
+{\listtext \uc0\u8259 }No demos\
+{\listtext \uc0\u8259 }Use metadata to load single class in CVMainViewController\
+{\listtext \uc0\u8259 }Custom flipside view and view controller\
+\pard\tx220\tx720\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li720\fi-720\pardirnatural
+\ls1\ilvl0\cf0 {\listtext \'95 }DONE\
+}
Oops, something went wrong.

0 comments on commit 3f5686a

Please sign in to comment.