Пример #1
0
 public void Dispose()
 {
     _source.StreamTypeChanged    -= onStreamTypeChanged;
     _source.FfmpegHeaderReceived -= onFfmpegHeaderReceived;
     _source.FfmpegStreamReceived -= onFfmpegStreamReceived;
     _source.Hikm4HeaderReceived  -= onHikm4HeaderReceived;
     _source.Hikm4StreamReceived  -= onHikm4StreamReceived;
     _source.Dispose();
 }
Пример #2
0
 public void Dispose()
 {
     try
     {
         Transceiver?.LocalVideoTrack?.Dispose();
         VideoSource?.Dispose();
         try
         {
             // Unable to exit process until DataChannel is removed/disposed,
             // and this throws internally (at least in 2.0 version).
             PeerSession?.RemoveDataChannel(CaptureChannel);
         }
         catch { }
         PeerSession?.Dispose();
     }
     catch { }
 }
Пример #3
0
        //SEARCH: RENDER STEREO FRAME TO VIDEO FORM
        private void StereoStreamFrameRender(VideoSource.StereoFrameSequenceElement stereoFrame)
        {
            this.UpdateCurPrevMEMSOrient();
            if (!stereoFrame.IsNotFullFrame)
            {
                var leftImg = new Image<Bgr, byte>(stereoFrame.LeftRawFrame);
                var rightImg = new Image<Bgr, byte>(stereoFrame.RightRawFrame);
                Bitmap stuff1Bmp = null;

                if (this.useCalibratedStereoRenderCheckBox.Checked)
                {
                    if (this.StereoCameraParams != null)
                    {
                        var tmpLeft = this.StereoCameraParams.LeftIntrinsicCameraParameters.Undistort(leftImg);
                        var tmpRight = this.StereoCameraParams.RightIntrinsicCameraParameters.Undistort(rightImg);

                        CvInvoke.cvRemap(tmpLeft, leftImg, this.StereoCameraParams.LeftMapX, this.StereoCameraParams.LeftMapY, (int)INTER.CV_INTER_LINEAR | (int)WARP.CV_WARP_FILL_OUTLIERS, new MCvScalar(0));
                        CvInvoke.cvRemap(tmpRight, rightImg, this.StereoCameraParams.RightMapX, this.StereoCameraParams.RightMapY, (int)INTER.CV_INTER_LINEAR | (int)WARP.CV_WARP_FILL_OUTLIERS, new MCvScalar(0));

                        //Image<Gray, short> dispImg;
                        //var points = this.Get3DFeatures(this.StereoCameraParams, stereoFrame, out dispImg);
                        //var centroid = this.GetPoint3DCloudCentroid(points);
                        //Console.WriteLine("Centr: {0}, {1}, {2};", centroid.x, centroid.y, centroid.z);
                        //this.videoForm.RenderStereoFrame(dispImg.ToBitmap(), null);
                    }

                }

                var leftGrayImg = leftImg.Convert<Gray, byte>();
                var rightGrayImg = rightImg.Convert<Gray, byte>();

                Bitmap leftFrameRender;
                Bitmap rightFrameRender;

                if (this.renderGrayCheckBox.Checked)
                {
                    leftFrameRender = new Bitmap(leftGrayImg.ToBitmap());
                    rightFrameRender = new Bitmap(rightGrayImg.ToBitmap());
                }
                else
                {
                    leftFrameRender = new Bitmap(leftImg.ToBitmap());
                    rightFrameRender = new Bitmap(rightImg.ToBitmap());
                }

                if (this.showDepthMapCheckBox.Checked)
                {
                    //var features = this.opticFlowProcessor.GetFeaturesToTrack(
                    //    stereoFrame: frame,
                    //    useGpu: true);
                    var depthMap = this.opticFlowProcessor.GetDispMap(leftGrayImg, rightGrayImg, this.useGPUCheckBox.Checked, this.GetParametersForStereoMapSolver(this.useGPUCheckBox.Checked));
                    stuff1Bmp = depthMap.ToBitmap();

                    //update frame
                    this.prevStereoDepthFrame = this.currStereoDepthFrame;
                    this.currStereoDepthFrame = new DataSource.OpticFlowFrameContainer()
                    {
                        DepthMapImg = depthMap,
                        StereoFrame = new VideoSource.StereoFrameSequenceElement(stereoFrame)
                    };
                    ////
                }

                //try to use odometry
                if (this.perfOdometryCheckBox.Checked)
                {
                    if (this.StereoCameraParams != null)
                    {
                        var rotMatrix = new Matrix<double>(3, 3);
                        rotMatrix.SetIdentity();
                        var rotMatr = Utils.CvHelper.MatrixToArray(rotMatrix);
                        rotMatrix.Dispose();
                        if (this.prevMEMSRotMatr != null && this.currentMEMSRotMatr != null)
                        {
                            rotMatr = this.OrientationCalc.GetRotationMatrixBetweenTwoStates(this.prevMEMSRotMatr, this.currentMEMSRotMatr, this.orientCalibMatrix);
                        }
                        List<PointF> currFreatures;
                        List<PointF> prevFeatures;
                        Matrix<double> resRotation;
                        var featuresToTrackParams = this.GetVisualOdometerFeaturesToTrackParams();
                        var featuresOpticFlowParams = this.GetVisualOdometerFeaturesOpticFlowParams();
                        var disparitiesParams = this.GetVisualOdometerDisparitiesParams();
                        var tDiff = this.visualOdometer.GetTranslationAndRotation(
                            rotMatrArray: rotMatr,
                            prevFrame: this.prevStereoDepthFrame,
                            currFrame: this.currStereoDepthFrame,
                            cameraParams: this.StereoCameraParams,
                            currFeaturesList: out currFreatures,
                            prevFeaturesList: out prevFeatures,
                            resRotation: out resRotation,
                            featuresToTrackParams: featuresToTrackParams,
                            featuresOpticFlowParams: featuresOpticFlowParams,
                            disparitiesParams: disparitiesParams
                            );

                        if (resRotation != null)
                        {
                            this.svdDiffRotMatrix = resRotation.Mul(this.svdDiffRotMatrix);
                        }

                        if (tDiff != null)
                        {
                            if (!(double.IsNaN(tDiff.Value.x) || double.IsNaN(tDiff.Value.y) || double.IsNaN(tDiff.Value.z)))
                            {
                                this.position3d.x += tDiff.Value.x;
                                this.position3d.y += tDiff.Value.y;
                                this.position3d.z += tDiff.Value.z;

                                this.RenderTranslatoin(this.position3d);
                            }
                            Console.WriteLine("TRANSLATION: X={0}; Y={1}; Z={2}", tDiff.Value.x, tDiff.Value.y, tDiff.Value.z);
                            Console.WriteLine("POSITION: X={0}; Y={1}; Z={2}", position3d.x, position3d.y, position3d.z);
                        }
                        if (this.renderFraturesCheckBox.Checked)
                        {
                            if (currFreatures != null && prevFeatures != null)
                            {
                                var dotSize = new Size(10, 10);
                                var g = Graphics.FromImage(leftFrameRender);
                                for (int i = 0; i < currFreatures.Count; ++i)
                                {
                                    g.DrawEllipse(Pens.Red, currFreatures[i].X - dotSize.Width / 2, currFreatures[i].Y - dotSize.Height / 2, dotSize.Width, dotSize.Height);
                                    g.DrawLine(Pens.Red, currFreatures[i], prevFeatures[i]);
                                }
                            }
                        }
                    }
                }
                ////
                this.memsRenderForm.Invoke((MethodInvoker)delegate { this.RenderOrientationTransformation(Utils.CvHelper.MatrixToArray(this.svdDiffRotMatrix)); });
                //general lr render
                this.videoForm.RenderStereoFrame(leftFrameRender, rightFrameRender);

                if (stuff1Bmp != null)
                {
                    this.videoForm.RenderToStuffPictureBox1(stuff1Bmp);
                }
                stereoFrame.Dispose();
            }
        }