Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. [DllImport(@"stasmstasm_dll.dll", CallingConvention = CallingConvention.Cdecl)]
  2. internal static extern void AsmSearchDll
  3. (
  4. [Out] out Int32 pnlandmarks,
  5. [Out] out Int32[] landmarks,
  6. [In, MarshalAs(UnmanagedType.LPStr)] String image_name,
  7. [In, MarshalAs(UnmanagedType.LPStr)] String image_data,
  8. [In] Int32 width,
  9. [In] Int32 height,
  10. [In] Int32 is_color,
  11. [In, MarshalAs(UnmanagedType.LPStr)] String conf_file0,
  12. [In, MarshalAs(UnmanagedType.LPStr)] String conf_file1
  13. );
  14.  
  15. public void SearchFacialFeatures()
  16. {
  17. string image_name = "image-5.jpg"; // imagePath;
  18. var image = new Image<Bgr, byte>(image_name).Convert<Gray, byte>();
  19.  
  20. int pnlandmarks = 0;
  21. var landmarks = new int[500];
  22.  
  23. var imageData = Marshal.PtrToStringAnsi(image.MIplImage.imageData);
  24. int imgWidth = image.Width;
  25. int imgHeight = image.Height;
  26. int is_color = 1;
  27. string confile_file0 = Path.GetFullPath(@"datamu-68-1d.conf");
  28. string config_file1 = Path.GetFullPath(@"datamu-76-2d.conf");
  29. string sDataDir = @"stasmdata";
  30.  
  31.  
  32. AsmSearchDll(out pnlandmarks, out landmarks, image_name, imageData, imgWidth, imgHeight, 1, null, null);
  33.  
  34. MessageBox.Show(image_name);
  35. }
  36.  
  37. AsmSearchDll(out pnlandmarks, out landmarks, image_name, imageData, imgWidth, imgHeight, 0, null, null);
  38.  
  39. void AsmSearchDll (
  40. int *pnlandmarks, // out: number of landmarks, 0 if can't get landmarks
  41. int landmarks[], // out: the landmarks, caller must allocate
  42. const char image_name[], // in: used in internal error messages, if necessary
  43. const char image_data[], // in: image data, 3 bytes per pixel if is_color
  44. const int width, // in: the width of the image
  45. const int height, // in: the height of the image
  46. const int is_color, // in: 1 if RGB image, 0 if grayscale
  47. const char conf_file0[], // in: 1st config filename, NULL for default
  48. const char conf_file1[]) // in: 2nd config filename, NULL for default, "" if none
  49.  
  50. const char *image_name = "../data/test-image.jpg";
  51.  
  52. IplImage *img = cvLoadImage(image_name, CV_LOAD_IMAGE_COLOR);
  53. if(img == NULL) {
  54. printf("Error: Cannot open %sn", image_name);
  55. return -1;
  56. }
  57. // sanity checks (AsmSearchDll assumes imageData is vector of b,r,g bytes)
  58.  
  59. if(img->nChannels != 3 || img->depth != IPL_DEPTH_8U ||
  60. img->origin != 0 || img->widthStep != 3 * img->width) {
  61. printf("Error: %s is an unrecognized image typen", image_name);
  62. return -1;
  63. }
  64.  
  65. // locate the facial landmarks with stasm
  66.  
  67. int nlandmarks;
  68. int landmarks[500]; // space for x,y coords of up to 250 landmarks
  69. AsmSearchDll(&nlandmarks, landmarks,
  70. image_name, img->imageData, img->width, img->height,
  71. 1 /* is_color */, NULL /* conf_file0 */, NULL /* conf_file1 */);
  72.  
  73. [DllImport(@"stasmstasm_dll.dll", CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
  74. internal static extern void AsmSearchDll
  75. (
  76. [Out] out Int32 pnlandmarks,
  77. [Out] Int32[] landmarks, // <-- the `out` keyword is removed
  78. [In, MarshalAs(UnmanagedType.LPStr)] String image_name,
  79. [In] IntPtr image_data, // <-- should not be passed as string
  80. [In] Int32 width,
  81. [In] Int32 height,
  82. [In] Int32 is_color,
  83. [In, MarshalAs(UnmanagedType.LPStr)] String conf_file0,
  84. [In, MarshalAs(UnmanagedType.LPStr)] String conf_file1
  85. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement