コード例 #1
0
        IEnumerator <ITask> UpdateImage(webcam.WebCamOperations webcamPort, ImageProcessingResultForm webcamForm)
        {
            long timestamp = _stopWatch.ElapsedMilliseconds;

            byte[] rgbData = null;
            Size   size    = new Size(0, 0);

            yield return(Arbiter.Choice(webcamPort.QueryFrame(),
                                        success =>
            {
                rgbData = success.Frame;
                size = success.Size;
            },
                                        failure =>
            {
                LogError(failure.ToException());
            }));

            TaskQueue.Enqueue(new Task(() =>
            {
                if (rgbData != null)
                {
                    ComputeGradient(ref rgbData, size);
                    UpdateBitmap(rgbData, size, webcamForm, timestamp);
                }
            }));
        }
コード例 #2
0
        IEnumerator <ITask> UpdateWebcamHelper(webcam.WebCamOperations webcamPort, ImageProcessingResultForm webcamForm,
                                               Port <DateTime> timerPort)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            yield return(new IterativeTask(() => UpdateImage(webcamPort, webcamForm)));

            Activate(Arbiter.Receive(false, timerPort, dateTime => UpdateWebcam(webcamPort,
                                                                                webcamForm, timerPort)));
            TaskQueue.EnqueueTimer(TimeSpan.FromMilliseconds(Math.Max(1, 60 - stopwatch.ElapsedMilliseconds)), timerPort);

            yield break;
        }
コード例 #3
0
ファイル: WebcamAdapter.cs プロジェクト: SamLin95/cs3630
 /// <summary>
 /// See adapter documentation in the Myro 3 developer manual.
 /// http://wiki.roboteducation.org/Myro_3.0_Developer_Manual
 /// </summary>
 public WebcamAdapter(ServiceInfoType serviceInfo)
 {
     ServiceInfo = serviceInfo;
     opPort = DssEnvironment.ServiceForwarder<webcam.WebCamOperations>(new Uri(serviceInfo.Service));
 }
コード例 #4
0
 void UpdateWebcam(webcam.WebCamOperations webcamPort, ImageProcessingResultForm webcamForm,
                   Port <DateTime> timerPort)
 {
     SpawnIterator <webcam.WebCamOperations, ImageProcessingResultForm, Port <DateTime> >(
         webcamPort, webcamForm, timerPort, UpdateWebcamHelper);
 }
コード例 #5
0
        IEnumerator<ITask> OnConnectWebCamHandler(OnConnectWebCam Opt)
        {
            Fault fault = null;
            SubscribeResponseType s;
            String camera = Opt.Service;

            _webCamPort = ServiceForwarder<cam.WebCamOperations>(camera);


            //cam.Subscribe subscribe = new cam.Subscribe();
            //subscribe.NotificationPort = _webCamNotify;


            yield return Arbiter.Choice(
                _webCamPort.Subscribe(_webCamNotify),
                //                subscribe.ResponsePort,
                delegate(SubscribeResponseType success)
                { s = success; },
                delegate(Fault f)
                {
                    fault = f;
                }
            );

            if (fault != null)
            {
                LogError(null, "Failed to subscribe to webcam", fault);
                yield break;
            }
        }       
コード例 #6
0
ファイル: WebcamAdapter.cs プロジェクト: yingted/Myro
 /// <summary>
 /// See adapter documentation in the Myro 3 developer manual.
 /// http://wiki.roboteducation.org/Myro_3.0_Developer_Manual
 /// </summary>
 public WebcamAdapter(ServiceInfoType serviceInfo)
 {
     ServiceInfo = serviceInfo;
     opPort      = DssEnvironment.ServiceForwarder <webcam.WebCamOperations>(new Uri(serviceInfo.Service));
 }
