【发布时间】:2018-08-14 11:53:13
【问题描述】:
我正在使用 dlib 的面部标志检测器,并希望将面部标志坐标存储在可在 Swift 中使用的数组中。
目前我已将地标坐标存储在向量中:
std::vector<dlib::point> facialLandmarks;
for (unsigned long k = 0; k < shape.num_parts(); k++) {
dlib::point p = shape.part(k);
facialLandmarks.push_back(p);
}
我现在想编写一个函数,将向量转换为 NSArray,以便我可以返回该数组并在我的 Swift 代码中使用它。
当我尝试以下操作时:
NSArray* facialLandmarksArray = &facialLandmarks[0];
我收到一个错误:
Cannot initialize a variable of type 'NSArray *__strong' with an rvalue of type 'std::__1::__vector_base<dlib::vector<long, 2>, std::__1::allocator<dlib::vector<long, 2> > >::value_type *' (aka 'dlib::vector<long, 2> *')
我真的对 Objective-C 或 C++ 知之甚少,但需要将其用于 Dlib。任何帮助将不胜感激!
【问题讨论】:
-
我不知道 Swift,但是查看文档,您如何确定您需要
NSArray而不是Array? -
@Cheersandhth.-Alf 那段代码实际上是 Obj-C,问题中没有 Swift 代码。
Array是 Swift 类型,Obj-C 只有NSArray。 -
@DávidPásztor:谢谢。
-
我已经创建了一个桥接头,这样我就可以将一个 Objective-C 类 (DlibWrapper.mm) 与我的 Swift 代码的其余部分一起使用。它运行良好,但现在我不知道如何将面部地标坐标存储在可以传递给我的 Swift 类之一的数据结构中。
-
@Hardy143 下面的答案对你有用吗?
标签: c++ objective-c nsarray