// Open video source public bool openInputSource(string identifier, TInputType type, bool isAutoPlay) { IVideoSource source; switch (type) { case TInputType.IMAGE: source = new ImageSource(); break; case TInputType.VIDEO: source = new VideoFileSource(); break; case TInputType.DEVICE: source = new CaptureDevice(); break; default: return(false); } source.VideoSource = identifier; // close previous file closeInputSource(); // create camera CCamera camera = new CCamera(source); // attach camera to camera window _cameraWindow.postRenderingEvent = postRenderingEvent; _cameraWindow.camera = camera; _cameraWindow.camera.preRenderingEvent = preRenderingEvent; _inputType = type; if (isAutoPlay) { play(); } else { //getFirstFrame(); } // reset statistics _statIndex = _statReady = 0; return(true); }
// On timer event - count fps private void _timer_Tick(object sender, EventArgs e) { CCamera camera = cameraWindow.camera; if (camera != null) { if (_inputType == TInputType.VIDEO) { _fps = camera.fps; } else if (_inputType != TInputType.IMAGE) { // get number of frames for the last second _statCount[_statIndex] = camera.framesReceived; // increment indexes if (++_statIndex >= _statLength) { _statIndex = 0; } if (_statReady < _statLength) { _statReady++; } float fps = 0; // calculate average value for (int i = 0; i < _statReady; i++) { fps += _statCount[i]; } fps /= _statReady; _statCount[_statIndex] = 0; _fps = fps; } } }