コード例 #7
0
ファイル: Dashboard.cs プロジェクト: romzes2/cslamme
        // TT - New handler for connecting to WebCam
        IEnumerator<ITask> OnConnectWebCamHandler(OnConnectWebCam Opt)
        {
            //ServiceInfoType info = null;
            Fault fault = null;
            SubscribeResponseType s;
            String camera = Opt.Service;

            _webCamPort = ServiceForwarder<cam.WebCamOperations>(camera);

            //cam.Subscribe subscribe = new cam.Subscribe();
            //subscribe.NotificationPort = _webCamNotify;

            //_webCamPort.Post(subscribe);

            yield return Arbiter.Choice(
                _webCamPort.Subscribe(_webCamNotify),
//                subscribe.ResponsePort,
                delegate(SubscribeResponseType success)
                { s = success; },
                delegate(Fault f)
                {
                    fault = f;
                }
            );

            if (fault != null)
            {
                LogError(null, "Failed to subscribe to webcam", fault);
                yield break;
            }

            RunForm runForm = new RunForm(CreateWebCamForm);

            WinFormsServicePort.Post(runForm);

            yield return Arbiter.Choice(
                runForm.pResult,
                delegate(SuccessResult success) { },
                delegate(Exception e)
                {
                    fault = Fault.FromException(e);
                }
            );

            if (fault != null)
            {
                LogError(null, "Failed to Create WebCam window", fault);
                yield break;
            }
            // The following code falls over with a null pointer
            // exception inside MainPortInterleave.CombineWith.
            // Since I don't know why, I have added the message
            // to the interleave that is created at startup.
            // This is a bit tacky, but does not seem to do any harm.
            /*
            Interleave x = Arbiter.Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup(
                        Arbiter.ReceiveWithIterator<cam.UpdateFrame>(true, _webCamNotify, CameraUpdateFrameHandler)
                    ),
                    new ConcurrentReceiverGroup()
            );

            base.MainPortInterleave.CombineWith(x);
            */

            // There is a bug in the simulated webcam. It does not
            // automatically send UpdateFrame messages when you
            // subscribe. If this is a simulated camera, then set
            // up a timer to poke the webcam service and make it
            // send a frame.
            if (camera.ToLower().Contains("simul"))
            {
                Activate(
                    Arbiter.Receive(false, TimeoutPort(_state.Options.CameraInterval), CameraTimer)
                );
            }

            yield break;

        }
コード例 #8
0
        IEnumerator <ITask> InitializeCamera()
        {
            ServiceInfoType info  = null;
            Fault           fault = null;

            yield return(Arbiter.Choice(
                             _blobTrackerPort.DsspDefaultLookup(),
                             delegate(LookupResponse success)
            {
                info = success;
            },
                             delegate(Fault f)
            {
                fault = f;
            }
                             ));

            if (fault != null)
            {
                LogError(null, "Lookup failed on BlobTracker partner", fault);
                yield break;
            }

            PartnerType camera = FindPartner(
                new XmlQualifiedName("WebCam", bt.Contract.Identifier),
                info.PartnerList
                );

            if (camera == null ||
                string.IsNullOrEmpty(camera.Service))
            {
                LogError("No camera partner found for BlobTracker");
                yield break;
            }

            _webCamPort = ServiceForwarder <cam.WebCamOperations>(camera.Service);

            yield return(Arbiter.Choice(
                             _webCamPort.Subscribe(_webCamNotify, typeof(cam.UpdateFrame)),
                             delegate(SubscribeResponseType success) { },
                             delegate(Fault f)
            {
                fault = f;
            }
                             ));

            if (fault != null)
            {
                LogError(null, "Failed to subscribe to webcam", fault);
                yield break;
            }

            yield return(Arbiter.Choice(
                             _blobTrackerPort.Subscribe(_blobTrackerNotify),
                             delegate(SubscribeResponseType success) { },
                             delegate(Fault f)
            {
                fault = f;
            }
                             ));

            if (fault != null)
            {
                LogError(null, "Failed to subscribe to blob tracker", fault);
                yield break;
            }

            RunForm runForm = new RunForm(CreateVisualization);

            WinFormsServicePort.Post(runForm);

            yield return(Arbiter.Choice(
                             runForm.pResult,
                             delegate(SuccessResult success) { },
                             delegate(Exception e)
            {
                fault = Fault.FromException(e);
            }
                             ));

            if (fault != null)
            {
                LogError(null, "Failed to Create Visualization window", fault);
                yield break;
            }

            base.MainPortInterleave.CombineWith(
                Arbiter.Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup(
                        Arbiter.Receive <cam.UpdateFrame>(true, _webCamNotify, CameraUpdateFrameHandler),
                        Arbiter.Receive <bt.ImageProcessed>(true, _blobTrackerNotify, BlobTrackerImageProcessedHandler),
                        Arbiter.Receive <Shutdown>(true, _shutdownPort, ShutdownHandler)
                        ),
                    new ConcurrentReceiverGroup(
                        Arbiter.Receive <bt.DeleteBin>(true, _blobTrackerNotify, EmptyHandler),
                        Arbiter.Receive <bt.InsertBin>(true, _blobTrackerNotify, EmptyHandler),
                        Arbiter.Receive <bt.UpdateBin>(true, _blobTrackerNotify, EmptyHandler)
                        )
                    )
                );
        }