我正在尝试将向量数组(来自 C++ 的 std::vector)解析为 NSNumber 的 NSMutableArray。但是,我添加到 NSNumber 数组的 Vector 始终为零,即使添加了 NSNumber(从 std::vector 解析)
在这个项目中,我试图将 OpenCV Canny Edge Detection Algorithm (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;
如上所述,“向量”变量始终为零,即使我向它添加了一个 NSNumber 对象。