Example #1
0
        private static void Main(string[] args)
        {
            var processor = BuildProcessor();

            var files = new List <string>();

            var path = args[0];

            if (File.Exists(path))
            {
                files.Add(path);
            }
            else if (Directory.Exists(path))
            {
                files.AddRange(Directory.GetFiles(path, "*.mp4"));
            }

            foreach (var file in files)
            {
                using (var capture = CvCapture.FromFile(file))
                    using (var windowOriginal = new CvWindow("Original", WindowMode.AutoSize))
                        using (var windowPreImage = new CvWindow("Pre-Image", WindowMode.AutoSize))
                            using (var windowPostImage = new CvWindow("Post-Image", WindowMode.AutoSize))
                            {
                                processor.OriginalWindow      = windowOriginal;
                                processor.PreProcessedWindow  = windowPreImage;
                                processor.PostProcessedWindow = windowPostImage;
                                processor.Process(capture);
                            }
            }
        }
Example #2
0
        public VideoWriter()
        {
            // (1)カメラに対するキャプチャ構造体を作成する
            using (CvCapture capture = CvCapture.FromCamera(0))
            {
                // (2)キャプチャサイズを取得する(この設定は,利用するカメラに依存する)
                int    width  = capture.FrameWidth;
                int    height = capture.FrameHeight;
                double fps    = 15;//capture.Fps;
                // (3)ビデオライタ構造体を作成する
                using (CvVideoWriter writer = new CvVideoWriter("cap.avi", FourCC.Prompt, fps, new CvSize(width, height)))
                    using (CvFont font = new CvFont(FontFace.HersheyComplex, 0.7, 0.7))
                        using (CvWindow window = new CvWindow("Capture", WindowMode.AutoSize))
                        {
                            // (4)カメラから画像をキャプチャし,ファイルに書き出す
                            for (int frames = 0; ; frames++)
                            {
                                IplImage frame = capture.QueryFrame();
                                string   str   = string.Format("{0}[frame]", frames);
                                frame.PutText(str, new CvPoint(10, 20), font, new CvColor(0, 255, 100));
                                writer.WriteFrame(frame);
                                window.ShowImage(frame);

                                int key = CvWindow.WaitKey((int)(1000 / fps));
                                if (key == '\x1b')
                                {
                                    break;
                                }
                            }
                        }
            }
        }
        private bool initCamera()
        {
            try
            {
                if (capture_type == DO_WITH_DIRECT_WEBCAM)
                {
                    capture = CvCapture.FromCamera(CaptureDevice.DShow, 0);
                    capture.SetCaptureProperty(CaptureProperty.FrameWidth, 680);
                    capture.SetCaptureProperty(CaptureProperty.FrameHeight, 480);

                    return(true);
                }

                if (capture_type == DO_WITH_IP_CAMERA)
                {
                    //capture = CvCapture.FromFile("http://192.168.0.5:8080/shot.jpg");
                    //capture.SetCaptureProperty(CaptureProperty.FrameWidth, 680);
                    //capture.SetCaptureProperty(CaptureProperty.FrameHeight, 480);

                    return(true);
                }

                return(false);
            }
            catch
            {
                return(false);
            }
        }
Example #4
0
        private void FormatVideo()
        {
            cap        = CvCapture.FromFile(fileName);
            uLastFrame = (UInt16)cap.FrameCount;
            img        = cap.QueryFrame();

            CvVideoWriter newVideo = new CvVideoWriter("videoFormated.avi", FourCC.Default, cap.Fps, img.Size);

            setProgressBarMargins(0, uLastFrame);


            for (int i = 1; i < uLastFrame; i++)
            {
                img = cap.QueryFrame();

                if (img == null)
                {
                    break;
                }

                newVideo.WriteFrame(img);
                setProgressBarValue(i);
            }

            newVideo.Dispose();
            setProgressBarValue(0);
        }
