0

I'm working on a image processing proyect where I need to locate and label some face attributes (ie.: mouth, nose, eyes, etc.). I'm trying to use the STASM-ASM algorithm (http://www.milbo.users.sonic.net/stasm/), I already used this technique in a previous proyect done in Windows where I obtained very good results.

The problem arrives when trying to use this utility in Linux, I builded the object .o files following the instructions provided from the author. Then, I created a static library following the instructions in How to create a static library with g++?. Then, I linked this static library to my proyect and included the following header file:

// 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 

When trying to build this proyect I get te following error:

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

This seems very strange to me as I'm sure the header file is correctly included. I also tried with the .hpp file included by the author on the package and obtained the same exact results. This problem is similar to the one treated in Trying to get stasm to work on Ubuntu . But, that post remains without a final solution. I hope someone could help me to work this out, the STASM-ASM utility is really great and it is pity it can't be used in linux as it is provided.

I think the problem is not of types mismatch, I concluded this after analyzing the call to the ASMSearchDll function and its declaration. The function is called as follows:

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

And the function definition is the following:

// 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

Additionally, if I change the format of one of the parameters passed to the function I get errors like the following:

../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]

I compiled again the .o files using the provided makefile, with these .o files I created shared and dynamic libraries following this tutorial: http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

I don't understand where the problem is.

Best Regards,

Luis

Community
  • 1
  • 1
LDDM
  • 23
  • 6
  • You have an array as the second argument in the header file, and using it on a pointer. And there are other type mismatches. If this is C++, it could certainly be complaining because of that... Or possibly because of the function being defined as _C_, and being understood as _C++_ when including the header? – vonbrand Feb 15 '13 at 02:08
  • @vonbrand Thank you for your time and answer. I think the problem is not of type mismatches, I will provide further details in the question. :D:D – LDDM Feb 19 '13 at 14:21

3 Answers3

0

Since the definition in stasm_dll.hpp is wrapped with extern "C", I think you have to do the same when you're including stasm.h later in your program, like:

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

this should get the calling conventions , C/C++ issues right

favoretti
  • 29,299
  • 4
  • 48
  • 61
berak
  • 39,159
  • 9
  • 91
  • 89
  • Thanks for your answer, I tried what you suggested but the problem persists. I will try to include the STASM-ASM utility from the source code, as it seems to me that the stasm-asm has been compiled and builded with Windows use in mind. This idea come to my mind as tried to include the library in many ways but did not succeed. In the question in http://stackoverflow.com/questions/13735735/trying-to-get-stasm-to-work-on-ubuntu the author arrives to a similar conclusion. – LDDM Feb 20 '13 at 00:48
0

As it is indicated here:

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

you need to invoke:

    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

I'm not sure whether you can call AsmSearchDll under Linux.

snedkov
  • 309
  • 2
  • 6
0

As commented, the function ASMSearchDLL has been thought for using in windows only and therefore can not be used with ease in linux.

Finally, I managed to use the function AsmSearch in linux with some minor changes. In order to use this function I builded a static library containing the .o files obtained from the source files included in th stasm-asm package.

More precisely, I added the following to the makefile file:

LIB_OBJ=\
       stasmlibrary.o\
       $(STASM_OBJ)

lib: $(LIB_OBJ)
       ar rs libstasm.a $(LIB_OBJ)

Where stasmlibrary.cpp and stasmlibrary.hpp contains the function I defined based in the AsmSearch provided in the package. The STASM_OBJ variable includes the following object files:

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

Thanks to all who answered this questions for their time and kind suggestions.

LDDM
  • 23
  • 6