Skip to content

Instantly share code, notes, and snippets.

@tyhenry
Created January 30, 2022 15:33
Show Gist options
  • Save tyhenry/c3d998994b9145f0d9c32ffef90f4afe to your computer and use it in GitHub Desktop.
Save tyhenry/c3d998994b9145f0d9c32ffef90f4afe to your computer and use it in GitHub Desktop.
ofxVimba sample
#include "ofApp.h"
using namespace cv;
using namespace ofxCv;
using namespace ofxVimba;
#define PAUSE_EXIT_FAILURE cout << "press any key to quit" << endl; std::cin.get(); ofExit(EXIT_FAILURE);
//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(0);
// ---------------- //
// setup vimba cams //
// ---------------- //
auto cams = camL.listDevices();
bool bHasCams = false;
if (cams.size() > 1) {
bHasCams =
camL.open(cams[0]) // TODO: replace with actual ID
&& camR.open(cams[1]);
}
if (!bHasCams) {
PAUSE_EXIT_FAILURE;
}
ofSetLogLevel("ofxVimbaCam", OF_LOG_ERROR);
}
//--------------------------------------------------------------
void ofApp::update() {
camL.update();
camR.update();
// detect faces
if (camL.isFrameNew()) {
resize(toCv(camL.getFrame()), camLGray, Size(), 0.5, 0.5);
cvtColor(camLGray, camLGray, CV_RGB2GRAY);
int nL = faceDetector.detectFaces(
facesL,
(unsigned char*)(camLGray.ptr(0)), camLGray.cols, camLGray.rows, (int)camLGray.step,
1.2f, 3, 48
);
}
if (camR.isFrameNew()) {
resize(toCv(camR.getFrame()), camRGray, Size(), 0.5, 0.5);
cvtColor(camRGray, camRGray, CV_RGB2GRAY);
int nR = faceDetector.detectFaces(
facesR,
(unsigned char*)(camRGray.ptr(0)), camRGray.cols, camRGray.rows, (int)camRGray.step,
1.2f, 3, 48
);
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255);
// draw splitscreen stereo cams
float camW = camL.getCamWidth();
float scale = ( camW > 0 ) ? ( ofGetWidth() * 0.5 / camL.getCamWidth() ) : 1;
ofPushMatrix();
ofScale(scale,scale);
ofSetLineWidth(10);
ofNoFill();
camL.draw(0,0);
// draw bounding box
ofSetColor(ofColor::red);
for (auto& face : facesL) {
ofDrawRectangle(face.x*2,face.y*2,face.w*2,face.h*2);
}
ofSetColor(255);
ofTranslate(camL.getCamWidth(),0);
camR.draw(0,0);
// draw bounding box
ofSetColor(ofColor::blue);
for (auto& face : facesR) {
ofDrawRectangle(face.x*2,face.y*2,face.w*2,face.h*2);
}
ofFill();
ofSetLineWidth(1);
ofSetColor(255);
ofPopMatrix();
ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate()), 10, 20);
}
#pragma once
#include "ofMain.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "ofxCv.h"
#include "ofxVimba.h"
#include "FaceDetector.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
ofxVimba::ofxVimbaCam camL, camR;
cv::Mat camLGray, camRGray;
FaceDetector faceDetector;
vector<FaceDetector::Face> facesL;
vector<FaceDetector::Face> facesR;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment