/// <summary> /// Initialize camera input, frame window and other image objects required. /// This is done after getting the settings of the tracker object of this class. /// </summary> private void InitializeCamera() { // Intialize camera try { //videoInput = new VideoInput(); capture = new CvCapture(CaptureDevice.Any, deviceID); DefaultBrightness = (int)capture.Brightness; } catch (Exception exception) { System.Windows.MessageBox.Show("Failed to initialize the camera, the program will be closed." + "\n\nThis is the internal error:\n" + exception.Message, "Notify", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information); System.Diagnostics.Process.GetCurrentProcess().Kill(); } // small frame to decrease computational complexity size = new CvSize(320, 240); capture.SetCaptureProperty(CaptureProperty.FrameHeight, size.Height); capture.SetCaptureProperty(CaptureProperty.FrameWidth, size.Width); capture.SetCaptureProperty(CaptureProperty.FrameCount, 15); frame1 = new IplImage(size, BitDepth.U8, 3); frame2 = new IplImage(size, BitDepth.U8, 3); grayFrame1 = new IplImage(size, BitDepth.U8, 1); grayFrame2 = new IplImage(size, BitDepth.U8, 1); transformedFrame = new IplImage(size, BitDepth.U8, 1); sift = new SIFT(); surf = new SURF(500, 4, 2, true); bruteForceMatcher = new BFMatcher(NormType.L2, false); flannBasedMatcher = new FlannBasedMatcher(); // windows to view what's going on window1 = new CvWindow("Camera 1", WindowMode.KeepRatio); window1.Resize(size.Width, size.Height); window1.Move(screenWidth - 17 - 2 * size.Width, 20); window2 = new CvWindow("Camera 2", WindowMode.KeepRatio); window2.Resize(size.Width, size.Height); window2.Move(screenWidth - 20 - 1 * size.Width, 20); window3 = new CvWindow("Result", WindowMode.KeepRatio); window3.Resize(size.Width * 2, size.Height); window3.Move(screenWidth - 20 - 2 * size.Width, 20 + size.Height); }
/// <summary> /// Initialize Camera, timer and some objects. /// </summary> private void Initialize() { // for generating random numbers random = new Random(); children = new IplImage[GenerationNo]; // initialize mainTimer workingThread = new Thread(new ThreadStart(Process)); // initialize timer used to count frames per seconds of the camera fpsTimer = new System.Windows.Forms.Timer(); fpsTimer.Interval = 1000; fpsTimer.Tick += new EventHandler((object obj, EventArgs eventArgs) => { labelFrameCounter.Content = counter.ToString(); }); // windows to view what's going on window1 = new CvWindow("Camera 1", WindowMode.KeepRatio); string imagePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Images\Monalisa.png"); frame = new IplImage(imagePath); size = new CvSize(frame.Width, frame.Height); int offset = 10; window1.Resize(size.Width, size.Height); window1.Move(screenWidth - (size.Width + offset) * 1, 20); window2 = new CvWindow("Camera 2", WindowMode.KeepRatio); window2.Resize(size.Width, size.Height); window2.Move(screenWidth - (size.Width + offset) * 2, 20); grayFrame = new IplImage(size, BitDepth.U8, 1); Cv.CvtColor(frame, grayFrame, ColorConversion.BgrToGray); parent = new IplImage(size, BitDepth.U8, 1); // show image on the separate window window1.Image = grayFrame; }
public IplImage BinarizerMethod_Hist(IplImage src) { bina = new IplImage(src.Size, BitDepth.U8, 1); gray = this.GrayScale(src); int area = 200; int num = 0; int row = (src.Width % area == 0) ? (int)(src.Width / area) : (int)(src.Width / area + 1); int col = (src.Height % area == 0) ? (int)(src.Height / area) : (int)(src.Height / area + 1); int count = row * col; float[] data = new float[count]; IplImage[] piece = new IplImage[count]; CvRect[] piece_roi = new CvRect[count]; for (int x = 0; x < src.Width; x = x + area) { for (int y = 0; y < src.Height; y = y + area) { CvRect roi = new CvRect { X = x, Y = y, Width = area, Height = area }; if (roi.X + roi.Width > src.Width) { roi.Width = area - ((roi.X + roi.Width) - src.Width); } if (roi.Y + roi.Height > src.Height) { roi.Height = area - ((roi.Y + roi.Height) - src.Height); } gray.SetROI(roi); piece[num] = new IplImage(gray.ROI.Size, BitDepth.U8, 1); Cv.Copy(gray, piece[num]); gray.ResetROI(); //히스토그램 계산// int[] size = { area }; CvHistogram hist = new CvHistogram(size, HistogramFormat.Array); Cv.CalcHist(piece[num], hist); float minValue, maxValue; hist.GetMinMaxValue(out minValue, out maxValue); int highlevel = 0; for (int i = 0; i < area; i++) { if (maxValue == hist.Bins[i].Val0) { highlevel = i; } } piece_roi[num] = roi; data[num] = highlevel; num++; } } CvMat kernel = new CvMat(row, col, MatrixType.F32C1, data); Cv.Normalize(kernel, kernel, 255, 0, NormType.C); for (int r = 0; r < count; r++) { Cv.Threshold(piece[r], piece[r], kernel[r], 255, ThresholdType.Otsu); Cv.SetImageROI(bina, piece_roi[r]); Cv.Copy(piece[r], bina); bina.ResetROI(); } //37강 - 윈도우 창// CvWindow win = new CvWindow("window", WindowMode.StretchImage, src); win.Resize(640, 480); win.Move(100, 0); win.ShowImage(piece[0]); win.Close(); new CvWindow(piece[0]).Move(0, 0); new CvWindow(piece[1]).Move(0, 200); new CvWindow(piece[2]).Move(0, 400); //37강 - 윈도우 창// return(bina); }
/// <summary> /// Initialize camera input, frame window and other image objects required. /// This is done after getting the settings of the tracker object of this class. /// </summary> public void InitilizeCamera() { // Intialize camera try { //capture_ = new Capture(1); videoInput = new VideoInput(); } catch (Exception exception) { MessageBox.Show("Failed to initialize the camera, the program will be closed." + "\n\nThis is the internal error:\n" + exception.Message, "Notify", MessageBoxButtons.OK, MessageBoxIcon.Information); System.Diagnostics.Process.GetCurrentProcess().Kill(); } // small frame to decrease computational complexity size = new CvSize(320, 240); videoInput.SetupDevice(deviceID, size.Width, size.Height); videoInput.SetIdealFramerate(deviceID, 30); frame = new IplImage(size, BitDepth.U8, 3); grayFrame = new IplImage(size, BitDepth.U8, 1); transformedFrame = new IplImage(size, BitDepth.U8, 1); // window to view what's going on window = new CvWindow("Force Field Transform", WindowMode.KeepRatio); window.Resize(320, 240); window.Move(screenWidth - 614, 55); }