Example #5
0
        private void CaptureCameraCallback()
        {
            const double ScaleFactor  = 2.5;
            const int    MinNeighbors = 1;
            CvSize       MinSize      = new CvSize(30, 30);

            CvCapture cap = CvCapture.FromCamera(1);
            CvHaarClassifierCascade cascade = CvHaarClassifierCascade.FromFile("haarcascade_eye.xml");

            while (true)
            {
                IplImage img = cap.QueryFrame();
                //IplImage.FromBitmap()
                //CvSeq<CvAvgComp> eyes = Cv.HaarDetectObjects(img, cascade, Cv.CreateMemStorage(), ScaleFactor, MinNeighbors, HaarDetectionType.DoCannyPruning, MinSize);

                //foreach (CvAvgComp eye in eyes.AsParallel())
                //{
                //    img.DrawRect(eye.Rect, CvColor.Red);

                //    if (eye.Rect.Left > pctCvWindow.Width / 2)
                //    {
                //        try
                //        {
                //            IplImage rightEyeImg1 = img.Clone();
                //            Cv.SetImageROI(rightEyeImg1, eye.Rect);
                //            IplImage rightEyeImg2 = Cv.CreateImage(eye.Rect.Size, rightEyeImg1.Depth, rightEyeImg1.NChannels);
                //            Cv.Copy(rightEyeImg1, rightEyeImg2, null);
                //            Cv.ResetImageROI(rightEyeImg1);


                //            Bitmap rightEyeBm = BitmapConverter.ToBitmap(rightEyeImg2);
                //            pctRightEye.Image = rightEyeBm;
                //        }
                //        catch { }
                //    }
                //    else
                //    {
                //        try
                //        {
                //            IplImage leftEyeImg1 = img.Clone();
                //            Cv.SetImageROI(leftEyeImg1, eye.Rect);
                //            IplImage leftEyeImg2 = Cv.CreateImage(eye.Rect.Size, leftEyeImg1.Depth, leftEyeImg1.NChannels);
                //            Cv.Copy(leftEyeImg1, leftEyeImg2, null);
                //            Cv.ResetImageROI(leftEyeImg1);

                //            Bitmap leftEyeBm = BitmapConverter.ToBitmap(leftEyeImg2);
                //            pctLeftEye.Image = leftEyeBm;
                //        }catch{}
                //    }
                //}

                Bitmap bm = BitmapConverter.ToBitmap(img);
                bm.SetResolution(pctCvWindow.Width, pctCvWindow.Height);
                //pctCvWindow.Image = bm;
                pb.Image = bm;
                img      = null;
                bm       = null;
                Thread.Sleep(100);
            }
        }
Example #6
0
        private void AviTestworker_DoWork(object sender, DoWorkEventArgs e)
        {
            appSettings.TestMode = true;
            BackgroundWorker bw = (BackgroundWorker)sender;

            using (CvCapture capture = new CvCapture(appSettings.TestFname))
            {
                int interval = (int)(1000 / AviTest_fps);
                while ((AviTest_image = capture.QueryFrame()) != null)
                {
                    if (bw.CancellationPending)
                    {
                        appSettings.TestMode = false;
                        e.Cancel             = true;
                        break;
                    }

                    for (int i = 0; i < 200; ++i)
                    {
                        image_data_write(ref AviTest_image, i, 0, 0);
                    }

                    bw.ReportProgress(0, AviTest_image);
                    System.Threading.Thread.Sleep(interval);
                }
            }
            appSettings.TestMode = false;
        }
Example #7
0
 private void BUT_Pick_File_Click(object sender, EventArgs e)
 {
     openFileDialog1.Filter = "Video files|*.avi";
     openFileDialog1.Title  = "Select a Video File";
     if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         capture = CvCapture.FromFile(openFileDialog1.FileName);
         if (capture.FrameCount > 0)
         {
             lABEl_indicator_source.Text      = "Файл";
             lABEl_indicator_source.BackColor = Color.Green;
             Label_ParamSource.Text           = "Ширина = " + capture.FrameWidth.ToString() + "\nВысота = " + capture.FrameHeight.ToString() + "\nКоличество кадров = " + capture.FrameCount.ToString();
             PropCentreImageX           = capture.FrameWidth / 2;
             PropCentreImageY           = capture.FrameHeight / 2;
             captureOpened              = true;
             toolStripStatusLabel1.Text = "Источник указан верно, переходите к настройкам параметров";
         }
         else
         {
             lABEl_indicator_source.Text      = "Файл поврежден";
             lABEl_indicator_source.BackColor = Color.Red;
             captureOpened = false;
         }
     }
 }
