After the camera takes the image, it converts the data into the corresponding image processing library image file.

After the camera takes the image, it converts the data into the corresponding image processing library image file.


Preface

The data contained in the image data packets after different cameras take images is not necessarily the same, and the image data after the camera takes pictures cannot be used directly by third-party visual libraries (Halcon, visionpro, etc.) (unless the vision library is used The built-in image capture tool instead of the camera's own SDK). Therefore, generally after the camera takes the image, it needs to be converted to the image type supported by the target vision library. The following content will be updated one after another (it will be updated here when used).


feed

General2D cameraThe key data in it are: data set (byte[]) or (Intptr), width of the image, height of the image

1. Dahua camera

First, the image data passed through the callback in Dahua's SDK is as follows;

    public interface IGrabbedRawData
    {
    
    
        byte[] Image {
    
     get; }     	//关键数据
        IntPtr Raw {
    
     get; }
        int ImageSize {
    
     get; }
        int Width {
    
     get; }			//关键数据
        int Height {
    
     get; }			//关键数据
        long BlockID {
    
     get; }
        long TimeStamp {
    
     get; }
        uint ImagePaddingX {
    
     get; }
        uint ImagePaddingY {
    
     get; }
        GvspPixelFormatType PixelFmt {
    
     get; }
        IChunkData ChunkData {
    
     get; }

        IGrabbedRawData Clone();
        void Show(IntPtr pWnd);
        void Show(IntPtr pWnd, float angle);
        Bitmap ToBitmap(bool color);
    }

1.to HImage

code show as below:

    public enum PixelFormatType
    {
    
    
        Mono8,
    }

    public class ImageData
    {
    
    
        public int Width {
    
     get; set; }
        public int Height {
    
     get; set; }

        public byte[] Raw {
    
     get; set; }
        public PixelFormatType PixelFmt {
    
     get; set; }

        public long TimeStamp {
    
     get; set; }

        public HImage ToHImage() 
        {
    
    
            HImage hImage = new HImage();
            switch (PixelFmt)
            {
    
    
                case PixelFormatType.Mono8:		//gray图像,彩色的大华相机还没用过
                    unsafe
                    {
    
    
                        void* p;
                        IntPtr ptr;
                        fixed (byte* pc = Raw)
                        {
    
    
                            p = (void*)pc;
                            ptr = new IntPtr(p);
                        }
                        hImage.GenImage1("byte", Width, Height, ptr);
                    }
                    break;
                default:
                    throw new Exception("图像格式未收录");
                    break;
            }
            return hImage;
        }


Summarize

Follow project updates.

Guess you like

Origin blog.csdn.net/qq_42504097/article/details/132064950