在iPhone中使用OpenCV时生成的图像拼接问题

时间:2013-11-14 07:22:33

标签: c++ ios opencv ios7 image-stitching

我正在使用OpenCV拼接图像。我正在使用尺寸为“720×960像素”的四张图像。从四张图片中我已经使用了三张图片,这些图片将在app启动时被拼接。当我点击针迹按钮时,第四个将缝合。它工作正常。但是当我将所有四个图像的尺寸从“720×960像素”改为640×960像素时,问题就会出现,并且在调整图像大小后再次运行代码时,三个图像已经显示就像我上面提到的那样,但是当我点击我必须缝合第四张图像的针迹按钮时,编译器会在控制台中显示一条消息,如下所述 -

  

无法拼接图片,错误代码= 1

     

<错误>:CGImageCreate:图像尺寸无效:0 x 0。

我使用了以下代码 -

在CVViewController.h中

import <UIKit/UIKit.h>

@interface CVViewController : UIViewController
{
    NSArray *arrayImgGlobal;

}
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView* spinner;
@property (nonatomic, weak) IBOutlet UIScrollView* scrollView;
@end

在CVViewController.m

#import "CVViewController.h"
#import "CVWrapper.h"

@interface CVViewController ()

@end

@implementation CVViewController

- (void)viewDidAppear:(BOOL)animated    
{
    [super viewDidAppear:animated];
    NSArray* imageArray = [NSArray arrayWithObjects:
                           [UIImage imageNamed:@"1@2x.jpg"],
                           [UIImage imageNamed:@"2@2x.jpg"],
                           [UIImage imageNamed:@"3@2x.jpg"],
                            nil];
    [self stitch:imageArray];
}

-(IBAction)onButtonStitch:(UIButton *)btn
{
    [self onBtnStitchPressed:arrayImgGlobal];
}
-(void)onBtnStitchPressed:(NSArray *)imageArray
{
    [self stitch:imageArray];
}

- (void) stitch : (NSArray *)imageArray
{
    [self.spinner startAnimating];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
              UIImage* stitchedImage = [CVWrapper processWithArray:imageArray];
        dispatch_async(dispatch_get_main_queue(), ^{

            NSLog (@"stitchedImage %@",stitchedImage);
            for (UIImageView *imgView in [self.scrollView subviews]) {
                [imgView removeFromSuperview];
            }
            UIImageView* imageView = [[UIImageView alloc] initWithImage:stitchedImage];

            self.imageView = imageView;
            [self.scrollView addSubview:self.imageView];
            self.scrollView.backgroundColor = [UIColor blackColor];
            self.scrollView.contentSize = self.imageView.bounds.size;
            self.scrollView.maximumZoomScale = 4.0;
            self.scrollView.minimumZoomScale = 0.5;
            self.scrollView.contentOffset = CGPointMake(-(self.scrollView.bounds.size.width-self.imageView.bounds.size.width)/2, -(self.scrollView.bounds.size.height-self.imageView.bounds.size.height)/2);
            NSLog (@"scrollview contentSize %@",NSStringFromCGSize(self.scrollView.contentSize));
            [self.spinner stopAnimating];

            NSArray *arrayImages = [NSArray arrayWithObjects:
                                    stitchedImage,
                                    [UIImage imageNamed:@"4@2x.jpg"],
                                    nil];
            arrayImgGlobal = arrayImages;

        });
    });
}
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return YES;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - scroll view delegate

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.imageView;
}
@end

我在Here

项目中使用的代码

还有一件事 - 我已经在ios 7.0模拟器中测试了我的代码以及上面的链接代码。当我将它运行到设备中时,它只是在我上面提到的控制台中显示消息。

有人可以告诉我哪里可能出错了以及如何解决?感谢

0 个答案:

没有答案