Skip to content

Commit ba74cf4

Browse files
NEW: Kinect configuration parameters to control image stream speed
1 parent c41741b commit ba74cf4

File tree

4 files changed

+80
-31
lines changed

4 files changed

+80
-31
lines changed

data/oinputserver.cfg

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ config:
5555
// Microsoft Speech Platform SDK 11 required for KinectSpeech
5656
MSKinectService:
5757
{
58-
checkInterval = 2.0;
58+
updateInterval = 1.0;
59+
imageStreamInterval = 0.05;
60+
5961
debug = false;
6062

6163
// Body Tracking
@@ -73,10 +75,10 @@ config:
7375
confidenceThreshold = 0.3;
7476

7577
// Color stream
76-
enableKinectColor = false;
78+
enableKinectColor = true;
7779

7880
// Depth stream
79-
enableKinectDepth = true;
81+
enableKinectDepth = false;
8082
lowDetailMaxDistance = 3000; // millimeters
8183
};
8284
/*

include/omicron/MSKinect2Service.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**************************************************************************************************
22
* THE OMICRON PROJECT
33
*-------------------------------------------------------------------------------------------------
4-
* Copyright 2010-2016 Electronic Visualization Laboratory, University of Illinois at Chicago
4+
* Copyright 2010-2019 Electronic Visualization Laboratory, University of Illinois at Chicago
55
* Authors:
66
* Arthur Nishimoto [email protected]
77
*-------------------------------------------------------------------------------------------------
8-
* Copyright (c) 2010-2016, Electronic Visualization Laboratory, University of Illinois at Chicago
8+
* Copyright (c) 2010-2019, Electronic Visualization Laboratory, University of Illinois at Chicago
99
* All rights reserved.
1010
* Redistribution and use in source and binary forms, with or without modification, are permitted
1111
* provided that the following conditions are met:
@@ -217,6 +217,9 @@ class MSKinectService: public Service
217217
MSKinectService* mysInstance;
218218
float myUpdateInterval;
219219
float myCheckKinectInterval;
220+
float lastUpdateTime;
221+
float lastSendTime;
222+
int currentPacket = 0;
220223

221224
static const int cScreenWidth = 320;
222225
static const int cScreenHeight = 240;
@@ -240,9 +243,12 @@ class MSKinectService: public Service
240243
// Color reader
241244
IColorFrameReader* m_pColorFrameReader;
242245
RGBQUAD* m_pColorRGBX;
246+
BYTE* color_pImage;
247+
bool color_pImageReady = false;
248+
int currentFrameTimestamp;
243249

244250
// Color event buffer
245-
byte imageBuffer[41472];
251+
byte imageEventBuffer[41472];
246252

247253
// Depth reader
248254
IDepthFrameReader* m_pDepthFrameReader;

src/omicron/omicron/InputServer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ void InputServer::handleEvent(const Event& evt)
253253
}
254254
else
255255
{
256-
client->sendEvent(eventPacketLarge, 32768);
256+
client->sendEvent(eventPacketLarge, 51200);
257+
//ofmsg("Sent frame %1% %2%", %evt.getSourceId() %evt.getFlags());
257258
}
258259
}
259260
else

src/omicron/omicron/MSKinect2Service.cpp

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**************************************************************************************************
22
* THE OMICRON PROJECT
33
*-------------------------------------------------------------------------------------------------
4-
* Copyright 2010-2016 Electronic Visualization Laboratory, University of Illinois at Chicago
4+
* Copyright 2010-2019 Electronic Visualization Laboratory, University of Illinois at Chicago
55
* Authors:
66
* Arthur Nishimoto [email protected]
77
*-------------------------------------------------------------------------------------------------
8-
* Copyright (c) 2010-2016, Electronic Visualization Laboratory, University of Illinois at Chicago
8+
* Copyright (c) 2010-2019, Electronic Visualization Laboratory, University of Illinois at Chicago
99
* All rights reserved.
1010
* Redistribution and use in source and binary forms, with or without modification, are permitted
1111
* provided that the following conditions are met:
@@ -72,7 +72,7 @@ MSKinectService::MSKinectService(){
7272
void MSKinectService::setup(Setting& settings)
7373
{
7474
myUpdateInterval = Config::getFloatValue("updateInterval", settings, 0.01f);
75-
myCheckKinectInterval = Config::getFloatValue("checkInterval", settings, 2.00f);
75+
myCheckKinectInterval = Config::getFloatValue("imageStreamInterval", settings, 0.2f);
7676

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

@@ -145,13 +145,57 @@ void MSKinectService::poll()
145145
{
146146
pollBody();
147147
}
148-
if (enableKinectColor)
148+
149+
float lastt = lastUpdateTime;
150+
151+
float curt = (float)((double)clock() / CLOCKS_PER_SEC);
152+
if (curt - lastt > mysInstance->myUpdateInterval)
149153
{
150-
pollColor();
154+
if (!color_pImageReady)
155+
{
156+
if (enableKinectColor)
157+
{
158+
pollColor();
159+
}
160+
}
161+
162+
if (enableKinectDepth)
163+
{
164+
pollDepth();
165+
}
166+
lastUpdateTime = curt;
151167
}
152-
if (enableKinectDepth)
168+
169+
if (color_pImageReady && curt - lastSendTime > mysInstance->myCheckKinectInterval)
153170
{
154-
pollDepth();
171+
unsigned long pImageSize = cColorWidth * cColorHeight * sizeof(RGBQUAD);
172+
173+
int nPackets = 270; // 1920 * 1080 = 2073600 * 4 = 8294400 / 256 = 32400 (max imageBuffer size = 41472)
174+
int dataPacketSize = pImageSize / nPackets;
175+
176+
int eventsPerUpdate = 10;
177+
178+
for (int i = 0; i < eventsPerUpdate; i++)
179+
{
180+
memcpy(imageEventBuffer, &color_pImage[currentPacket * dataPacketSize], dataPacketSize);
181+
Event* evt = mysInstance->writeHead();
182+
evt->reset(Event::Update, Service::Generic, currentFrameTimestamp);
183+
evt->setPosition(cColorWidth, cColorHeight, 0); // Position: imageWidth, imageHeight, typeFlag (Color = 0, Depth = 1)
184+
evt->setFlags(currentPacket);
185+
186+
evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageEventBuffer);
187+
mysInstance->unlockEvents();
188+
currentPacket++;
189+
190+
if (currentPacket > nPackets - 1)
191+
{
192+
currentPacket = 0;
193+
color_pImageReady = false;
194+
break;
195+
}
196+
}
197+
198+
lastSendTime = curt;
155199
}
156200
#ifdef OMICRON_USE_KINECT_FOR_WINDOWS_AUDIO
157201
if( enableKinectAudio )
@@ -283,22 +327,13 @@ void MSKinectService::pollColor()
283327

284328
if (SUCCEEDED(hr))
285329
{
286-
BYTE* pImage = reinterpret_cast<BYTE*>(pBuffer);
287-
unsigned long pImageSize = cColorWidth * cColorHeight * sizeof(RGBQUAD);
330+
color_pImage = reinterpret_cast<BYTE*>(pBuffer);
288331

289-
int nPackets = 270; // 1920 * 1080 = 2073600 * 4 = 8294400 / 256 = 32400 (max imageBuffer size = 41472)
290-
int dataPacketSize = pImageSize / nPackets;
291-
292-
for (int i = 0; i < nPackets; i++)
293-
{
294-
memcpy(imageBuffer, &pImage[i * dataPacketSize], dataPacketSize);
295-
Event* evt = mysInstance->writeHead();
296-
evt->reset(Event::Update, Service::Generic, 0);
297-
evt->setFlags(i);
332+
color_pImageReady = true;
298333

299-
evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageBuffer);
300-
mysInstance->unlockEvents();
301-
}
334+
timeb tb;
335+
ftime(&tb);
336+
currentFrameTimestamp = tb.millitm + (tb.time & 0xfffff) * 1000;
302337
}
303338

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

455+
timeb tb;
456+
ftime(&tb);
457+
int timestamp = tb.millitm + (tb.time & 0xfffff) * 1000;
458+
420459
for (int i = 0; i < nPackets; i++)
421460
{
422-
memcpy(imageBuffer, &pImage[i * dataPacketSize], dataPacketSize);
461+
memcpy(imageEventBuffer, &pImage[i * dataPacketSize], dataPacketSize);
423462
Event* evt = mysInstance->writeHead();
424-
evt->reset(Event::Update, Service::Generic, 1);
463+
evt->reset(Event::Update, Service::Generic, timestamp);
464+
evt->setPosition(cDepthWidth, cDepthHeight, 1); // Position: imageWidth, imageHeight, typeFlag (Color = 0, Depth = 1)
425465
evt->setFlags(i);
426466

427-
evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageBuffer);
467+
evt->setExtraData(EventBase::ExtraDataString, dataPacketSize, 1, imageEventBuffer);
428468
mysInstance->unlockEvents();
429469
}
430470
}

0 commit comments

Comments
 (0)