@alberto2000 wrote:
Hi, I'm trying to get a video input from a 1920x1080 @ 30 fps USB 3.0 camera and output it again at the same resolution and framerate running on an UpBoard (www.up-board.org). The way I've programmed it now is below but I only get about 15 fps and I wonder if there's any improvements in the way I programmed to improve efficiency and performance.
Basically, I take the video from the camera, make background substraction (on backspace keypress) resp. substract the new image from the last saved one and then output the difference image again.
Thanks for any help on this, I'm quite new to C++ and Graphics programming.
--
myApp.h
#pragma once #include "ofMain.h" #include "hgDraw.h" #include "ofxOpenCv.h" #include "ofxCv.h" class hgApp : public ofBaseApp { public: void setup(); void update(); void draw(); ofImage *getOutputImagePointer(); void keyPressed(int key); private: ofVideoGrabber vidGrabber; ofImage outputImage; ofPixels bgImage, diffImage; cv::Mat camMat, bgMat, diffMat; hgDraw drawManager; };
--
myApp.cpp
#include "hgApp.h" void hgApp::setup() { ofSetFrameRate(30); ofSetVerticalSync(true); vidGrabber.setDeviceID(0); vidGrabber.setDesiredFrameRate(30); vidGrabber.setup(1920, 1080); ofxCv::imitate(outputImage, vidGrabber); ofxCv::imitate(bgImage, vidGrabber); ofxCv::imitate(diffImage, vidGrabber); drawManager.setup(getOutputImagePointer()); } void hgApp::update() { ofSetWindowTitle("Framerate: " + ofToString(ofGetFrameRate(), 2)); vidGrabber.update(); if(vidGrabber.isFrameNew()) { camMat = ofxCv::toCv(vidGrabber); bgMat = ofxCv::toCv(bgImage); diffMat = ofxCv::toCv(diffImage); cv::absdiff(bgMat, camMat, diffMat); ofxCv::toOf(diffMat, outputImage); outputImage.update(); } } void hgApp::draw() { drawManager.draw(); } ofImage *hgApp::getOutputImagePointer() { ofImage *outputPointer = &outputImage; return outputPointer; } void hgApp::keyPressed(int key) { camMat.copyTo(bgMat); }
--
myDrawer.h
#pragma once #include "ofMain.h" #include "ofxOpenCv.h" #include "ofxCv.h" class hgDraw { public: void setup(ofImage const *_playoutImage); void draw(); private: ofImage const *playoutImage; };
--
myDrawer.cpp
#include "hgDraw.h" void hgDraw::setup(ofImage const *_playoutImage) { playoutImage = _playoutImage; } void hgDraw::draw() { ofBackground(0); ofSetColor(255); ofNoFill(); playoutImage->draw(0, 0); }
Posts: 1
Participants: 1