Skip to content

Commit

Permalink
NEW: Kinect configuration parameters to control image stream speed
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurnishimoto committed Jan 22, 2019
1 parent c41741b commit ba74cf4
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 31 deletions.
8 changes: 5 additions & 3 deletions data/oinputserver.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ config:
// Microsoft Speech Platform SDK 11 required for KinectSpeech
MSKinectService:
{
checkInterval = 2.0;
updateInterval = 1.0;
imageStreamInterval = 0.05;

debug = false;

// Body Tracking
Expand All @@ -73,10 +75,10 @@ config:
confidenceThreshold = 0.3;

// Color stream
enableKinectColor = false;
enableKinectColor = true;

// Depth stream
enableKinectDepth = true;
enableKinectDepth = false;
lowDetailMaxDistance = 3000; // millimeters
};
/*
Expand Down
12 changes: 9 additions & 3 deletions include/omicron/MSKinect2Service.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**************************************************************************************************
* THE OMICRON PROJECT
*-------------------------------------------------------------------------------------------------
* Copyright 2010-2016 Electronic Visualization Laboratory, University of Illinois at Chicago
* Copyright 2010-2019 Electronic Visualization Laboratory, University of Illinois at Chicago
* Authors:
* Arthur Nishimoto [email protected]
*-------------------------------------------------------------------------------------------------
* Copyright (c) 2010-2016, Electronic Visualization Laboratory, University of Illinois at Chicago
* Copyright (c) 2010-2019, Electronic Visualization Laboratory, University of Illinois at Chicago
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
Expand Down Expand Up @@ -217,6 +217,9 @@ class MSKinectService: public Service
MSKinectService* mysInstance;
float myUpdateInterval;
float myCheckKinectInterval;
float lastUpdateTime;
float lastSendTime;
int currentPacket = 0;

static const int cScreenWidth = 320;
static const int cScreenHeight = 240;
Expand All @@ -240,9 +243,12 @@ class MSKinectService: public Service
// Color reader
IColorFrameReader* m_pColorFrameReader;
RGBQUAD* m_pColorRGBX;
BYTE* color_pImage;
bool color_pImageReady = false;
int currentFrameTimestamp;

// Color event buffer
byte imageBuffer[41472];
byte imageEventBuffer[41472];

// Depth reader
IDepthFrameReader* m_pDepthFrameReader;
Expand Down
3 changes: 2 additions & 1 deletion src/omicron/omicron/InputServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ void InputServer::handleEvent(const Event& evt)
}
else
{
client->sendEvent(eventPacketLarge, 32768);
client->sendEvent(eventPacketLarge, 51200);
//ofmsg("Sent frame %1% %2%", %evt.getSourceId() %evt.getFlags());
}
}
else
Expand Down
88 changes: 64 additions & 24 deletions src/omicron/omicron/MSKinect2Service.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**************************************************************************************************
* THE OMICRON PROJECT
*-------------------------------------------------------------------------------------------------
* Copyright 2010-2016 Electronic Visualization Laboratory, University of Illinois at Chicago
* Copyright 2010-2019 Electronic Visualization Laboratory, University of Illinois at Chicago
* Authors:
* Arthur Nishimoto [email protected]
*-------------------------------------------------------------------------------------------------
* Copyright (c) 2010-2016, Electronic Visualization Laboratory, University of Illinois at Chicago
* Copyright (c) 2010-2019, Electronic Visualization Laboratory, University of Illinois at Chicago
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
Expand Down Expand Up @@ -72,7 +72,7 @@ MSKinectService::MSKinectService(){
void MSKinectService::setup(Setting& settings)
{
myUpdateInterval = Config::getFloatValue("updateInterval", settings, 0.01f);
myCheckKinectInterval = Config::getFloatValue("checkInterval", settings, 2.00f);
myCheckKinectInterval = Config::getFloatValue("imageStreamInterval", settings, 0.2f);

m_bSeatedMode = Config::getBoolValue("seatedMode", settings, false);

Expand Down Expand Up @@ -145,13 +145,57 @@ void MSKinectService::poll()
{
pollBody();
}
if (enableKinectColor)

float lastt = lastUpdateTime;

float curt = (float)((double)clock() / CLOCKS_PER_SEC);
if (curt - lastt > mysInstance->myUpdateInterval)
{
pollColor();
if (!color_pImageReady)
{
if (enableKinectColor)
{
pollColor();
}
}

if (enableKinectDepth)
{
pollDepth();
}
lastUpdateTime = curt;
}
if (enableKinectDepth)

if (color_pImageReady && curt - lastSendTime > mysInstance->myCheckKinectInterval)
{
pollDepth();
unsigned long pImageSize = cColorWidth * cColorHeight * sizeof(RGBQUAD);

int nPackets = 270; // 1920 * 1080 = 2073600 * 4 = 8294400 / 256 = 32400 (max imageBuffer size = 41472)
int dataPacketSize = pImageSize / nPackets;

int eventsPerUpdate = 10;

for (int i = 0; i < eventsPerUpdate; i++)
{
memcpy(imageEventBuffer, &color_pImage[currentPacket * dataPacketSize], dataPacketSize);
Event* evt = mysInstance->writeHead();
evt->reset(Event::Update, Service::Generic, currentFrameTimestamp);
evt->setPosition(cColorWidth, cColorHeight, 0); // Position: imageWidth, imageHeight, typeFlag (Color = 0, Depth = 1)
evt->setFlags(currentPacket);

evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageEventBuffer);
mysInstance->unlockEvents();
currentPacket++;

if (currentPacket > nPackets - 1)
{
currentPacket = 0;
color_pImageReady = false;
break;
}
}

lastSendTime = curt;
}
#ifdef OMICRON_USE_KINECT_FOR_WINDOWS_AUDIO
if( enableKinectAudio )
Expand Down Expand Up @@ -283,22 +327,13 @@ void MSKinectService::pollColor()

if (SUCCEEDED(hr))
{
BYTE* pImage = reinterpret_cast<BYTE*>(pBuffer);
unsigned long pImageSize = cColorWidth * cColorHeight * sizeof(RGBQUAD);
color_pImage = reinterpret_cast<BYTE*>(pBuffer);

int nPackets = 270; // 1920 * 1080 = 2073600 * 4 = 8294400 / 256 = 32400 (max imageBuffer size = 41472)
int dataPacketSize = pImageSize / nPackets;

for (int i = 0; i < nPackets; i++)
{
memcpy(imageBuffer, &pImage[i * dataPacketSize], dataPacketSize);
Event* evt = mysInstance->writeHead();
evt->reset(Event::Update, Service::Generic, 0);
evt->setFlags(i);
color_pImageReady = true;

evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageBuffer);
mysInstance->unlockEvents();
}
timeb tb;
ftime(&tb);
currentFrameTimestamp = tb.millitm + (tb.time & 0xfffff) * 1000;
}

SafeRelease(pFrameDescription);
Expand Down Expand Up @@ -417,14 +452,19 @@ void MSKinectService::pollDepth()
int nPackets = 32; // 512 * 424 = 217088 * 4 = 868352 / 32 = 27136 (max imageBuffer size = 41472)
int dataPacketSize = pImageSize / nPackets;

timeb tb;
ftime(&tb);
int timestamp = tb.millitm + (tb.time & 0xfffff) * 1000;

for (int i = 0; i < nPackets; i++)
{
memcpy(imageBuffer, &pImage[i * dataPacketSize], dataPacketSize);
memcpy(imageEventBuffer, &pImage[i * dataPacketSize], dataPacketSize);
Event* evt = mysInstance->writeHead();
evt->reset(Event::Update, Service::Generic, 1);
evt->reset(Event::Update, Service::Generic, timestamp);
evt->setPosition(cDepthWidth, cDepthHeight, 1); // Position: imageWidth, imageHeight, typeFlag (Color = 0, Depth = 1)
evt->setFlags(i);

evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageBuffer);
evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageEventBuffer);
mysInstance->unlockEvents();
}
}
Expand Down

0 comments on commit ba74cf4

Please sign in to comment.