我正在尝试将OpenCVCircles和OpenCVSquares合并为一个项目。如果我直接(独立地)从Xcode项目文件中打开它们,则它们可以正常工作,但是如果我将CVSquares.h和CVSquares.cpp文件移到OpenCVCircles项目中,它将开始抱怨:“使用未声明的标识符CVSquares”。这发生在CVWrapper.mm中(请参阅最后的问题行):
#import "CVWrapper.h"
#import "CVCircles.h"
#import "CVSquares.h"
#import "UIImage+OpenCV.h"
//remove 'magic numbers' from original C++ source so we can manipulate them from obj-C
#define TOLERANCE 0.3
#define THRESHOLD 50
#define LEVELS 9
#define ACCURACY 0
@implementation CVWrapper
+ (NSMutableArray*) detectedCirclesInImage:(UIImage*) image
{
double dp = 1;
double minDist = 10;
double param1 = 100;
double param2 = 30;
int min_radius = 1;
int max_radius = 30;
return [[self class] detectedCirclesInImage:image
dp:dp
minDist:minDist
param1:param1
param2:param2
min_radius:min_radius
max_radius:max_radius];
}
+ (NSMutableArray*) detectedCirclesInImage:(UIImage*)image
dp:(CGFloat)dp
minDist:(CGFloat)minDist
param2:(CGFloat)param2
{
double param1 = 100;
int min_radius = 1;
int max_radius = 30;
return [[self class] detectedCirclesInImage:image
dp:dp
minDist:minDist
param1:param1
param2:param2
min_radius:min_radius
max_radius:max_radius];
}
+ (NSMutableArray*) detectedCirclesInImage:(UIImage*)image
dp:(CGFloat)dp
minDist:(CGFloat)minDist
param2:(CGFloat)param2
min_radius:(int)min_radius
max_radius:(int)max_radius
{
double param1 = 100;
return [[self class] detectedCirclesInImage:image
dp:dp
minDist:minDist
param1:param1
param2:param2
min_radius:min_radius
max_radius:max_radius];
}
+ (NSMutableArray*) detectedCirclesInImage:(UIImage*)image
dp:(CGFloat)dp
minDist:(CGFloat)minDist
param1:(CGFloat)param1
param2:(CGFloat)param2
min_radius:(int)min_radius
max_radius:(int)max_radius
{
NSMutableArray *array = [[NSMutableArray alloc] init];
UIImage* modifiedImage = nil;
cv::Mat matImage = [image CVMat];
int num_circles = 0;
matImage = CVCircles::detectedCirclesInImage
(matImage, dp, minDist, param1, param2, min_radius, max_radius, &num_circles);
modifiedImage = [UIImage imageWithCVMat:matImage];
NSLog(@"n circles: %i",num_circles);
[array addObject:modifiedImage];
[array addObject:[NSNumber numberWithInt:num_circles]];
NSLog(@"array: %@, %@",[array objectAtIndex:0],[array objectAtIndex:1]);
return array;
}
+ (UIImage*) detectedSquaresInImage:(UIImage*) image
{
//if we call this method with no parameters,
//we use the defaults from the original c++ project
return [[self class] detectedSquaresInImage:image
tolerance:TOLERANCE
threshold:THRESHOLD
levels:LEVELS
accuracy:ACCURACY];
}
+ (UIImage*) detectedSquaresInImage:(UIImage*) image
tolerance:(CGFloat) tolerance
threshold:(NSInteger)threshold
levels:(NSInteger)levels
accuracy:(NSInteger)accuracy
{
//NSLog (@"detectedSquaresInImage");
UIImage* result = nil;
cv::Mat matImage = [image CVMat];
//ERROR IS ON THIS LINE
matImage = CVSquares::detectedSquaresInImage (matImage, tolerance, threshold, levels, accuracy);
result = [UIImage imageWithCVMat:matImage];
//NSLog (@"detectedSquaresInImage result");
return result;
}
@end
我的印象是我正在双重定义某些内容,某些文件中缺少.mm等,但是我整天都在为此而苦苦挣扎,但我无法使其正常工作(今天是我第一次使用C++) 。任何帮助将非常感激。
PS:感谢代工(无论他/她是谁)为2个很棒的即插即用项目!
最佳答案
最后将所有CVSquares.cpp代码粘贴到CVCircles.cpp代码中(以及将CVSquares.h粘贴到CVCircles.h中)并调用:
matImage = CVCircles::detectedSquaresInImage (matImage, tolerance, threshold, levels, accuracy);
否则无法正常工作。希望能帮助到你!