public HighGuiTrackbar(HighGuiWindow window, string name, int initial, int limit) { this.window = window; this.name = name; position.Value = initial; onTrackbarHolder = new OnTrackbar(OnTrackbarCallback); int wnd = HighGui.cvCreateTrackbar(name, window.Name, position.Pointer, limit, Marshal.GetFunctionPointerForDelegate(onTrackbarHolder)); SetHandle(new IntPtr(wnd)); }
void DrawSquares(List<CvPoint> squares, PieceInfo[] pieces, HighGuiWindow window) { using (IplImage cpy = lastFrame.CloneImage()) { StructureSafeMemoryBox<CvPoint> pt = new StructureSafeMemoryBox<CvPoint>(4); IntPtrSafeMemoryBox rect = new IntPtrSafeMemoryBox(); rect.Value = pt.Pointer; Int32SafeMemoryBox count = new Int32SafeMemoryBox(); count.Value = 4; for (int i = 0; i < squares.Count; i += 4) { pt[0] = squares[i + 0]; pt[1] = squares[i + 1]; pt[2] = squares[i + 2]; pt[3] = squares[i + 3]; CvPoint center = new CvPoint((squares[i + 0].x + squares[i + 2].x) / 2, (squares[i + 0].y + squares[i + 2].y) / 2); // CvScalar color = new CvScalar(0, 255, 255); CxCore.cvPolyLine(cpy, rect.Pointer, count.Pointer, 1, 1, CvScalar.FromRGB(255, 255, 0), 3, CxCore.CV_AA, 0); } PieceInfo[,] layout = lastLayout; if (layout != null) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { pt[0] = new CvPoint(j * 20 + 3, i * 20 + 3); pt[1] = new CvPoint(j * 20 + 3, i * 20 + 18); pt[2] = new CvPoint(j * 20 + 18, i * 20 + 18); pt[3] = new CvPoint(j * 20 + 18, i * 20 + 3); CvScalar color = CvScalar.FromRGB(layout[i, j].color[0], layout[i, j].color[1], layout[i, j].color[2]); CxCore.cvFillPoly(cpy, rect.Pointer, count.Pointer, 1, color, CxCore.CV_AA, 0); } } } count.Dispose(); rect.Dispose(); pt.Dispose(); window.ShowImage(cpy); } }
private void CaptureFramesThread() { try { isBusy = true; using (window = new HighGuiWindow(Title)) { IntPtr hWnd = HighGui.cvGetWindowHandle(Title); using (capture = new CvCapture(0)) { IplImage frame = capture.GetNextFrame(); OnInitialize(frame); while (true) { if (flipImage) IplImage.Flip(frame, lastFrame, 0); else frame.CopyTo(lastFrame); ProcessFrame(); const int EscapeKey = 27; const int InterFrameDelay = 50; if (closing) break; int key = HighGui.cvWaitKey(InterFrameDelay); if (!IsWindowVisible(hWnd) || key == EscapeKey) { Hide(); OnClosed(); break; } frame = capture.GetNextFrame(); } } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Camera error: " + ex.ToString()); OnCameraError(); } isBusy = false; }