Example #8
0
        private static double getFps(CvCapture capture)
        {
            while (capture.QueryFrame() == null)
            {
                /* start camera */
            }

            double counter = 0;
            double seconds = 0;
            var    watch   = Stopwatch.StartNew();

            while (capture.QueryFrame() != null)
            {
                counter++;
                seconds = watch.ElapsedMilliseconds / (double)1000;
                if (seconds >= 3)
                {
                    watch.Stop();
                    break;
                }
            }
            var fps = counter / seconds;

            return(fps);
        }
Example #9
0
        private void CaptureCameraCallback()
        {
            using (var cap = CvCapture.FromCamera(2))
            {
                cap.SetCaptureProperty(CaptureProperty.FrameWidth, Layout.Width);
                cap.SetCaptureProperty(CaptureProperty.FrameHeight, Layout.Height);
                var mat = new CvMat();
                var img = new IplImage();
                while (true)
                {
                    img = cap.QueryFrame();

                    var img1  = img;
                    var taskA = Task.Factory.StartNew(() =>
                    {
                        var b = img1.ToBitmap();

                        ImgOut.Image = b;

                        img = null;
                        b   = null;
                    });
                }
            }
        }
 // Use this for initialization
 void Start()
 {
     //CvCapture capture;
     // Webカメラを使うという宣言
     _Capture = Cv.CreateCameraCapture(0);
     // 横幅と縦幅の設定
     Cv.SetCaptureProperty(_Capture, CaptureProperty.FrameWidth, CAPTURE_WIDTH);
     Cv.SetCaptureProperty(_Capture, CaptureProperty.FrameHeight, CAPTURE_HEIGHT);
     // Webカメラからフレーム取得
     //IplImage frame;
     _Frame = Cv.QueryFrame(_Capture);
     // Unity上に縦幅と横幅のフレームサイズをコンソール出力
     Debug.Log("width:" + _Frame.Width + " height:" + _Frame.Height);
     // 動画内のRGBを取るための変数を初期化
     _Window = new CvWindow("GetRGBWindow", _Frame);
     _Window.OnMouseCallback += new CvMouseCallback(GetClickedPixelRgb);
     // 領域分割に使う色をHSVで指定
     pointhsv = new CvScalar(0.0, 0.0, 0.0);
     // ウィンドウの名前設定
     Cv.NamedWindow("Original");
     Cv.NamedWindow("STEP1:Smoothing");
     Cv.NamedWindow("STEP2:HSV");
     Cv.NamedWindow("STEP3:Segmentation");
     Cv.NamedWindow("STEP4:Morphology");
     Cv.NamedWindow("STEP5:Detected");
     Cv.NamedWindow("window");
 }
Example #11
0
        public EyeDetect()
        {
            CvColor[] colors = new CvColor[] {
                new CvColor(0, 0, 255),
                new CvColor(0, 128, 255),
                new CvColor(0, 255, 255),
                new CvColor(0, 255, 0),
                new CvColor(255, 128, 0),
                new CvColor(255, 255, 0),
                new CvColor(255, 0, 0),
                new CvColor(255, 0, 255),
            };

            const double Scale        = 1.25;
            const double ScaleFactor  = 2.5;
            const int    MinNeighbors = 2;

            using (CvCapture cap = CvCapture.FromCamera(1))
                using (CvWindow w = new CvWindow("Eye Tracker"))
                {
                    while (CvWindow.WaitKey(10) < 0)
                    {
                        using (IplImage img = cap.QueryFrame())
                            using (IplImage smallImg = new IplImage(new CvSize(Cv.Round(img.Width / Scale), Cv.Round(img.Height / Scale)), BitDepth.U8, 1))
                            {
                                using (IplImage gray = new IplImage(img.Size, BitDepth.U8, 1))
                                {
                                    Cv.CvtColor(img, gray, ColorConversion.BgrToGray);
                                    Cv.Resize(gray, smallImg, Interpolation.Linear);
                                    Cv.EqualizeHist(smallImg, smallImg);
                                }

                                using (CvHaarClassifierCascade cascade = CvHaarClassifierCascade.FromFile("C:\\Program Files\\OpenCV\\data\\haarcascades\\haarcascade_eye.xml"))
                                    using (CvMemStorage storage = new CvMemStorage())
                                    {
                                        storage.Clear();

                                        Stopwatch         watch = Stopwatch.StartNew();
                                        CvSeq <CvAvgComp> eyes  = Cv.HaarDetectObjects(smallImg, cascade, storage, ScaleFactor, MinNeighbors, 0, new CvSize(30, 30));
                                        watch.Stop();
                                        //Console.WriteLine("detection time = {0}msn", watch.ElapsedMilliseconds);

                                        for (int i = 0; i < eyes.Total; i++)
                                        {
                                            CvRect  r      = eyes[i].Value.Rect;
                                            CvPoint center = new CvPoint
                                            {
                                                X = Cv.Round((r.X + r.Width * 0.5) * Scale),
                                                Y = Cv.Round((r.Y + r.Height * 0.5) * Scale)
                                            };
                                            int radius = Cv.Round((r.Width + r.Height) * 0.25 * Scale);
                                            img.Circle(center, radius, colors[i % 8], 3, LineType.AntiAlias, 0);
                                        }
                                    }

                                w.Image = img;
                            }
                    }
                }
        }
