Skip to content

Instantly share code, notes, and snippets.

@eightlines
Created September 5, 2013 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eightlines/6450537 to your computer and use it in GitHub Desktop.
Save eightlines/6450537 to your computer and use it in GitHub Desktop.
Omek Beckon SDK for Panasonic for openFrameworks
#include "DIMager.h"
DIMager::DIMager() {
motionSensor = IMotionSensor::createCameraSensor();
if (!motionSensor) cout << "Camera not found." << endl;
sensor = motionSensor->getSensor();
if(!sensor->isAlive()) cout << "Failed to initialize." << endl;
motionSensor->setVerbosityLevel(3, "log4cxx.cfg");
cout << "Flip Image " << sensor->setCameraParameter("flipped", 1) << endl;
cout << "Set Max Players (2) " << motionSensor->setMaxCandidates(2) << endl;
width = sensor->getImageWidth(IMAGE_TYPE_COLOR);
height = sensor->getImageHeight(IMAGE_TYPE_COLOR);
channels = sensor->getImageChannels(IMAGE_TYPE_COLOR);
bpp = sensor->getImageBpp(IMAGE_TYPE_COLOR) / 8; // Bits Per Pixel
imageBufferSize = width * height * channels * bpp;
depth.allocate(width, height, GL_LUMINANCE);
mask.allocate(width, height, GL_LUMINANCE);
if (motionSensor->run() == OMK_SUCCESS) cout << "DImager Running" << endl;
}
void DIMager::update() {
updateDepth();
updateMask();
}
void DIMager::updateDepth() {
int widthStep = 0;
char *cDepth = (char *)malloc(imageBufferSize * sizeof(char*));
unsigned char *ucDepth = (unsigned char *)cDepth;
ofPixels pix;
pix.allocate(width, height, OF_IMAGE_GRAYSCALE);
pix.setFromExternalPixels(ucDepth, width, height, 2);
if (motionSensor->hasNewFrameData(0)) {
if (motionSensor->copyRawImage(cDepth, imageBufferSize, widthStep, true) == OMK_SUCCESS) {
depth.loadData(pix);
}
}
delete cDepth;
}
void DIMager::updateMask() {
int numPlayers = motionSensor->getNumOfPlayers();
if (numPlayers > 0) {
char *cMask = (char *)malloc(imageBufferSize * sizeof(char*));
unsigned char *ucMask = (unsigned char *)cMask;
int w, h;
float cen3D[] = {0, 0, 0};
float cen2D[] = {0, 0};
ofPixels pix;
pix.allocate(width, height, OF_IMAGE_GRAYSCALE);
pix.setFromExternalPixels(ucMask, width, height, 1);
if (motionSensor->copyPlayerMask(cMask, imageBufferSize, 0, w, h, cen3D, cen2D) == OMK_SUCCESS) {
mask.loadData(pix);
}
delete cMask;
}
}
ofTexture DIMager::getTexture(int view) {
if (view == MASK) {
return mask;
} else {
return depth;
}
}
ofPixels DIMager::getPixels(int view) {
ofPixels p;
if (view == MASK) mask.readToPixels(p);
return p;
}
int DIMager::getWidth() {
return width;
}
int DIMager::getHeight() {
return height;
}
int DIMager::getParticipants() {
return motionSensor->getNumOfPlayers();
}
#pragma once
#include "ofMain.h"
#include "Shadow/ISensor.h"
#include "Shadow/IMotionSensor.h"
#include "Shadow/ShadowDefines.h"
using namespace Omek;
class DIMager {
public:
enum VIEW {
DEPTH,
MASK
};
DIMager();
void update();
ofTexture getTexture(int view);
ofPixels getPixels(int view);
int getWidth();
int getHeight();
int getParticipants();
private:
IMotionSensor *motionSensor;
ISensor *sensor;
int width, height, channels, bpp;
unsigned int imageBufferSize;
ofTexture depth, mask;
void updateDepth();
void updateMask();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment