示例#1
0
        public static ImageRgb toImgRgb(this Bitmap bmp)
        {
            ImageRgb img = new ImageRgb();

            img.resize(bmp.Width, bmp.Height);
            try
            {
                unsafe
                {
                    BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, img.width(), img.height()),
                                                      System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                                      System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                    byte[] rawData = new byte[bmpData.Stride * bmpData.Height];
                    Marshal.Copy(bmpData.Scan0, rawData, 0, rawData.Length);

                    Marshal.Copy(rawData, 0, img.getRawImage(), rawData.Length);


                    bmp.UnlockBits(bmpData);
                }
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("Exception while accessing image: " + e);
            }

            return(img);
        }
示例#2
0
        public static Bitmap toBmp(this ImageRgb img)
        {
            int    w   = img.width();
            int    h   = img.height();
            Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            try
            {
                unsafe
                {
                    BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, w, h),
                                                      System.Drawing.Imaging.ImageLockMode.WriteOnly,
                                                      System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                    byte[] rawData = new byte[bmpData.Stride * bmpData.Height];
                    Marshal.Copy(img.getRawImage(), rawData, 0, rawData.Length);

                    Marshal.Copy(rawData, 0, bmpData.Scan0, rawData.Length);

                    bmp.UnlockBits(bmpData);
                }
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("Exception while accessing image: " + e);
            }

            return(bmp);
        }
        /// <summary>
        /// Write the predicted value on the yarp port.
        /// </summary>
        public override void WritePredictedValue()
        {
            ImageRgb img = portPredicted.prepare();

            Vector2Image(PredictedValue, ref img);
            portPredicted.write();
        }
示例#4
0
    public new ImageRgb read(bool shouldWait)
    {
        global::System.IntPtr cPtr = yarpPINVOKE.TypedReaderImageRgb_read__SWIG_0(swigCPtr, shouldWait);
        ImageRgb ret = (cPtr == global::System.IntPtr.Zero) ? null : new ImageRgb(cPtr, false);

        return(ret);
    }
        public override System.Drawing.Bitmap GetAsBmp(float[] rawValues)
        {
            ImageRgb img = new ImageRgb();

            Vector2Image(rawValues, ref img);
            return(img.toBmp());
        }
        /// <summary>
        /// Self explicit
        /// </summary>
        /// <param name="img"></param>
        /// <returns></returns>
        protected float[] Image2Vector(ImageRgb img)
        {
            double t0 = Time.now();

            ImageRgb img2 = new ImageRgb();

            img2.copy(img, w, h);

            float[] v = new float[size];

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    PixelRgb px = img2.pixel(i, j);
                    v[j * w + i]     = px.r / 255.0f; //Scale in [0,1]
                    v[j * w + i + 1] = px.g / 255.0f; //Scale in [0,1]
                    v[j * w + i + 2] = px.b / 255.0f; //Scale in [0,1]
                }
            }
            double t1 = Time.now();

            //Console.WriteLine("Image2Vector : " + (t1 - t0).ToString());

            return(v);
        }
示例#7
0
    public ImageRgb asImageOfPixelRgb()
    {
        global::System.IntPtr cPtr = yarpPINVOKE.Things_asImageOfPixelRgb(swigCPtr);
        ImageRgb ret = (cPtr == global::System.IntPtr.Zero) ? null : new ImageRgb(cPtr, false);

        return(ret);
    }