Example #12
0
        private void btnOpenCam_Click(object sender, EventArgs e)
        {
            if (Opened)
            {
                if (Playing == false)
                {
                    timer1.Enabled     = true;
                    Playing            = true;
                    measure            = false;
                    btnMeasure.Enabled = false;
                    labelSatatus.Text  = "Kamrea çalışıyor !";
                    return;
                }
            }

            try
            {
                cap = CvCapture.FromCamera(CaptureDevice.Any);
                double fps = cap.GetCaptureProperty(CaptureProperty.Fps);
                cap.SetCaptureProperty(CaptureProperty.FrameHeight, 600);
                cap.SetCaptureProperty(CaptureProperty.FrameWidth, 800);
                Opened                  = true;
                Playing                 = true;
                timer1.Interval         = 10;
                timer1.Enabled          = true;
                labelSatatus.Text       = "Kamrea çalışıyor !";
                btnTakeSnapshot.Enabled = true;
            }
            catch
            {
                Playing = false;
                MessageBox.Show("Kamerayı Açamıyorum !");
            }
        }
Example #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (timer != null)
            {
                DestroyCamera();
            }

            timer          = new Timer();
            timer.Tick    += timer_Tick;
            timer.Interval = 1000 / 60;

            camera = cvlib.CvCreateCameraCapture(0);
            if (camera.ptr == IntPtr.Zero)
            {
                throw new Exception("could not create camera");
            }

            IplImage frame = cvlib.CvQueryFrame(ref camera);


            double width  = cvlib.cvGetCaptureProperty(camera, cvlib.CV_CAP_PROP_FRAME_WIDTH);
            double height = cvlib.cvGetCaptureProperty(camera, cvlib.CV_CAP_PROP_FRAME_HEIGHT);

            firstFrame = cvlib.CvCreateImage(new CvSize((int)width, (int)height), (int)cvlib.IPL_DEPTH_8U, 1);
            cvlib.CvCvtColor(ref frame, ref firstFrame, cvlib.CV_BGR2GRAY);

            pictureBox1.Size = new Size((int)width, (int)height);


            timer.Start();
        }
        public void Process(CvCapture capture)
        {
            FrameCounter = 0;
            while (true)
            {
                FrameCounter++;
                var frame = capture.QueryFrame();
                if (frame == null)
                {
                    break;
                }

                if (FrameCounter > FrameSkipValue)
                {
                    var method = new ProcessIplImage(Process);
                    method.BeginInvoke(frame, null, null);
                    FrameCounter = 0;
                }

                var key = CvWindow.WaitKey(33);
                if (key == 27)
                {
                    break;
                }
            }
        }
