Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [DllImport(@"stasmstasm_dll.dll", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void AsmSearchDll
- (
- [Out] out Int32 pnlandmarks,
- [Out] out Int32[] landmarks,
- [In, MarshalAs(UnmanagedType.LPStr)] String image_name,
- [In, MarshalAs(UnmanagedType.LPStr)] String image_data,
- [In] Int32 width,
- [In] Int32 height,
- [In] Int32 is_color,
- [In, MarshalAs(UnmanagedType.LPStr)] String conf_file0,
- [In, MarshalAs(UnmanagedType.LPStr)] String conf_file1
- );
- public void SearchFacialFeatures()
- {
- string image_name = "image-5.jpg"; // imagePath;
- var image = new Image<Bgr, byte>(image_name).Convert<Gray, byte>();
- int pnlandmarks = 0;
- var landmarks = new int[500];
- var imageData = Marshal.PtrToStringAnsi(image.MIplImage.imageData);
- int imgWidth = image.Width;
- int imgHeight = image.Height;
- int is_color = 1;
- string confile_file0 = Path.GetFullPath(@"datamu-68-1d.conf");
- string config_file1 = Path.GetFullPath(@"datamu-76-2d.conf");
- string sDataDir = @"stasmdata";
- AsmSearchDll(out pnlandmarks, out landmarks, image_name, imageData, imgWidth, imgHeight, 1, null, null);
- MessageBox.Show(image_name);
- }
- AsmSearchDll(out pnlandmarks, out landmarks, image_name, imageData, imgWidth, imgHeight, 0, null, null);
- 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 if 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
- const char *image_name = "../data/test-image.jpg";
- IplImage *img = cvLoadImage(image_name, CV_LOAD_IMAGE_COLOR);
- if(img == NULL) {
- printf("Error: Cannot open %sn", image_name);
- return -1;
- }
- // sanity checks (AsmSearchDll assumes imageData is vector of b,r,g bytes)
- if(img->nChannels != 3 || img->depth != IPL_DEPTH_8U ||
- img->origin != 0 || img->widthStep != 3 * img->width) {
- printf("Error: %s is an unrecognized image typen", image_name);
- return -1;
- }
- // locate the facial landmarks with stasm
- int nlandmarks;
- int landmarks[500]; // space for x,y coords of up to 250 landmarks
- AsmSearchDll(&nlandmarks, landmarks,
- image_name, img->imageData, img->width, img->height,
- 1 /* is_color */, NULL /* conf_file0 */, NULL /* conf_file1 */);
- [DllImport(@"stasmstasm_dll.dll", CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
- internal static extern void AsmSearchDll
- (
- [Out] out Int32 pnlandmarks,
- [Out] Int32[] landmarks, // <-- the `out` keyword is removed
- [In, MarshalAs(UnmanagedType.LPStr)] String image_name,
- [In] IntPtr image_data, // <-- should not be passed as string
- [In] Int32 width,
- [In] Int32 height,
- [In] Int32 is_color,
- [In, MarshalAs(UnmanagedType.LPStr)] String conf_file0,
- [In, MarshalAs(UnmanagedType.LPStr)] String conf_file1
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement