1793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifdef HAVE_INTELPERC 2793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 3793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "cap_intelperc.hpp" 4793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 5793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernamespace cv 6793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 7793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 8793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler///////////////// IntelPerCStreamBase ////////////////// 9793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 10793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIntelPerCStreamBase::IntelPerCStreamBase() 11793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler : m_profileIdx(-1) 12793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler , m_frameIdx(0) 13793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler , m_timeStampStartNS(0) 14793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 15793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 16793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIntelPerCStreamBase::~IntelPerCStreamBase() 17793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 18793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 19793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 20793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamBase::isValid() 21793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 22793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (m_device.IsValid() && m_stream.IsValid()); 23793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 24793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamBase::grabFrame() 25793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 26793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_stream.IsValid()) 27793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 28793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (-1 == m_profileIdx) 29793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 30793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!setProperty(CV_CAP_PROP_INTELPERC_PROFILE_IDX, 0)) 31793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 32793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 33793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCSmartSP sp; 34793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_pxcImage.ReleaseRef(); 35793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR > m_stream->ReadStreamAsync(&m_pxcImage, &sp)) 36793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 37793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR > sp->Synchronize()) 38793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 39793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (0 == m_timeStampStartNS) 40793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_timeStampStartNS = m_pxcImage->QueryTimeStamp(); 41793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_timeStamp = (double)((m_pxcImage->QueryTimeStamp() - m_timeStampStartNS) / 10000); 42793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_frameIdx++; 43793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return true; 44793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 45793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint IntelPerCStreamBase::getProfileIDX() const 46793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 47793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return m_profileIdx; 48793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 49793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdouble IntelPerCStreamBase::getProperty(int propIdx) const 50793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 51793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler double ret = 0.0; 52793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler switch (propIdx) 53793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 54793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_INTELPERC_PROFILE_COUNT: 55793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ret = (double)m_profiles.size(); 56793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 57793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_FRAME_WIDTH : 58793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if ((0 <= m_profileIdx) && (m_profileIdx < m_profiles.size())) 59793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ret = (double)m_profiles[m_profileIdx].imageInfo.width; 60793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 61793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_FRAME_HEIGHT : 62793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if ((0 <= m_profileIdx) && (m_profileIdx < m_profiles.size())) 63793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ret = (double)m_profiles[m_profileIdx].imageInfo.height; 64793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 65793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_FPS : 66793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if ((0 <= m_profileIdx) && (m_profileIdx < m_profiles.size())) 67793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 68793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ret = ((double)m_profiles[m_profileIdx].frameRateMin.numerator / (double)m_profiles[m_profileIdx].frameRateMin.denominator 69793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler + (double)m_profiles[m_profileIdx].frameRateMax.numerator / (double)m_profiles[m_profileIdx].frameRateMax.denominator) / 2.0; 70793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 71793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 72793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_POS_FRAMES: 73793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ret = (double)m_frameIdx; 74793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 75793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_POS_MSEC: 76793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ret = m_timeStamp; 77793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 78793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }; 79793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return ret; 80793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 81793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamBase::setProperty(int propIdx, double propVal) 82793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 83793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool isSet = false; 84793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler switch (propIdx) 85793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 86793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_INTELPERC_PROFILE_IDX: 87793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 88793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int propValInt = (int)propVal; 89793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (0 > propValInt) 90793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 91793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_profileIdx = propValInt; 92793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler isSet = true; 93793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 94793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler else if (propValInt < m_profiles.size()) 95793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 96793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (m_profileIdx != propValInt) 97793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 98793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_profileIdx = propValInt; 99793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (m_stream.IsValid()) 100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_stream->SetProfile(&m_profiles[m_profileIdx]); 101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_frameIdx = 0; 102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_timeStampStartNS = 0; 103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler isSet = true; 105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }; 109793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return isSet; 110793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamBase::initDevice(PXCSession *session) 112793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 113793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (NULL == session) 114793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 115793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 116793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler pxcStatus sts = PXC_STATUS_NO_ERROR; 117793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCSession::ImplDesc templat; 118793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler memset(&templat,0,sizeof(templat)); 119793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler templat.group = PXCSession::IMPL_GROUP_SENSOR; 120793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler templat.subgroup= PXCSession::IMPL_SUBGROUP_VIDEO_CAPTURE; 121793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 122793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler for (int modidx = 0; PXC_STATUS_NO_ERROR <= sts; modidx++) 123793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 124793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCSession::ImplDesc desc; 125793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler sts = session->QueryImpl(&templat, modidx, &desc); 126793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR > sts) 127793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 128793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 129793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCSmartPtr<PXCCapture> capture; 130793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler sts = session->CreateImpl<PXCCapture>(&desc, &capture); 131793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!capture.IsValid()) 132793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler continue; 133793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 134793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler /* enumerate devices */ 135793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler for (int devidx = 0; PXC_STATUS_NO_ERROR <= sts; devidx++) 136793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 137793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCSmartPtr<PXCCapture::Device> device; 138793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler sts = capture->CreateDevice(devidx, &device); 139793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR <= sts) 140793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 141793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_device = device.ReleasePtr(); 142793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return true; 143793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 144793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 145793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 146793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 147793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 148793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 149793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervoid IntelPerCStreamBase::initStreamImpl(PXCImage::ImageType type) 150793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 151793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 152793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return; 153793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 154793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler pxcStatus sts = PXC_STATUS_NO_ERROR; 155793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler /* enumerate streams */ 156793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler for (int streamidx = 0; PXC_STATUS_NO_ERROR <= sts; streamidx++) 157793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 158793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCCapture::Device::StreamInfo sinfo; 159793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler sts = m_device->QueryStream(streamidx, &sinfo); 160793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR > sts) 161793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 162793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXCCapture::VideoStream::CUID != sinfo.cuid) 163793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler continue; 164793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (type != sinfo.imageType) 165793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler continue; 166793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 167793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler sts = m_device->CreateStream<PXCCapture::VideoStream>(streamidx, &m_stream); 168793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == sts) 169793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 170793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_stream.ReleaseRef(); 171793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 172793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 173793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamBase::validProfile(const PXCCapture::VideoStream::ProfileInfo& /*pinfo*/) 174793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 175793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return true; 176793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 177793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervoid IntelPerCStreamBase::enumProfiles() 178793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 179793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_profiles.clear(); 180793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_stream.IsValid()) 181793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return; 182793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler pxcStatus sts = PXC_STATUS_NO_ERROR; 183793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler for (int profidx = 0; PXC_STATUS_NO_ERROR <= sts; profidx++) 184793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 185793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCCapture::VideoStream::ProfileInfo pinfo; 186793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler sts = m_stream->QueryProfile(profidx, &pinfo); 187793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR > sts) 188793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 189793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (validProfile(pinfo)) 190793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_profiles.push_back(pinfo); 191793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 192793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 193793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 194793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler///////////////// IntelPerCStreamImage ////////////////// 195793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 196793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIntelPerCStreamImage::IntelPerCStreamImage() 197793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 198793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 199793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIntelPerCStreamImage::~IntelPerCStreamImage() 200793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 201793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 202793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 203793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamImage::initStream(PXCSession *session) 204793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 205793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!initDevice(session)) 206793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 207793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler initStreamImpl(PXCImage::IMAGE_TYPE_COLOR); 208793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_stream.IsValid()) 209793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 210793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler enumProfiles(); 211793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return true; 212793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 213793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdouble IntelPerCStreamImage::getProperty(int propIdx) const 214793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 215793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler switch (propIdx) 216793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 217793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_BRIGHTNESS: 218793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 219793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 220793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 221793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 222793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_COLOR_BRIGHTNESS, &fret)) 223793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 224793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 225793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 226793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 227793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_CONTRAST: 228793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 229793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 230793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 231793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 232793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_COLOR_CONTRAST, &fret)) 233793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 234793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 235793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 236793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 237793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_SATURATION: 238793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 239793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 240793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 241793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 242793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_COLOR_SATURATION, &fret)) 243793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 244793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 245793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 246793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 247793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_HUE: 248793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 249793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 250793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 251793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 252793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_COLOR_HUE, &fret)) 253793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 254793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 255793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 256793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 257793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_GAMMA: 258793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 259793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 260793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 261793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 262793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_COLOR_GAMMA, &fret)) 263793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 264793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 265793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 266793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 267793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_SHARPNESS: 268793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 269793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 270793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 271793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 272793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_COLOR_SHARPNESS, &fret)) 273793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 274793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 275793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 276793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 277793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_GAIN: 278793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 279793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 280793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 281793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 282793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_COLOR_GAIN, &fret)) 283793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 284793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 285793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 286793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 287793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_BACKLIGHT: 288793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 289793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 290793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 291793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 292793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_COLOR_BACK_LIGHT_COMPENSATION, &fret)) 293793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 294793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 295793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 296793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 297793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_EXPOSURE: 298793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 299793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 300793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 301793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 302793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_COLOR_EXPOSURE, &fret)) 303793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 304793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 305793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 306793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 307793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler //Add image stream specific properties 308793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 309793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return IntelPerCStreamBase::getProperty(propIdx); 310793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 311793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamImage::setProperty(int propIdx, double propVal) 312793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 313793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler switch (propIdx) 314793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 315793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_BRIGHTNESS: 316793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 317793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 318793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 319793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_COLOR_BRIGHTNESS, (float)propVal)); 320793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 321793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 322793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_CONTRAST: 323793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 324793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 325793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 326793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_COLOR_CONTRAST, (float)propVal)); 327793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 328793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 329793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_SATURATION: 330793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 331793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 332793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 333793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_COLOR_SATURATION, (float)propVal)); 334793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 335793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 336793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_HUE: 337793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 338793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 339793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 340793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_COLOR_HUE, (float)propVal)); 341793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 342793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 343793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_GAMMA: 344793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 345793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 346793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 347793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_COLOR_GAMMA, (float)propVal)); 348793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 349793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 350793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_SHARPNESS: 351793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 352793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 353793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 354793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_COLOR_SHARPNESS, (float)propVal)); 355793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 356793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 357793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_GAIN: 358793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 359793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 360793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 361793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_COLOR_GAIN, (float)propVal)); 362793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 363793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 364793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_BACKLIGHT: 365793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 366793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 367793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 368793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_COLOR_BACK_LIGHT_COMPENSATION, (float)propVal)); 369793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 370793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 371793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_EXPOSURE: 372793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 373793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 374793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 375793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_COLOR_EXPOSURE, (float)propVal)); 376793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 377793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 378793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler //Add image stream specific properties 379793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 380793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return IntelPerCStreamBase::setProperty(propIdx, propVal); 381793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 382793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamImage::retrieveAsOutputArray(cv::OutputArray image) 383793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 384793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_pxcImage.IsValid()) 385793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 386793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCImage::ImageInfo info; 387793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_pxcImage->QueryInfo(&info); 388793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 389793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCImage::ImageData data; 390793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_pxcImage->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::COLOR_FORMAT_RGB24, &data); 391793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 392793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXCImage::SURFACE_TYPE_SYSTEM_MEMORY != data.type) 393793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 394793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 395793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::Mat temp(info.height, info.width, CV_8UC3, data.planes[0], data.pitches[0]); 396793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler temp.copyTo(image); 397793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 398793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_pxcImage->ReleaseAccess(&data); 399793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return true; 400793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 401793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 402793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler///////////////// IntelPerCStreamDepth ////////////////// 403793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 404793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIntelPerCStreamDepth::IntelPerCStreamDepth() 405793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 406793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 407793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerIntelPerCStreamDepth::~IntelPerCStreamDepth() 408793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 409793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 410793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 411793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamDepth::initStream(PXCSession *session) 412793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 413793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!initDevice(session)) 414793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 415793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler initStreamImpl(PXCImage::IMAGE_TYPE_DEPTH); 416793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_stream.IsValid()) 417793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 418793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler enumProfiles(); 419793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return true; 420793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 421793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdouble IntelPerCStreamDepth::getProperty(int propIdx) const 422793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 423793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler switch (propIdx) 424793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 425793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_INTELPERC_DEPTH_LOW_CONFIDENCE_VALUE: 426793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 427793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 428793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 429793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 430793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_DEPTH_LOW_CONFIDENCE_VALUE, &fret)) 431793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 432793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 433793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 434793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 435793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE: 436793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 437793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 438793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 439793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 440793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_DEPTH_SATURATION_VALUE, &fret)) 441793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 442793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 443793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 444793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 445793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_INTELPERC_DEPTH_CONFIDENCE_THRESHOLD: 446793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 447793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 448793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 449793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float fret = 0.0f; 450793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryProperty(PXCCapture::Device::PROPERTY_DEPTH_CONFIDENCE_THRESHOLD, &fret)) 451793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)fret; 452793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 453793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 454793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 455793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_HORZ: 456793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 457793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 458793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0f; 459793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCPointF32 ptf; 460793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryPropertyAsPoint(PXCCapture::Device::PROPERTY_DEPTH_FOCAL_LENGTH, &ptf)) 461793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)ptf.x; 462793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 463793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 464793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 465793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_VERT: 466793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 467793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 468793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0f; 469793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCPointF32 ptf; 470793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR == m_device->QueryPropertyAsPoint(PXCCapture::Device::PROPERTY_DEPTH_FOCAL_LENGTH, &ptf)) 471793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)ptf.y; 472793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0.0; 473793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 474793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 475793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler //Add depth stream sepcific properties 476793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 477793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return IntelPerCStreamBase::getProperty(propIdx); 478793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 479793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamDepth::setProperty(int propIdx, double propVal) 480793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 481793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler switch (propIdx) 482793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 483793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_INTELPERC_DEPTH_LOW_CONFIDENCE_VALUE: 484793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 485793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 486793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 487793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_DEPTH_LOW_CONFIDENCE_VALUE, (float)propVal)); 488793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 489793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 490793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE: 491793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 492793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 493793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 494793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_DEPTH_SATURATION_VALUE, (float)propVal)); 495793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 496793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 497793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_PROP_INTELPERC_DEPTH_CONFIDENCE_THRESHOLD: 498793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 499793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_device.IsValid()) 500793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 501793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXC_STATUS_NO_ERROR == m_device->SetProperty(PXCCapture::Device::PROPERTY_DEPTH_CONFIDENCE_THRESHOLD, (float)propVal)); 502793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 503793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler break; 504793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler //Add depth stream sepcific properties 505793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 506793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return IntelPerCStreamBase::setProperty(propIdx, propVal); 507793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 508793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamDepth::retrieveDepthAsOutputArray(cv::OutputArray image) 509793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 510793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return retriveFrame(CV_16SC1, 0, image); 511793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 512793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamDepth::retrieveIRAsOutputArray(cv::OutputArray image) 513793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 514793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return retriveFrame(CV_16SC1, 1, image); 515793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 516793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamDepth::retrieveUVAsOutputArray(cv::OutputArray image) 517793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 518793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return retriveFrame(CV_32FC2, 2, image); 519793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 520793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamDepth::validProfile(const PXCCapture::VideoStream::ProfileInfo& pinfo) 521793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 522793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (PXCImage::COLOR_FORMAT_DEPTH == pinfo.imageInfo.format); 523793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 524793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool IntelPerCStreamDepth::retriveFrame(int type, int planeIdx, cv::OutputArray frame) 525793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 526793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!m_pxcImage.IsValid()) 527793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 528793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCImage::ImageInfo info; 529793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_pxcImage->QueryInfo(&info); 530793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 531793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler PXCImage::ImageData data; 532793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_pxcImage->AcquireAccess(PXCImage::ACCESS_READ, &data); 533793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 534793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXCImage::SURFACE_TYPE_SYSTEM_MEMORY != data.type) 535793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 536793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 537793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::Mat temp(info.height, info.width, type, data.planes[planeIdx], data.pitches[planeIdx]); 538793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler temp.copyTo(frame); 539793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 540793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_pxcImage->ReleaseAccess(&data); 541793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return true; 542793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 543793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 544793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler///////////////// VideoCapture_IntelPerC ////////////////// 545793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 546793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerVideoCapture_IntelPerC::VideoCapture_IntelPerC() 547793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler : m_contextOpened(false) 548793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 549793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler pxcStatus sts = PXCSession_Create(&m_session); 550793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (PXC_STATUS_NO_ERROR > sts) 551793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return; 552793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_contextOpened = m_imageStream.initStream(m_session); 553793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler m_contextOpened &= m_depthStream.initStream(m_session); 554793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 555793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerVideoCapture_IntelPerC::~VideoCapture_IntelPerC(){} 556793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 557793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerdouble VideoCapture_IntelPerC::getProperty(int propIdx) const 558793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 559793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler double propValue = 0; 560793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int purePropIdx = propIdx & ~CV_CAP_INTELPERC_GENERATORS_MASK; 561793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (CV_CAP_INTELPERC_IMAGE_GENERATOR == (propIdx & CV_CAP_INTELPERC_GENERATORS_MASK)) 562793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 563793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler propValue = m_imageStream.getProperty(purePropIdx); 564793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 565793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler else if (CV_CAP_INTELPERC_DEPTH_GENERATOR == (propIdx & CV_CAP_INTELPERC_GENERATORS_MASK)) 566793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 567793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler propValue = m_depthStream.getProperty(purePropIdx); 568793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 569793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler else 570793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 571793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler propValue = m_depthStream.getProperty(purePropIdx); 572793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 573793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return propValue; 574793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 575793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool VideoCapture_IntelPerC::setProperty(int propIdx, double propVal) 576793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 577793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool isSet = false; 578793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int purePropIdx = propIdx & ~CV_CAP_INTELPERC_GENERATORS_MASK; 579793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (CV_CAP_INTELPERC_IMAGE_GENERATOR == (propIdx & CV_CAP_INTELPERC_GENERATORS_MASK)) 580793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 581793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler isSet = m_imageStream.setProperty(purePropIdx, propVal); 582793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 583793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler else if (CV_CAP_INTELPERC_DEPTH_GENERATOR == (propIdx & CV_CAP_INTELPERC_GENERATORS_MASK)) 584793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 585793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler isSet = m_depthStream.setProperty(purePropIdx, propVal); 586793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 587793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler else 588793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 589793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler isSet = m_depthStream.setProperty(purePropIdx, propVal); 590793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 591793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return isSet; 592793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 593793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 594793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool VideoCapture_IntelPerC::grabFrame() 595793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 596793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (!isOpened()) 597793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 598793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 599793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool isGrabbed = false; 600793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (m_depthStream.isValid()) 601793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler isGrabbed = m_depthStream.grabFrame(); 602793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if ((m_imageStream.isValid()) && (-1 != m_imageStream.getProfileIDX())) 603793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler isGrabbed &= m_imageStream.grabFrame(); 604793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 605793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return isGrabbed; 606793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 607793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool VideoCapture_IntelPerC::retrieveFrame(int outputType, cv::OutputArray frame) 608793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 609793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler switch (outputType) 610793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 611793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_INTELPERC_DEPTH_MAP: 612793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return m_depthStream.retrieveDepthAsOutputArray(frame); 613793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_INTELPERC_UVDEPTH_MAP: 614793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return m_depthStream.retrieveUVAsOutputArray(frame); 615793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_INTELPERC_IR_MAP: 616793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return m_depthStream.retrieveIRAsOutputArray(frame); 617793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler case CV_CAP_INTELPERC_IMAGE: 618793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return m_imageStream.retrieveAsOutputArray(frame); 619793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 620793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return false; 621793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 622793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint VideoCapture_IntelPerC::getCaptureDomain() 623793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 624793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return CV_CAP_INTELPERC; 625793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 626793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 627793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerbool VideoCapture_IntelPerC::isOpened() const 628793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 629793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return m_contextOpened; 630793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 631793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 632793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 633793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 634793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif //HAVE_INTELPERC 635