Example #15
0
        private void ExecuteStart()
        {
            this.ExecuteStop();

            this._CvCapture = this.CreateCvCapture();
            if (this._CvCapture == null)
            {
                return;
            }

            var ms = 60;

            this._CaptureHandler = Observable.Interval(TimeSpan.FromMilliseconds(ms), DispatcherScheduler.Current)
                                   .Select(_ =>
            {
                if (this._CvCapture == null)
                {
                    return(null);
                }

                return(Cv.QueryFrame(this._CvCapture));
            })
                                   .Where(frame => frame != null)
                                   .Subscribe(frame =>
            {
                var writeableBitmap = frame.ToWriteableBitmap();
                frame.Dispose();
                this.CameraImage = writeableBitmap;
            });
        }
Example #16
0
 // Use this for initialization
 void Start()
 {
     capture = Cv.CreateCameraCapture(0);
     Cv.SetCaptureProperty(capture, CaptureProperty.FrameWidth, CAPTURE_WIDTH);
     Cv.SetCaptureProperty(capture, CaptureProperty.FrameHeight, CAPTURE_HEIGHT);
     captureTexture          = new Texture2D(CAPTURE_WIDTH, CAPTURE_HEIGHT, TextureFormat.RGBA32, false);
     isCaptureDisplayEnabled = true;
 }
Example #17
0
 private async Task <IplImage> QueryFrameAsync(CvCapture capture)
 {
     // awaitできる形で、非同期にフレームの取得を行います。
     return(await Task.Run(() =>
     {
         return capture.QueryFrame();
     }));
 }
Example #18
0
 // shows a live view of the current web cam
 private static void Live(CvCapture cap, CvWindow winScr)
 {
     while (CvWindow.WaitKey(10) != 27)
     {
         IplImage src = cap.QueryFrame();
         winScr.Image = src;
     }
 }
Example #19
0
        private static async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
        {
            var message = messageEventArgs.Message;

            if (message == null || message.Type != MessageType.TextMessage)
            {
                return;
            }
            if (message.Text.StartsWith("/help"))
            {
                var text = "Hello! I'm Susu.\n Here are some commands :)\n /GetPic - Get a random picture, of me of course!";
                await Bot.SendTextMessageAsync(message.Chat.Id, text);
            }
            else if (message.Text.StartsWith("/getpic"))
            {
                await Bot.SendTextMessageAsync(message.Chat.Id, ":D");

                var        files      = Directory.GetFiles("c:\\susu", "*.jpg");
                FileInfo   fileInfo   = new FileInfo(files[rand.Next(files.Length)]);
                FileStream fs         = fileInfo.OpenRead();
                FileToSend fileToSend = new FileToSend(fileInfo.FullName, fs);
                await Bot.SendPhotoAsync(message.Chat.Id, fileToSend);
            }
            else if (message.Text.StartsWith("/getvideo"))
            {
                await Bot.SendTextMessageAsync(message.Chat.Id, ":D");

                var        files      = Directory.GetFiles("c:\\susu", "*.mp4");
                FileInfo   fileInfo   = new FileInfo(files[rand.Next(files.Length)]);
                FileStream fs         = fileInfo.OpenRead();
                FileToSend fileToSend = new FileToSend(fileInfo.FullName, fs);
                await Bot.SendVideoAsync(message.Chat.Id, fileToSend);
            }
            else if (message.Text.StartsWith("/howareyou"))
            {
                await Bot.SendTextMessageAsync(message.Chat.Id, "Meh, i will show you");

                using (CvCapture cap = CvCapture.FromCamera(2))
                {
                    using (IplImage img = cap.QueryFrame())
                    {
                        i = i + 1;
                        var file = string.Format("c:\\susu\\000{0}.jpg", i);
                        img.SaveImage(file);
                        FileInfo   fileInfo   = new FileInfo(file);
                        FileStream fs         = fileInfo.OpenRead();
                        FileToSend fileToSend = new FileToSend(fileInfo.FullName, fs);
                        await Bot.SendPhotoAsync(message.Chat.Id, fileToSend);
                    }
                }
            }
            else if (message.Text.StartsWith("/Bye"))
            {
                await Bot.SendTextMessageAsync(message.Chat.Id, "GoodBye!!");

                _disconnectApp = true;
            }
        }
Example #20
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            m_cvCap = CvCapture.FromCamera(0);
            
            m_cvCap.FrameWidth = 320;
            m_cvCap.FrameHeight = 240;

            timer1.Interval = 20;
            timer1.Enabled = true;
        }
