1 #include "VideoSource_Kinect2Net.hh"
3 #include <Base/Image/ImageIO.hh>
10 VideoSource_Kinect2Net::VideoSource_Kinect2Net(){
18 VideoSource_Kinect2Net::~VideoSource_Kinect2Net(){
21 void* VideoSource_Kinect2Net::runner(
void *args) {
29 std::vector<char> binary;
30 while (!n->stopThread_) {
34 GetSystemTimeAsFileTime((FILETIME*)&wintime);
35 wintime -= 116444736000000000i64;
36 ts.tv_sec = (long)(wintime / 10000000i64);
37 ts.tv_nsec = (long)(wintime % 10000000i64 *100);
39 clock_gettime(CLOCK_REALTIME, &ts);
42 if (n->client_.
GetData(
"img", binary) == 0) {
43 int semOk = sem_timedwait(&n->depthbuffer_.sProd, &ts);
45 std::cout <<
"net runner dropping frames!" << std::endl;
48 n->depthbuffer_.buffer[ n->depthbuffer_.curProd ].CopyIn_NoInit ( binary.data() );
49 n->depthbuffer_.curProd = (n->depthbuffer_.curProd+1) % buffersize_;
50 sem_post(&n->depthbuffer_.sCons);
52 semOk = sem_timedwait(&n->irbuffer_.sProd, &ts);
54 std::cout <<
"net runner dropping frames!" << std::endl;
58 n->irbuffer_.buffer[ n->irbuffer_.curProd ].CopyIn_NoInit ( binary.data()+512*424*
sizeof(float) );
59 n->irbuffer_.curProd = (n->irbuffer_.curProd+1) % buffersize_;
60 sem_post(&n->irbuffer_.sCons);
68 int VideoSource_Kinect2Net::OpenDevice(){
69 return OpenDevice(
"localhost", 8090);
72 int VideoSource_Kinect2Net::OpenDevice(std::string host,
int port) {
78 int VideoSource_Kinect2Net::CloseDevice(){
83 int VideoSource_Kinect2Net::PreGrab(){
85 pthread_create(&grabThread_, NULL, &runner,
this);
89 int VideoSource_Kinect2Net::PostGrab(){
91 pthread_join(grabThread_, NULL);
96 Image.
Init(512,424,1,ImageBase::ST_float);
101 Image.
Init(512,424,1,ImageBase::ST_float);
106 sem_wait(&irbuffer_.sCons);
107 image.
CopyIn_NoInit( irbuffer_.buffer[ irbuffer_.curCons ].GetImageData() );
108 irbuffer_.curCons = (irbuffer_.curCons+1) % buffersize_;
109 sem_post(&irbuffer_.sProd);
114 sem_wait(&depthbuffer_.sCons);
115 image.
CopyIn_NoInit( depthbuffer_.buffer[ depthbuffer_.curCons ].GetImageData() );
116 depthbuffer_.curCons = (depthbuffer_.curCons+1) % buffersize_;
117 sem_post(&depthbuffer_.sProd);
122 int VideoSource_Kinect2Net::GetNumDevices(){
void CopyIn_NoInit(void *data)
Take some data and fill it into the Image.
int RegisterMsg(std::string msgName, EdataType dataType, int amount=1)
only registered msgs are accepted by commPartners Register a msg with this functions.
int ConnectServer(std::string serverName, unsigned int port=D_CS_DEFAULT_PORT, unsigned int timeOut=20000)
for a client: tries to connect to server with hostname serverName.
void SetVerbose(bool on)
gives some information about establising conn, and disconnecting etc.
The image template class for specific storage types.
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
Checks for VideoSource capabilities.
This is the base class for images in BIAS.
Provides remote access to a Microsoft Kinect2 camera.
int GetData(const std::string &msgName, std::vector< float > &floatData)
returns instantly:<br> 0 if new data has arrived and the data in xxxData 1 if no new data has arri...