unsigned char* videoInputCamera::getFrame()
{

	if (isFrameNew()){

		unsigned char * src = sgCallback->pixels;
		unsigned char *dest = cam_buffer;

		if (!cfg->color) {

			if (cfg->frame) flip_crop_rgb2gray(cfg->cam_width,src,dest);
			else flip_rgb2gray(cfg->cam_width,cfg->cam_height,src,dest);

		} else {

			if (cfg->frame) flip_crop(cfg->cam_width,cfg->cam_height,src,dest,cfg->buf_format);
			else flip(cfg->cam_width,cfg->cam_height,src,dest,cfg->buf_format);
		}

		lost_frames = 0;
		return cam_buffer;
	} else  {
		if (lost_frames>timeout) { // give up after 5 (at init) or 2 (at runtime) seconds
			disconnect = true;
			running = false;
		} lost_frames++;
		//Sleep(1);
		return NULL;
	}
}
Beispiel #2
0
void FileGrabber::update(){
	ofVideoPlayer::update();
	if(isFrameNew()){
		VideoFrame * frame = getNextVideoFrame();
		newFrameEvent.notify(this,*frame);
		frame->release();
	}
}
Beispiel #3
0
//--------------------------------------------------------------
void ofApp::setup(){
	ofSetVerticalSync(true); // this seems to have no effect on windows/64/glfw currently
	ofSetFrameRate(60);

	gui.init();
	auto rootGrid = gui.addGrid();

	auto deviceList = ofxBlackmagic::Iterator::getDeviceList();

	for(auto device : deviceList) {
		auto input = shared_ptr<ofxBlackmagic::Input>(new ofxBlackmagic::Input());

		static int index = 0;
		auto mode = bmdModeHD1080p30; // switch this mode to match the resolution/refresh of your input stream
		input->startCapture(device, mode);
		this->inputs.push_back(input);

		auto panel = make_shared<ofxCvGui::Panels::Draws>(*input);
		panel->setCaption(input->getDevice().modelName);

		panel->onDraw += [input] (ofxCvGui::DrawArguments&) {
			if (input->isFrameNew()) {
				ofxCvGui::Utils::drawText("New frame", 30, 90);
			}
		};

		rootGrid->add(panel);
	}

	gui.addInspector();


	ofxCvGui::InspectController::X().onClear += [this](ofxCvGui::InspectArguments & args) {
		args.inspector->add(ofxCvGui::Widgets::LiveValueHistory::make("FPS", []() {
			return ofGetFrameRate();
		}));

		for (auto input : this->inputs) {
			args.inspector->add(ofxCvGui::Widgets::LiveValue<string>::make("Timecode", [input]() {
				stringstream ss;
				ss << input->getFrame().getTimecode();
				return ss.str();
			}));
		}
	};

	ofxCvGui::InspectController::X().clear();
}