Example #21
0
    // Use this for initialization
    void Start()
    {
        capture = Cv.CreateCameraCapture(0);
        Cv.SetCaptureProperty(capture, CaptureProperty.FrameWidth, CAPTURE_WIDTH);
        Cv.SetCaptureProperty(capture, CaptureProperty.FrameHeight, CAPTURE_HEIGHT);
        IplImage frame = Cv.QueryFrame(capture);

        //IplImage imgSrc = new IplImage(Const.ImageShapes, LoadMode.Color);
        Debug.Log("width:" + frame.Width + " height:" + frame.Height);
        texture = new Texture2D(frame.Width, frame.Height, TextureFormat.RGBA32, false);
    }
Example #22
0
 public CaptureCamera()
 {
     using (CvCapture cap = CvCapture.FromCamera(0)) // device type + camera index
         using (CvWindow w = new CvWindow("SampleCapture"))
         {
             while (CvWindow.WaitKey(10) < 0)
             {
                 w.Image = cap.QueryFrame();
             }
         }
 }
        static WebcamController()
        {
            //카메라 지정
            //0번카메라를 사용한다.
            m_cvCap             = CvCapture.FromCamera(0);
            m_cvCap.FrameWidth  = 320;
            m_cvCap.FrameHeight = 240;

            m_updateDel = null;

            updateFrame();
        }
Example #24
0
 // use circle detection only
 private static void CircleOnly(CvCapture cap, CvWindow winScr)
 {
     srcImage       = PerspectiveCorretoin.GetCorrectedImage(cap.QueryFrame());
     gray           = new IplImage(srcImage.Size, BitDepth.U8, 1);
     blurKernelSize = new Size(9, 9);
     while (CvWindow.WaitKey(10) != 27)
     {
         srcImage = PerspectiveCorretoin.GetCorrectedImage(cap.QueryFrame());
         ShowFPS();
         FindCircle(srcImage, winScr);
     }
 }
        private void btnVideo_Click(object sender, EventArgs e)
        {
            double vidWidth, vidHeight;

            if (btnVideo.Text.Equals("Start Video"))
            {
                train_data();

                videoCapture = highgui.CvCreateCameraCapture(0);

                //check bila valid
                if (videoCapture.ptr == IntPtr.Zero)
                {
                    MessageBox.Show("Pengambilan gambar gagal");
                    return;
                }

                btnVideo.Text = "Stop Video";

                highgui.CvSetCaptureProperty(ref videoCapture, highgui.CV_CAP_PROP_FRAME_WIDTH, 640);
                highgui.CvSetCaptureProperty(ref videoCapture, highgui.CV_CAP_PROP_FRAME_HEIGHT, 320);

                highgui.CvQueryFrame(ref videoCapture);

                vidWidth  = highgui.cvGetCaptureProperty(videoCapture, highgui.CV_CAP_PROP_FRAME_WIDTH);
                vidHeight = highgui.cvGetCaptureProperty(videoCapture, highgui.CV_CAP_PROP_FRAME_HEIGHT);

                picBoxMain.Width  = (int)vidWidth;
                picBoxMain.Height = (int)vidHeight;

                WriteLine("Pengambilan gambar dari webcam dengan resolusi: " + vidWidth.ToString() + " x " + vidHeight.ToString(), true, false);

                timerGrab.Interval = 42;
                timerFPS.Interval  = 1100;
                timerGrab.Enabled  = true;
                timerFPS.Enabled   = true;

                hc  = new HaarClassifier(this);
                abs = new AbsDiff(this);
            }
            else
            {
                btnVideo.Text     = "Start Video";
                timerFPS.Enabled  = false;
                timerGrab.Enabled = false;

                if (videoCapture.ptr != IntPtr.Zero)
                {
                    highgui.CvReleaseCapture(ref videoCapture);
                    videoCapture.ptr = IntPtr.Zero;
                }
            }
        }
Example #26
0
        private void button1_Click(object sender, EventArgs e)
        {
            CvCapture test = Cv.CreateCameraCapture(3);

            if (test == null)
            {
                label5.Text = "取得失敗";
            }
            else
            {
                IplImage test1 = Cv.QueryFrame(test);
            }
        }
