我试图解析一个Vector数组(从C ++的std :: vector)到NSNumber的NSMutableArray。但是,我添加到NSNumber数组的Vector总是为nil,即使添加了NSNumber(从std :: vector解析)
在这个项目中,我正在尝试将OpenCV Canny边缘检测算法(C ++)连接到我的Swift项目。他们的一个方法将所有照片的边缘返回为std :: vector。所以,我正在尝试将其解析为与Swift兼容的数组(使用Objective-C ++作为中间语言)。截至目前,似乎只有一行无法正常工作(如上所述)。我也是一个初学的Objective-C ++程序员,因此代码中可能存在一些常见的错误,我还没有找到。
/*Ptr<LineSegmentDetector>*/
cv::Ptr<cv::LineSegmentDetector> ls = cv::createLineSegmentDetector(cv::LSD_REFINE_STD) ;//Creates the line detector (AKA what I called the edge detector)
std::vector<cv::Vec4f> lines_std;
[image convertToMat: &mat];
// Detect the lines
ls->detect(mat, lines_std);
//Swift compatible NSMutableArray to return from this method
NSMutableArray *edgeLines;
printf("currently finding the edge lines");
for (int i = 0; i < lines_std.size(); i ++) {
NSMutableArray<NSNumber *> *vector;
//Convert from Vec4f to NSNumber
for (int k = 0; k < 4; k ++) {
[vector addObject: [NSNumber numberWithFloat: (lines_std[i][k])]]; //HERE, I'm parsing each float value in each vector (from std::vector<cv::Vec4f>) and adding it to a NSArray, like a vector
}
//Here, I add the vectors to the return NSMutable array
[edgeLines insertObject:vector atIndex:edgeLines.count];
}
return edgeLines;
如上所述,“vector”变量总是为nil,即使我正在向它添加NSNumber对象。
我发现了问题,我没有用过这一行:NSMutableArray * vector = [[NSMutableArray alloc] init];