Example #1
0
        /// <summary>
        /// Private Constructor
        /// </summary>
        Camera()
        {
            try
            {
                // pre-allocate and initialize the variables and data structures for brightness correction
                imgGPU           = worker.Malloc <byte>(new byte[640 * 640]);
                meanImg          = worker.Malloc <float>(new float[640 * 640]);
                addReduce        = DeviceSumModuleF32.Default.Create(numPixels);
                correctionFactor = worker.Malloc <float>(640 * 640);
                float[] temp = new float[640 * 640];
                for (int i = 0; i < temp.Length; i++)
                {
                    temp[i] = 1;
                }
                correctionFactor.Scatter(temp);
                scalarOutput = worker.Malloc <float>(1);

                if (File.Exists("correctionFactor.dat"))
                {
                    FileStream stream = new FileStream("correctionFactor.dat", FileMode.Open);
                    byte[]     buffer = new byte[640 * 640 * 4];
                    stream.Read(buffer, 0, (int)Math.Min(buffer.Length, stream.Length));
                    for (int i = 0; i < 640 * 640; i++)
                    {
                        temp[i] = BitConverter.ToSingle(buffer, 4 * i);
                    }
                    stream.Close();

                    correctionFactor.Scatter(temp);
                }

                // initialize CUDA parameters
                var blockDims = new dim3(32, 32);
                var gridDims  = new dim3(Common.divup(640, blockDims.x), Common.divup(640, blockDims.y));
                lp = new LaunchParam(gridDims, blockDims);

                // set up the camera parameters and events
                provider = new IduleProviderCsCam(0);
                provider.Initialize();
                if (provider.IsConnected)
                {
                    provider.ImageTransaction += provider_ImageTransaction;
                    provider.Interrupt        += provider_Interrupt;
                    provider.Exception        += camera_Exception;
                    provider.WriteRegister(new NanEyeGSRegisterPayload(false, 0x05, true, 0, prescaler));
                    provider.WriteRegister(new NanEyeGSRegisterPayload(false, 0x06, true, 0, exposure));
                    ProcessingWrapper.pr[0].ReduceProcessing = true;
                }
            }
            catch (Exception ex) { OnError(ex.Message); }
        }
Example #2
0
 /// <summary>
 /// Private Constructor
 /// </summary>
 Camera()
 {
     try
     {
         provider = new IduleProviderCsCam(0);
         provider.Initialize();
         if (provider.IsConnected)
         {
             provider.ImageProcessed += provider_ImageProcessed;
             provider.Interrupt      += provider_Interrupt;
             provider.Exception      += camera_Exception;
             provider.WriteRegister(new NanEyeGSRegisterPayload(false, 0x05, true, 0, prescaler));
             provider.WriteRegister(new NanEyeGSRegisterPayload(false, 0x06, true, 0, exposure));
             //ProcessingWrapper.pr[0].ReduceProcessing = true;
         }
     }
     catch (Exception ex) { OnError(ex.Message); }
 }
Example #3
0
        public void Reconnect()
        {
            Disconnect();
            Thread.Sleep(100);

            provider = new IduleProviderCsCam(0);
            provider.Initialize();
            if (provider.IsConnected)
            {
                provider.ImageTransaction += provider_ImageTransaction;
                provider.Interrupt        += provider_Interrupt;
                provider.Exception        += camera_Exception;
                provider.WriteRegister(new NanEyeGSRegisterPayload(false, 0x05, true, 0, prescaler));
                provider.WriteRegister(new NanEyeGSRegisterPayload(false, 0x06, true, 0, exposure));
                ProcessingWrapper.pr[0].ReduceProcessing = true;
            }

            Connect();
        }