Example #27
0
 private void camera_On()
 {
     try
     {
         capture = CvCapture.FromCamera(CaptureDevice.DShow, 0);
         capture.SetCaptureProperty(CaptureProperty.FrameWidth, 640);
         capture.SetCaptureProperty(CaptureProperty.FrameHeight, 360);
     }
     catch
     {
         timer1.Enabled = false;
     }
 }
Example #28
0
 private void Form1_Load_1(object sender, EventArgs e)
 {
     try
     {
         capture = CvCapture.FromCamera(CaptureDevice.DShow, 0);
         capture.SetCaptureProperty(CaptureProperty.FrameWidth, 640);
         capture.SetCaptureProperty(CaptureProperty.FrameHeight, 480);
     }
     catch
     {
         timer1.Enabled = false;
     }
 }
    // Use this for initialization
    void Start()
    {
        cascade = CvHaarClassifierCascade.FromFile(@"./Assets/haarcascade_frontalface_alt.xml");
        capture = Cv.CreateCameraCapture(0);
        Cv.SetCaptureProperty(capture, CaptureProperty.FrameWidth, CAPTURE_WIDTH);
        Cv.SetCaptureProperty(capture, CaptureProperty.FrameHeight, CAPTURE_HEIGHT);
        IplImage frame = Cv.QueryFrame(capture);

        Cv.NamedWindow("FaceDetect");

        CvSVM          svm      = new CvSVM();
        CvTermCriteria criteria = new CvTermCriteria(CriteriaType.Epsilon, 1000, double.Epsilon);
        CvSVMParams    param    = new CvSVMParams(CvSVM.C_SVC, CvSVM.RBF, 10.0, 8.0, 1.0, 10.0, 0.5, 0.1, null, criteria);
    }
Example #30
0
        void CreateCapture()
        {
            //capture = cvlib.CvCreateFileCapture("d:\\reference 3.avi");
            capture = cvlib.CvCreateCameraCapture(0);
            if (capture.ptr == IntPtr.Zero)
            {
                throw new Exception("could not create capture");
            }

            cvlib.CvQueryFrame(ref capture);
            context.Width  = cvlib.cvGetCaptureProperty(capture, cvlib.CV_CAP_PROP_FRAME_WIDTH);
            context.Height = cvlib.cvGetCaptureProperty(capture, cvlib.CV_CAP_PROP_FRAME_HEIGHT);
            context.Fps    = cvlib.cvGetCaptureProperty(capture, cvlib.CV_CAP_PROP_FPS);
        }
Example #31
0
        private static void Track()
        {
            using (var video = new CvCapture("data/bach.mp4"))
            {
                IplImage frame = null;
                IplImage gray = null;
                IplImage binary = null;
                IplImage render = null;
                IplImage renderTracks = null;
                CvTracks tracks = new CvTracks();
                CvWindow window = new CvWindow("render");
                CvWindow windowTracks = new CvWindow("tracks");

                for (int i = 0; ; i++)
                {
                    frame = video.QueryFrame();
                    //if (frame == null)
                    //    frame = new IplImage("data/shapes.png");
                    if (gray == null)
                    {
                        gray = new IplImage(frame.Size, BitDepth.U8, 1);
                        binary = new IplImage(frame.Size, BitDepth.U8, 1);
                        render = new IplImage(frame.Size, BitDepth.U8, 3);
                        renderTracks = new IplImage(frame.Size, BitDepth.U8, 3);
                    }

                    render.Zero();
                    renderTracks.Zero();

                    Cv.CvtColor(frame, gray, ColorConversion.BgrToGray);
                    Cv.Threshold(gray, binary, 0, 255, ThresholdType.Otsu);

                    CvBlobs blobs = new CvBlobs(binary);
                    CvBlobs newBlobs = new CvBlobs(blobs
                        .OrderByDescending(pair => pair.Value.Area)
                        .Take(200)
                        .ToDictionary(pair => pair.Key, pair => pair.Value), blobs.Labels);
                    newBlobs.RenderBlobs(binary, render);
                    window.ShowImage(render);

                    newBlobs.UpdateTracks(tracks, 10.0, Int32.MaxValue);
                    tracks.Render(binary, renderTracks);
                    windowTracks.ShowImage(renderTracks);

                    Cv.WaitKey(200);
                    Console.WriteLine(i);
                }
            }
        }