示例#8
0
    public new ImageRgb lastRead()
    {
        global::System.IntPtr cPtr = yarpPINVOKE.TypedReaderImageRgb_lastRead(swigCPtr);
        ImageRgb ret = (cPtr == global::System.IntPtr.Zero) ? null : new ImageRgb(cPtr, false);

        return(ret);
    }
    public new ImageRgb read()
    {
        global::System.IntPtr cPtr = yarpPINVOKE.BufferedPortImageRgb_read__SWIG_1(swigCPtr);
        ImageRgb ret = (cPtr == global::System.IntPtr.Zero) ? null : new ImageRgb(cPtr, false);

        return(ret);
    }
 public new void onRead(ImageRgb datum, TypedReaderImageRgb reader)
 {
     yarpPINVOKE.TypedReaderCallbackImageRgb_onRead__SWIG_1(swigCPtr, ImageRgb.getCPtr(datum), TypedReaderImageRgb.getCPtr(reader));
     if (yarpPINVOKE.SWIGPendingException.Pending)
     {
         throw yarpPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#11
0
 public new void onRead(ImageRgb datum)
 {
     yarpPINVOKE.BufferedPortImageRgb_onRead__SWIG_1(swigCPtr, ImageRgb.getCPtr(datum));
     if (yarpPINVOKE.SWIGPendingException.Pending)
     {
         throw yarpPINVOKE.SWIGPendingException.Retrieve();
     }
 }
        void timer_Tick(object sender, EventArgs e)
        {
            ImageRgb img = activity.read(false);

            if (img != null)
            {
                m_activity.Image = ImageManipulation.toBmp(img);
            }
        }
        /// <summary>
        /// Read the real value on the yarp port.
        /// Convert the image into a vector.
        /// </summary>
        public override void ReadRealValue()
        {
            ImageRgb img = portReal.read(isBlockingRead);

            if (img != null)
            {
                RealValue = Image2Vector(img);
            }
        }
示例#14
0
    public new static bool read(ImageRgb dest, string src, image_fileformat format)
    {
        bool ret = yarpPINVOKE.read__SWIG_0(ImageRgb.getCPtr(dest), src, (int)format);

        if (yarpPINVOKE.SWIGPendingException.Pending)
        {
            throw yarpPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    public virtual bool putAudioVisual(ImageRgb image, Sound sound)
    {
        bool ret = yarpPINVOKE.IFrameWriterAudioVisual_putAudioVisual(swigCPtr, ImageRgb.getCPtr(image), Sound.getCPtr(sound));

        if (yarpPINVOKE.SWIGPendingException.Pending)
        {
            throw yarpPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
示例#16
0
    public new bool write(ImageRgb data)
    {
        bool ret = yarpPINVOKE.Port_write__SWIG_6(swigCPtr, ImageRgb.getCPtr(data));

        if (yarpPINVOKE.SWIGPendingException.Pending)
        {
            throw yarpPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
示例#17
0
    public new static bool read(ImageRgb dest, string src)
    {
        bool ret = yarpPINVOKE.read__SWIG_1(ImageRgb.getCPtr(dest), src);

        if (yarpPINVOKE.SWIGPendingException.Pending)
        {
            throw yarpPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
示例#18
0
    public virtual bool putImage(ImageRgb image)
    {
        bool ret = yarpPINVOKE.IFrameWriterImage_putImage(swigCPtr, ImageRgb.getCPtr(image));

        if (yarpPINVOKE.SWIGPendingException.Pending)
        {
            throw yarpPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
示例#19
0
    public new static bool write(ImageRgb src, string dest)
    {
        bool ret = yarpPINVOKE.write__SWIG_1(ImageRgb.getCPtr(src), dest);

        if (yarpPINVOKE.SWIGPendingException.Pending)
        {
            throw yarpPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
    protected override void ThreadFunction()
    {
        inputImage = imagePort.read();
        if(inputImage != null)
        {
            convertToTexture2D();

            imageReceived = true;
        }
    }
示例#21
0
 void timer_Tick(object sender, EventArgs e)
 {
     for (int i = 0; i < r_l; i++)
     {
         ImageRgb img = layersActivity[i].read(false);
         if (img != null)
         {
             m_layers[i].Image = ImageManipulation.toBmp(img);
         }
     }
 }
示例#22
0
        public override bool updateModule()
        {
            bool error = base.updateModule();
            //Broadcast the activity
            CVZ_TPC ctpc = cvz as CVZ_TPC;

            if (broadcastDisplay)
            {
                ImageRgb img = activity.prepare();
                img = ctpc.GetFrequencyVisualization().toImgRgb();
                activity.write();
            }
            return(error);
        }
示例#23
0
        public override bool updateModule()
        {
            bool error = base.updateModule();

            //Broadcast the activity
            CVZ_MMCM mmcm = cvz as CVZ_MMCM;

            for (int i = 0; i < mmcm.Layers; i++)
            {
                ImageRgb img = layersActivity[i].prepare();
                img = mmcm.GetVisualization(i).toImgRgb();
                layersActivity[i].write();
            }

            return(error);
        }
        /// <summary>
        /// Self explicit
        /// </summary>
        /// <param name="v"></param>
        /// <param name="img"></param>
        protected void Vector2Image(float[] v, ref ImageRgb img)
        {
            double t0 = Time.now();

            img.resize(w, h);
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    img.pixel(i, j).r = (byte)(v[j * w + i] * 255);
                    img.pixel(i, j).g = (byte)(v[j * w + i + 1] * 255);
                    img.pixel(i, j).b = (byte)(v[j * w + i + 2] * 255);
                }
            }
            double t1 = Time.now();

            //Console.WriteLine("Vector2img : " + (t1 - t0).ToString());
        }
 public new void onRead(ImageRgb datum, TypedReaderImageRgb reader)
 {
     yarpPINVOKE.TypedReaderCallbackImageRgb_onRead__SWIG_1(swigCPtr, ImageRgb.getCPtr(datum), TypedReaderImageRgb.getCPtr(reader));
     if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve();
 }
    // Use this for initialization
    void Start()
    {
        Debug.Log ("Initialising Network ... ");
        Network.init();
        Debug.Log ("Initialising Port");
        imagePort = new BufferedPortImageRgb();
        Debug.Log ("Open Port");
        imagePort.open (sourcePortName);

        Debug.Log ("Connect Port");
        Network.connect(sourcePortName, destPortName);

        //RenderTexture.active = view;
        resWidth = view.width;
        resHeight = view.height;
        temp2D = new Texture2D(resWidth,resHeight, TextureFormat.ARGB32, false);

        texImage = imagePort.prepare();

        //set resolution and parameters of image
        texImage.resize(resWidth, resHeight);
        texImage.setTopIsLowIndex(false);
        texImage.setQuantum(1);
        texImage.zero();

        System.IntPtr imagePtr = texImage.getRawImage();
        int imageSize = texImage.getRawImageSize();
        byteArray = new byte[imageSize];

        newPtr = Marshal.AllocHGlobal(byteArray.Length);
    }
示例#27
0
 public virtual bool getAudioVisual(ImageRgb image, Sound sound)
 {
     bool ret = yarpPINVOKE.IAudioVisualGrabber_getAudioVisual(swigCPtr, ImageRgb.getCPtr(image), Sound.getCPtr(sound));
     if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
示例#28
0
    public virtual bool getImageCrop(cropType_id_t cropType, SWIGTYPE_p_yarp__sig__VectorOfT_std__pairT_int_int_t_t vertices, ImageRgb image)
    {
        bool ret = yarpPINVOKE.IFrameGrabberImage_getImageCrop(swigCPtr, (int)cropType, SWIGTYPE_p_yarp__sig__VectorOfT_std__pairT_int_int_t_t.getCPtr(vertices), ImageRgb.getCPtr(image));

        if (yarpPINVOKE.SWIGPendingException.Pending)
        {
            throw yarpPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
示例#29
0
 public virtual bool putImage(ImageRgb image)
 {
     bool ret = yarpPINVOKE.IFrameWriterImage_putImage(swigCPtr, ImageRgb.getCPtr(image));
     if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
示例#30
0
    public ImageRgb prepare()
    {
        ImageRgb ret = new ImageRgb(yarpPINVOKE.BufferedPortImageRgb_prepare(swigCPtr), false);

        return(ret);
    }
示例#31
0
 public new bool write(ImageRgb data)
 {
     bool ret = yarpPINVOKE.Port_write__SWIG_6(swigCPtr, ImageRgb.getCPtr(data));
     if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
 public new void onRead(ImageRgb datum)
 {
     yarpPINVOKE.BufferedPortImageRgb_onRead__SWIG_1(swigCPtr, ImageRgb.getCPtr(datum));
     if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve();
 }
 public ImageRgb prepare()
 {
     ImageRgb ret = new ImageRgb(yarpPINVOKE.BufferedPortImageRgb_prepare(swigCPtr), false);
     return ret;
 }
示例#34
0
 internal static HandleRef getCPtr(ImageRgb obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
示例#35
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageRgb obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
    void Update()
    {
        //prepare port
        texImage = imagePort.prepare();

        //set resolution and parameters of image
        //texImage.resize(resWidth, resHeight);
        //texImage.setTopIsLowIndex(false);
        //texImage.setQuantum(1);

        //texImage.zero(); //test
    }
示例#37
0
文件: yarp.cs 项目: johnty/YarpUnity
 public static new bool read(ImageRgb dest, string src)
 {
     bool ret = yarpPINVOKE.read__SWIG_0(ImageRgb.getCPtr(dest), src);
     if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
示例#38
0
文件: yarp.cs 项目: johnty/YarpUnity
 public static new bool write(ImageRgb src, string dest)
 {
     bool ret = yarpPINVOKE.write__SWIG_0(ImageRgb.getCPtr(src), dest);
     if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }