2012-05-15 79 views
0

我嘗試創建一個這樣的程序:http://www.youtube.com/watch?v=V9LY8JqKLqE&feature=my_liked_videos&list=LLIeJ9s3lwD-lrqYMU409iAQOpenCV的,IOS,模板匹配,地方匹配良好的

但遺憾的是我不知道如何標記找到

我重新思考這個的地方教程:http://aptogo.co.uk/2011/09/face-tracking/

我的源代碼: 我實現模板圖像到DemoVideoCaptureViewController.mm文件

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIImage *testImage = [UIImage imageNamed:@"tt2.jpg"]; 
    tempMat = [testImage CVMat]; 

    std::vector<cv::KeyPoint> keypoints; 
    cv::SurfFeatureDetector surf (250); 
    surf.detect(tempMat, keypoints); 

    cv::SurfDescriptorExtractor surfDesc; 
    surfDesc.compute(tempMat, keypoints, description1); 
} 

我嘗試在這裏找到對象:

- (void)processFrame:(cv::Mat &)mat videoRect:(CGRect)rect videoOrientation:(AVCaptureVideoOrientation)videOrientation 
{ 

    cv::FlannBasedMatcher matcher; 
    std::vector< cv::vector<cv::DMatch> > matches; 
    std::vector<cv::DMatch> good_matches; 

    cv::SurfFeatureDetector surf2 (250); 
    std::vector<cv::KeyPoint> kp_image; 

    surf2.detect(mat, kp_image); 
    cv::SurfDescriptorExtractor surfDesc2; 
    surfDesc2.compute(mat, kp_image, des_image); 

    if ((des_image.rows > 0) && (description1.rows > 0)) { 

     matcher.knnMatch(description1, des_image, matches, 2); 

     for (int i = 0; i < MIN(des_image.rows-1, (int) matches.size()); i++) { 

      if ((matches[i][0].distance < 0.6*(matches[i][1].distance)) && ((int) matches[i].size() <= 2 && (int) matches[i].size() > 0)) { 
       good_matches.push_back(matches[i][0]); 
      } 

     } 

     [CATransaction begin]; 
     [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; 

     **//remove old layer** 

     for (CALayer *layer in self.view.layer.sublayers) { 
      NSString *layerName = [layer name]; 
      if ([layerName isEqualToString:@"Layer"]) 
       [layer setHidden:YES]; 
     } 

     [CATransaction commit]; 

     if (good_matches.size() >= 4) { 
      NSLog(@"Finding"); 
     } 
    } 
} 

但我不知道如何把一個層上camrea視圖

可能有人幫助我嗎?

回答

0

您發佈的視頻中的應用程序可以按照「使用實用計算機視覺項目掌握OpenCV」一書中的第3章(無標記增強現實)創建。

你還得做一些步驟,比如計算單應性。而且您不需要使用CATransaction或任何其他iOS類。 CvVideoCamera和線就足夠了。