【问题标题】:STASM-ASM not working in linuxSTASM-ASM 在 linux 中不起作用
【发布时间】:2013-01-30 23:50:47
【问题描述】:

我正在开发一个图像处理项目,我需要在其中定位和标记一些面部属性(即:嘴巴、鼻子、眼睛等)。我正在尝试使用 STASM-ASM 算法 (http://www.milbo.users.sonic.net/stasm/),我已经在之前在 Windows 中完成的项目中使用了这种技术,并获得了非常好的结果。

尝试在 Linux 中使用此实用程序时出现问题,我按照作者提供的说明构建了对象 .o 文件。然后,我按照How to create a static library with g++? 中的说明创建了一个静态库。然后,我将此静态库链接到我的项目并包含以下头文件:

// stasm.h

#ifndef STASM_H_
#define STASM_H_
void AsmSearchDll(int *pnlandmarks, int landmarks[], const char image_name[], const char          image_data[], const int width, const int height, const int is_color, const char con f_file0[], const char conf_file1[]);

#endif 

在尝试构建此项目时,我收到以下错误:

undefined reference to `AsmSearchDll(int*, int*, char const*, char const*, int, int, int, char const*, char const*)'

这对我来说似乎很奇怪,因为我确定头文件已正确包含。我还尝试了作者在包中包含的 .hpp 文件,并获得了相同的确切结果。这个问题类似于Trying to get stasm to work on Ubuntu 中处理的问题。但是,该帖子仍然没有最终解决方案。我希望有人能帮我解决这个问题,STASM-ASM 实用程序真的很棒,可惜它不能在 linux 中使用,因为它提供了。

我认为问题不在于类型不匹配,我在分析了对 ASMSearchDll 函数的调用及其声明后得出了这个结论。函数调用如下:

AsmSearchDll(&nlandmarks, landmarks, image_name, img->imageData, img->width, img->height,1 /* is_color */, NULL /* conf_file0 */, NULL /* conf_file1 */);

函数定义如下:

// stasm_dll.hpp

#ifndef stasm_dll_hpp
#define stasm_dll_hpp

extern "C"
void AsmSearchDll(
int *pnlandmarks,          // out: number of landmarks, 0 if can't get landmarks
int landmarks[],           // out: the landmarks, caller must allocate
const char image_name[],   // in: used in internal error messages, if necessary
const char image_data[],   // in: image data, 3 bytes per pixel if is_color
const int width,           // in: the width of the image
const int height,          // in: the height of the image
const int is_color,        // in: 1 if RGB image, 0 for grayscale
const char conf_file0[],   // in: 1st config filename, NULL for default
const char conf_file1[]);  // in: 2nd config filename, NULL for default, "" if none
#endif // stasm_dll_hpp

此外,如果我更改传递给函数的参数之一的格式,我会收到如下错误:

../src/PruebaStasm.cpp:44:155: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
../src/stasm_dll.hpp:6:6: error:   initializing argument 1 of ‘void AsmSearchDll(int*, int*, const char*, const char*, int, int, int, const char*, const char*)’ [-fpermissive]

我使用提供的 makefile 再次编译了 .o 文件,这些 .o 文件是我按照本教程创建的共享库和动态库:http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

我不明白问题出在哪里。

最好的问候,

路易斯

【问题讨论】:

  • 你有一个数组作为头文件中的第二个参数,并在指针上使用它。还有其他类型不匹配。如果这是 C++,它肯定会因此而抱怨......或者可能是因为函数被定义为 C,并且在包含头文件时被理解为 C++ ?
  • @vonbrand 感谢您的宝贵时间和回答。我认为问题不在于类型不匹配,我将在问题中提供更多详细信息。 :D:D

标签: linux gcc ubuntu opencv


【解决方案1】:

由于 stasm_dll.hpp 中的定义是用 extern "C" 包裹的,我认为当您稍后在程序中包含 stasm.h 时也必须这样做,例如:

extern "C" {
 #include "stasm.h"
}

这应该得到调用约定,正确的 C/C++ 问题

【讨论】:

  • 感谢您的回答,我尝试了您的建议,但问题仍然存在。我将尝试从源代码中包含 STASM-ASM 实用程序,因为在我看来,stasm-asm 已在考虑 Windows 使用的情况下进行编译和构建。这个想法出现在我的脑海中,试图以多种方式包含图书馆,但没有成功。在stackoverflow.com/questions/13735735/… 的问题中,作者得出了类似的结论。
【解决方案2】:

如这里所示:

http://www.milbo.users.sonic.net/stasm/minimal.html

你需要调用:

    SHAPE                               // results returned as a SHAPE
    AsmSearch(
      SHAPE &StartShape,              // out: start shape returned in here
      DET_PARAMS &DetParams,          // out: face detector parameters
      double &MeanTime,               // out: mean time per image (face det failed excluded)
      const RgbImage &RgbImg,         // in: find face features in this image
      const char sImage[],            // in: file path for RgbImg, for err msgs
      const bool fRowley=false,       // in: true to use VJ detector, else Rowley
      const char sConfFile0[]="../data/mu-68-1d.conf", // in: 1st config filename
      const char sConfFile1[]="../data/mu-76-2d.conf", // in: 2nd config filename
      const char sDataDir[]="../data",// in: data directory
      const char sShapeFile[]=NULL,   // in: if not NULL then use face detector in here
      bool fIssueWarnings=true);      // in: true to issue warnings if needed

我不确定你是否可以在 Linux 下调用 AsmSearchDll。

【讨论】:

    【解决方案3】:

    正如所评论的,ASMSearchDLL 函数被认为只能在 Windows 中使用,因此不能在 linux 中轻松使用。

    最后,我设法在 linux 中使用了 AsmSearch 功能,并做了一些小的改动。为了使用这个功能,我构建了一个静态库,其中包含从 stasm-asm 包中包含的源文件获得的 .o 文件。

    更准确地说,我在 makefile 文件中添加了以下内容:

    LIB_OBJ=\
           stasmlibrary.o\
           $(STASM_OBJ)
    
    lib: $(LIB_OBJ)
           ar rs libstasm.a $(LIB_OBJ)
    

    其中 stasmlibrary.cpp 和 stasmlibrary.hpp 包含我在包中提供的 AsmSearch 中定义的函数。 STASM_OBJ 变量包括以下目标文件:

    stasm.o\
    atface.o\
    ezfont.o\
    find.o\
    follow.o\
    forward.o\
    imfile.o\
    imwrite.o\
    imgiven.o\
    imshape.o\
    imutil.o\
    initnet.o\
    jpegutil.o\
    landmarks.o\
    mat.o\
    matvec.o\
    mchol.o\
    mrand.o\
    prof.o\
    readconf.o\
    rgbimutil.o\
    rowley.o\
    rowleyhand.o\
    search.o\
    shapefile.o\
    shapemodel.o\
    sparsemat.o\
    startshape.o\
    safe_alloc.o\
    tclHash.o\
    util.o\
    violajones.o\
    vjhand.o\
    wrbmp.o\
    asmsearch.o\
    initasm.o\
    readasm.o\
    err.o\
    release.o\
    tab.o
    

    感谢所有回答此问题的人的宝贵时间和善意的建议。

    【讨论】:

      猜你喜欢
      • 2011-10-06
      • 2012-01-26
      • 2011-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多