我正在使用 OpenCV 拼接图像。我正在使用四张尺寸为"720 × 960 像素"的图像。从四个图像中,我使用了三个图像,这些图像将在应用程序启动时进行拼接。当我点击缝合按钮时,第四个将缝合。它工作正常。但是,当我将所有四个图像的大小从“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
我在项目中使用的代码在这里
还有一件事-我已经在 ios 7.0 模拟器中测试了我的代码以及上面的链接代码。当我将它运行到设备中时,它只是在控制台中显示了我上面提到的消息。
有人可以告诉我哪里可能出错以及如何解决吗?谢谢