shimat / opencvsharp

OpenCV wrapper for .NET
Apache License 2.0
5.39k stars 1.15k forks source link

VideoCaptureProperties.ConvertRgb is not work #1223

Closed lvzaina closed 3 years ago

lvzaina commented 3 years ago

Summary of your issue

I need to read the raw data ("yuyv" format) from the uvc camera. I set ConvertRgb to 0 in emgucv and it works fine. SetCaptureProperty(Emgu.CV.CvEnum.CapProp.ConvertRgb, 0); In opencvsharp but no change Set(VideoCaptureProperties.ConvertRgb, 0);

Environment

OpenCvSharp4/4.5.1.20210210

What did you do when you faced the problem?

can't find the details of VideoCaptureProperties.ConvertRgb,It seems to be encapsulated in a library file.

Example code:

        public void OpenUSBCarmera(double width, double height, CaptureDataHandler handler, int index = 0)
        {
            Console.WriteLine("OpenUSBCarmera[" + index + "]:width:" + width + "height:" + height);
            try
            {
                if (_cameraCapture != null)
                {
                    _cameraCapture.Dispose();
                }
                _cameraCapture = returnCapture(width, height, index); 

                _dataHandler = handler;
                //_cameraCapture.FourCC = OpenCvSharp.FourCC.IYUV.ToString();
                _cameraCapture.Open(index);
                _cameraCapture.Set(VideoCaptureProperties.ConvertRgb, 0);
                _captureInProgress = true;
                Console.WriteLine("=ConvertRgb:" + _cameraCapture.Get(VideoCaptureProperties.Format));
                _frame = new Mat();

                Console.WriteLine("Fps:" + _cameraCapture.Fps);
                if (_cameraCapture != null && _cameraCapture.CvPtr != IntPtr.Zero)
                {
                    int sleepTime = (int)Math.Round(1000 / _cameraCapture.Fps);
                    Task task = new Task(() =>
                    {
                        while (_captureInProgress)
                        {
                            _cameraCapture.Read(_frame);
                            if (_frame == null || _frame.Empty())
                            {
                                return;
                            }
                            if (_dataHandler != null)
                            {
                                _dataHandler.Invoke(_frame);
                            }
                            Cv2.WaitKey(sleepTime);
                        }
                    });
                    task.Start();

                }
            }
            catch (Exception ex)
            {
                LogUtil.LogInfo(GetType(), ex.Message);
            }
        }
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.