Example #32
0
        private void btnVideo_Click(object sender, EventArgs e)
        {
            double vidWidth, vidHeight;

            if (btnVideo.Text.Equals("Start Video"))
            {
                train_data();

               videoCapture= cvlib.cvCreateCameraCapture(0);

               cvlib.cvWaitKey(10);

                //check if valid
                if (videoCapture.ptr == IntPtr.Zero)
                {
                    MessageBox.Show("Failed shooting");
                    return;
                }

                btnVideo.Text = "Stop Video";

                cvlib.cvSetCaptureProperty( videoCapture, cvlib.CV_CAP_PROP_FRAME_WIDTH, 640);
                cvlib.cvSetCaptureProperty( videoCapture, cvlib.CV_CAP_PROP_FRAME_HEIGHT, 320);

               IplImage frame= cvlib.cvQueryFrame( videoCapture);

                vidWidth = cvlib.cvGetCaptureProperty(videoCapture, cvlib.CV_CAP_PROP_FRAME_WIDTH);
                vidHeight = cvlib.cvGetCaptureProperty(videoCapture, cvlib.CV_CAP_PROP_FRAME_HEIGHT);

                picBoxMain.Width = (int)vidWidth;
                picBoxMain.Height = (int)vidHeight;

                WriteLine("Taking pictures from a webcam with a resolution: " + vidWidth.ToString() + " x " + vidHeight.ToString(), true, false);

                timerGrab.Interval = 42;
                timerFPS.Interval = 1100;
                timerGrab.Enabled = true;
                timerFPS.Enabled = true;

                hc = new HaarClassifier(this);
                abs = new AbsDiff(this);
            }
            else
            {
                btnVideo.Text = "Start Video";
                timerFPS.Enabled = false;
                timerGrab.Enabled = false;

                if (videoCapture.ptr != IntPtr.Zero)
                {
                    cvlib.cvReleaseCapture( videoCapture);
                    videoCapture.ptr = IntPtr.Zero;
                }
            }
        }
        private void btnVideo_Click(object sender, EventArgs e)
        {
            double vidWidth, vidHeight;

            if (btnVideo.Text.Equals("Start Video"))
            {
                train_data();

                videoCapture = highgui.CvCreateCameraCapture(0);

                //check bila valid
                if (videoCapture.ptr == IntPtr.Zero)
                {
                    MessageBox.Show("Pengambilan gambar gagal");
                    return;
                }

                btnVideo.Text = "Stop Video";

                highgui.CvSetCaptureProperty(ref videoCapture, highgui.CV_CAP_PROP_FRAME_WIDTH, 640);
                highgui.CvSetCaptureProperty(ref videoCapture, highgui.CV_CAP_PROP_FRAME_HEIGHT, 320);

                highgui.CvQueryFrame(ref videoCapture);

                vidWidth = highgui.cvGetCaptureProperty(videoCapture, highgui.CV_CAP_PROP_FRAME_WIDTH);
                vidHeight = highgui.cvGetCaptureProperty(videoCapture, highgui.CV_CAP_PROP_FRAME_HEIGHT);

                picBoxMain.Width = (int)vidWidth;
                picBoxMain.Height = (int)vidHeight;

                WriteLine("Pengambilan gambar dari webcam dengan resolusi: " + vidWidth.ToString() + " x " + vidHeight.ToString(), true, false);

                timerGrab.Interval = 42;
                timerFPS.Interval = 1100;
                timerGrab.Enabled = true;
                timerFPS.Enabled = true;

                hc = new HaarClassifier(this);
                abs = new AbsDiff(this);
            }
            else
            {
                btnVideo.Text = "Start Video";
                timerFPS.Enabled = false;
                timerGrab.Enabled = false;

                if (videoCapture.ptr != IntPtr.Zero)
                {
                    highgui.CvReleaseCapture(ref videoCapture);
                    videoCapture.ptr = IntPtr.Zero;
                }
            }
        }