C# Samples?

C# Samples?

Are there any more c# samples online?

or perhaps videos?

14 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Intel have provide couple of C# samples with sdk which you can find in frameworks folder. I am C# developer as well, as per my knowledge there is not external videos or samples available. But the provided samples are well enough to get you going.

No there aren't any samples for C # ,the samples are there only in the SDK Samples folder.You can also check for Framework samples PDF where you can just check the last pages of samples PDf.You will get all the details how to utilize the pipeline as well as how easy it is to convert C++ examples to C#.

C# with Excel

I highly recommend this library for creating Excel files.


There are C# samples adn so long as you run them in Admin mode with the camera attached they work fine, the source is also available in the SDK folder under "framework\csharp" folder in the install dir (shortcut should be on your desktop)

There are some C# code snippets in the documentation but this is where I have to disagree with Shyam as they are appauling.

The demos are all WinForms projects based and unpinning the workings into a non WinForms project is a nightmare.  The documentation snippets on the whole dont work.

Still getting through it myself and when I have it working I will share a blog post on getting it working.

In support of what Simon J said, here's an example taken from the reference manual sdkmanuals.pdf:

        //Original code copied from PDF manual sdkmanuals.pdf for SDK R3 (same as R2 from what I can tell)
        PXCMFaceAnalysis.Recognition.Model createModelFromImage(PXCMImage image)
            PXCMImage[] images = new PXCMImages[]{
            PXCMScheduler.SyncPoint sp;
            face.ProcessImageAsync(images, out sp);
            int fid;
            face.QueryFace(0, out fid);
            PXCMFaceAnalysis.Recognition rec = face.DynamicCast<PXCMFaceAnalysis.Recognition>(PXCFaceAnalysis::Recognition.CUID);
            PXCMFaceAnalysis.Recognition.Model m1;
            rec.CreateModel(fid, out m1);
            return m1;
        bool IsSimilar(PXCMImage image1, PXCMImage image2) {    
            PXCMFaceAnalysis.Recognition.Model[] ref=new PXCMFaceAnalysis.Recognition.Model[]{                         
            PXCMFaceAnalysis.Recognition.Model cur=createModelFromImage(image2);
            uint index;    
            return cur.Compare(ref,null,out index) >=pxcmStatus.PXCM_STATUS_NO_ERROR; 


        //Altered code - still working on getting this to actually work though, but at least it doesn't throw errors immediately
        PXCMFaceAnalysis.Recognition.Model createModelFromImage(PXCMImage image)
            PXCMImage[] images = new PXCMImage[] { image, null, null, null };
            PXCMScheduler.SyncPoint sp;
            face.ProcessImageAsync(images, out sp);
            sp.Synchronize(); sp.Dispose();
            int fid;
            ulong ul;
            face.QueryFace(0, out fid, out ul);
            PXCMFaceAnalysis.Recognition rec = face.DynamicCast<PXCMFaceAnalysis.Recognition>(PXCMFaceAnalysis.Recognition.CUID);
            PXCMFaceAnalysis.Recognition.Model m1;
            rec.CreateModel(fid, out m1); return m1;
        bool IsSimilar(PXCMImage image1, PXCMImage image2)
            PXCMFaceAnalysis.Recognition.Model[] refs = new PXCMFaceAnalysis.Recognition.Model[]{                         
            PXCMFaceAnalysis.Recognition.Model cur = createModelFromImage(image2);
            uint index;
            return cur.Compare(refs, null, out index) >= pxcmStatus.PXCM_STATUS_NO_ERROR;

There is NO way that this C# code was actually tested before it was pasted into the manual, which is not something that I expected from Intel. It also shows that the support for C# was probably just some window-dressing in order to say that C# is supported, since there is ample evidence that this was simply pasted from C++. From what I can tell, their Java support is just as bad, if that.

I expect Intel to deliver high-quality, well-tested, stable code examples & well-documented real-word examples, not this type of thing.

Right to help out, I've created a C# sample project implementation which also uses MonoGame.


hope this helps.

Should provide some support to others trying to use C#, will continue to update and add to the sample as I'm creating my own project.

Anyone else is free to use or even Fork the git repo to contribute.

Great work! Thanks for sharing.

Thanks simsam7

Will see if I can get time to add the face tracking code although need to focus on my entry really.

c# code snippets http://csharp.net-informations.com c# samples


Here's some sample code of tested C# code to convert a PXCMImage to Bitmap/JPEG and back again:

        private Bitmap PXCMImageToBitmap(PXCMImage image)
            Bitmap bitmap = null;
            PXCMImage.ImageData data;
            if (image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.ColorFormat.COLOR_FORMAT_RGB32, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                PXCMImage.ImageInfo imageInfo = image.imageInfo;
                bitmap = data.ToBitmap(imageInfo.width, imageInfo.height);
                image.ReleaseAccess(ref data);
            return bitmap;

        private PXCMImage BitmapToPXCMImage(Bitmap bitmap)
            ///* Read bitmap into the memory if we're getting it from a file */
            //Bitmap bitmap = (Bitmap)Image.FromFile(file);

            /* Get a system memory allocator */
            PXCMAccelerator accel;

            PXCMSession qsession;
            PXCMSession.CreateInstance(out qsession);
            qsession.CreateAccelerator(out accel);

            PXCMImage.ImageInfo iinfo = new PXCMImage.ImageInfo();
            iinfo.width = (uint)bitmap.Width;
            iinfo.height = (uint)bitmap.Height;
            iinfo.format = PXCMImage.ColorFormat.COLOR_FORMAT_RGB32;

            /* Create the image */
            PXCMImage image;
            accel.CreateImage(ref iinfo, out image);

            /* Copy the data */
            PXCMImage.ImageData idata;
            image.AcquireAccess(PXCMImage.Access.ACCESS_WRITE, out idata);

            BitmapData bdata = new BitmapData();
            bdata.Scan0 = idata.buffer.planes[0];
            bdata.Stride = idata.buffer.pitches[0];
            bdata.PixelFormat = PixelFormat.Format32bppRgb;
            bdata.Width = bitmap.Width;
            bdata.Height = bitmap.Height;
            BitmapData bdata2 = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                      ImageLockMode.ReadOnly | ImageLockMode.UserInputBuffer,
                      PixelFormat.Format32bppRgb, bdata);

            image.ReleaseAccess(ref idata);

            // do something with the image
            return image;


        public void SavePicture(Bitmap bitmap, String filename)

            // Get an ImageCodecInfo object that represents the JPEG codec.
            picImageCodecInfo = GetEncoderInfo("image/jpeg");

            // for the Quality parameter category.
            picEncoder = System.Drawing.Imaging.Encoder.Quality;

            // Create an EncoderParameters object.
            // An EncoderParameters object has an array of EncoderParameter
            // objects. In this case, there is only one
            // EncoderParameter object in the array.
            picEncoderParameters = new EncoderParameters(1);

            // Save the bitmap as a JPEG file with quality level 85.
            picEncoderParameter = new EncoderParameter(picEncoder, 85L);
            picEncoderParameters.Param[0] = picEncoderParameter;
            bitmap.Save(filename, picImageCodecInfo, picEncoderParameters);

            PXCMImage pimage = BitmapToPXCMImage(bitmap);
            //Switch back just as a test
            pimage = BitmapToPXCMImage(bitmap);

        private static ImageCodecInfo GetEncoderInfo(String mimeType)
            int j;
            ImageCodecInfo[] encoders;
            encoders = ImageCodecInfo.GetImageEncoders();
            for (j = 0; j < encoders.Length; ++j)
                if (encoders[j].MimeType == mimeType)
                    return encoders[j];
            return null;

        public void DisplayBitmap(Bitmap picture)
            lock (this)
                bitmap = new Bitmap(picture);
                if ((saving == true) && (tbSave.Text.Length>0))
                    SavePicture(bitmap, tbSave.Text.Replace(".jpg", "") + ".jpg");
                    saving = false;

The code has been constructed based on information provided on this forum, as well as the SDK manuals, but I found that running some of the samples code pieces I got on the forum even did not always run without error. Not sure if that might have been due to changes in the SDK or something, but as far as I can tell, what I have here works, without throwing errors when exiting the application or other runtime errors.

If you use this code and you find errors, please let me know. Let's help each other make the code bulletproof, these are basic functions that should 'just work'.

Hope it helps someone, I'll add more code as I find time. :-)

Nice link for concise C# snippets, thanks Norman.

I've added simsam7's PXCMIMage helper functions to the C# samples lib I posted about earlier so we have all such code in one place.

Hope this helps

This is the link to the Github page that Simon is referring to: https://github.com/DDReaper/MonoGame-IntelSDK

If we can get more people to pitch in, we can all make faster progress.

Leave a Comment

Please sign in to add a comment. Not a member? Join today